Example #1
0
 /**
  * Method to get package data.
  * Packages are all stored in jos_fabrik_packages - so don't use {package} in the query to load them
  *
  * @param   int  $pk  The id of the package.
  *
  * @return  mixed	Menu item data object on success, false on failure.
  */
 public function &getItem($pk = null)
 {
     // Initialise variables.
     $pk = !empty($pk) ? $pk : (int) $this->getState('package.id');
     if (!isset($this->_item)) {
         $this->_item = array();
     }
     if (!isset($this->_item[$pk])) {
         try {
             $db = FabrikWorker::getDbo();
             $query = $db->getQuery(true);
             $query->select('label, params, published, component_name');
             $query->from('#__fabrik_packages');
             $query->where('id = ' . (int) $pk);
             // Filter by published state.
             $published = $this->getState('filter.published');
             $archived = $this->getState('filter.archived');
             if (is_numeric($published)) {
                 $query->where('(published = ' . (int) $published . ' OR published =' . (int) $archived . ')');
             }
             $db->setQuery($query);
             $data = $db->loadObject();
             if ($error = $db->getErrorMsg()) {
                 throw new Exception($error);
             }
             if (empty($data)) {
                 throw new JException(FText::_('COM_FABRIK_ERROR_PACKAGE_NOT_FOUND'), 404);
             }
             // Check for published state if filter set.
             if ((is_numeric($published) || is_numeric($archived)) && ($data->published != $published && $data->published != $archived)) {
                 throw new JException(FText::_('COM_FABRIK_ERROR_PACKAGE_NOT_FOUND'), 404);
             }
             // Convert parameter fields to objects.
             $registry = new Registry();
             $registry->loadJSON($data->params);
             $data->params = clone $this->getState('params');
             $data->params->merge($registry);
             $this->_item[$pk] = $data;
         } catch (JException $e) {
             $this->setError($e);
             $this->_item[$pk] = false;
         }
     }
     return $this->_item[$pk];
 }