Hey guys,
First, thank you for a great extension. I'm working on a commercial project where we use both Cobalt 8 and Emerald 9 and although both Components are great there is quite a lot of custom modules that we need to build.
Right now I'm trying to get my head around how to use the filter function of cobalt.
What I want to do is getting records from a specific Category and it's sub categories and then filter it based on selected tags.
Here is the code so far.
private function getRecordsByTags($tags,$category_id) {
include_once JPATH_ROOT. DIRECTORY_SEPARATOR .'components'. DIRECTORY_SEPARATOR .'com_cobalt'. DIRECTORY_SEPARATOR .'api.php';
$db = JFactory::getDbo();
$tags_by_id = array();
foreach($tags as $tag) {
$sql = 'SELECT id FROM #__js_res_tags WHERE tag = "' . $tag . '"';
$db->setQuery($sql);
$result = $db->loadObject();
array_push($tags_by_id,$result->id);
}
ArrayHelper::clean_r($tags_by_id);
JArrayHelper::toInteger($tags_by_id);
$app = JFactory::getApplication('site');
$app->setUserState('com_cobalt.filter_tag', $tags_by_id);
$params = new JRegistry;
$params->set('section_id', 4);
$params->set('cat_restrict', 0);
$params->set('catids',$category_id);
$params->set('tmpl', 'result_array');
$app = JFactory::getApplication();
$api = new CobaltApi();
$result = $api->records(
$params->get('section_id'),
$params->get('view_what', 'all'),
$params->get('orderby'),
$params->get('types', 0),
$user_id,
$cat_id,
$params->get('limit', 5),
$params->get('tmpl'),
false,
false,
$params->get('lang_mode', 0));
/* Display the records in $category_id filtered by tags */
foreach($result{'list'} as $record) {
echo '<h5>'.$record->title.'</h5>';
}
}
I have no problem getting the records but the filter don't seem to work, would you like to help me to understand what I'm doing wrong?
Thank you very much.
Hey guys,
First, thank you for a great extension. I'm working on a commercial project where we use both Cobalt 8 and Emerald 9 and although both Components are great there is quite a lot of custom modules that we need to build.
Right now I'm trying to get my head around how to use the filter function of cobalt.
What I want to do is getting records from a specific Category and it's sub categories and then filter it based on selected tags.
Here is the code so far.
I have no problem getting the records but the filter don't seem to work, would you like to help me to understand what I'm doing wrong?
Thank you very much.