/** * Add the page title and toolbar. * * @return void */ protected function addToolbar() { JRequest::setVar('hidemainmenu', true); $uid = JFactory::getUser()->get('id'); $is_new = $this->item->id == 0; $checked_out = !($this->item->checked_out == 0 || $this->item->checked_out == $uid); $access = PFforumHelper::getReplyActions($this->item->id, $this->state->get('topic_id')); JToolBarHelper::title(JText::_('COM_PROJECTFORK_PAGE_' . ($checked_out ? 'VIEW_REPLY' : ($is_new ? 'ADD_REPLY' : 'EDIT_REPLY'))), 'article-add.png'); // Build the actions for new and existing records. // For new records, check the create permission. if ($is_new && $this->state->get('topic_id')) { JToolBarHelper::apply('reply.apply'); JToolBarHelper::save('reply.save'); JToolBarHelper::save2new('reply.save2new'); JToolBarHelper::cancel('reply.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('reply.apply'); JToolBarHelper::save('reply.save'); JToolBarHelper::save2new('reply.save2new'); } } // JToolBarHelper::save2copy('reply.save2copy'); JToolBarHelper::cancel('reply.cancel', 'JTOOLBAR_CLOSE'); } }
/** * Method to get item data. * * @param integer $pk The id of the item. * * @return mixed $item Item data object on success, false on failure. */ public function getItem($pk = null) { // Get the record from the parent class method $item = parent::getItem($pk); if ($item === false) { return false; } // Compute selected asset permissions. $user = JFactory::getUser(); $uid = $user->get('id'); $access = PFforumHelper::getReplyActions($item->id); $view_access = true; if ($item->access && !$user->authorise('core.admin')) { $view_access = in_array($item->access, $user->getAuthorisedViewLevels()); } $item->params->set('access-view', $view_access); if (!$view_access) { $item->params->set('access-edit', false); $item->params->set('access-change', false); } else { // Check general edit permission first. if ($access->get('core.edit')) { $item->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 == $item->created_by) { $item->params->set('access-edit', true); } } // Check edit state permission. $item->params->set('access-change', $access->get('core.edit.state')); } return $item; }
/** * Method to check if you can add a new record. * * @param array $data An array of input data. * * @return boolean */ protected function allowAdd($data = array()) { $topic = isset($data['topic_id']) ? (int) $data['topic_id'] : JRequest::getUInt('filter_topic'); $access = PFforumHelper::getActions($topic); if (!$topic) { $this->setError(JText::_('COM_PROJECTFORK_WARNING_TOPIC_NOT_FOUND')); return false; } $access = PFforumHelper::getReplyActions(); return $access->get('core.create'); }
</a> </div> <?php } ?> </div> </div> </div> <!-- End Topic --> <!-- Start Replies --> <?php $k = 0; foreach ($this->items as $i => $item) { $access = PFforumHelper::getReplyActions($item->id); $can_create = $access->get('core.create'); $can_edit = $access->get('core.edit'); $can_change = $access->get('core.edit.state'); $can_edit_own = $access->get('core.edit.own') && $item->created_by == $uid; $date_opts = array('past-class' => '', 'past-icon' => 'calendar'); ?> <div class="row-fluid"> <div class="span12"> <img title="<?php echo $this->escape($item->author_name); ?> " src="<?php echo JHtml::_('projectfork.avatar.path', $item->created_by); ?>
/** * Add the page title and toolbar. * * @return void */ protected function addToolbar() { $access = PFforumHelper::getReplyActions(null, (int) $this->state->get('filter.topic')); JToolBarHelper::title(JText::_('COM_PROJECTFORK_REPLIES_TITLE'), 'article.png'); if ($access->get('core.create')) { JToolBarHelper::addNew('reply.add'); } if ($access->get('core.edit')) { JToolBarHelper::editList('reply.edit'); } if ($access->get('core.edit.state')) { JToolBarHelper::divider(); JToolBarHelper::publish('replies.publish', 'JTOOLBAR_PUBLISH', true); JToolBarHelper::unpublish('replies.unpublish', 'JTOOLBAR_UNPUBLISH', true); JToolBarHelper::divider(); JToolBarHelper::archiveList('replies.archive'); JToolBarHelper::checkin('replies.checkin'); } if ($this->state->get('filter.published') == -2 && $access->get('core.delete')) { JToolBarHelper::deleteList('', 'replies.delete', 'JTOOLBAR_EMPTY_TRASH'); JToolBarHelper::divider(); } elseif ($access->get('core.edit.state')) { JToolBarHelper::trash('replies.trash'); JToolBarHelper::divider(); } }
/** * Method to auto-populate the model state. * Note. Calling getState in this method will result in recursion. * * @return void */ protected function populateState($ordering = 'a.created', $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 - Topic $topic = JRequest::getCmd('filter_topic', ''); $this->setState('filter.topic', $topic); // Filter - Project $project = PFApplicationHelper::getActiveProjectId('filter_project'); if (!$project && $topic > 0) { $db = JFactory::getDbo(); $query = $db->getQuery(true); $query->select('project_id')->from('#__pf_topics')->where('id = ' . $db->quote((int) $topic)); $db->setQuery($query); $project = (int) $db->loadResult(); PFApplicationHelper::setActiveProject($project); } $this->setState('filter.project', $project); if ($topic) { $access = PFforumHelper::getActions($topic); } else { $access = PFforumHelper::getReplyActions(); } // Filter on published for those who do not have edit or edit.state rights. if (!$access->get('core.edit.state') && !$access->get('core.edit')) { $this->setState('filter.published', 1); $state = ''; } // Filter - Search $value = JRequest::getString('filter_search', ''); $this->setState('filter.search', $value); // Filter - Author $author = $app->getUserStateFromRequest($this->context . '.filter.author', 'filter_author', ''); $this->setState('filter.author', $author); // Do not allow to filter by author 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); }
/** * Generates the toolbar for the top of the view * * @return string Toolbar with buttons */ protected function getToolbar() { $options = array(); $topic = $this->state->get($this->get('Name') . '.topic'); $access = PFforumHelper::getReplyActions($this->item->id, $topic); if ($access->get('core.create')) { PFToolbar::button('JSAVE', $this->getName() . '.save', false, array('icon' => 'icon-white icon-ok')); } PFToolbar::button('JCANCEL', $this->getName() . '.cancel', false, array('class' => '', 'icon' => '')); return PFToolbar::render(); }