Beispiel #1
0
 /**
  * Adds the page title and toolbar.
  *
  */
 protected function addToolbar()
 {
     JRequest::setVar('hidemainmenu', true);
     $uid = JFactory::getUser()->get('id');
     $access = PFprojectsHelper::getActions($this->item->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_PROJECT' : ($is_new ? 'ADD_PROJECT' : 'EDIT_PROJECT'))), 'article-add.png');
     // Build the actions for new and existing records
     // For new records, check the create permission.
     if ($is_new) {
         JToolBarHelper::apply('project.apply');
         JToolBarHelper::save('project.save');
         JToolBarHelper::save2new('project.save2new');
         JToolBarHelper::cancel('project.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('project.apply');
                 JToolBarHelper::save('project.save');
                 JToolBarHelper::save2new('project.save2new');
             }
         }
         JToolBarHelper::save2copy('project.save2copy');
         JToolBarHelper::cancel('project.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 = PFprojectsHelper::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)
 {
     $this->state = $this->get('State');
     $this->item = $this->get('Item');
     $this->form = $this->get('Form');
     $this->params = $this->state->params;
     $this->return_page = $this->get('ReturnPage');
     $this->toolbar = $this->getToolbar();
     // Permission check.
     if ($this->item->id <= 0) {
         $access = PFprojectsHelper::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;
     }
     // Bind form data.
     if (!empty($this->item)) {
         $this->form->bind($this->item);
     }
     // 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->params->get('pageclass_sfx'));
     // Prepare the document
     $this->_prepareDocument();
     // Display the view
     parent::display($tpl);
 }
 /**
  * Method to find all projects a user has access to
  *
  * @param              $pk    The user id
  * @return    array           The project IDs
  */
 public function getProjects($pk = NULL)
 {
     $user = JFactory::getUser($pk);
     $db = JFactory::getDbo();
     $query = $db->getQuery(true);
     $access = PFprojectsHelper::getActions();
     $groups = implode(',', $user->getAuthorisedViewLevels());
     $query->select('id')->from('#__pf_projects')->where('access IN(' . $groups . ')');
     if (!$access->get('core.edit.state') && !$access->get('core.edit')) {
         $query->where('state = 1');
     }
     $db->setQuery((string) $query);
     $projects = (array) $db->loadColumn();
     return $projects;
 }
Beispiel #5
0
    echo JHtml::_('select.options', JHtml::_('jgrid.publishedOptions'), 'value', 'text', $this->state->get('filter.published'), true);
    ?>
                            </select>
                        </div>
                    <?php 
}
?>
                </div>
            </div>
            <div class="clearfix"></div>
            <div class="row-striped">
                <?php 
$k = 0;
$current_cat = '';
foreach ($this->items as $i => $item) {
    $access = PFprojectsHelper::getActions($item->id);
    $link = PfprojectsHelperRoute::getDashboardRoute($item->slug);
    $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;
    // Calculate project progress
    $task_count = (int) $item->tasks;
    $completed = (int) $item->completed_tasks;
    // Repo directory
    $repo_dir = (int) $this->params->get('repo_dir');
    if ($item->progress >= 67) {
        $progress_class = 'info';
    }
    if ($item->progress == 100) {
        $progress_class = 'success';
Beispiel #6
0
 /**
  * Generates the toolbar for the top of the view
  *
  * @return    string    Toolbar with buttons
  */
 protected function getToolbar()
 {
     $id = empty($this->item) || empty($this->item->id) ? null : $this->item->id;
     $access = PFprojectsHelper::getActions($id);
     $uid = JFactory::getUser()->get('id');
     if (!empty($id)) {
         $slug = $this->item->id . ':' . $this->item->alias;
         $return = base64_encode(PFprojectsHelperRoute::getDashboardRoute($slug));
         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::_(PFprojectsHelperRoute::getProjectsRoute() . '&task=form.edit&id=' . $slug . '&return=' . $return)));
     }
     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 = 'category_title, a.title', $direction = 'ASC')
 {
     $app = JFactory::getApplication();
     $params = $app->getParams();
     $menu = $app->getMenu()->getActive();
     $itemid = $app->input->get('Itemid', 0, 'int');
     // 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;
         }
     }
     $this->context .= '.' . $itemid;
     // Adjust the context to support modal layouts.
     $layout = JRequest::getCmd('layout');
     // View Layout
     $this->setState('layout', $layout);
     if ($layout && $layout != 'print') {
         $this->context .= '.' . $layout;
     }
     // Set params state
     $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.
     $access = PFprojectsHelper::getActions();
     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 - Author
     $author = $app->getUserStateFromRequest($this->context . '.filter.author', 'filter_author', '');
     $this->setState('filter.author', $author);
     // Filter - Category
     $cat = $app->getUserStateFromRequest($this->context . '.filter.category', 'filter_category', $params->get('filter_category'));
     $this->setState('filter.category', $cat);
     // Filter - Is set
     $this->setState('filter.isset', is_numeric($state) || !empty($search) || is_numeric($author) || is_numeric($cat));
     // 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
     $sort = $app->getUserStateFromRequest($this->context . '.list.ordering', 'filter_order', $params->get('filter_order'));
     $this->setState('list.ordering', $sort);
     $app->set('filter_order', $sort);
     JRequest::setVar('filter_order', $sort);
     // Set order direction
     $dir = $app->getUserStateFromRequest($this->context . '.list.direction', 'filter_order_Dir', $params->get('filter_order_Dir'));
     $this->setState('list.direction', $dir);
     $app->set('filter_order_Dir', $dir);
     JRequest::setVar('filter_order_Dir', $dir);
     // Call parent method
     parent::populateState($ordering, $direction);
 }
Beispiel #8
0
 /**
  * Method to auto-populate the model state.
  * Note. Calling getState in this method will result in recursion.
  *
  * @return    void
  */
 protected function populateState($ordering = 'category_title, a.title', $direction = 'ASC')
 {
     $app = JFactory::getApplication();
     // 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.
     $access = PFprojectsHelper::getActions();
     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 - Author
     $author = $app->getUserStateFromRequest($this->context . '.filter.author', 'filter_author', '');
     $this->setState('filter.author', $author);
     // Filter - Category
     $cat = $app->getUserStateFromRequest($this->context . '.filter.category', 'filter_category', '');
     $this->setState('filter.category', $cat);
     // Filter - Is set
     $this->setState('filter.isset', is_numeric($state) || !empty($search) || is_numeric($author) || is_numeric($cat));
     // Call parent method
     parent::populateState($ordering, $direction);
 }
Beispiel #9
0
 /**
  * Generates the toolbar for the top of the view
  *
  * @return    string    Toolbar with buttons
  */
 protected function getToolbar()
 {
     $access = PFprojectsHelper::getActions();
     $state = $this->get('State');
     $options = array();
     PFToolbar::button('COM_PROJECTFORK_ACTION_NEW', 'form.add', false, array('access' => $access->get('core.create')));
     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 get the data of a project.
  *
  * @param     integer    The id of the item.
  *
  * @return    mixed      Item data object on success, false on failure.
  */
 public function &getItem($pk = null)
 {
     // Initialise variables.
     $pk = !empty($pk) ? $pk : (int) $this->getState('filter.project');
     if ($this->_item === null) {
         $this->_item = array();
     }
     if (!$pk) {
         $this->_item[$pk] = null;
         return $this->_item[$pk];
     }
     if (!isset($this->_item[$pk])) {
         try {
             $query = $this->_db->getQuery(true);
             $query->select($this->getState('item.select', 'a.id, a.asset_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.start_date, a.end_date'));
             $query->from('#__pf_projects AS a');
             // Join on user table.
             $query->select('u.name AS author')->join('LEFT', '#__users AS u on u.id = a.created_by')->where('a.id = ' . (int) $pk);
             $this->_db->setQuery($query);
             $data = $this->_db->loadObject();
             if ($error = $this->_db->getErrorMsg()) {
                 throw new Exception($error);
             }
             if (empty($data)) {
                 if (PFApplicationHelper::getActiveProjectId() == $pk) {
                     PFApplicationHelper::setActiveProject(0);
                     $this->_item[$pk] = null;
                     return $this->_item[$pk];
                 }
                 return JError::raiseError(404, JText::_('COM_PROJECTFORK_ERROR_PROJECT_NOT_FOUND'));
             }
             // Convert parameter fields to objects.
             $registry = new JRegistry();
             $registry->loadString($data->attribs);
             $data->params = clone $this->getState('params');
             $data->params->merge($registry);
             // Get the attachments
             if (PFApplicationHelper::exists('com_pfrepo')) {
                 $attachments = $this->getInstance('Attachments', 'PFrepoModel');
                 $data->attachments = $attachments->getItems('com_pfprojects.project', $data->id);
             } else {
                 $data->attachments = array();
             }
             // Compute selected asset permissions.
             $user = JFactory::getUser();
             // Technically guest could edit the item, but lets not check that to improve performance a little.
             if (!$user->get('guest')) {
                 $uid = $user->get('id');
                 $access = PFprojectsHelper::getActions($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.
                 $user = JFactory::getUser();
                 $groups = $user->getAuthorisedViewLevels();
                 $data->params->set('access-view', in_array($data->access, $groups));
             }
             $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];
 }
 public function display($cachable = false, $urlparams = false)
 {
     PFprojectsHelper::addSubmenu(JFactory::getApplication()->input->get('view', $this->default_view));
     parent::display();
     return $this;
 }