/** * @since 1.2.5 */ public function getTotal() { if ($this->getState('fieldsandfilters.random.selected', false)) { return $this->getState('list.limit'); } return parent::getTotal(); }
/** * Constructor. * * @param array An optional associative array of configuration settings. * @see JController * @since 1.6 */ public function __construct($config = array()) { if (empty($config['filter_fields'])) { $config['filter_fields'] = array('id', 'a.id', 'title', 'a.title', 'alias', 'a.alias', 'checked_out', 'a.checked_out', 'checked_out_time', 'a.checked_out_time', 'catid', 'a.catid', 'category_title', 'state', 'a.state', 'access', 'a.access', 'access_level', 'created', 'a.created', 'created_by', 'a.created_by', 'ordering', 'a.ordering', 'featured', 'a.featured', 'language', 'a.language', 'hits', 'a.hits', 'publish_up', 'a.publish_up', 'publish_down', 'a.publish_down', 'fp.ordering'); } parent::__construct($config); }
/** * @return JQuery */ function _getListQuery() { // Create a new query object. $query = parent::_getListQuery(); // Filter by frontpage. if ($this->getState('filter.frontpage')) { $query->join('INNER', '#__content_frontpage AS fp ON fp.content_id = a.id'); } //echo nl2br(str_replace('#__','jos_',$query)); return $query; }
private static function _search($keyword = '') { $result = array(); require_once JPATH_ROOT . '/components/com_content/helpers/route.php'; require_once JPATH_ADMINISTRATOR . '/components/com_content/models/articles.php'; $a = new ContentModelArticles(); $db = $a->getDbo(); $query = $db->getQuery(true); // Select the required fields from the table. $query->select($a->getState('list.select', 'a.id, a.title, a.alias, a.catid, a.language')); $query->from('#__content AS a'); // Join over the categories. $query->select('c.title AS category_title')->join('LEFT', '#__categories AS c ON c.id = a.catid'); if (!empty($keyword)) { if (stripos($keyword, 'id:') === 0) { $query->where('a.id = ' . (int) substr($keyword, 3)); } elseif (stripos($keyword, 'author:') === 0) { $keyword2 = $db->quote('%' . $db->escape(substr($keyword, 7), true) . '%'); $query->where('(ua.name LIKE ' . $keyword2 . ' OR ua.username LIKE ' . $keyword2 . ')'); } else { $keyword2 = $db->quote('%' . str_replace(' ', '%', $db->escape(trim($keyword), true) . '%')); $query->where('(a.title LIKE ' . $keyword2 . ' OR a.alias LIKE ' . $keyword2 . ')'); } } $db->setQuery($query, 0, 10); $articles = $db->loadAssocList(); foreach ($articles as $article) { $result[] = array('title' => $article['title'], 'link' => ContentHelperRoute::getArticleRoute($article['id'], $article['catid'], $article['language']), 'info' => $article['category_title']); } $db = JFactory::getDbo(); $db->setQuery('SELECT * FROM #__menu WHERE title LIKE ' . $db->quote('%' . str_replace(' ', '%', $db->escape(trim($keyword), true) . '%')) . ' AND client_id = 0 AND menutype != "" LIMIT 0,10'); $menuItems = $db->loadAssocList(); foreach ($menuItems as $mi) { $result[] = array('title' => $mi['title'] . ' [' . $mi['menutype'] . ']', 'link' => $mi['link'], 'info' => n2_('Menu item')); } if (count($result) == 0 && !empty($keyword)) { return self::_search(); } return $result; }
private static function _search($keyword = '') { $result = array(); require_once JPATH_ROOT . '/components/com_content/helpers/route.php'; require_once JPATH_ADMINISTRATOR . '/components/com_content/models/articles.php'; $a = new ContentModelArticles(); $db = $a->getDbo(); $query = $db->getQuery(true); // Select the required fields from the table. $query->select($a->getState('list.select', 'a.id, a.title, a.introtext, a.images, a.alias, a.catid, a.language')); $query->from('#__content AS a'); // Join over the categories. $query->select('c.title AS category_title')->join('LEFT', '#__categories AS c ON c.id = a.catid'); if (!empty($keyword)) { if (stripos($keyword, 'id:') === 0) { $query->where('a.id = ' . (int) substr($keyword, 3)); } elseif (stripos($keyword, 'author:') === 0) { $keyword2 = $db->quote('%' . $db->escape(substr($keyword, 7), true) . '%'); $query->where('(ua.name LIKE ' . $keyword2 . ' OR ua.username LIKE ' . $keyword2 . ')'); } else { $keyword2 = $db->quote('%' . str_replace(' ', '%', $db->escape(trim($keyword), true) . '%')); $query->where('(a.title LIKE ' . $keyword2 . ' OR a.alias LIKE ' . $keyword2 . ')'); } } $db->setQuery($query, 0, 10); $articles = $db->loadAssocList(); foreach ($articles as $article) { $images = new N2Data($article['images'], true); $image = $images->get('image_fulltext', $images->get('image_intro', '')); if (substr($image, 0, 2) != '//' && substr($image, 0, 4) != 'http') { $image = JUri::root(false) . $image; } $result[] = array('title' => $article['title'], 'description' => $article['introtext'], 'image' => N2ImageHelper::dynamic($image), 'link' => ContentHelperRoute::getArticleRoute($article['id'], $article['catid'], $article['language']), 'info' => $article['category_title']); } if (count($result) == 0 && !empty($keyword)) { return self::_search(); } return $result; }
protected function getListQuery() { $db = $this->getDbo(); $query = parent::getListQuery(); if(strpos((string)$query->__get('select'), 'introtext') === false) { $query->select('a.'. $db->qn('introtext')); } // $query->select('CASE WHEN CHAR_LENGTH(a.'. $db->qn('introtext').') > 0 THEN a.' // . $db->qn('introtext'). ' ELSE a.'. $db->qn('fulltext'). ' END AS description'); return $query; }
/** * override method */ function _getListQuery() { $query = parent::_getListQuery(); $aId = $this->getState('filter.a_id'); if (is_numeric($aId)) { $type = $this->getState('filter.a_id.include', true) ? '= ' : '<>'; $query->where('a.id ' . $type . (int) $aId); } else { if (is_array($aId)) { JArrayHelper::toInteger($aId); $aId = implode(',', $aId); $type = $this->getState('filter.a_id.include', true) ? 'IN' : 'NOT IN'; $query->where('a.id ' . $type . ' (' . $aId . ')'); } } return $query; }
protected function populateState($ordering = null, $direction = null) { $app = JFactory::getApplication(); $session = JFactory::getSession(); if ($layout = JRequest::getVar('layout')) { $this->context .= '.'.$layout; } //$search = $this->getUserStateFromRequest($this->context.'.filter.search', 'filter_search'); $search = JRequest::getVar('filter_search'); $this->setState('filter.search', $search); //$access = $this->getUserStateFromRequest($this->context.'.filter.access', 'filter_access', 0, 'int'); $access = JRequest::getVar('filter_access'); $this->setState('filter.access', $access); //$authorId = $app->getUserStateFromRequest($this->context.'.filter.author_id', 'filter_author_id'); $authorId = JRequest::getVar('filter_author_id'); $this->setState('filter.author_id', $authorId); //$published = $this->getUserStateFromRequest($this->context.'.filter.published', 'filter_published', ''); $published = JRequest::getVar('published'); $this->setState('filter.published', $published); //$categoryId = $this->getUserStateFromRequest($this->context.'.filter.category_id', 'filter_category_id'); $categoryId = JRequest::getVar('category_id'); $this->setState('filter.category_id', $categoryId); //$language = $this->getUserStateFromRequest($this->context.'.filter.language', 'filter_language', ''); $language = JRequest::getVar('language'); $this->setState('filter.language', $language); if(JRequest::getVar('order_key')!==0 && JRequest::getVar('order_filter')!==0){ //print_r(JRequest::getVar('order_key'));print_r(JRequest::getVar('order_filter'));die; $orderCol = JRequest::getVar('order_key'); $orderDirn = JRequest::getVar('order_filter'); } //print_r($orderCol);print_r($orderDirn);die; parent::populateState('a.'.$orderCol, $orderDirn); }
/** * JModelLegacy override to add alternating value for $odd * * @param string $query The query. * @param integer $limitstart Offset. * @param integer $limit The number of records. * * @return array An array of results. * * @since 12.2 * @throws RuntimeException */ protected function _getList($query, $limitstart = 0, $limit = 0) { $result = parent::_getList($query, $limitstart, $limit); $odd = 1; foreach ($result as $k => $row) { $result[$k]->odd = $odd; $odd = 1 - $odd; } return $result; }
/** * Method to auto-populate the model state. * * Note. Calling getState in this method will result in recursion. * * @param string $ordering An optional ordering field. * @param string $direction An optional direction (asc|desc). * * @return void * * @since 3.5 */ protected function populateState($ordering = 'a.title', $direction = 'asc') { parent::populateState($ordering, $direction); }
/** * Get the list of items. * * @return JDatabaseQuery */ protected function getListQuery() { // Set the blog ordering $params = $this->state->params; $articleOrderby = $params->get('orderby_sec', 'rdate'); $articleOrderDate = $params->get('order_date'); $categoryOrderby = $params->def('orderby_pri', ''); $secondary = ContentHelperQuery::orderbySecondary($articleOrderby, $articleOrderDate) . ', '; $primary = ContentHelperQuery::orderbyPrimary($categoryOrderby); $orderby = $primary . ' ' . $secondary . ' a.created DESC '; $this->setState('list.ordering', $orderby); $this->setState('list.direction', ''); // Create a new query object. $query = parent::getListQuery(); // Filter by frontpage. if ($this->getState('filter.frontpage')) { $query->join('INNER', '#__content_frontpage AS fp ON fp.content_id = a.id'); } // Filter by categories $featuredCategories = $this->getState('filter.frontpage.categories'); if (is_array($featuredCategories) && !in_array('', $featuredCategories)) { $query->where('a.catid IN (' . implode(',', $featuredCategories) . ')'); } return $query; }
protected function getStoreId($id = '') { // Compile the store id. $id .= ':' . $this->getState('tag.filter.search'); return parent::getStoreId($id); }
public function get() { //init variable $app = JFactory::getApplication(); $result = new stdClass(); $items = array(); $article_id = $app->input->get('id', 0, 'INT'); $catid = $app->input->get('category_id', 0, 'INT'); //featured - hide,only,show $featured = $app->input->get('featured', '', 'STRING'); $auther_id = $app->input->get('auther_id', 0, 'INT'); $limitstart = $app->input->get('limitstart', 0, 'INT'); $limit = $app->input->get('limit', 0, 'INT'); //range/relative - if range then startdate enddate mandetory $date_filtering = $app->input->get('date_filtering', '', 'STRING'); $start_date = $app->input->get('start_date_range', '', 'STRING'); $end_date = $app->input->get('end_date_range', '', 'STRING'); $realtive_date = $app->input->get('relative_date', '', 'STRING'); $listOrder = $app->input->get('listOrder', 'ASC', 'STRING'); $art_obj = new ContentModelArticles(); $art_obj->setState('list.direction', $listOrder); if ($limit) { $art_obj->setState('list.start', $limitstart); $art_obj->setState('list.limit', $limit); } //filter by category if ($catid) { $art_obj->setState('filter.category_id', $catid); } //filter by auther if ($auther_id) { $art_obj->setState('filter.author_id', $auther_id); } //filter by featured if ($featured) { $art_obj->setState('filter.featured', $featured); } //filter by article if ($article_id) { $art_obj->setState('filter.article_id', $article_id); } //filtering if ($date_filtering) { $art_obj->setState('filter.date_filtering', $date_filtering); if ($date_filtering == 'range') { $art_obj->setState('filter.start_date_range', $start_date); $art_obj->setState('filter.end_date_range', $end_date); } } /* //get article data if($article_id) { $artcl = new ContentModelArticle(); $adetails = $artcl->getItem($article_id); //$art_obj->setState('filter.article_id',$article_id ); }*/ $rows = $art_obj->getItems(); //test code /*JPluginHelper::importPlugin( 'content' ); $dispatcher = JEventDispatcher::getInstance(); $results = $dispatcher->trigger( 'onContentPrepare', array( 'com_content', &$row , ) ); */ // //format data $obj = new BlogappSimpleSchema(); //$dispatcher = JEventDispatcher::getInstance(); //$item = $obj->mapPost($a_data,'', 100, array('text')); foreach ($rows as $row) { if (!isset($row->text) || empty($row->text)) { $row->text = $row->introtext . " " . $row->fulltext; } /* $document = JFactory::getDocument(); $document->setType('html'); JPluginHelper::importPlugin( 'content' ); $dispatcher = JEventDispatcher::getInstance(); $dispatcher->trigger('onContentPrepare', array ('com_content.article', &$row, &$row->params, null)); */ $items[] = $obj->mapPost($row, '', 100, array()); } $this->plugin->setResponse($items); }
/** * Get the list of items. * * @return JDatabaseQuery */ protected function getListQuery() { // Create a new query object. $query = parent::getListQuery(); // Filter by categories $featuredCategories = $this->getState('filter.frontpage.categories'); if (is_array($featuredCategories) && !in_array('', $featuredCategories)) { $query->where('a.catid IN (' . implode(',', $featuredCategories) . ')'); } return $query; }