/** * <p>public static function get/load the templates object in the database</p> * @param boolean $onlyPublish - to get/load only the template that is publish (publish = 1) * @param boolean $onlyDefault - to load only the default template (premium = 1) * @param mixed $templateSearch - the template to be seach * @param int $start - start of query * @param int $limit - limit of query * @param availability - show only available templates */ public static function getTemplates($onlyPublish = true, $onlyDefault = false, $templateSearch = '', $start = -1, $limit = -1, $setSort = null, $onlyavailable = -1) { $db = JFactory::getDBO(); $query = 'SELECT * FROM `#__jnews_templates` '; $where[] = $onlyPublish ? ' `published`=1 ' : ' `published`<>-1 '; $where[] = $onlyDefault ? ' `premium`=1 ' : ' `premium`<>-1 '; //if the search of template is not empty //if the value is a numeric, we consider it as the template_id so we search by template_id if (!empty($templateSearch)) { if (is_numeric($templateSearch)) { $where[] = ' `template_id` =' . $templateSearch; } else { $where[] = ' (name LIKE \'%' . $templateSearch . '%\' OR namekey LIKE \'%' . $templateSearch . '%\') '; } } $query .= count($where) ? " WHERE " . implode(' AND ', $where) : ""; if ($onlyavailable == 1 && JRequest::getVAr('task') == 'assign') { $query .= ' AND `availability`=1 '; } if (!empty($setSort)) { $s = is_int($setSort->orderValue) ? "{$setSort->orderValue}" : "`{$setSort->orderValue}`"; $query .= "ORDER BY {$s} {$setSort->orderDir}"; } else { $query .= 'ORDER BY `premium` DESC, `created` DESC, `published` DESC, `ordering` ASC, `name` ASC'; } if ($start != -1 && $limit != -1) { $query .= ' LIMIT ' . $start . ', ' . $limit; } $db->setQuery($query); $templates = $db->loadObjectlist(); return $templates; }