Esempio n. 1
0
 public static function getItemRoute($id, $catid = 0, $producerid = null)
 {
     $link = 'index.php?option=com_djcatalog2&view=item&id=' . $id;
     $input = JFactory::getApplication()->input;
     if ($input->get('option') == 'com_djcatalog2' && $input->get('view') == 'archived') {
         if (($Itemid = $input->get('Itemid')) > 0) {
             $link .= '&Itemid=' . $Itemid;
         }
     } else {
         $needles = array('item' => array((int) $id));
         if ((int) $catid >= 0) {
             $user = JFactory::getUser();
             $groups = $user->getAuthorisedViewLevels();
             $categories = Djc2Categories::getInstance(array('state' => '1', 'access' => $groups));
             $category = $categories->get((int) $catid);
             if ($category) {
                 $path = $category->getPath();
                 $path[] = 0;
                 JArrayHelper::toInteger($path);
                 $needles['items'] = $path;
                 $link .= '&cid=' . $catid;
             }
         }
         if ($producerid === null) {
             if (self::$producer_lookup === null) {
                 self::$producer_lookup = array();
                 $db = JFactory::getDbo();
                 $db->setQuery('select id, producer_id from #__djc2_items where published=1');
                 $ids = $db->loadObjectList();
                 if (count($ids) > 0) {
                     foreach ($ids as $row) {
                         if ($row->producer_id > 0) {
                             self::$producer_lookup[$row->id] = $row->producer_id;
                         }
                     }
                 }
             }
             if (isset(self::$producer_lookup[(int) $id])) {
                 $producerid = self::$producer_lookup[(int) $id];
             }
         }
         if ($producerid !== null && (int) $producerid >= 0) {
             if (!is_array($needles['items'])) {
                 $needles['items'] = array();
             }
             $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=' . $item;
         }
     }
     return $link;
 }
Esempio n. 2
0
 public static function getItemRoute($id, $catid = 0, $producerid = null)
 {
     $needles = array('item' => array((int) $id));
     //Create the link
     $link = 'index.php?option=com_djcatalog2&view=item&id=' . $id;
     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) {
         if (self::$producer_lookup === null) {
             self::$producer_lookup = array();
             $db = JFactory::getDbo();
             $db->setQuery('select id, producer_id from #__djc2_items where published=1');
             $ids = $db->loadObjectList();
             if (count($ids) > 0) {
                 foreach ($ids as $row) {
                     if ($row->producer_id > 0) {
                         self::$producer_lookup[$row->id] = $row->producer_id;
                     }
                 }
             }
         }
         if (isset(self::$producer_lookup[(int) $id])) {
             $producerid = self::$producer_lookup[(int) $id];
         }
     }
     if ($producerid !== null && (int) $producerid >= 0) {
         if (!is_array($needles['items'])) {
             $needles['items'] = array();
         }
         $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=' . $item;
     }
     return $link;
 }