Soldato
Right, so I'm a front end dev and don't really dabble in much else (yet).
Basically I'm using CMSMS and the LISE/Listit module. Sadly the module has a terrible search so I'm writing a plugin that will query the modules tables and pull back what I need back into the template (Smarty). This means the user can still use the modules admin which is nice and easy to use and I'm displaying the
I have somehow managed to make it work despite limited experience, despite one issues where I'm now stuck and would like some help please.
The search is explicit in that the categories (makes) and titles (models) are pulled into the search form dynamically so there's no free-form user input there and no guessing as such.
The problem is it pulls through all the data fine and spits it out, but if you search 'any' for the category (make) it doesn't pull through a name as it's not being searched against. I now it would never work as I have done it, but I'm not sure how I would go about making it work.
The problem is there's a table for the items, table for the categories (makes) and a table that says what items are in each category. Code and tables below:
cms_module_lisevehicles_item_categories:
cms_module_lisevehicles_category:
cms_module_lisevehicles_item:
Any help would be greatly appreciated. I'm sure it could be done better and my logics probably all wrong. Any insight on making it better and cleaner would be amazing <3
Basically I'm using CMSMS and the LISE/Listit module. Sadly the module has a terrible search so I'm writing a plugin that will query the modules tables and pull back what I need back into the template (Smarty). This means the user can still use the modules admin which is nice and easy to use and I'm displaying the
I have somehow managed to make it work despite limited experience, despite one issues where I'm now stuck and would like some help please.
The search is explicit in that the categories (makes) and titles (models) are pulled into the search form dynamically so there's no free-form user input there and no guessing as such.
The problem is it pulls through all the data fine and spits it out, but if you search 'any' for the category (make) it doesn't pull through a name as it's not being searched against. I now it would never work as I have done it, but I'm not sure how I would go about making it work.
The problem is there's a table for the items, table for the categories (makes) and a table that says what items are in each category. Code and tables below:
PHP:
function smarty_cms_function_vehicles($params, &$smarty) {
# Get parameters of the search
$search_parameters = [];
if (!empty($_GET) || isset($params)) {
$parameters = $params;
if (!empty($_GET)) { # URL Parameters or search form submitted via GET (default)
$search_parameters = $_GET;
} else if (!empty($parameters)) { # Directly called
$search_parameters = $parameters;
}
# Assign incoming values to search chunks
foreach ($search_parameters as $key => $value) {
if (is_array($value)) {
$value = implode(',', $value);
} else {
$value = ($value == 'any' || $value == 'Select Model') ? '' : $value;
}
$search_chunks[$key] = $value;
$make = $search_chunks['make'];
$model = $search_chunks['model'];
}
}
if (!function_exists('getMake')) {
function getMake($make) {
# Get make
$db = cmsms()->GetDb();
$sql = "SELECT * FROM cms_module_lisevehicles_category WHERE category_name=? LIMIT 1";
$result = $db->Execute($sql, [
$make
]);
$row = $result->FetchRow();
$make = $row['category_id'];
$makeName = $row['category_name'];
return array($make, $makeName);
}
}
$makes = getMake($make);
$make = $makes[0];
$makeName = $makes[1];
if (!function_exists('getIds')) {
function getIds($make) {
$ids = [];
# Get ids
$db = cmsms()->GetDb();
$sql = "SELECT item_id FROM cms_module_lisevehicles_item_categories WHERE category_id=?";
$result = $db->Execute($sql, [
$make
]);
while($row = $result->FetchRow()) {
$id = $row['item_id'];
$ids[] = $id;
}
return $ids;
}
}
$test = getIds($make);
$ids = implode(',',array_map('intval',$test));
if (!function_exists('getVehicles')) {
function getVehicles($ids,$model,$makeName) {
$vehicles = [];
# Get vehicles
$db = cmsms()->GetDb();
if (empty($ids) && empty($model)) {
$sql = "SELECT * FROM cms_module_lisevehicles_item";
$result = $db->Execute($sql);
} else if (empty($model)) {
$sql = "SELECT * FROM cms_module_lisevehicles_item WHERE item_id IN($ids)";
$result = $db->Execute($sql);
} else if (!empty($model)) {
$sql = "SELECT * FROM cms_module_lisevehicles_item WHERE item_id IN($ids) AND title=?";
$result = $db->Execute($sql, [
$model
]);
}
while($row = $result->FetchRow()) {
$vehicle = new stdClass();
$vehicle->make = $makeName;
$vehicle->model = $row['title'];
$vehicles[] = $vehicle;
}
return $vehicles;
}
}
$vehicles = getVehicles($ids,$model,$makeName);
$smarty->assign('vehicles', $vehicles);
}
cms_module_lisevehicles_item_categories:
cms_module_lisevehicles_category:
cms_module_lisevehicles_item:
Any help would be greatly appreciated. I'm sure it could be done better and my logics probably all wrong. Any insight on making it better and cleaner would be amazing <3