/** * 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 = PFtasksHelper::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; }
/** * Add the page title and toolbar. * */ protected function addToolbar() { JRequest::setVar('hidemainmenu', true); $uid = JFactory::getUser()->get('id'); $access = PFtasksHelper::getActions($this->item->id); $checked_out = !($this->item->checked_out == 0 || $this->item->checked_out == $uid); $is_new = $this->item->id == 0; JToolBarHelper::title(JText::_('COM_PROJECTFORK_PAGE_' . ($checked_out ? 'VIEW_TASK' : ($is_new ? 'ADD_TASK' : 'EDIT_TASK'))), 'article-add.png'); // Build the actions for new and existing records. // For new records, check the create permission. if ($is_new) { JToolBarHelper::apply('task.apply'); JToolBarHelper::save('task.save'); JToolBarHelper::save2new('task.save2new'); JToolBarHelper::cancel('task.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('task.apply'); JToolBarHelper::save('task.save'); JToolBarHelper::save2new('task.save2new'); } } JToolBarHelper::save2copy('task.save2copy'); JToolBarHelper::cancel('task.cancel', 'JTOOLBAR_CLOSE'); } }
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 = PFtasksHelper::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); }
?> <ul class="list-tasks list-striped list-condensed unstyled" id="tasklist_<?php echo $i; ?> "> <?php $k = 1 - $k; $list_open = true; $current_list = $item->list_title; $x++; // End of Task List } ?> <?php // Start task item $access = PFtasksHelper::getActions($item->id); $item_order[] = $item->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; // Task completed javascript $cbjs = ''; $disabled = ' disabled = disabled'; $checked = $item->complete ? ' checked="checked"' : ''; if ($can_change) { $cbjs = ' onclick="setTaskComplete(' . intval($item->id) . ', this.checked);"'; $disabled = ''; } // list item class
/** * Method to auto-populate the model state. * Note. Calling getState in this method will result in recursion. * * @return void */ protected function populateState($ordering = 'a.title', $direction = 'ASC') { $app = JFactory::getApplication(); $access = PFtasksHelper::getActions(); $user = JFactory::getUser(); // 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('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 - Milestone $milestone = $app->getUserStateFromRequest($this->context . '.filter.milestone', 'filter_milestone', ''); $this->setState('filter.milestone', $milestone); // Filter - Task list $list = $app->getUserStateFromRequest($this->context . '.filter.tasklist', 'filter_tasklist', ''); $this->setState('filter.tasklist', $list); // Filter - Author $author = $app->getUserStateFromRequest($this->context . '.filter.author', 'filter_author', ''); $this->setState('filter.author', $author); // Filter - Assigned User $assigned = $app->getUserStateFromRequest($this->context . '.filter.assigned', 'filter_assigned', ''); $this->setState('filter.assigned', $assigned); // Filter - Priority $priority = $app->getUserStateFromRequest($this->context . '.filter.priority', 'filter_priority', ''); $this->setState('filter.priority', $priority); // Filter - Complete $complete = $app->getUserStateFromRequest($this->context . '.filter.complete', 'filter_complete', ''); $this->setState('filter.complete', $complete); // Filter - Labels $labels = JRequest::getVar('filter_label', array()); $this->setState('filter.labels', $labels); // Do not allow some filters if no project is selected if (!is_numeric($project) || intval($project) == 0) { $this->setState('filter.tasklist', ''); $this->setState('filter.milestone', ''); $this->setState('filter.labels', array()); $milestone = ''; $list = ''; $labels = array(); if ($author != $user->id) { $this->setState('filter.author', ''); $author = ''; } if ($assigned != $user->id) { $this->setState('filter.assigned', ''); $assigned = ''; } } if (!is_array($labels)) { $labels = array(); } // Filter - Is set $this->setState('filter.isset', is_numeric($state) || !empty($search) || is_numeric($author) || is_numeric($assigned) || is_numeric($list) && $list > 0 || is_numeric($milestone) && $milestone > 0 || count($labels) || is_numeric($complete)); // Call parent method parent::populateState($ordering, $direction); }
function prepareData() { $module = JModuleHelper::getModule('mod_pf_time'); $params = new JRegistry(); $params->loadString($module->params); $action = JRequest::getVar('action', null); $filter_author = $params->get('filter_own', null); $filter_start_date = JRequest::getVar('filter_start_date', null); $filter_end_date = JRequest::getVar('filter_end_date', null); $filter_project = JRequest::getVar('filter_project', null); $app = JFactory::getApplication(); $db = JFactory::getDBO(); $query = $db->getQuery(true); $user = JFactory::getUser(); $access = PFtasksHelper::getActions(); $taskdata = null; // Select the required fields from the table. $query->select('a.id, a.project_id, a.task_id, a.task_title, a.description, ' . 'a.checked_out, a.checked_out_time, a.state, a.access, a.rate, a.billable,' . 'a.created, a.created_by, a.log_date, a.log_time '); $query->from('#__pf_timesheet AS a'); // Join over the users for the checked out user. $query->select('uc.name AS editor'); $query->join('LEFT', '#__users AS uc ON uc.id = a.checked_out'); // Join over the asset groups. $query->select('ag.title AS access_level'); $query->join('LEFT', '#__viewlevels AS ag ON ag.id = a.access'); // Join over the users for the author. $query->select('ua.name AS author_name'); $query->join('LEFT', '#__users AS ua ON ua.id = a.created_by'); // Join over the projects for the project title. $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 over the tasks for the task title. $query->select('t.id AS task_exists, t.alias AS task_alias, t.estimate'); $query->join('LEFT', '#__pf_tasks AS t ON t.id = a.task_id'); // Join over the milestones for the milestone alias. $query->select('m.id AS milestone_id, m.alias AS milestone_alias'); $query->join('LEFT', '#__pf_milestones AS m ON m.id = t.milestone_id'); // Join over the task lists for the list alias. $query->select('l.id AS list_id, l.alias AS list_alias'); $query->join('LEFT', '#__pf_task_lists AS l ON l.id = t.list_id'); // Implement View Level Access if (!$user->authorise('core.admin')) { $levels = implode(',', $user->getAuthorisedViewLevels()); $query->where('a.access IN (' . $levels . ')'); } // Calculate billable amount $query->select('CASE WHEN (a.billable = 1 AND a.rate > 0 AND a.log_time > 0) ' . 'THEN ((a.log_time / 60) * (a.rate / 60)) ' . 'ELSE "0.00"' . 'END AS billable_total'); // Filter fields $filters = array(); $filters['a.project_id'] = array('INT-NOTZERO', $filter_project); if ($filter_author == 1) { $filters['a.created_by'] = array('INT-NOTZERO', $user->get('id')); } // Apply Filter PFQueryHelper::buildFilter($query, $filters); //finally add our own date range filter if ($filter_start_date && $filter_end_date) { $query->where("a.log_date between '{$filter_start_date}' AND '{$filter_end_date}'"); } else { if ($filter_start_date) { $query->where("a.log_date >= '{$filter_start_date}'"); } else { if ($filter_end_date) { $query->where("a.log_date <= '{$filter_end_date}'"); } } } // Add the list ordering clause. $order_col = 'a.log_date'; $order_dir = 'desc'; $query->order($db->escape($order_col . ' ' . $order_dir)); $query->group('a.id'); $db->setQuery($query); $taskdata = $db->loadObjectList(); if ($action == 'export') { exportData($taskdata); } else { displayData($taskdata); } }
/** * Generates the toolbar for the top of the view * * @return string Toolbar with buttons */ protected function getToolbar() { $access = PFtasksHelper::getActions(); $state = $this->get('State'); $create = $access->get('core.create'); if ($create) { $items = array(); $items[] = array('text' => 'COM_PROJECTFORK_ACTION_NEW_TASK', 'task' => 'taskform.add'); $items[] = array('text' => 'COM_PROJECTFORK_ACTION_NEW_TASKLIST', 'task' => 'tasklistform.add'); PFToolbar::dropdownButton($items); } $items = array(); if ($access->get('core.edit.state')) { $items[] = array('text' => 'COM_PROJECTFORK_ACTION_PUBLISH', 'task' => $this->getName() . '.publish'); $items[] = array('text' => 'COM_PROJECTFORK_ACTION_UNPUBLISH', 'task' => $this->getName() . '.unpublish'); $items[] = array('text' => 'COM_PROJECTFORK_ACTION_ARCHIVE', 'task' => $this->getName() . '.archive'); $items[] = array('text' => 'COM_PROJECTFORK_ACTION_CHECKIN', 'task' => $this->getName() . '.checkin'); } if ($state->get('filter.published') == -2 && $access->get('core.delete')) { $items[] = array('text' => 'COM_PROJECTFORK_ACTION_DELETE', 'task' => $this->getName() . '.delete'); } elseif ($access->get('core.edit.state')) { $items[] = array('text' => 'COM_PROJECTFORK_ACTION_TRASH', 'task' => $this->getName() . '.trash'); } if (count($items)) { PFToolbar::listButton($items); } 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.title', $direction = 'ASC') { $app = JFactory::getApplication(); $access = PFtasksHelper::getActions(); $user = JFactory::getUser(); // Adjust the context to support modal layouts. $layout = JRequest::getCmd('layout'); $params = $app->getParams(); $itemid = $app->input->get('Itemid', 0, 'int'); $menu = $app->getMenu()->getActive(); // Merge app params with menu item params if ($menu) { $menu_params = new JRegistry(); $menu_params->loadString($menu->params); $clone_params = clone $menu_params; $clone_params->merge($params); if (!$itemid) { $itemid = (int) $menu->id; } } // View Layout $this->setState('layout', $layout); if ($layout && $layout != 'print') { $this->context .= '.' . $layout; } $this->context .= '.' . $itemid; // Set Params $this->setState('params', $params); // State $state = $app->getUserStateFromRequest($this->context . '.filter.published', 'filter_published', $params->get('filter_published')); $this->setState('filter.published', $state); // 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 $search = JRequest::getString('filter_search', ''); $this->setState('filter.search', $search); // Filter - Project $project = PFApplicationHelper::getActiveProjectId('filter_project'); $this->setState('filter.project', $project); // Filter - Milestone $milestone = $app->getUserStateFromRequest($this->context . '.filter.milestone', 'filter_milestone', ''); $this->setState('filter.milestone', $milestone); // Filter - Task list $list = $app->getUserStateFromRequest($this->context . '.filter.tasklist', 'filter_tasklist', ''); $this->setState('filter.tasklist', $list); // Filter - Author $author = $app->getUserStateFromRequest($this->context . '.filter.author', 'filter_author', ''); $this->setState('filter.author', $author); // Filter - Assigned User $assigned = $app->getUserStateFromRequest($this->context . '.filter.assigned', 'filter_assigned', ''); $this->setState('filter.assigned', $assigned); // Filter - Priority $priority = $app->getUserStateFromRequest($this->context . '.filter.priority', 'filter_priority', ''); $this->setState('filter.priority', $priority); // Filter - Complete $complete = $app->getUserStateFromRequest($this->context . '.filter.complete', 'filter_complete', ''); $this->setState('filter.complete', $complete); // Filter - Labels $labels = JRequest::getVar('filter_label', array()); $this->setState('filter.labels', $labels); // Do not allow some filters if no project is selected if (!is_numeric($project) || intval($project) == 0) { $this->setState('filter.tasklist', ''); $this->setState('filter.milestone', ''); $this->setState('filter.labels', array()); $milestone = ''; $list = ''; $labels = array(); if ($author != $user->id) { $this->setState('filter.author', ''); $author = ''; } if ($assigned != $user->id) { $this->setState('filter.assigned', ''); $assigned = ''; } } if (!is_array($labels)) { $labels = array(); } // Filter - Is set $this->setState('filter.isset', is_numeric($state) || !empty($search) || is_numeric($author) || is_numeric($assigned) || is_numeric($list) && $list > 0 || is_numeric($milestone) && $milestone > 0 || count($labels) || is_numeric($complete)); // Set list limit $cfg = JFactory::getConfig(); $limit = $app->getUserStateFromRequest($this->context . '.list.limit', 'limit', $params->get('display_num', $cfg->get('list_limit')), 'uint'); $this->setState('list.limit', $limit); $app->set('list_limit', $limit); JRequest::setVar('list_limit', $limit); // Set sorting order $ordering = $app->getUserStateFromRequest($this->context . '.list.ordering', 'filter_order', $params->get('filter_order')); $this->setState('list.ordering', $ordering); $app->set('filter_order', $ordering); JRequest::setVar('filter_order', $ordering); // Set order direction $direction = $app->getUserStateFromRequest($this->context . '.list.direction', 'filter_order_Dir', $params->get('filter_order_Dir')); $this->setState('list.direction', $direction); $app->set('filter_order_Dir', $direction); JRequest::setVar('filter_order_Dir', $direction); // Call parent method parent::populateState($ordering, $direction); }
/** * Method to auto-populate the model state. * Note. Calling getState in this method will result in recursion. * * @return void */ protected function populateState() { // Load state from the request. $pk = JRequest::getInt('id'); $this->setState($this->getName() . '.id', $pk); $offset = JRequest::getUInt('limitstart'); $this->setState('list.offset', $offset); // Load the parameters. $params = JFactory::getApplication('site')->getParams(); $this->setState('params', $params); $access = PFtasksHelper::getActions(); if (!$access->get('core.edit.state') && !$access->get('core.edit')) { $this->setState('filter.published', 1); $this->setState('filter.archived', 2); } }
/** * Generates the toolbar for the top of the view * * @return string Toolbar with buttons */ protected function getToolbar() { $access = PFtasksHelper::getActions($this->item->id); $uid = JFactory::getUser()->get('id'); $slug = $this->item->id . ':' . $this->item->alias; PFToolbar::button('COM_PROJECTFORK_ACTION_EDIT', '', false, array('access' => $access->get('core.edit') || $access->get('core.edit.own') && $uid == $this->item->created_by, 'href' => JRoute::_(PFtasksHelperRoute::getTasksRoute() . '&task=taskform.edit&id=' . $slug))); return PFToolbar::render(); }