public function display($tpl = null) { $this->items = $this->get('Items'); $this->pagination = $this->get('Pagination'); $this->state = $this->get('State'); $this->categories = Djc2Categories::getInstance(); $user = JFactory::getUser(); // Check for errors. if (count($errors = $this->get('Errors'))) { JError::raiseError(500, implode("\n", $errors)); return false; } $this->ordering = array(); foreach ($this->items as &$item) { if (!isset($this->ordering[$item->parent_id])) { $this->ordering[$item->parent_id] = array(); } $this->ordering[$item->parent_id][] = $item->id; } $this->addToolbar(); if (class_exists('JHtmlSidebar') && $user->authorise('core.admin')) { $this->sidebar = JHtmlSidebar::render(); } $version = new JVersion(); if (version_compare($version->getShortVersion(), '3.0.0', '<')) { $tpl = 'legacy'; } parent::display($tpl); }
function display($tpl = null) { JHTML::_('behavior.modal'); $app = JFactory::getApplication(); $document = JFactory::getDocument(); $model = $this->getModel(); $params = Djcatalog2Helper::getParams(); $menus = $app->getMenu('site'); $menu = $menus->getActive(); $dispatcher = JDispatcher::getInstance(); $categories = Djc2Categories::getInstance(array('state' => '1')); $item = $model->getData(); /* If Item not published set 404 */ if ($item->id == 0 || !$item->published) { throw new Exception(JText::_('COM_DJCATALOG2_PRODUCT_NOT_FOUND'), 404); } /* plugins */ JPluginHelper::importPlugin('djcatalog2'); $results = $dispatcher->trigger('onPrepareItemDescription', array(&$item, &$params, 0)); $this->assignref('categories', $categories); $this->assignref('item', $item); $this->assignref('images', $images); $this->assignref('params', $params); $this->_prepareDocument(); parent::display($tpl); }
public static function getHtml($cid, $expand, $params, $root_id = 0, $moduleId) { $user = JFactory::getUser(); $groups = $user->getAuthorisedViewLevels(); $categories = Djc2Categories::getInstance(array('state' => '1', 'access' => $groups)); $root = $categories->get(0); $class_sfx = htmlspecialchars($params->get('moduleclass_sfx', '')); $current = $categories->get($cid); $path = array(); if (!empty($current)) { foreach ($current->getPath() as $item) { $path[] = (int) $item; } } if ((int) $root_id > 0) { if ($new_root = $categories->get($root_id)) { $root = $new_root; } } $show_count = (bool) $params->get('display_counter', false); $layout = $params->get('category_layout', 'list'); $html = ''; if ($layout == 'list') { $html = '<ul class="menu' . $class_sfx . ' nav mod_djc2categories_list">'; self::makeList($html, $root, $path, $expand, $cid, 0, $show_count); $html .= '</ul>'; } else { $html = '<form class="mod_djc2categories_form" name="mod_djc2categories_form" id="mod_djc2categories_form-' . $moduleId . '" method="post" action="' . JRoute::_('index.php?option=com_djcatalog2&task=search') . '">'; $category_options = $categories->getOptionList('- ' . JText::_('MOD_DJC2CATEGORIES_SELECT_CATEGORY') . ' -'); if ((int) $root_id > 0) { $category_path = $current->getPath(); $parent_category = null; $parent_id = count($category_path) || (int) $cid == 0 ? $root_id : 0; $parent_category = $categories->get($parent_id); if ($parent_category) { $childrenList = array($parent_category->id); $parent_category->makeChildrenList($childrenList); foreach ($category_options as $key => $option) { if (!in_array($option->value, $childrenList)) { unset($category_options[$key]); } if ($option->value == $parent_category->id) { $category_options[$key]->text = '- ' . JText::_('MOD_DJC2CATEGORIES_SELECT_CATEGORY') . ' -'; } } } } $html .= JHTML::_('select.genericlist', $category_options, 'cid', 'class="inputbox mod_djc2categories_list" onchange="this.form.submit();"', 'value', 'text', $cid, 'mod_djc2categories_list-' . $moduleId); $html .= '<noscript><input type="submit" /></noscript>'; $html .= '</form>'; } return $html; }
function display($tpl = null) { $categories = Djc2Categories::getInstance(); $this->categories = $categories->getOptionList('- ' . JText::_('JNONE') . ' -'); $this->producers = $this->get('Producers'); $this->users = $this->get('Users'); $this->fieldgroups = $this->get('Fieldgroups'); $this->addToolbar(); if (class_exists('JHtmlSidebar')) { $this->sidebar = JHtmlSidebar::render(); } $version = new JVersion(); if (version_compare($version->getShortVersion(), '3.0.0', '<')) { $tpl = 'legacy'; } parent::display($tpl); }
function getProducers($filter_catid = 0) { if (!$this->_producers) { $db = JFactory::getDbo(); $query = null; if ($filter_catid > 0) { $categories = Djc2Categories::getInstance(array('state' => '1')); if ($parent = $categories->get((int) $filter_catid)) { $childrenList = array($parent->id); $parent->makeChildrenList($childrenList); $query = 'SELECT DISTINCT p.* ' . ' FROM #__djc2_producers as p ' . ' INNER JOIN #__djc2_items AS i ON p.id = i.producer_id ' . ' INNER JOIN #__djc2_categories AS c ON c.id = i.cat_id ' . ' WHERE c.id IN (' . implode(',', $childrenList) . ') AND p.published=1 ORDER BY p.name'; } } else { $query = 'SELECT p.* ' . ' FROM #__djc2_producers as p WHERE p.published=1 ORDER BY p.name'; } $db->setQuery($query); $this->_producers = $db->loadAssocList(); } return $this->_producers; }
public function display($tpl = null) { $this->items = $this->get('Items'); $this->pagination = $this->get('Pagination'); $this->state = $this->get('State'); $this->producers = $this->get('Producers'); $categories = Djc2Categories::getInstance(); $this->categories = $categories->getOptionList('- ' . JText::_('COM_DJCATALOG2_SELECT_CATEGORY') . ' -'); // Check for errors. if (count($errors = $this->get('Errors'))) { JError::raiseError(500, implode("\n", $errors)); return false; } JToolBarHelper::title(JText::_('COM_DJCATALOG2_RELATED_ITEMS'), 'generic.png'); $version = new JVersion(); if (version_compare($version->getShortVersion(), '3.0.0', '<')) { $tpl = 'legacy'; } parent::display($tpl); }
public function display($tpl = null) { $this->items = $this->get('Items'); $this->pagination = $this->get('Pagination'); $this->state = $this->get('State'); $this->producers = $this->get('Producers'); $categories = Djc2Categories::getInstance(); $this->categories = $categories->getOptionList('- ' . JText::_('COM_DJCATALOG2_SELECT_CATEGORY') . ' -'); // Check for errors. if (count($errors = $this->get('Errors'))) { JError::raiseError(500, implode("\n", $errors)); return false; } $this->addToolbar(); if (class_exists('JHtmlSidebar')) { $this->sidebar = JHtmlSidebar::render(); } $version = new JVersion(); if (version_compare($version->getShortVersion(), '3.0.0', '<')) { $tpl = 'legacy'; } parent::display($tpl); }
public static function getHtml($cid, $expand, $params, $root_id = 0) { $categories = Djc2Categories::getInstance(array('state' => '1')); $root = $categories->get(0); $class_sfx = htmlspecialchars($params->get('moduleclass_sfx', '')); $current = $categories->get($cid); $path = array(); if (!empty($current)) { foreach ($current->getPath() as $item) { $path[] = (int) $item; } } if ((int) $root_id > 0) { if ($new_root = $categories->get($root_id)) { $root = $new_root; } } $show_count = (bool) $params->get('display_counter', false); $html = '<ul class="menu' . $class_sfx . ' nav">'; self::makeList($html, $root, $path, $expand, $cid, 0, $show_count); $html .= '</ul>'; return $html; }
* but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with DJ-Catalog2. If not, see <http://www.gnu.org/licenses/>. * */ defined('_JEXEC') or die('Restricted access'); ?> <div class="djc_items mod_djc_items djc_clearfix" id="mod_djc_items-<?php echo $module_id; ?> "> <?php $categories = Djc2Categories::getInstance(array('state' => '1')); foreach ($items as $item) { $product_url = JRoute::_(DJCatalogHelperRoute::getItemRoute($item->slug, $item->catslug)); ?> <div class="djc_item mod_djc_item"> <?php if ($item->item_image && $params->get('showimage', '1') == '1' && ((int) $params->get('imagewidth', '120') > 0 || (int) $params->get('imageheight', '120') > 0)) { ?> <div class="djc_image"> <?php if ($params->get('linkimage', '1') == '1') { ?> <a href="<?php echo $product_url; ?> ">
public function display($tpl = null) { $app = JFactory::getApplication(); $jinput = $app->input; $user = JFactory::getUser(); $categories = Djc2Categories::getInstance(array('state' => '1')); $menus = $app->getMenu('site'); $menu = $menus->getActive(); JModelLegacy::addIncludePath(JPATH_BASE . DS . 'components' . DS . 'com_djcatalog2' . DS . 'models', 'DJCatalog2Model'); $model = JModelLegacy::getInstance('Items', 'Djcatalog2Model', array('ignore_request' => true)); $mOption = empty($menu->query['option']) ? null : $menu->query['option']; $mCatid = empty($menu->query['cid']) ? null : (int) $menu->query['cid']; $mProdid = empty($menu->query['pid']) ? null : (int) $menu->query['pid']; $filter_catid = $jinput->getInt('cid', null); if ($filter_catid === null && $mOption == 'com_djcatalog2' && $mCatid) { $filter_catid = $mCatid; $jinput->set('cid', $filter_catid); } $category = $categories->get((int) $jinput->getInt('cid', 0)); $filter_producerid = $jinput->get('pid', null, 'string'); if ($filter_producerid === null && $mOption == 'com_djcatalog2' && $mProdid) { $filter_producerid = $mProdid; $jinput->set('pid', (int) $filter_producerid); } $search = urldecode($jinput->get('mapsearch', '', 'string')); $search = JString::strtolower($search); $this->state = $model->getState(); $this->params = $params = Djcatalog2Helper::getParams(); if ($filter_catid) { $model->setState('filter.category', (int) $filter_catid); } if ($filter_producerid) { $model->setState('filter.producer', (int) $filter_producerid); } if (JString::strlen($search) > 0) { $model->setState('filter.map.address', $search); } else { $search = ''; } // state 0 means both published and unpublished $model->setState('filter.state', 1); $map_radius = $jinput->get('ms_radius', false, 'int'); $model->setState('filter.map.radius', $map_radius); $map_unit = $jinput->get('ms_unit', false, 'string'); $model->setState('filter.map.unit', $map_unit); $model->setState('filter.map', true); $model->setState('filter.catalogue', false); $ordering = 'i.ordering'; // $app->getUserStateFromRequest('com_djcatalog2.myitems.ordering', 'order', 'i.ordering'); $model->setState('list.ordering', $ordering); $order_dir = 'asc'; //$app->getUserStateFromRequest('com_djcatalog2.myitems.order_dir', 'dir', 'asc'); $model->setState('list.direction', $order_dir); $this->items = $model->getItems(); //$this->pagination = $model->getPagination(); $lists = array(); $lists['search'] = $search; // category filter $category_options = $categories->getOptionList('- ' . JText::_('COM_DJCATALOG2_SELECT_CATEGORY') . ' -'); if ($filter_catid > 0 && !empty($category)) { $category_path = $category->getPath(); if (count($category_path) > 0) { if ($mCatid == 0) { $parent_category = $categories->get(0); } else { $parent_category = $categories->get((int) end($category_path)); } if ($parent_category) { $childrenList = array($parent_category->id); $parent_category->makeChildrenList($childrenList); foreach ($category_options as $key => $option) { if (!in_array($option->value, $childrenList)) { unset($category_options[$key]); } if ($option->value == $parent_category->id) { $category_options[$key]->text = '- ' . JText::_('COM_DJCATALOG2_SELECT_CATEGORY') . ' -'; } } } } } $lists['categories'] = JHTML::_('select.genericlist', $category_options, 'cid', 'class="inputbox input"', 'value', 'text', $filter_catid); // producer filter $producers_first_option = new stdClass(); $producers_first_option->id = '0'; $producers_first_option->text = '- ' . JText::_('COM_DJCATALOG2_SELECT_PRODUCER') . ' -'; $producers_first_option->disable = false; $prodList = $model->getProducers(); $producers = count($prodList) ? array_merge(array($producers_first_option), $prodList) : array($producers_first_option); $lists['producers'] = JHTML::_('select.genericlist', $producers, 'pid', 'class="inputbox input"', 'id', 'text', (int) $filter_producerid); $this->assignref('lists', $lists); // Check for errors. if (count($errors = $this->get('Errors'))) { JError::raiseError(500, implode("\n", $errors)); return false; } $this->_prepareDocument(); parent::display($tpl); }
function display($tpl = null) { JHTML::_('behavior.modal'); $app = JFactory::getApplication(); $document = JFactory::getDocument(); $model = $this->getModel(); $menus = $app->getMenu('site'); $menu = $menus->getActive(); $dispatcher = JDispatcher::getInstance(); $user = JFactory::getUser(); $groups = $user->getAuthorisedViewLevels(); $categories = Djc2Categories::getInstance(array('state' => '1', 'access' => $groups)); $limitstart = $app->input->get('limitstart', 0, 'int'); $state = $this->get('State'); $item = $this->get('Item'); $this->contactform = $this->get('Form'); $this->showcontactform = $app->getUserState('com_djcatalog2.contact.data') ? 'false' : 'true'; if (empty($item) || !$item->published) { throw new Exception(JText::_('COM_DJCATALOG2_PRODUCT_NOT_FOUND'), 404); } $catid = (int) $app->input->get('cid'); $category = $categories->get($item->cat_id); $current_category = $catid == $item->cat_id ? $category : $categories->get($catid); if ($current_category && $current_category->id > 0 && $current_category->published == 0 || empty($category)) { if ($category && $category->id > 0 && $category->published == 0 || empty($category)) { throw new Exception(JText::_('COM_DJCATALOG2_PRODUCT_NOT_FOUND'), 404); } } if (!in_array($current_category->access, $groups)) { throw new Exception(JText::_('JERROR_ALERTNOAUTHOR'), 403); } if ($item->parent_id > 0) { $app->redirect(JRoute::_(DJCatalogHelperRoute::getItemRoute($item->parent_id . ':' . $item->alias, $item->cat_id . ':' . $item->category_alias))); } // if category id in the URL differs from product's category id // we add canonical link to document's header /*if (JString::strcmp(DJCatalogHelperRoute::getItemRoute($item->slug, (int)$item->cat_id), DJCatalogHelperRoute::getItemRoute($item->slug, (int)$catid)) != 0) { $document->addHeadLink(JRoute::_(DJCatalogHelperRoute::getItemRoute($item->slug, $item->catslug)), 'canonical'); //$document->addCustomTag('<link rel="canonical" href="'.JRoute::_(DJCatalogHelperRoute::getItemRoute($item->slug, $item->catslug)).'"/>'); }*/ foreach ($this->document->_links as $key => $headlink) { if ($headlink['relation'] == 'canonical') { unset($this->document->_links[$key]); } } $this->document->addHeadLink(JRoute::_(DJCatalogHelperRoute::getItemRoute($item->slug, $item->catslug)), 'canonical'); $app->input->set('refcid', $app->input->getString('cid')); // if category id is not present in the URL or it equals 0 // we set it to product's cat id if ($catid == 0) { $app->input->set('cid', $item->cat_id); } // params in this view should be generated only after we make sure // that product's cat id is in the request. $params = Djcatalog2Helper::getParams(); if (!empty($item) && !empty($item->params)) { $item_params = new JRegistry($item->params); $params->merge($item_params); } if (!in_array($item->access, $groups)) { if ($params->get('items_show_restricted') && $user->guest) { $uri = JURI::getInstance(); $return_url = base64_encode((string) $uri); $app->redirect(JRoute::_('index.php?option=com_users&view=login&return=' . $return_url, false), JText::_('COM_DJCATALOG2_PLEASE_LOGIN')); return true; } else { throw new Exception(JText::_('JERROR_ALERTNOAUTHOR'), 403); } } /* plugins */ JPluginHelper::importPlugin('djcatalog2'); JPluginHelper::importPlugin('content'); $results = $dispatcher->trigger('onPrepareItemDescription', array(&$item, &$params, $limitstart)); $item->event = new stdClass(); $item->event->afterDJCatalog2DisplayTitle = false; $item->event->beforeDJCatalog2DisplayContent = false; $item->event->afterDJCatalog2DisplayContent = false; if ($this->getLayout() != 'print') { $resultsAfterTitle = $dispatcher->trigger('onAfterDJCatalog2DisplayTitle', array(&$item, &$params, $limitstart)); $item->event->afterDJCatalog2DisplayTitle = trim(implode("\n", $resultsAfterTitle)); $resultsBeforeContent = $dispatcher->trigger('onBeforeDJCatalog2DisplayContent', array(&$item, &$params, $limitstart)); $item->event->beforeDJCatalog2DisplayContent = trim(implode("\n", $resultsBeforeContent)); $resultsAfterContent = $dispatcher->trigger('onAfterDJCatalog2DisplayContent', array(&$item, &$params, $limitstart)); $item->event->afterDJCatalog2DisplayContent = trim(implode("\n", $resultsAfterContent)); } $this->assignref('categories', $categories); $this->assignref('category', $category); $this->assignref('item', $item); $this->assignref('images', $images); $this->assignref('files', $files); $this->assignref('params', $params); $this->relateditems = $model->getRelatedItems(); $this->attributes = $model->getAttributes(); $this->navigation = $model->getNavigation($this->item->id, $this->item->cat_id, $params); $this->children = $model->getChildren($this->item->id); if (!empty($this->children)) { $childrenModel = $model->getChildrenModel(); $this->childrenAttributes = $childrenModel->getAttributes(); $this->childrenColumns = $childrenModel->getFieldGroups($childrenModel); } if ($app->input->get('pdf') == '1' && $app->input->get('tmpl') == 'component' && $this->getLayout() == 'print') { if (JFile::exists(JPath::clean(JPATH_ROOT . '/libraries/dompdf/dompdf_config.inc.php')) == false) { throw new Exception('DOMPDF Libary is missing!'); } $this->_preparePDF(); $app->close(); return true; } $this->_prepareDocument(); $model->hit(); parent::display($tpl); }
protected function getListQuery() { // Create a new query object. $db = $this->getDbo(); $query = $db->getQuery(true); $categories = Djc2Categories::getInstance(); // Select the required fields from the table. $select_default = 'a.*, uc.name AS editor, img.fullname AS item_image, img.caption AS image_caption, img.path as image_path, img.fullpath as image_fullpath'; $query->select($this->getState('list.select', $select_default)); $query->from('#__djc2_categories AS a'); // Join over the users for the checked out user. //$query->select('uc.name AS editor'); $query->join('LEFT', '#__users AS uc ON uc.id=a.checked_out'); //$query->select('img.fullname AS item_image, img.caption AS image_caption'); //$query->join('LEFT', '#__djc2_images AS img ON img.item_id=a.id AND img.type=\'category\' AND img.ordering=1'); //$query->join('left', '(SELECT im1.* from #__djc2_images as im1 GROUP BY im1.item_id, im1.type ORDER BY im1.ordering asc) AS img ON img.item_id = a.id AND img.type=\'category\''); //$query->join('left', '(select im1.fullname, im1.caption, im1.type, im1.item_id, im1.path, im1.fullpath from #__djc2_images as im1, (select item_id, type, min(ordering) as lowest_order from #__djc2_images group by item_id, type) as im2 where im1.item_id = im2.item_id and im1.type=im2.type and im1.ordering = im2.lowest_order group by im1.type, im1.item_id, im1.path, im1.fullpath) AS img ON img.item_id = a.id AND img.type=\'category\''); $query->join('left', '#__djc2_images as img on img.id = (select id from #__djc2_images where type=\'category\' and item_id = a.id order by ordering asc limit 1)'); // Filter by search in title. $search = $this->getState('filter.search'); if (!empty($search)) { if (stripos($search, 'id:') === 0) { $category = $categories->get((int) substr($search, 3)); $return_false = true; if ($category) { $path = $category->getPath(); JArrayHelper::toInteger($path); if (count($path) > 0) { $query->where('a.id IN (' . implode(",", $path) . ')'); $return_false = false; } } if ($return_false) { $query->where('1=0'); } } else { $search = $db->quote('%' . $db->escape($search, true) . '%'); $id_query = $db->getQuery(true); $id_query->select('distinct id'); $id_query->from('#__djc2_categories'); $id_query->where('(name LIKE ' . $search . ' OR alias LIKE ' . $search . ')'); $id_query->order('parent_id asc'); $db->setQuery($id_query); $rows = $db->loadColumn(); $return_false = true; $ids = array(); if (count($rows) > 0) { $rows = array_unique($rows); foreach ($rows as $id) { $category = $categories->get($id); $path = $category->getPath(); JArrayHelper::toInteger($path); $ids = array_merge($ids, $path); } $ids = array_unique($ids); if (count($ids) > 0) { $query->where('a.id IN (' . implode(",", $ids) . ')'); $return_false = false; } } if ($return_false) { $query->where('1=0'); } } } //$parent_id = JRequest::getInt('parent_id', 0); //$query->where('a.parent_id=\''.$parent_id.'\''); // Add the list ordering clause. $orderCol = $this->state->get('list.ordering', 'a.ordering'); $orderDirn = $this->state->get('list.direction', 'asc'); if ($orderCol == 'a.ordering') { $orderCol = 'a.parent_id ' . $orderDirn . ', a.ordering ' . $orderDirn; $query->order($db->escape($orderCol)); } else { $query->order($db->escape($orderCol . ' ' . $orderDirn)); } return $query; }
function getCategoryParams($catid) { if (!isset($this->_categoryparams[$catid])) { $categories = Djc2Categories::getInstance(array('state' => '1')); $category = $categories->get($catid); $this->_categoryparams[$catid] = $this->_cparams; if (!empty($category)) { $catpath = array_reverse($category->getPath()); foreach ($catpath as $k => $v) { $parentCat = $categories->get((int) $v); if (!empty($parentCat) && !empty($category->params)) { $catparams = new JRegistry($parentCat->params); $this->_categoryparams[$catid]->merge($catparams); } } } } return $this->_categoryparams[$catid]; }
protected function getListQuery() { // Create a new query object. $db = $this->getDbo(); $query = $db->getQuery(true); $user = JFactory::getUser(); // Select the required fields from the table. //$select_default = 'a.*, c.name AS category_name, c.id AS cat_id, p.name AS producer_name, uc.name AS editor, img.fullname AS item_image, img.caption AS image_caption, img.path as image_path, img.fullpath as image_fullpath '; $select_default = 'a.*, c.name AS category_name, c.id AS cat_id, p.name AS producer_name, uc.name AS editor '; $query->select($this->getState('list.select', $select_default)); $query->from('#__djc2_items AS a'); // Join over the categories. //$query->select('c.name AS category_name, c.id AS cat_id'); //$query->join('INNER', '#__djc2_items_categories AS ic ON a.id = ic.item_id AND ic.default=1'); //$query->join('LEFT', '#__djc2_categories AS c ON c.id = ic.category_id'); $query->join('LEFT', '#__djc2_categories AS c ON c.id = a.cat_id'); // Join over the producers. //$query->select('p.name AS producer_name'); $query->join('LEFT', '#__djc2_producers AS p ON p.id = a.producer_id'); // Join over the users for the checked out user. //$query->select('uc.name AS editor'); $query->join('LEFT', '#__users AS uc ON uc.id=a.checked_out'); $query->select('ag.title AS access_level'); $query->join('LEFT', '#__viewlevels AS ag ON ag.id = a.access'); //$query->select('img.fullname AS item_image, img.caption AS image_caption'); //$query->join('LEFT', '#__djc2_images AS img ON img.item_id=a.id AND img.type=\'item\' AND img.ordering=1'); //$query->join('left', '(SELECT im1.* from #__djc2_images as im1 GROUP BY im1.item_id, im1.type ORDER BY im1.ordering asc) AS img ON img.item_id = a.id AND img.type=\'item\''); //$query->join('left', '(select im1.fullname, im1.caption, im1.type, im1.item_id, im1.path, im1.fullpath from #__djc2_images as im1, (select item_id, type, min(ordering) as lowest_order from #__djc2_images group by item_id, type) as im2 where im1.item_id = im2.item_id and im1.type=im2.type and im1.ordering = im2.lowest_order group by im1.type, im1.item_id, im1.path, im1.fullpath) AS img ON img.item_id = a.id AND img.type=\'item\''); //$query->join('left', '#__djc2_images as img on img.id = (select id from #__djc2_images where type=\'item\' and item_id = a.id order by ordering asc limit 1)'); // Filter by published state $published = $this->getState('filter.published'); if (is_numeric($published)) { $query->where('a.published = ' . (int) $published); } /*else if ($published === '') { $query->where('(a.published = 0 OR a.published = 1)'); }*/ // Filter by search in title. $search = $this->getState('filter.search'); if (!empty($search)) { if (stripos($search, 'id:') === 0) { $query->where('a.id = ' . (int) substr($search, 3)); } else { $search = $db->quote('%' . $db->escape($search, true) . '%'); $query->where('(a.name LIKE ' . $search . ' OR a.alias LIKE ' . $search . ')'); } } // Filter by category state $category = $this->getState('filter.category'); if (is_numeric($category) && $category != 0) { $category_subquery = 'SELECT DISTINCT ic.item_id ' . 'FROM #__djc2_items_categories AS ic ' . 'INNER JOIN #__djc2_categories AS cc ON cc.id=ic.category_id '; $categories = Djc2Categories::getInstance(); if ($parent = $categories->get((int) $category)) { $childrenList = array($parent->id); $parent->makeChildrenList($childrenList); if ($childrenList) { $cids = implode(',', $childrenList); $category_subquery .= ' WHERE ic.category_id IN (' . $cids . ')'; $query->join('inner', '(' . $category_subquery . ') as category_filter ON a.id = category_filter.item_id'); } } } // Filter by producer state $producer = $this->getState('filter.producer'); if (is_numeric($producer) && $producer != 0) { $query->where('a.producer_id = ' . (int) $producer); } $parent = $this->getState('filter.parent'); if (is_numeric($parent)) { $query->where('a.parent_id = ' . (int) $parent); } // Filter by primary keys $item_ids = $this->getState('filter.ids'); if ($item_ids != '') { $query->where('a.id IN (' . $item_ids . ')'); } if (!$user->authorise('core.admin')) { $groups = implode(',', $user->getAuthorisedViewLevels()); $query->where('a.access IN (' . $groups . ')'); } // Add the list ordering clause. $orderCol = $this->state->get('list.ordering', 'a.name'); $orderDirn = $this->state->get('list.direction', 'asc'); if ($orderCol == 'a.ordering' || $orderCol == 'category_name') { $orderCol = 'c.name ' . $orderDirn . ', a.ordering'; } $query->order($db->escape($orderCol . ' ' . $orderDirn)); return $query; }
public function delete(&$cid = array()) { if (count($cid)) { $categories = Djc2Categories::getInstance(); $categoryList = $cid; foreach ($cid as $catid) { $sublist = array($catid); if ($parent = $categories->get($catid)) { $parent->makeChildrenList($sublist); } $categoryList = array_merge($categoryList, $sublist); } $categoryList = array_unique($categoryList); $cids = implode(',', $categoryList); $this->_db->setQuery("SELECT COUNT(*) FROM #__djc2_items WHERE cat_id IN ( " . $cids . " )"); if ($this->_db->loadResult() > 0) { $this->setError(JText::_('COM_DJCATALOG2_DELETE_CATEGORIES_HAVE_ITEMS')); return false; } $cid = $categoryList; if (parent::delete($cid)) { // since products may still be assigned to additional categories, we need to break those relations $this->_db->setQuery('delete from #__djc2_items_categories where category_id in (' . implode(',', $cid) . ')'); if (!$this->_db->query()) { $this->setError($this->_db->getErrorMsg()); return false; } return true; } } return false; }
function getSubCategories($category) { /* $db = JFactory::getDbo(); $parent_id = $category->id; $db->setQuery(' select c.id as category_id, count(i.id) as item_count from #__djc2_categories as c left join #__djc2_items_categories as ic on c.id = ic.category_id left join #__djc2_items as i on i.id = ic.item_id where i.published = 1 OR i.id IS NULL group by c.id order by c.parent_id, c.ordering asc, c.name asc '); $categoryList = $db->loadObjectList('category_id'); $children = $category->getChildren(); foreach ($children as $k=>$v) { $this->countChildren($v, $categoryList); } $subcategories = array(); foreach ($children as $subcategory) { if (array_key_exists($subcategory->id, $categoryList)) { $subcategories[] = $subcategory; } } return $subcategories;*/ $db = JFactory::getDbo(); $parent_id = $category->id; $children = $category->getChildren(); $categories = Djc2Categories::getInstance(array('state' => '1')); $subcategories = array(); $category_subquery = 'SELECT ic.item_id ' . 'FROM #__djc2_items_categories AS ic ' . 'INNER JOIN #__djc2_categories AS c ON c.id=ic.category_id ' . 'WHERE c.published = 1'; foreach ($children as $k => $child) { if ($parent = $categories->get((int) $child->id)) { $childrenList = array($parent->id); $parent->makeChildrenList($childrenList); if ($childrenList) { $cids = implode(',', $childrenList); $child_subquery = $category_subquery . ' AND ic.category_id IN (' . $cids . ')'; $db->setQuery(' SELECT COUNT(DISTINCT i.id) FROM #__djc2_items AS i INNER JOIN (' . $child_subquery . ') AS category_filter ON i.id = category_filter.item_id WHERE i.published = 1 '); $children[$k]->item_count = $db->loadResult(); $subcategories[$child->id] = $children[$k]; } } } return $subcategories; }
function DJCatalog2ParseRoute($segments) { $app = JFactory::getApplication(); $menu = $app->getMenu(); $activemenu = $menu->getActive(); $db = JFactory::getDBO(); $params = JComponentHelper::getParams('com_djcatalog2'); $catalogViews = array('item', 'items', 'producer', 'itemform', 'myitems', 'producers', 'cart', 'checkout', 'orders', 'order', 'query', 'map', 'archived'); $component_views = array('items' => 'items', 'item' => 'item', 'producer' => 'producer', 'myitems' => 'myitems', 'itemform' => 'itemform', 'producers' => 'producers', 'cart' => 'cart', 'orders' => 'orders', 'order' => 'order', 'checkout' => 'checkout', 'query' => 'query', 'map' => 'map', 'archived' => 'archived'); foreach ($component_views as $view_name => $seotag) { $view_alias = $params->get('seo_' . $view_name . '_view', $view_name); $view_alias = JApplication::stringURLSafe(trim($view_alias)); if (count($segments)) { if ($segments[0] == $view_alias || str_replace(':', '-', $segments[0]) == $view_alias) { $segments[0] = $view_name; break; } } } $query = array(); if (count($segments)) { if (!in_array($segments[0], $catalogViews)) { if ($activemenu) { $temp = array(); $temp[0] = $activemenu->query['view']; switch ($temp[0]) { case 'item': $temp[1] = @$activemenu->query['id']; foreach ($segments as $k => $v) { $temp[$k + 1] = $v; } break; case 'items': case 'archived': $temp[1] = @$activemenu->query['cid']; if (count($segments) == 1) { $parts = explode(':', $segments[0], 2); $id = $parts[0]; $alias = isset($parts[1]) ? $parts[1] : null; if ((int) $id > 0) { $user = JFactory::getUser(); $groups = $user->getAuthorisedViewLevels(); $categories = Djc2Categories::getInstance(array('state' => '1', 'access' => $groups)); $category = $categories->get((int) $id); if (!empty($category) && ($category->alias == $alias || empty($alias))) { $temp[1] = $segments[0]; } else { $temp[0] = 'item'; } } } else { $temp[0] = 'item'; } foreach ($segments as $k => $v) { $temp[$k + 1] = $v; } break; case 'producer': $temp[1] = @$activemenu->query['pid']; foreach ($segments as $k => $v) { $temp[$k + 1] = $v; } break; case 'myitems': //$temp[1] = @$activemenu->query['id']; foreach ($segments as $k => $v) { $temp[$k + 1] = $v; } break; case 'producers': foreach ($segments as $k => $v) { $temp[$k + 1] = $v; } break; case 'itemform': foreach ($segments as $k => $v) { $temp[$k + 1] = $v; } break; case 'cart': case 'checkout': case 'query': case 'orders': case 'order': foreach ($segments as $k => $v) { $temp[$k + 1] = $v; } break; case 'map': $temp[1] = @$activemenu->query['cid']; foreach ($segments as $k => $v) { $temp[$k + 1] = $v; } break; } $segments = $temp; } } if (isset($segments[0])) { switch ($segments[0]) { case 'items': case 'archived': $query['view'] = $segments[0]; if (isset($segments[1]) && $segments[1] != '') { $query['cid'] = $segments[1] == 'all' ? 0 : DJCatalogHelperRoute::parseAlias($segments[1]); } break; case 'itemstable': $query['view'] = 'itemstable'; if (isset($segments[1])) { $query['cid'] = $segments[1] == 'all' ? 0 : DJCatalogHelperRoute::parseAlias($segments[1]); } break; case 'item': $query['view'] = 'item'; if (count($segments) > 2) { if (isset($segments[1]) && $segments[1] != '') { $query['cid'] = $segments[1] == 'all' ? 0 : DJCatalogHelperRoute::parseAlias($segments[1]); } if (isset($segments[2])) { $query['id'] = DJCatalogHelperRoute::parseAlias($segments[2]); } } else { if (isset($segments[1])) { $query['id'] = DJCatalogHelperRoute::parseAlias($segments[1]); if ($activemenu && $activemenu->query['option'] == 'com_djcatalog2' && $activemenu->query['view'] == 'items' && !empty($activemenu->query['cid'])) { $query['cid'] = $activemenu->query['cid']; } } } break; case 'producer': $query['view'] = 'producer'; if (isset($segments[1])) { $query['pid'] = $segments[1]; } break; case 'itemform': $query['view'] = 'itemform'; if (isset($segments[1])) { $query['id'] = $segments[1]; } break; case 'myitems': $query['view'] = 'myitems'; break; case 'producers': $query['view'] = 'producers'; break; case 'cart': $query['view'] = 'cart'; break; case 'orders': $query['view'] = 'orders'; break; case 'checkout': $query['view'] = 'checkout'; break; case 'query': $query['view'] = 'query'; break; case 'order': $query['view'] = 'order'; if (isset($segments[1])) { $query['oid'] = $segments[1]; } break; case 'map': $query['view'] = 'map'; if (isset($segments[1])) { $query['cid'] = $segments[1] == 'all' ? 0 : DJCatalogHelperRoute::parseAlias($segments[1]); } break; } } } return $query; }
public function display($tpl = null) { JHTML::_('behavior.modal'); $app = JFactory::getApplication(); $jinput = $app->input; $view = $jinput->get('view'); $document = JFactory::getDocument(); $menus = $app->getMenu('site'); $menu = $menus->getActive(); $mOption = empty($menu->query['option']) ? null : $menu->query['option']; $mCatid = empty($menu->query['cid']) ? null : (int) $menu->query['cid']; $mProdid = empty($menu->query['pid']) ? null : (int) $menu->query['pid']; $filter_catid = $jinput->getInt('cid', null); if ($filter_catid === null && $mOption == 'com_djcatalog2' && $mCatid) { $filter_catid = $mCatid; $jinput->set('cid', $filter_catid); } $filter_producerid = $jinput->get('pid', null, 'string'); if ($filter_producerid === null && $mOption == 'com_djcatalog2' && $mProdid) { $filter_producerid = $mProdid; $jinput->set('pid', (int) $filter_producerid); } JModelLegacy::addIncludePath(JPATH_BASE . DS . 'components' . DS . 'com_djcatalog2' . DS . 'models', 'DJCatalog2Model'); $model = JModelLegacy::getInstance('Items', 'Djcatalog2Model', array('ignore_request' => true)); $this->state = $model->getState(); $params = Djcatalog2Helper::getParams(); $filter_order = $jinput->get('order', $params->get('items_default_order', 'i.ordering'), 'cmd'); $filter_order_Dir = $jinput->get('dir', $params->get('items_default_order_dir', 'asc'), 'word'); $search = urldecode($jinput->get('search', '', 'string')); $search = JString::strtolower($search); $limitstart = $jinput->get('limitstart', 0, 'int'); $limit_items_show = $params->get('limit_items_show', 10); $lists = array(); if ($filter_order_Dir == '' || $filter_order_Dir == 'desc') { $lists['order_Dir'] = 'asc'; } else { $lists['order_Dir'] = 'desc'; } $lists['order'] = $filter_order; $categories = Djc2Categories::getInstance(array('state' => '1')); // current category $category = $categories->get((int) $jinput->getInt('cid', 0)); if ($category && $category->id > 0 && $category->published == 0 || empty($category)) { throw new Exception(JText::_('COM_DJCATALOG2_PRODUCT_NOT_FOUND'), 404); } //$model->setState('list.start', $app->input->get('limitstart', 0)); $model->setState('list.start', $limitstart); $model->setState('list.limit', 10); // state 2 means archived $model->setState('filter.state', 2); $model->setState('filter.category', (int) $filter_catid); $model->setState('filter.producer', (int) $filter_producerid); $model->setState('filter.catalogue', false); $model->setState('list.ordering', $filter_order); $model->setState('list.direction', $filter_order_Dir); $this->items = $model->getItems(); $this->pagination = $model->getPagination(); $this->params = $params; $this->lists = $lists; $this->attributes = $model->getAttributes(); $this->column_attributes = $model->getFieldGroups(); $this->sortables = $model->getSortables(); // Check for errors. if (count($errors = $this->get('Errors'))) { JError::raiseError(500, implode("\n", $errors)); return false; } $this->_prepareDocument(); parent::display($tpl); }
public static function getParams($reload = false) { if (!self::$params || $reload == true) { $app = JFactory::getApplication(); // our params $params = new JRegistry(); // component's global params $cparams = JComponentHelper::getParams('com_djcatalog2'); // current params - all $aparams = $app->getParams(); // curent params - djc2 only $mparams = $app->getParams('com_djcatalog2'); // first let's use all current params $params->merge($aparams); // then override them with djc2 global settings - in case some other extension share's the same parameter name $params->merge($cparams); // finally, override settings with current params, but only related to djc2. $params->merge($mparams); // ...and then, override with category specific params $option = $app->input->get('option'); $view = $app->input->get('view'); if ($option = 'com_djcatalog2' && ($view = 'item' || ($view = 'items' || ($view = 'archived')))) { $user = JFactory::getUser(); $groups = $user->getAuthorisedViewLevels(); $categories = Djc2Categories::getInstance(array('state' => '1', 'access' => $groups)); $category = $categories->get((int) $app->input->get('cid', 0, 'int')); if (!empty($category)) { $catpath = array_reverse($category->getPath()); foreach ($catpath as $k => $v) { $parentCat = $categories->get((int) $v); if (!empty($parentCat) && !empty($category->params)) { $catparams = new JRegistry($parentCat->params); $params->merge($catparams); } } } } $listLayout = $app->input->get('l', $app->getUserState('com_djcatalog2.list_layout', null), 'cmd'); if ($listLayout == 'items') { $app->setUserState('com_djcatalog2.list_layout', 'items'); $params->set('list_layout', 'items'); } else { if ($listLayout == 'table') { $app->setUserState('com_djcatalog2.list_layout', 'table'); $params->set('list_layout', 'table'); } } $catalogMode = $app->input->get('cm', null, 'int'); $indexSearch = $app->input->get('ind', null, 'string'); $globalSearch = urldecode($app->input->get('search', '', 'string')); $globalSearch = trim(JString::strtolower($globalSearch)); if (substr($globalSearch, 0, 1) == '"' && substr($globalSearch, -1) == '"') { $globalSearch = substr($globalSearch, 1, -1); } if (strlen($globalSearch) > 0 && strlen($globalSearch) < 3 || strlen($globalSearch) > 20) { $globalSearch = null; } if ($catalogMode === 0 || $globalSearch || $indexSearch) { $params->set('product_catalogue', '0'); // set 'filtering' variable in REQUEST // so we could hide for example sub-categories // when searching/filtering is performed $app->input->set('filtering', true); } self::$params = $params; } return self::$params; }
protected function getInput() { $app = JFactory::getApplication(); $attr = ''; $class = $this->element['class'] ? $this->element['class'] : ''; $class .= $this->element['required'] == 'true' ? ' required' : ''; $attr .= $class ? ' class="' . (string) $class . '"' : ''; $attr .= (string) $this->element['disabled'] == 'true' ? ' disabled="disabled"' : ''; $default_name = $this->element['default_name'] ? '- ' . JText::_($this->element['default_name']) . ' -' : null; $default_value = $this->element['default'] ? $this->element['default'] : ''; if ($default_name && $default_value == $this->value && $default_value == '') { $this->value = -1; } $allowed_categories = array(); if (!empty($this->element['allowed_categories'])) { if (!is_array($this->element['allowed_categories'])) { $allowed_categories = explode(',', $this->element['allowed_categories']); } } $ignored_values = array(); if (!empty($this->element['ignored_values'])) { if (!is_array($this->element['ignored_values'])) { $ignored_values = explode(',', $this->element['ignored_values']); } } if (is_array($this->value)) { foreach ($this->value as $k => $v) { if (in_array($v, $ignored_values)) { unset($this->value[$k]); } } } else { if (in_array($this->value, $ignored_values)) { $this->value = null; } } $context = $app->isAdmin() ? 'admin' : 'site'; $context .= '.' . $app->input->get('option') . '.' . $app->input->get('view') . '.' . $app->input->get('layout'); $current_category = $context == 'admin.com_djcatalog2.category.edit' ? $app->input->get('id', null, 'int') : null; $categories = Djc2Categories::getInstance(); $category_limit = isset($this->element['limit']) ? (int) $this->element['limit'] : null; $html = ''; if ($category_limit > 0) { $optionList = $categories->getOptionList('--', $this->element['parent'] != 'true' ? false : true, null, false, $allowed_categories, $default_value); $values = $this->value; if (!is_array($values)) { $values = array($values); } $values = array_reverse($values); //$html .= '<fieldset>'; for ($i = 0; $i < $category_limit; $i++) { $current_value = count($values) > 0 ? array_pop($values) : null; $html .= '<div class="control-label">'; $html .= '<label for="' . $this->id . '_' . $i . '">' . JText::_('COM_DJCATALOG2_ADDITIONAL_CATEGORY') . ' #' . ($i + 1) . '</label>'; $html .= '</div><div class="controls">'; $html .= JHTML::_('select.genericlist', $optionList, $this->name, trim($attr), 'value', 'text', $current_value, $this->id . '_' . $i); $html .= '</div>'; } //$html .= '</fieldset>'; } else { if ($category_limit === null) { $attr .= $this->element['size'] ? ' size="' . (int) $this->element['size'] . '"' : ''; $attr .= $this->element['multiple'] == 'true' ? ' multiple="multiple"' : ''; $optionList = $categories->getOptionList($default_name, $this->element['parent'] != 'true' ? false : true, $current_category, $this->element['default_disable'] == 'true' ? true : false, $allowed_categories, $default_value); $html = JHTML::_('select.genericlist', $optionList, $this->name, trim($attr), 'value', 'text', $this->value, $this->id); } } return $html; }
function display($tpl = null) { $app = JFactory::getApplication(); $document = JFactory::getDocument(); $model = $this->getModel(); $config = JFactory::getConfig(); $siteEmail = $config->get('mailfrom'); $fromName = $config->get('fromname'); $feedEmail = $config->get('feed_email', 'author'); $document->editor = $fromName; if ($feedEmail != 'none') { $document->editorEmail = $siteEmail; } $menus = $app->getMenu('site'); $menu = $menus->getActive(); $mOption = empty($menu->query['option']) ? null : $menu->query['option']; $mCatid = empty($menu->query['cid']) ? null : (int) $menu->query['cid']; $mProdid = empty($menu->query['pid']) ? null : (int) $menu->query['pid']; $filter_catid = $app->input->get('cid', null, 'int'); if ($filter_catid === null && $mOption == 'com_djcatalog2' && $mCatid) { $filter_catid = $mCatid; $app->input->set('cid', $filter_catid); } $filter_producerid = $app->input->get('pid', null, 'string'); if ($filter_producerid === null && $mOption == 'com_djcatalog2' && $mProdid) { $filter_producerid = $mProdid; $app->input->set('pid', $filter_producerid); } $params = Djcatalog2Helper::getParams(); $params->set('product_catalogue', false); $filter_order = $params->get('rss_items_default_order', 'i.date'); $filter_order_Dir = $params->get('rss_items_default_order_dir', 'desc'); $limitstart = $app->input->get('limitstart', 0, 'int'); $limit_items_show = $params->get('rss_limit_items_show', $config->get('feed_limit', 10)); $app->input->set('limit', $limit_items_show); $dispatcher = JDispatcher::getInstance(); $categories = Djc2Categories::getInstance(array('state' => '1')); // current category $category = $categories->get((int) $app->input->get('cid', 0, 'default')); $subcategories = null; if (!empty($category)) { $subcategories = $category->getChildren(); } /* If Cateogory not published set 404 */ if ($category && $category->id > 0 && $category->published == 0 || empty($category)) { throw new Exception(JText::_('COM_DJCATALOG2_PRODUCT_NOT_FOUND'), 404); } $title = $params->get('page_title', ''); if ($menu && ($menu->query['option'] != 'com_djcatalog2' || $menu->query['view'] != 'items' || $id != $category->id)) { if (!empty($category->metatitle)) { $title = $category->metatitle; } else { if ($category->name && $category->id > 0) { $title = $category->name; } } } if (empty($title)) { $title = $config->get('sitename'); } $document->setTitle($title); $rows = $model->getItems(); $document->link = JRoute::_(DJCatalogHelperRoute::getCategoryRoute($category->catslug)); foreach ($rows as $row) { // Strip html from feed item title $title = $this->escape($row->name); $title = html_entity_decode($title, ENT_COMPAT, 'UTF-8'); // Compute the article slug $row->slug = $row->alias ? $row->id . ':' . $row->alias : $row->id; // Url link to article $link = JRoute::_(DJCatalogHelperRoute::getItemRoute($row->slug, $category->id == 0 ? $row->catslug : $category->catslug)); // Get description, author and date $date = $row->created; // Load individual item creator class $item = new JFeedItem(); $item->title = $title; $item->link = $link; $item->date = $date; $item->author = $row->author; $item->category = $category->id == 0 ? $row->category : $category->name; //$item->authorEmail = $siteEmail; if ($feedEmail == 'site') { $item->authorEmail = $siteEmail; } else { if ($feedEmail === 'author') { $item->authorEmail = $row->author_email; } } $description = ''; if ($row->item_image && (int) $params->get('rss_image_link_item', '1')) { //$item->image = new JFeedImage(); //$item->image->url = DJCatalog2ImageHelper::getImageUrl($row->item_image,'small'); //$item->image->link = $item->link; //$item->image->title = $row->image_caption; $description .= '<img src="' . DJCatalog2ImageHelper::getImageUrl($row->image_fullpath, 'small') . '" alt="' . $row->image_caption . '"/>'; } if ($params->get('rss_description_type', '1') != '0') { $description .= $params->get('rss_description_type', '1') == '1' && $row->intro_desc ? $row->intro_desc : $row->description; if ($params->get('rss_showreadmore_item', '1')) { $description .= '<p class="feed-readmore"><a target="_blank" href ="' . $item->link . '">' . JText::_('COM_DJCATALOG2_READMORE') . '</a></p>'; } } // Load item description and add div $item->description = '<div class="feed-description">' . $description . '</div>'; // Loads item info into rss array $document->addItem($item); } }
function display($tpl = null) { JHTML::_('behavior.modal'); $app = JFactory::getApplication(); $jinput = $app->input; $view = $jinput->get('view'); $document = JFactory::getDocument(); $model = $this->getModel(); $menus = $app->getMenu('site'); $menu = $menus->getActive(); $mOption = empty($menu->query['option']) ? null : $menu->query['option']; $mCatid = empty($menu->query['cid']) ? null : (int) $menu->query['cid']; $mProdid = empty($menu->query['pid']) ? null : (int) $menu->query['pid']; $filter_catid = $jinput->getInt('cid', null); if ($filter_catid === null && $mOption == 'com_djcatalog2' && $mCatid) { $filter_catid = $mCatid; $jinput->set('cid', $filter_catid); } $filter_producerid = $jinput->get('pid', null, 'string'); if ($filter_producerid === null && $mOption == 'com_djcatalog2' && $mProdid) { $filter_producerid = $mProdid; $jinput->set('pid', (int) $filter_producerid); } $params = Djcatalog2Helper::getParams(); $filter_order = $jinput->get('order', $params->get('items_default_order', 'i.ordering'), 'cmd'); $filter_order_Dir = $jinput->get('dir', $params->get('items_default_order_dir', 'asc'), 'word'); $search = urldecode($jinput->get('search', '', 'string')); $search = JString::strtolower($search); $limitstart = $jinput->get('limitstart', 0, 'int'); $limit_items_show = $params->get('limit_items_show', 10); //$jinput->set('limit', $limit_items_show); if (JString::strlen($search) > 0 && JString::strlen($search) < 2 || JString::strlen($search) > 40) { JError::raiseNotice(E_USER_NOTICE, JText::_('COM_DJCATALOG2_SEARCH_RESTRICTION')); } if ($filter_order_Dir == '' || $filter_order_Dir == 'desc') { $lists['order_Dir'] = 'asc'; } else { $lists['order_Dir'] = 'desc'; } $lists['order'] = $filter_order; $layout = $jinput->get('layout', 'default', 'string'); $dispatcher = JDispatcher::getInstance(); $categories = Djc2Categories::getInstance(array('state' => '1')); // current category $category = $categories->get((int) $jinput->getInt('cid', 0)); $subcategories = null; if (!empty($category)) { $subcategories = $category->getChildren(); //$subcategories = $model->getSubCategories($category); } /* If Cateogory not published set 404 */ if ($category && $category->id > 0 && $category->published == 0 || empty($category)) { throw new Exception(JText::_('COM_DJCATALOG2_PRODUCT_NOT_FOUND'), 404); } $list = $model->getItems(); $total = count($list); //$model->getTotal(); $pagination = $model->getPagination(); // search filter $lists['search'] = $search; // category filter $category_options = $categories->getOptionList('- ' . JText::_('COM_DJCATALOG2_SELECT_CATEGORY') . ' -'); if ($filter_catid > 0 && (int) $params->get('category_filter_type', '0') > 0) { $category_path = $category->getPath(); if (count($category_path) > 0) { $parent_category = null; if ($params->get('category_filter_type', '1') == '1' || count($category_path) == 1) { $parent_category = $categories->get((int) end($category_path)); } else { if ($params->get('category_filter_type', '1') == '3') { $parent_category = $categories->get($category->id); } else { $parent_category = $categories->get((int) $category_path[1]); } } if ($parent_category) { $childrenList = array($parent_category->id); $parent_category->makeChildrenList($childrenList); foreach ($category_options as $key => $option) { if (!in_array($option->value, $childrenList)) { unset($category_options[$key]); } } } } } $lists['categories'] = JHTML::_('select.genericlist', $category_options, 'cid', 'class="inputbox input"', 'value', 'text', $filter_catid); // producer filter $producers_first_option = new stdClass(); $producers_first_option->id = '0'; $producers_first_option->text = '- ' . JText::_('COM_DJCATALOG2_SELECT_PRODUCER') . ' -'; $producers_first_option->disable = false; $prodList = $model->getProducers(); $producers = count($prodList) ? array_merge(array($producers_first_option), $prodList) : array($producers_first_option); $lists['producers'] = JHTML::_('select.genericlist', $producers, 'pid', 'class="inputbox input"', 'id', 'text', (int) $filter_producerid); $lists['index'] = $model->getIndexCount(); /* plugins */ if ($category && $category->id > 0) { JPluginHelper::importPlugin('djcatalog2'); $results = $dispatcher->trigger('onPrepareItemDescription', array(&$category, &$params, $limitstart)); } $this->assignref('document', $document); $this->assignref('item', $category); $this->assignref('categories', $categories); $this->assignref('subcategories', $subcategories); $this->assignref('lists', $lists); $this->assignref('items', $list); $this->assignref('lists', $lists); $this->assignref('total', $total); $this->assignref('pagination', $pagination); $this->assignref('params', $params); $this->assignref('model', $model); $this->attributes = $model->getAttributes(); $this->column_attributes = $model->getFieldGroups(); $this->sortables = $model->getSortables(); $this->_prepareDocument(); parent::display($tpl); }
protected function getListQuery() { // Create a new query object. $db = $this->getDbo(); $query = $db->getQuery(true); // Select the required fields from the table. $select_default = 'a.*, c.name AS category_name, c.id AS cat_id, p.name AS producer_name '; $query->select($this->getState('list.select', $select_default)); $query->from('#__djc2_items AS a'); // Join over the categories. //$query->select('c.name AS category_name, c.id AS cat_id'); //$query->join('INNER', '#__djc2_items_categories AS ic ON a.id = ic.item_id AND ic.default=1'); //$query->join('LEFT', '#__djc2_categories AS c ON c.id = ic.category_id'); $query->join('LEFT', '#__djc2_categories AS c ON c.id = a.cat_id'); // Join over the producers. //$query->select('p.name AS producer_name'); $query->join('LEFT', '#__djc2_producers AS p ON p.id = a.producer_id'); $query->select('t.value as tax_rate'); $query->join('left', '#__djc2_tax_rates as t on a.tax_rate_id = t.id'); // Join over the users for the checked out user. //$query->select('uc.name AS editor'); //$query->join('LEFT', '#__users AS uc ON uc.id=a.checked_out'); //$query->select('img.fullname AS item_image, img.caption AS image_caption'); //$query->join('LEFT', '#__djc2_images AS img ON img.item_id=a.id AND img.type=\'item\' AND img.ordering=1'); //$query->join('left', '(SELECT im1.* from #__djc2_images as im1 GROUP BY im1.item_id, im1.type ORDER BY im1.ordering asc) AS img ON img.item_id = a.id AND img.type=\'item\''); //$query->join('left', '(select im1.fullname, im1.caption, im1.type, im1.item_id, im1.path, im1.fullpath from #__djc2_images as im1, (select item_id, type, min(ordering) as lowest_order from #__djc2_images group by item_id, type) as im2 where im1.item_id = im2.item_id and im1.type=im2.type and im1.ordering = im2.lowest_order group by im1.type, im1.item_id, im1.path, im1.fullpath) AS img ON img.item_id = a.id AND img.type=\'item\''); // Filter by published state $published = $this->getState('filter.published'); if (is_numeric($published)) { $query->where('a.published = ' . (int) $published); } else { if ($published === '') { $query->where('(a.published = 0 OR a.published = 1)'); } } // Filter by search in title. $search = $this->getState('filter.search'); if (!empty($search)) { if (stripos($search, 'id:') === 0) { $query->where('a.id = ' . (int) substr($search, 3)); } else { $search = $db->quote('%' . $db->escape($search, true) . '%'); $query->where('(a.name LIKE ' . $search . ' OR a.alias LIKE ' . $search . ')'); } } // Filter by category state $category = $this->getState('filter.category'); if (is_numeric($category) && $category != 0) { //$query->where('a.cat_id = ' . (int) $category); $categories = Djc2Categories::getInstance(); if ($parent = $categories->get((int) $category)) { $childrenList = array($parent->id); $parent->makeChildrenList($childrenList); if ($childrenList) { $cids = implode(',', $childrenList); $db->setQuery('SELECT item_id FROM #__djc2_items_categories AS ic INNER JOIN #__djc2_categories AS c ON c.id=ic.category_id WHERE category_id IN (' . $cids . ')'); $items = $db->loadColumn(); if (count($items)) { $items = array_unique($items); $query->where('a.id IN (' . implode(',', $items) . ')'); } else { $query->where('1=0'); } //$where[] = 'i.cat_id IN ( '.$cids.' )'; } else { if ($category != 0) { $query->where('1=0'); } } } } // Filter by producer state $producer = $this->getState('filter.producer'); if (is_numeric($producer) && $producer != 0) { $query->where('a.producer_id = ' . (int) $producer); } // Filter by primary keys $item_ids = $this->getState('filter.ids'); if ($item_ids != '') { $query->where('a.id IN (' . $item_ids . ')'); } $customer_group = $this->getState('filter.customergroup'); if (is_numeric($customer_group) && (int) $customer_group != 0) { $query->select('cg.price as group_price'); $query->join('left', '#__djc2_prices as cg on cg.group_id =' . (int) $customer_group . ' AND cg.item_id=a.id'); } // Add the list ordering clause. $orderCol = $this->state->get('list.ordering', 'a.name'); $orderDirn = $this->state->get('list.direction', 'asc'); if ($orderCol == 'a.ordering' || $orderCol == 'category_name') { $orderCol = 'c.name ' . $orderDirn . ', a.ordering'; } $query->order($db->escape($orderCol . ' ' . $orderDirn)); return $query; }
static function getDJCatalog2Category(&$xmap, &$parent, &$params, &$catid) { $database = JFactory::getDBO(); $djc2categories = Djc2Categories::getInstance(array('state' => '1')); $category = $djc2categories->get((int) $catid); if (!$category) { return false; } $categories = $category->getChildren(); $xmap->changeLevel(1); foreach ($categories as $row) { if (!$row->created) { $row->created = $xmap->now; } $node = new stdclass(); $node->name = $row->name; $node->link = DJCatalogHelperRoute::getCategoryRoute($row->id . ':' . $row->alias); $node->id = $parent->id; $node->uid = 'com_djcatalog2c' . $row->id; $node->browserNav = $parent->browserNav; $node->modified = $row->created; $node->priority = $params['cat_priority']; $node->changefreq = $params['cat_changefreq']; $node->expandible = true; $node->secure = $parent->secure; if ($xmap->printNode($node) !== FALSE) { self::getDJCatalog2Category($xmap, $parent, $params, $row->id); } } /* Returns URLs of all listings in the current category */ if ($params['include_products']) { $query = " SELECT a.name, a.alias, a.id, a.cat_id, c.alias as cat_alias, UNIX_TIMESTAMP(a.created) as `created` \n" . " FROM #__djc2_items AS a \n" . " INNER JOIN #__djc2_categories as c on c.id = a.cat_id" . " WHERE a.cat_id = " . (int) $catid . " AND a.published=1" . " ORDER BY a.ordering ASC, a.name ASC "; $database->setQuery($query); $rows = $database->loadObjectList(); foreach ($rows as $row) { $node = new stdclass(); $node->name = $row->name; $node->link = DJCatalogHelperRoute::getItemRoute($row->id . ':' . $row->alias, $row->cat_id . ':' . $row->cat_alias); $node->id = $parent->id; $node->uid = 'com_djcatalog2i' . $row->id; $node->browserNav = $parent->browserNav; $node->modified = $row->created; $node->priority = $params['link_priority']; $node->changefreq = $params['link_changefreq']; $node->expandible = false; $node->secure = $parent->secure; $xmap->printNode($node); } } $xmap->changeLevel(-1); return true; }
public static function getCategoryRoute($catid, $producerid = null) { $needles = array('items' => array((int) $catid)); //Create the link $link = 'index.php?option=com_djcatalog2&view=items'; if ((int) $catid >= 0) { $categories = Djc2Categories::getInstance(array('state' => '1')); $category = $categories->get((int) $catid); if ($category) { $path = $category->getPath(); $path[] = 0; JArrayHelper::toInteger($path); $needles['items'] = $path; $link .= '&cid=' . $catid; } } if ($producerid !== null && (int) $producerid >= 0) { $link .= '&pid=' . $producerid; $producer_needles = array(); foreach ($needles['items'] as $k => $v) { $producer_needles[] = $v . '-' . (int) $producerid; } $needles['items'] = array_merge($producer_needles, $needles['items']); } if ($item = self::_findItem($needles)) { $link .= '&Itemid=' . self::_findItem($needles); } return $link; }
function _buildContentWhere() { $db = JFactory::getDBO(); $app = JFactory::getApplication(); $filter_catid = 0; // $this->_mparams->get('catid', 0); $filter_featured = $this->_mparams->get('featured_only', 0); $option = $app->input->get('option', '', 'string'); $view = $app->input->get('view', '', 'string'); $id = $itemId = $app->input->get('id', '', 'int'); if ($option != 'com_djcatalog2' || $view != 'item' || !$id) { return false; } if ($option != 'com_djcatalog2' || $view != 'item' || !$itemId) { return false; } $where = array(); $where[] = '(i.id IN (SELECT related_item FROM #__djc2_items_related WHERE item_id=' . (int) $id . ') )'; if ($filter_featured > 0) { $where[] = 'i.featured = 1'; } if ($filter_catid > 0) { $categories = Djc2Categories::getInstance(array('state' => '1')); if ($parent = $categories->get((int) $filter_catid)) { $childrenList = array($parent->id); $parent->makeChildrenList($childrenList); if ($childrenList) { $cids = implode(',', $childrenList); $db->setQuery('SELECT item_id FROM #__djc2_items_categories AS ic INNER JOIN #__djc2_categories AS c ON c.id=ic.category_id WHERE category_id IN (' . $cids . ') AND c.published = 1'); $items = $db->loadColumn(); if (count($items)) { $items = array_unique($items); $where[] = 'i.id IN (' . implode(',', $items) . ')'; } //$where[] = 'i.cat_id IN ( '.$cids.' )'; } else { if ($filter_catid != 0) { JError::raiseError(404, JText::_("COM_DJCATALOG2_PAGE_NOT_FOUND")); } } } } $where[] = 'i.published = 1'; $where[] = 'c.published = 1'; $where = count($where) ? ' WHERE ' . implode(' AND ', $where) : ''; return $where; }