示例#1
0
/**
* Compiles a list of categories for a section
* @param database A database connector object
* @param string The name of the category section
* @param string The name of the current user
*/
function showSections($scope, $option)
{
    global $mainframe;
    $db =& JFactory::getDBO();
    $user =& JFactory::getUser();
    $filter_order = $mainframe->getUserStateFromRequest($option . '.filter_order', 'filter_order', 's.ordering', 'cmd');
    $filter_order_Dir = $mainframe->getUserStateFromRequest($option . '.filter_order_Dir', 'filter_order_Dir', '', 'word');
    $filter_state = $mainframe->getUserStateFromRequest($option . '.filter_state', 'filter_state', '', 'word');
    $search = $mainframe->getUserStateFromRequest($option . '.search', 'search', '', 'string');
    $search = JString::strtolower($search);
    $limit = $mainframe->getUserStateFromRequest('global.list.limit', 'limit', $mainframe->getCfg('list_limit'), 'int');
    $limitstart = $mainframe->getUserStateFromRequest($option . '.limitstart', 'limitstart', 0, 'int');
    $where[] = 's.scope = ' . $db->Quote($scope);
    if ($filter_state) {
        if ($filter_state == 'P') {
            $where[] = 's.published = 1';
        } else {
            if ($filter_state == 'U') {
                $where[] = 's.published = 0';
            }
        }
    }
    if ($search) {
        $where[] = 'LOWER(s.title) LIKE ' . $db->Quote('%' . $db->getEscaped($search, true) . '%', false);
    }
    $where = count($where) ? ' WHERE ' . implode(' AND ', $where) : '';
    $orderby = ' ORDER BY ' . $filter_order . ' ' . $filter_order_Dir . ', s.ordering';
    // get the total number of records
    $query = 'SELECT COUNT(*)' . ' FROM #__sections AS s' . $where;
    $db->setQuery($query);
    $total = $db->loadResult();
    jimport('joomla.html.pagination');
    $pageNav = new JPagination($total, $limitstart, $limit);
    $query = 'SELECT s.*, g.name AS groupname, u.name AS editor' . ' FROM #__sections AS s' . ' LEFT JOIN #__content AS cc ON s.id = cc.sectionid' . ' LEFT JOIN #__users AS u ON u.id = s.checked_out' . ' LEFT JOIN #__groups AS g ON g.id = s.access' . $where . ' GROUP BY s.id' . $orderby;
    $db->setQuery($query, $pageNav->limitstart, $pageNav->limit);
    $rows = $db->loadObjectList();
    if ($db->getErrorNum()) {
        echo $db->stderr();
        return false;
    }
    $count = count($rows);
    // number of Active Categories
    for ($i = 0; $i < $count; $i++) {
        $query = 'SELECT COUNT( a.id )' . ' FROM #__categories AS a' . ' WHERE a.section = ' . $db->Quote($rows[$i]->id) . ' AND a.published <> -2';
        $db->setQuery($query);
        $active = $db->loadResult();
        $rows[$i]->categories = $active;
    }
    // number of Active Items
    for ($i = 0; $i < $count; $i++) {
        $query = 'SELECT COUNT( a.id )' . ' FROM #__content AS a' . ' WHERE a.sectionid = ' . (int) $rows[$i]->id . ' AND a.state <> -2';
        $db->setQuery($query);
        $active = $db->loadResult();
        $rows[$i]->active = $active;
    }
    // number of Trashed Items
    for ($i = 0; $i < $count; $i++) {
        $query = 'SELECT COUNT( a.id )' . ' FROM #__content AS a' . ' WHERE a.sectionid = ' . (int) $rows[$i]->id . ' AND a.state = -2';
        $db->setQuery($query);
        $trash = $db->loadResult();
        $rows[$i]->trash = $trash;
    }
    // state filter
    $lists['state'] = JHTML::_('grid.state', $filter_state);
    // table ordering
    $lists['order_Dir'] = $filter_order_Dir;
    $lists['order'] = $filter_order;
    // search filter
    $lists['search'] = $search;
    sections_html::show($rows, $scope, $user->get('id'), $pageNav, $option, $lists);
}
示例#2
0
/**
* Compiles a list of categories for a section
* @param database A database connector object
* @param string The name of the category section
* @param string The name of the current user
*/
function showSections($scope, $option)
{
    global $database, $my, $mainframe, $mosConfig_list_limit;
    $limit = intval($mainframe->getUserStateFromRequest("viewlistlimit", 'limit', $mosConfig_list_limit));
    $limitstart = intval($mainframe->getUserStateFromRequest("view{$option}limitstart", 'limitstart', 0));
    // get the total number of records
    $query = "SELECT COUNT(*)" . "\n FROM #__sections" . "\n WHERE scope = " . $database->Quote($scope);
    $database->setQuery($query);
    $total = $database->loadResult();
    require_once $GLOBALS['mosConfig_absolute_path'] . '/administrator/includes/pageNavigation.php';
    $pageNav = new mosPageNav($total, $limitstart, $limit);
    $query = "SELECT c.*, g.name AS groupname, u.name AS editor" . "\n FROM #__sections AS c" . "\n LEFT JOIN #__content AS cc ON c.id = cc.sectionid" . "\n LEFT JOIN #__users AS u ON u.id = c.checked_out" . "\n LEFT JOIN #__groups AS g ON g.id = c.access" . "\n WHERE scope = " . $database->Quote($scope) . "\n GROUP BY c.id" . "\n ORDER BY c.ordering, c.name";
    $database->setQuery($query, $pageNav->limitstart, $pageNav->limit);
    $rows = $database->loadObjectList();
    if ($database->getErrorNum()) {
        echo $database->stderr();
        return false;
    }
    $count = count($rows);
    // number of Active Items
    for ($i = 0; $i < $count; $i++) {
        $query = "SELECT COUNT( a.id )" . "\n FROM #__categories AS a" . "\n WHERE a.section = '" . (int) $rows[$i]->id . "'" . "\n AND a.published != -2";
        $database->setQuery($query);
        $active = $database->loadResult();
        $rows[$i]->categories = $active;
    }
    // number of Active Items
    for ($i = 0; $i < $count; $i++) {
        $query = "SELECT COUNT( a.id )" . "\n FROM #__content AS a" . "\n WHERE a.sectionid = " . (int) $rows[$i]->id . "\n AND a.state != -2";
        $database->setQuery($query);
        $active = $database->loadResult();
        $rows[$i]->active = $active;
    }
    // number of Trashed Items
    for ($i = 0; $i < $count; $i++) {
        $query = "SELECT COUNT( a.id )" . "\n FROM #__content AS a" . "\n WHERE a.sectionid = " . (int) $rows[$i]->id . "\n AND a.state = -2";
        $database->setQuery($query);
        $trash = $database->loadResult();
        $rows[$i]->trash = $trash;
    }
    sections_html::show($rows, $scope, $my->id, $pageNav, $option);
}