function __construct() { $mainframe = JFactory::getApplication(); $db = Komento::getDBO(); $this->limit = $mainframe->getUserStateFromRequest('com_komento.reports.limit', 'limit', $mainframe->getCfg('list_limit'), 'int'); $this->limitstart = $mainframe->getUserStateFromRequest('com_komento.reports.limitstart', 'limitstart', 0, 'int'); $this->filter_publish = $mainframe->getUserStateFromRequest('com_komento.reports.filter_publish', 'filter_publish', '*', 'string'); $this->filter_component = $mainframe->getUserStateFromRequest('com_komento.reports.filter_component', 'filter_component', '*', 'string'); $this->order = $mainframe->getUserStateFromRequest('com_komento.reports.filter_order', 'filter_order', 'created', 'cmd'); $this->order_dir = $mainframe->getUserStateFromRequest('com_komento.reports.filter_order_Dir', 'filter_order_Dir', 'DESC', 'word'); $this->search = $mainframe->getUserStateFromRequest('com_komento.reports.search', 'search', '', 'string'); Komento::import('helper', 'string'); $this->search = KomentoStringHelper::escape(trim(JString::strtolower($this->search))); parent::__construct(); }
function getData($options = array()) { $mainframe = JFactory::getApplication(); $view = JRequest::getVar('view'); // define default values $defaultOptions = array('no_tree' => 0, 'component' => '*', 'published' => '*', 'userid' => '', 'parent_id' => 0, 'no_search' => 0, 'no_child' => 0); // take the input values and clear unexisting keys $options = Komento::mergeOptions($defaultOptions, $options); $querySelect = ''; $querySelectCount = ''; $queryWhere = array(); $queryOrder = ''; $queryLimit = ''; $queryTotal = ''; $filter_publish = $mainframe->getUserStateFromRequest('com_komento.' . $view . '.filter_publish', 'filter_publish', $options['published'], 'string'); $filter_component = $mainframe->getUserStateFromRequest('com_komento.' . $view . '.filter_component', 'filter_component', $options['component'], 'string'); $filter_order = $mainframe->getUserStateFromRequest('com_komento.' . $view . '.filter_order', 'filter_order', 'created', 'string'); $filter_order_Dir = $mainframe->getUserStateFromRequest('com_komento.' . $view . '.filter_order_Dir', 'filter_order_Dir', 'DESC', 'word'); $search = $mainframe->getUserStateFromRequest('com_komento.' . $view . '.search', 'search', '', 'string'); $limit = $mainframe->getUserStateFromRequest('com_komento.' . $view . '.limit', 'limit', $mainframe->getCfg('list_limit'), 'int'); $limitstart = $mainframe->getUserStateFromRequest('com_komento.' . $view . '.limitstart', 'limitstart', 0, 'int'); Komento::import('helper', 'string'); $search = KomentoStringHelper::escape(trim(JString::strtolower($search))); // clear search if nosearch = 1 // for view parent purposes during search if ($options['no_search']) { $search = ''; } /*if( $options['no_tree'] == 0 ) { // $querySelect = 'SELECT x.*, COUNT(y.id) - 1 AS childs FROM ' . $this->db->namequote('#__komento_comments') . ' AS x'; // $querySelect .= ' INNER JOIN ' . $this->db->namequote('#__komento_comments') . ' AS y'; // $querySelect .= ' ON x.component = y.component'; // $querySelect .= ' AND x.cid = y.cid'; // $querySelect .= ' AND x.lft BETWEEN y.lft AND y.rgt'; $querySelect = 'SELECT * FROM ' . $this->db->nameQuote( '#__komento_comments' ); } else { $querySelect = 'SELECT x.*, y.depth FROM ('; $querySelect .= ' SELECT a.*, COUNT(a.id) - 1 AS childs FROM ' . $this->db->namequote('#__komento_comments') . ' AS a'; $querySelect .= ' INNER JOIN ' . $this->db->namequote('#__komento_comments') . ' AS b'; $querySelect .= ' WHERE a.component = b.component'; $querySelect .= ' AND a.cid = b.cid'; $querySelect .= ' AND b.lft BETWEEN a.lft AND a.rgt'; $querySelect .= ' GROUP BY a.id) AS x'; $querySelect .= ' LEFT JOIN ('; $querySelect .= ' SELECT a.*, COUNT(c.id) - 1 AS depth FROM ' . $this->db->namequote('#__komento_comments') . ' AS a'; $querySelect .= ' INNER JOIN ' . $this->db->namequote('#__komento_comments') . ' AS c'; $querySelect .= ' WHERE a.component = c.component'; $querySelect .= ' AND a.cid = c.cid'; $querySelect .= ' AND a.lft BETWEEN c.lft AND c.rgt'; $querySelect .= ' GROUP BY a.id) AS y ON x.id = y.id'; }*/ $querySelect = 'SELECT * FROM ' . $this->db->nameQuote('#__komento_comments'); $querySelectCount = 'SELECT COUNT(1) FROM ' . $this->db->nameQuote('#__komento_comments'); // filter by component if ($filter_component != '*') { $queryWhere[] = $this->db->nameQuote('component') . ' = ' . $this->db->quote($filter_component); } // filter by publish state if ($filter_publish != '*') { $queryWhere[] = $this->db->nameQuote('published') . ' = ' . $this->db->quote($filter_publish); } /* // filter by user // not implemented yet $filter_user = $mainframe->getUserStateFromRequest( 'com_komento.comments.filter_user', 'filter_user', '*', 'string' ); if($filter_user != '*') { $queryWhereForA[] = 'a.created_by = ' . $this->db->quote($filter_user); } */ if ($search) { $queryWhere[] = 'LOWER( ' . $this->db->nameQuote('comment') . ' ) LIKE \'%' . $search . '%\' '; } else { if ($options['no_tree'] == 0) { $queryWhere[] = $this->db->nameQuote('parent_id') . ' = ' . $this->db->quote($options['parent_id']); } } if (count($queryWhere) > 0) { $queryWhere = ' WHERE ' . implode(' AND ', $queryWhere); } else { $queryWhere = ''; } $queryOrder = ' ORDER BY ' . $filter_order . ' ' . $filter_order_Dir; if ($options['parent_id'] == 0 && $limit != 0) { $queryLimit = ' LIMIT ' . $limitstart . ',' . $limit; } $queryTotal = $querySelectCount . $queryWhere; // set pagination $this->db->setQuery($queryTotal); $this->_total = $this->db->loadResult(); jimport('joomla.html.pagination'); $this->_pagination = new JPagination($this->_total, $limitstart, $limit); // actual query $query = $querySelect . $queryWhere . $queryOrder . $queryLimit; $this->db->setQuery($query); $result = $this->db->loadObjectList(); if ($this->db->getErrorNum() > 0) { JError::raiseError($this->db->getErrorNum(), $this->db->getErrorMsg() . $this->db->stderr()); } if (!empty($result) && $options['no_child'] == 0) { $ids = array(); foreach ($result as $row) { $ids[] = $row->id; } $childCount = $this->getChildCount($ids); foreach ($result as &$row) { $row->childs = isset($childCount[$row->id]) ? $childCount[$row->id] : 0; } } return $result; }
public function escape( $val ) { return KomentoStringHelper::escape( $val ); }