/** * 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 = PFtimeHelper::getActions($this->item->id); JToolBarHelper::title(JText::_('COM_PROJECTFORK_PAGE_' . ($checked_out ? 'VIEW_TIME' : ($is_new ? 'ADD_TIME' : 'EDIT_TIME'))), 'article-add.png'); // Build the actions for new and existing records. // For new records, check the create permission. if ($is_new) { JToolBarHelper::apply('time.apply'); JToolBarHelper::save('time.save'); JToolBarHelper::save2new('time.save2new'); JToolBarHelper::cancel('time.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('time.apply'); JToolBarHelper::save('time.save'); JToolBarHelper::save2new('time.save2new'); } } JToolBarHelper::cancel('time.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 = PFtimeHelper::getActions($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; }
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(); // Check for errors. if (count($errors = $this->get('Errors'))) { JError::raiseWarning(500, implode("\n", $errors)); return false; } // Permission check. if ($this->item->id <= 0) { $access = PFtimeHelper::getActions(); $authorised = $access->get('core.create'); } else { $authorised = $this->item->params->get('access-edit'); } if ($authorised !== true) { JError::raiseError(403, JText::_('JERROR_ALERTNOAUTHOR')); 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); }
/** * Method to auto-populate the model state. * Note. Calling getState in this method will result in recursion. * * @return void */ protected function populateState($ordering = 'a.log_date', $direction = 'DESC') { $app = JFactory::getApplication(); $access = PFtimeHelper::getActions(); // Adjust the context to support modal layouts. $layout = JRequest::getCmd('layout'); // View Layout $this->setState('layout', $layout); if ($layout && $layout != 'print') { $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. if (!$access->get('time.edit.state') && !$access->get('time.edit')) { $this->setState('filter.published', 1); $state = ''; } // Filter - Search $search = JRequest::getString('filter_search', ''); $this->setState('filter.search', $search); // Filter - Project // Filter - Project $project = PFApplicationHelper::getActiveProjectId('filter_project'); $this->setState('filter.project', $project); // Filter - Task $task = $app->getUserStateFromRequest($this->context . '.filter.task', 'filter_task', ''); $this->setState('filter.task', $task); // 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 (intval($project) == 0) { $this->setState('filter.author', ''); $this->setState('filter.task', ''); $author = ''; $task = ''; } // Filter - Is set $this->setState('filter.isset', is_numeric($state) || !empty($search) || is_numeric($author) || is_numeric($task)); // Call parent method parent::populateState($ordering, $direction); }
</th> <th width="10%" class="hidden-phone"><?php echo JText::_('COM_PROJECTFORK_TIME_TRACKING_RATE'); ?> </th> <th width="10%" class="hidden-phone"><?php echo JText::_('COM_PROJECTFORK_TIME_TRACKING_BILLABLE'); ?> </th> </tr> </thead> <tbody> <?php $k = 0; foreach ($this->items as $i => $item) { $access = PFtimeHelper::getActions($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; if ($item->log_time > 0) { $list_total_time += (int) $item->log_time; } if ((double) $item->billable_total > 0.0) { $list_total_billable += (double) $item->billable_total; } $percentage = $item->estimate == 0 ? 0 : round($item->log_time * (100 / $item->estimate)); if ($percentage > 100) { $percentage = 100; } $percentage_class = 'progress';
/** * Generates the toolbar for the top of the view * * @return string Toolbar with buttons */ protected function getToolbar() { $access = PFtimeHelper::getActions(); $state = $this->get('State'); if ($access->get('core.create')) { $options = array(); $options[] = array('text' => 'COM_PROJECTFORK_ACTION_NEW', 'task' => 'form.add'); $options[] = array('text' => 'COM_PROJECTFORK_TIME_RECORDER_OPEN', 'task' => 'recorder'); PFToolbar::dropdownButton($options); } $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(); }