Example #1
0
 /**
  * Method to get a list of items.
  * Overriden to inject convert the attribs field into a JParameter object.
  *
  * @return    mixed    $items    An array of objects on success, false on failure.
  */
 public function getItems()
 {
     // Get the list of revisions
     $items = parent::getItems();
     // Iterate through each revision to add some additional stuff
     foreach ($items as $i => &$item) {
         $params = new JRegistry();
         $params->loadString($item->attribs);
         // Convert the parameter fields into objects.
         $items[$i]->params = clone $this->getState('params');
         // Create slugs
         $item->slug = $item->alias ? $item->id . ':' . $item->alias : $item->id;
         $item->project_slug = $item->project_alias ? $item->project_id . ':' . $item->project_alias : $item->project_id;
         // Get the thumbnails
         PFdesignsHelper::getThumbnails($item, 'revision');
     }
     return $items;
 }
Example #2
0
 /**
  * Method to get item data.
  *
  * @param     integer    The id of the item.
  * @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($this->getName() . '.id');
     if ($this->_item === null) {
         $this->_item = array();
     }
     if (!isset($this->_item[$pk])) {
         try {
             $db = $this->getDbo();
             $query = $db->getQuery(true);
             $query->select($this->getState('item.select', 'a.id, a.asset_id, a.project_id, a.parent_id, a.title, a.alias, a.description AS text, ' . 'a.created, a.created_by, a.modified_by, a.checked_out, a.checked_out_time, ' . 'a.attribs, a.access, a.state, a.file_name, a.file_extension, a.file_size,' . 'a.ordering'));
             $query->from('#__pf_design_revisions AS a');
             // Join on project table.
             $query->select('p.title AS project_title, p.alias AS project_alias');
             $query->join('LEFT', '#__pf_projects AS p on p.id = a.project_id');
             // Join on user table.
             $query->select('u.name AS author_name');
             $query->join('LEFT', '#__users AS u on u.id = a.created_by');
             $query->where('a.id = ' . (int) $pk);
             // Filter by published state.
             $published = $this->getState('filter.published');
             $archived = $this->getState('filter.archived');
             if (is_numeric($published)) {
                 $query->where('(a.state = ' . (int) $published . ' OR a.state =' . (int) $archived . ')');
             }
             $db->setQuery($query);
             $data = $db->loadObject();
             if ($error = $db->getErrorMsg()) {
                 throw new Exception($error);
             }
             if (empty($data)) {
                 return JError::raiseError(404, JText::_('COM_PROJECTFORK_ERROR_DESIGN_NOT_FOUND'));
             }
             // Check for published state if filter set.
             if ((is_numeric($published) || is_numeric($archived)) && ($data->state != $published && $data->state != $archived)) {
                 return JError::raiseError(404, JText::_('COM_PROJECTFORK_ERROR_DESIGN_NOT_FOUND'));
             }
             // Generate slugs
             $data->slug = $data->alias ? $data->id . ':' . $data->alias : $data->id;
             $data->project_slug = $data->project_alias ? $data->project_id . ':' . $data->project_alias : $data->project_id;
             // Convert parameter fields to objects.
             $registry = new JRegistry();
             $registry->loadString($data->attribs);
             $data->params = clone $this->getState('params');
             $data->params->merge($registry);
             // Compute selected asset permissions.
             // Technically guest could edit an item, but lets not check that to improve performance a little.
             if (!JFactory::getUser()->get('guest')) {
                 $uid = JFactory::getUser()->get('id');
                 $access = PFdesignsHelper::getRevisionActions($data->id);
                 // Check general edit permission first.
                 if ($access->get('core.edit')) {
                     $data->params->set('access-edit', true);
                 } elseif (!empty($uid) && $access->get('core.edit.own')) {
                     // Check for a valid user and that they are the owner.
                     if ($uid == $data->created_by) {
                         $data->params->set('access-edit', true);
                     }
                 }
             }
             // Compute view access permissions.
             if ($access = $this->getState('filter.access')) {
                 // If the access filter has been set, we already know this user can view.
                 $data->params->set('access-view', true);
             } else {
                 // If no access filter is set, the layout takes some responsibility for display of limited information.
                 $access = PFdesignsHelper::getRevisionActions($data->id);
                 if ($access->get('core.admin')) {
                     $data->params->set('access-view', true);
                 } else {
                     $groups = JFactory::getUser()->getAuthorisedViewLevels();
                     $data->params->set('access-view', in_array($data->access, $groups));
                 }
             }
             // Get the thumbnails
             PFdesignsHelper::getThumbnails($data, 'revision');
             // Get the approval list
             $data->approved = array();
             $data->declined = array();
             $approvals = $this->getItemApprovals($data->id);
             foreach ($approvals as $approval) {
                 $app_uid = (int) $approval->created_by;
                 $app_data = array('created' => $approval->created, 'author' => $approval->author_name);
                 if ($approval->state == '1') {
                     $data->approved[$app_uid] = $app_data;
                 } else {
                     $data->declined[$app_uid] = $app_data;
                 }
             }
             $this->_item[$pk] = $data;
         } catch (JException $e) {
             if ($e->getCode() == 404) {
                 // Need to go thru the error handler to allow Redirect to work.
                 JError::raiseError(404, $e->getMessage());
             } else {
                 $this->setError($e);
                 $this->_item[$pk] = false;
             }
         }
     }
     return $this->_item[$pk];
 }
Example #3
0
 /**
  * Method to get a list of items.
  * Overriden to inject convert the attribs field into a JParameter object.
  *
  * @return    mixed    $items    An array of objects on success, false on failure.
  */
 public function getItems()
 {
     // Get the list of designs
     $items = parent::getItems();
     $labels = $this->getInstance('Labels', 'PFModel');
     $cfg = JComponentHelper::getParams('com_pfdesigns', true);
     $user = JFactory::getUser();
     list($p_w, $p_h) = explode('x', $cfg->get('img_preview_size', '300x300'), 2);
     // Iterate through each design to add some additional stuff
     foreach ($items as $i => &$item) {
         $params = new JRegistry();
         $params->loadString($item->attribs);
         // Convert the parameter fields into objects.
         $items[$i]->params = clone $this->getState('params');
         // Create slugs
         $item->slug = $item->alias ? $item->id . ':' . $item->alias : $item->id;
         $item->project_slug = $item->project_alias ? $item->project_id . ':' . $item->project_alias : $item->project_id;
         $item->album_slug = $item->album_alias ? $item->album_id . ':' . $item->album_alias : $item->album_id;
         // Get the labels
         if ($items[$i]->label_count > 0) {
             $item->labels = $labels->getConnections('com_pfdesigns.design', $item->id);
         } else {
             $item->labels = array();
         }
         // Get thumbnails
         PFdesignsHelper::getThumbnails($item);
         // Get the latest revision
         $item->revision = $this->getLatestRevision($item->id);
         if (!is_null($item->revision)) {
             PFdesignsHelper::getThumbnails($item->revision, 'revision');
         }
     }
     return $items;
 }