/** * Helper for mod_knvbapi2 * * @param json/registry $params Module parameters * * @return array $items Items to display */ public static function getList(&$params) { // Get the dbo $db = JFactory::getDbo(); // Get an instance of the generic competities model $model = JModelLegacy::getInstance('Competities', 'Knvbapi2Model', array('ignore_request' => true)); // Set application parameters in model $app = JFactory::getApplication(); $app_params = $app->getParams(); $model->setState('params', $app_params); // Set the filters based on the module params $model->setState('list.start', 0); $model->setState('list.limit', (int) $params->get('count', 5)); $model->setState('filter.published', 1); // Access filter $access = !JComponentHelper::getParams('com_knvbapi2')->get('show_competitie_noauth'); $authorised = JAccess::getAuthorisedViewLevels(JFactory::getUser()->get('id')); $model->setState('filter.access', $access); // User filter $user_id = JFactory::getUser()->get('id'); switch ($params->get('user_id')) { case 'by_me': $model->setState('filter.created_by_id', (int) $user_id); break; case 'not_me': $model->setState('filter.created_by_id', $user_id); $model->setState('filter.created_by_id.include', false); break; case '0': break; default: $model->setState('filter.created_by_id', (int) $params->get('user_id')); break; } // Filter by language $model->setState('filter.language', JLanguageMultilang::isEnabled()); // Filter by featured $model->setState('filter.featured', $params->get('show_featured')); // Filter by language $model->setState('filter.language', JLanguageMultilang::isEnabled()); $order_map = array('m_dsc' => 'a.modified DESC, a.created', 'c_dsc' => 'a.created', 'p_dsc' => 'a.publish_up', 'h_dsc' => 'a.hits', 'n_asc' => 'a.name', 'n_dsc' => 'a.name', 'o_asc' => 'a.ordering'); $ordering = JArrayHelper::getValue($order_map, $params->get('ordering'), 'a.name'); if (JString::substr($params->get('ordering'), -3, 3) == 'dsc') { $dir = 'DESC'; } else { $dir = 'ASC'; } $model->setState('list.ordering', $ordering); $model->setState('list.direction', $dir); $items = $model->getItems(); if ($params->get('itemid') != '') { $item_id_str = '&Itemid=' . (string) $params->get('itemid'); $keep_item_id = false; } else { $item_id_str = ''; $keep_item_id = true; } if ($params->get('competitie_layout') != '') { $layout = str_replace('_:', '', (string) $params->get('competitie_layout')); $layout_str = '&layout=' . $layout; } else { $layout = ''; $layout_str = ''; } foreach ($items as &$item) { $item->slug = $item->id . ':' . $item->alias; if ($access or in_array($item->access, $authorised)) { if ($item_id_str == '') { // We know that user has the privilege to view the competitie $item->link = JRoute::_(Knvbapi2HelperRoute::getCompetitieRoute($item->slug, $item->language, $layout)); } else { $item->link = JRoute::_('index.php?option=com_knvbapi2&view=competitie' . $layout_str . $item_id_str . '&id=' . $item->id); } } else { $item->link = JRoute::_('index.php?option=com_users&view=login'); } } return $items; }
/** * Helper for mod_knvbapi2 * * @param json/registry $params Module parameters * * @return array $items Items to display */ public static function getList(&$params) { // Get the dbo $db = JFactory::getDbo(); $component_object_names = explode(':', $params->get('componentobject')); JModelLegacy::addIncludePath(JPATH_SITE . '/components/com_knvbapi2/models', 'Knvbapi2Model' . $component_object_names[1]); // Get an instance of the model $model = JModelLegacy::getInstance($component_object_names[1], 'Knvbapi2Model', array('ignore_request' => true)); // Set application parameters in model $app = JFactory::getApplication(); $app_params = $app->getParams(); $model->setState('params', $app_params); // Set the filters based on the module params $model->setState('list.start', 0); $model->setState('list.limit', (int) $params->get('count', 5)); $model->setState('filter.state', 1); // Access filter $access = !JComponentHelper::getParams('com_knvbapi2')->get('show_' . JString::strtolower($component_object_names[0]) . '_noauth'); $authorised = JAccess::getAuthorisedViewLevels(JFactory::getUser()->get('id')); $model->setState('filter.access', $access); // User filter $user_id = JFactory::getUser()->get('id'); switch ($params->get('user_id')) { case 'by_me': $model->setState('filter.created_by_id', (int) $user_id); break; case 'not_me': $model->setState('filter.created_by_id', $user_id); $model->setState('filter.created_by_id.include', false); break; case '0': break; default: $model->setState('filter.created_by_id', (int) $params->get('user_id')); break; } // Filter by language $model->setState('filter.language', JLanguageMultilang::isEnabled()); // Set ordering but check that the component object for ordering matches the slected component object if (JString::strtolower($component_object_names[1]) == JString::substr($params->get('ordering'), 0, JString::strlen($params->get('ordering')) - 6)) { $order_map = array('teamids m_dsc' => 'a.modified DESC, a.created', 'teamids c_dsc' => 'a.created', 'teamids p_dsc' => 'a.publish_up', 'teamids h_dsc' => 'a.hits', 'teamids n_asc' => 'a.name', 'teamids n_dsc' => 'a.name', 'teamids o_asc' => 'a.ordering', 'teamnaams m_dsc' => 'a.modified DESC, a.created', 'teamnaams c_dsc' => 'a.created', 'teamnaams p_dsc' => 'a.publish_up', 'teamnaams h_dsc' => 'a.hits', 'teamnaams n_asc' => 'a.name', 'teamnaams n_dsc' => 'a.name', 'teamnaams o_asc' => 'a.ordering', 'selecties m_dsc' => 'a.modified DESC, a.created', 'selecties c_dsc' => 'a.created', 'selecties p_dsc' => 'a.publish_up', 'selecties h_dsc' => 'a.hits', 'selecties n_asc' => 'a.name', 'selecties n_dsc' => 'a.name', 'selecties o_asc' => 'a.ordering', 'competities m_dsc' => 'a.modified DESC, a.created', 'competities c_dsc' => 'a.created', 'competities p_dsc' => 'a.publish_up', 'competities h_dsc' => 'a.hits', 'competities n_asc' => 'a.name', 'competities n_dsc' => 'a.name', 'competities o_asc' => 'a.ordering'); $ordering = JArrayHelper::getValue($order_map, $params->get('ordering')); } else { $ordering = 'a.id'; } if (JString::substr($params->get('ordering'), -3, 3) == 'dsc') { $dir = 'DESC'; } else { $dir = 'ASC'; } $model->setState('list.ordering', $ordering); $model->setState('list.direction', $dir); $items = $model->getItems(); if ($params->get('itemid') != '') { $item_id_str = '&Itemid=' . (string) $params->get('itemid'); $keep_item_id = false; } else { $item_id_str = ''; $keep_item_id = true; } foreach ($items as &$item) { if (isset($item->alias)) { $item->slug = $item->id . ':' . $item->alias; } else { $item->slug = $item->id; } if (isset($item->catid)) { $item->catslug = $item->catid . ':' . $item->category_alias; } if (!isset($item->access) or $access or in_array($item->access, $authorised)) { if ($item_id_str == '') { // We know that user has the privilege to view the item $route_function = 'get' . $component_object_names[0] . 'Route'; if (isset($item->catid) and isset($item->language)) { $item->link = JRoute::_(Knvbapi2HelperRoute::$route_function($item->slug, $item->catid, $item->language)); } else { if (isset($item->catid)) { $item->link = JRoute::_(Knvbapi2HelperRoute::$route_function($item->slug, $item->catid)); } else { if (isset($item->language)) { $item->link = JRoute::_(Knvbapi2HelperRoute::$route_function($item->slug, $item->language)); } else { $item->link = JRoute::_(Knvbapi2HelperRoute::$route_function($item->slug)); } } } } else { $item->link = JRoute::_('index.php?option=com_knvbapi2&view=' . JString::strtolower($component_object_names[0]) . $item_id_str . '&id=' . $item->id); } } else { $item->link = JRoute::_('index.php?option=com_users&view=login'); } } return $items; }