/** * Adds the page title and toolbar. * */ protected function addToolbar() { JRequest::setVar('hidemainmenu', true); $id = $this->item->id; $uid = JFactory::getUser()->get('id'); $access = PFdesignsHelper::getAlbumActions($id); $checked_out = !($this->item->checked_out == 0 || $this->item->checked_out == $uid); $is_new = (int) $this->item->id == 0; JToolBarHelper::title(JText::_('COM_PROJECTFORK_PAGE_' . ($checked_out ? 'VIEW_DESIGN_ALBUM' : ($is_new ? 'ADD_DESIGN_ALBUM' : 'EDIT_DESIGN_ALBUM'))), 'article-add.png'); // Build the actions for new and existing records // For new records, check the create permission. if ($is_new) { JToolBarHelper::apply('album.apply'); JToolBarHelper::save('album.save'); JToolBarHelper::save2new('album.save2new'); JToolBarHelper::cancel('album.cancel'); } else { // Can't save the record if it's checked out. if (!$checked_out) { if ($access->get('core.edit') || $access->get('core.edit.own') && $this->item->created_by == $uid) { JToolBarHelper::apply('album.apply'); JToolBarHelper::save('album.save'); JToolBarHelper::save2new('album.save2new'); } } JToolBarHelper::cancel('album.cancel', 'JTOOLBAR_CLOSE'); } }
/** * Method to get item data. * * @param integer $id The id of the item. * @return mixed Item data object on success, false on failure. */ public function getItem($id = null) { // Initialise variables. $id = (int) (!empty($id)) ? $id : $this->getState($this->getName() . '.id'); // Get a row instance. $table = $this->getTable(); // Attempt to load the row. $return = $table->load($id); // Check for a table object error. if ($return === false && $table->getError()) { $this->setError($table->getError()); return false; } $properties = $table->getProperties(1); $value = JArrayHelper::toObject($properties, 'JObject'); // Convert attrib field to Registry. $value->params = new JRegistry(); $value->params->loadString($value->attribs); $value->attribs = $value->params->toArray(); // Compute selected asset permissions. $uid = JFactory::getUser()->get('id'); if ($id) { $access = PFdesignsHelper::getAlbumActions($value->id); } else { $access = PFdesignsHelper::getAlbumActions(); } // Check general edit permission first. if ($access->get('core.edit')) { $value->params->set('access-edit', true); } elseif (!empty($uid) && $access->get('core.edit.own')) { // Now check if edit.own is available. // Check for a valid user and that they are the owner. if ($uid == $value->created_by) { $value->params->set('access-edit', true); } } // Check edit state permission. $value->params->set('access-change', $access->get('core.edit.state')); return $value; }
public function display($tpl = null) { // Initialise variables. $app = JFactory::getApplication(); $user = JFactory::getUser(); // Get model data. $this->state = $this->get('State'); $this->item = $this->get('Item'); $this->form = $this->get('Form'); $this->return_page = $this->get('ReturnPage'); $this->toolbar = $this->getToolbar(); // Permission check. if ($this->item->id <= 0) { $access = PFdesignsHelper::getAlbumActions(); $authorised = $access->get('core.create'); } else { $authorised = $this->item->params->get('access-edit'); } if ($authorised !== true) { JError::raiseError(403, JText::_('JERROR_ALERTNOAUTHOR')); return false; } // Check for errors. if (count($errors = $this->get('Errors'))) { JError::raiseWarning(500, implode("\n", $errors)); return false; } //Escape strings for HTML output $this->pageclass_sfx = htmlspecialchars($this->state->params->get('pageclass_sfx')); $this->params = $this->state->params; $this->user = $user; // Prepare the document $this->_prepareDocument(); // Display the view parent::display($tpl); }
/** * Generates the toolbar for the top of the view * * @return string Toolbar with buttons */ protected function getToolbar() { $access = PFdesignsHelper::getAlbumActions(); $state = $this->get('State'); PFToolbar::button('COM_PROJECTFORK_ACTION_NEW', 'albumform.add', false, array('access' => $access->get('core.create'))); $options = array(); if ($access->get('core.edit.state')) { $options[] = array('text' => 'COM_PROJECTFORK_ACTION_PUBLISH', 'task' => $this->getName() . '.publish'); $options[] = array('text' => 'COM_PROJECTFORK_ACTION_UNPUBLISH', 'task' => $this->getName() . '.unpublish'); $options[] = array('text' => 'COM_PROJECTFORK_ACTION_ARCHIVE', 'task' => $this->getName() . '.archive'); $options[] = array('text' => 'COM_PROJECTFORK_ACTION_CHECKIN', 'task' => $this->getName() . '.checkin'); } if ($state->get('filter.published') == -2 && $access->get('core.delete')) { $options[] = array('text' => 'COM_PROJECTFORK_ACTION_DELETE', 'task' => $this->getName() . '.delete'); } elseif ($access->get('core.edit.state')) { $options[] = array('text' => 'COM_PROJECTFORK_ACTION_TRASH', 'task' => $this->getName() . '.trash'); } if (count($options)) { PFToolbar::listButton($options); } PFToolbar::filterButton($this->state->get('filter.isset')); return PFToolbar::render(); }
/** * Method to auto-populate the model state. * Note. Calling getState in this method will result in recursion. * * @return void */ protected function populateState($ordering = 'a.ordering', $direction = 'ASC') { $app = JFactory::getApplication(); // Adjust the context to support modal layouts. $layout = JRequest::getCmd('layout'); // View Layout $this->setState('layout', $layout); if ($layout) { $this->context .= '.' . $layout; } // Params $value = $app->getParams(); $this->setState('params', $value); // State $state = $app->getUserStateFromRequest($this->context . '.filter.published', 'filter_published', ''); $this->setState('filter.published', $state); // Filter on published for those who do not have edit or edit.state rights. $access = PFdesignsHelper::getAlbumActions(); if (!$access->get('core.edit.state') && !$access->get('core.edit')) { $this->setState('filter.published', 1); $state = ''; } // Filter - Search $search = JRequest::getString('filter_search', ''); $this->setState('filter.search', $search); // Filter - Project $project = PFApplicationHelper::getActiveProjectId('filter_project'); $this->setState('filter.project', $project); // Filter - Author $author = $app->getUserStateFromRequest($this->context . '.filter.author', 'filter_author', ''); $this->setState('filter.author', $author); // Do not allow some filters if no project is selected if (!is_numeric($project) || intval($project) == 0) { $this->setState('filter.author', ''); $author = ''; } // Filter - Is set $this->setState('filter.isset', is_numeric($state) || !empty($search) || is_numeric($author)); // Call parent method parent::populateState($ordering, $direction); }
?> </th> <?php } ?> <th width="1%" class="nowrap hidden-phone"> <?php echo JHtml::_('grid.sort', 'JGRID_HEADING_ID', 'a.id', $list_dir, $list_order); ?> </th> </tr> </thead> <tbody> <?php foreach ($this->items as $i => $item) { $access = PFdesignsHelper::getAlbumActions($item->id); $ordering = $list_order == 'a.ordering'; $can_create = $access->get('core.create'); $can_edit = $access->get('core.edit'); $can_checkin = $user->authorise('core.manage', 'com_checkin') || $item->checked_out == $uid || $item->checked_out == 0; $can_edit_own = $access->get('core.edit.own') && $item->created_by == $uid; $can_change = $access->get('core.edit.state') && $can_checkin; // Prepare re-order conditions $order_up = false; $order_down = false; $prev_item = null; $next_item = null; $prev_i = $i - 1; $next_i = $i + 1; if (array_key_exists($prev_i, $this->items)) { $prev_item = $this->items[$prev_i];
/** * Build a list of item albums * * @return jdatabasequery */ public function getAlbums() { // Return empty array if no project is select $project = (int) $this->getState('filter.project'); if ($project <= 0) { return array(); } $db = $this->getDbo(); $query = $db->getQuery(true); $user = JFactory::getUser(); $access = PFdesignsHelper::getAlbumActions(); // Construct the query $query->select('c.id AS value, c.title AS text')->from('#__pf_design_albums AS c')->join('INNER', '#__pf_designs AS a ON a.album_id = c.id'); // Implement View Level Access if (!$user->authorise('core.admin', 'com_pfdesigns')) { $levels = implode(',', $user->getAuthorisedViewLevels()); $query->where('c.access IN (' . $levels . ')'); } // Filter fields $filters = array(); $filters['c.project_id'] = array('INT-NOTZERO', $this->getState('filter.project')); if (!$access->get('core.edit.state') && !$access->get('core.edit')) { $filters['c.state'] = array('STATE', '1'); } // Apply Filter PFQueryHelper::buildFilter($query, $filters); // Group and order $query->group('c.id'); $query->order('c.title ASC'); // Return the result $db->setQuery((string) $query); return (array) $db->loadObjectList(); }