/** * Method to auto-populate the model state. * Note: Calling getState in this method will result in recursion. * * @param string $ordering Default field to sort the items by * @param string $direction Default list sorting direction * * @return void */ protected function populateState($ordering = 'a.created', $direction = 'desc') { // Initialise variables. $app = JFactory::getApplication(); // Adjust the context to support modal layouts. if ($layout = JRequest::getVar('layout')) { $this->context .= '.' . $layout; } // Filter - Search $search = $this->getUserStateFromRequest($this->context . '.filter.search', 'filter_search'); $this->setState('filter.search', $search); // Filter - Author $author_id = $app->getUserStateFromRequest($this->context . '.filter.author_id', 'filter_author_id'); $this->setState('filter.author_id', $author_id); // Filter - State $published = $this->getUserStateFromRequest($this->context . '.filter.published', 'filter_published', ''); $this->setState('filter.published', $published); // Filter - Access $access = $this->getUserStateFromRequest($this->context . '.filter.access', 'filter_access', ''); $this->setState('filter.access', $access); // Filter - Project $project = PFApplicationHelper::getActiveProjectId('filter_project'); $this->setState('filter.project', $project); // Disable author filter if no project is selected if (!$project) { $this->setState('filter.author_id', ''); } // List state information. parent::populateState($ordering, $direction); }
/** * 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()) { // Get form input $project = isset($data['project_id']) ? (int) $data['project_id'] : PFApplicationHelper::getActiveProjectId(); $ms = isset($data['milestone_id']) ? (int) $data['milestone_id'] : 0; $user = JFactory::getUser(); $db = JFactory::getDbo(); $is_sa = $user->authorise('core.admin'); $levels = $user->getAuthorisedViewLevels(); $query = $db->getQuery(true); $asset = 'com_pftasks'; $access = true; // Check if the user has access to the project if ($project) { // Check if in allowed projects when not a super admin if (!$is_sa) { $access = in_array($project, PFUserHelper::getAuthorisedProjects()); } // Change the asset name $asset .= '.project.' . $project; } // Check if the user can access the selected milestone when not a super admin if (!$is_sa && $ms && $access) { $query->select('access')->from('#__pf_milestones')->where('id = ' . $db->quote((int) $ms)); $db->setQuery($query); $lvl = $db->loadResult(); $access = in_array($lvl, $levels); } return $user->authorise('core.create', $asset) && $access; }
/** * Method to get a list of tasks * * @return array $items The tasks */ public static function getItems($params) { JLoader::register('PFtasksModelTasks', JPATH_SITE . '/components/com_pftasks/models/tasks.php'); $model = JModelLegacy::getInstance('Tasks', 'PFtasksModel', array('ignore_request' => true)); // Set application parameters in model $app = JFactory::getApplication(); $appParams = $app->getParams(); $model->setState('params', $appParams); // Set the filters based on the module params $model->setState('list.start', 0); $model->setState('list.limit', (int) $params->get('count', 10)); $model->setState('filter.published', 1); // Set project filter if (!(int) $params->get('tasks_of')) { $model->setState('filter.project', PFApplicationHelper::getActiveProjectId()); } else { $project = (int) $params->get('project'); if ($project) { $model->setState('filter.project', $project); } else { $model->setState('filter.project', PFApplicationHelper::getActiveProjectId()); } } // Set completition filter $model->setState('filter.complete', $params->get('filter_complete')); // Sort and order $model->setState('list.ordering', $params->get('sort')); $model->setState('list.direction', $params->get('order')); $items = $model->getItems(); return $items; }
/** * 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()) { $user = JFactory::getUser(); $db = JFactory::getDbo(); $query = $db->getQuery(true); $access = true; $project = isset($data['project_id']) ? (int) $data['project_id'] : PFApplicationHelper::getActiveProjectId(); $album = isset($data['album_id']) ? (int) $data['album_id'] : 0; $asset = 'com_pfdesigns'; // Check if the user has access to the album if (!$user->authorise('core.admin')) { if ($album && $access) { $query->clear(); $query->select('access')->from('#__pf_design_albums')->where('id = ' . (int) $album); $db->setQuery($query); $access = in_array((int) $db->loadResult(), $levels); } } // Check if the user has access to the project if (!$user->authorise('core.admin')) { if ($project && $access) { $query->select('access')->from('#__pf_projects')->where('id = ' . (int) $project); $db->setQuery($query); $access = in_array((int) $db->loadResult(), $user->getAuthorisedViewLevels()); // Change the asset name if (version_compare(PFVERSION, '4.2', 'ge')) { $asset .= '.project.' . $project; } } } return $user->authorise('core.create', $asset) && $access; }
/** * Creates a link to a milestone item view * * @param string $milestone_slug The milestone slug * @param string $project_slug The project slug. Optional * * @return string $link The link */ public static function getMilestoneRoute($milestone_slug, $project_slug = '') { if (!$project_slug) { $project_slug = PFApplicationHelper::getActiveProjectId(); } $link = 'index.php?option=com_pfmilestones&view=milestone&filter_project=' . $project_slug . '&id=' . $milestone_slug; // Get the id from the slug if (strrpos($milestone_slug, ':') !== false) { $slug_parts = explode(':', $milestone_slug); $milestone_id = (int) $slug_parts[0]; } else { $milestone_id = (int) $milestone_slug; } $needles = array('id' => array($milestone_slug)); $item = PFApplicationHelper::itemRoute($needles, 'com_pfmilestones.milestone'); if (!$item) { $app = JFactory::getApplication(); // Stay on current menu item if we are viewing a milestone list if ($app->input->get('option') == 'com_pfmilestones' && $app->input->get('view') == 'milestones') { $item = PFApplicationHelper::getActiveMenuItemId(); } else { // Find overview menu item $item = PFApplicationHelper::itemRoute(null, 'com_pfmilestones.milestones'); } } if ($item) { $link .= '&Itemid=' . $item; } return $link; }
/** * Displays the view. * */ public function display($tpl = null) { // Get data from model $this->items = $this->get('Items'); $this->state = $this->get('State'); $this->albums = $this->get('Albums'); $this->designs = $this->get('Designs'); if (PFApplicationHelper::getActiveProjectId() <= 0) { $text = JText::_('COM_PROJECTFORK_DESIGNS_WARNING_IMPORT_SELECT_PROJECT'); JFactory::getApplication()->enqueueMessage($text); } // Check for errors if (count($errors = $this->get('Errors'))) { JError::raiseError(500, implode("\n", $errors)); return false; } if ($this->getLayout() !== 'modal') { $this->addToolbar(); if (version_compare(JVERSION, '3', 'ge')) { PFdesignsHelper::addSubmenu('import'); $this->sidebar = JHtmlSidebar::render(); } } parent::display($tpl); }
/** * Returns a list of buttons for the frontend * * @return array */ public static function getSiteButtons() { $user = JFactory::getUser(); $buttons = array(); $pid = PFApplicationHelper::getActiveProjectId(); $asset = 'com_pfmilestones'; if ($pid) { $asset .= '.project.' . $pid; } if ($user->authorise('core.create', $asset)) { $buttons[] = array('title' => 'MOD_PF_DASH_BUTTONS_ADD_MILESTONE', 'link' => PFmilestonesHelperRoute::getMilestonesRoute() . '&task=form.add', 'icon' => JHtml::image('com_projectfork/projectfork/header/icon-48-milestoneform.add.png', JText::_('MOD_PF_DASH_BUTTONS_ADD_MILESTONE'), null, true)); } return $buttons; }
/** * Method to display a view. * * @param boolean If true, the view output will be cached * @param array An array of safe url parameters * * @return jcontroller This object to support chaining. */ public function display($cachable = false, $urlparams = false) { $view = JRequest::getCmd('view', $this->default_view); $layout = JRequest::getCmd('layout'); $id = JRequest::getUint('id'); // Inject default view if not set if (empty($view)) { JRequest::setVar('view', $this->default_view); $view = $this->default_view; } if ($view == $this->default_view) { $parent_id = JRequest::getUInt('filter_parent_id'); $project = PFApplicationHelper::getActiveProjectId('filter_project'); if ($parent_id && $project === "") { $this->setRedirect('index.php?option=com_pfrepo&view=' . $this->default_view); return $this; } elseif ($parent_id > 1 && $project > 0) { // Check if the folder belongs to the project $db = JFactory::getDbo(); $query = $db->getQuery(true); $query->select('project_id')->from('#__pf_repo_dirs')->where('id = ' . (int) $parent_id); $db->setQuery($query); $pid = $db->loadResult(); if ($pid != $project) { // No match, redirect to the project root dir $query->clear(); $query->select('id, path')->from('#__pf_repo_dirs')->where('parent_id = 1')->where('project_id = ' . (int) $project); $db->setQuery($query, 0, 1); $dir = $db->loadObject(); if ($dir) { $this->setRedirect('index.php?option=com_pfrepo&view=' . $this->default_view . '&filter_project=' . $project . '&filter_parent_id=' . $dir->id); return $this; } } } } // Check form edit access if ($layout == 'edit' && !$this->checkEditId('com_pfrepo.edit.' . $view, $id)) { $this->setError(JText::sprintf('JLIB_APPLICATION_ERROR_UNHELD_ID', $id)); $this->setMessage($this->getError(), 'error'); $this->setRedirect(JRoute::_('index.php?option=com_pfrepo&view=' . $this->default_view, false)); return false; } // Add the sub-menu PFrepoHelper::addSubmenu($view); // Display the view parent::display($cachable, $urlparams); return $this; }
/** * Gets a list of actions that can be performed. * * @param integer $id The item id * * @return jobject */ public static function getActions($id = 0) { $user = JFactory::getUser(); $result = new JObject(); if (empty($id)) { $pid = PFApplicationHelper::getActiveProjectId(); $asset = empty($pid) ? self::$extension : 'com_pfmilestones.project.' . $pid; } else { $asset = 'com_pfmilestones.milestone.' . (int) $id; } $actions = array('core.admin', 'core.manage', 'core.create', 'core.edit', 'core.edit.own', 'core.edit.state', 'core.delete'); foreach ($actions as $action) { $result->set($action, $user->authorise($action, $asset)); } return $result; }
/** * Method to auto-populate the model state. * Note. Calling getState in this method will result in recursion. * * @return void */ protected function populateState($ordering = null, $direction = null) { parent::populateState(); $app = JFactory::getApplication(); $user = JFactory::getUser(); $model = $this->getInstance('Form', 'PFprojectsModel', array('ignore_request' => true)); $groups = array(); // Filter - State $this->setState('filter.state', 0); // Filter - Project $pid = PFApplicationHelper::getActiveProjectId('filter_project'); $this->setState('filter.project', $pid); // Override group filter by active project if ($pid) { $tmp_groups = $model->getUserGroups($pid); // Get group ids if (is_array($tmp_groups)) { foreach ($tmp_groups as $group) { $groups[] = (int) $group; } } } else { // No active project. Filter by all accessible projects if (!$user->authorise('core.admin')) { $umodel = $this->getInstance('User', 'PFusersModel'); $projects = $umodel->getProjects(); foreach ($projects as $project) { $tmp_groups = $model->getUserGroups($project); if ($tmp_groups !== false) { // Get group ids if (is_array($tmp_groups)) { foreach ($tmp_groups as $group) { $groups[] = (int) $group; } } } } } } if (count($groups)) { $this->setState('filter.groups', $groups); } else { if (!$user->authorise('core.admin')) { $this->setState('filter.groups', array('1')); } } }
/** * 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()) { // Get form input $project = isset($data['project_id']) ? (int) $data['project_id'] : PFApplicationHelper::getActiveProjectId(); $user = JFactory::getUser(); $asset = 'com_pftime'; $access = true; if ($project) { // Check if the user has viewing access when not a super admin if (!$user->authorise('core.admin')) { $access = in_array($project, PFUserHelper::getAuthorisedProjects()); } // Change the asset name $asset .= '.project.' . $project; } return $user->authorise('core.create', $asset) && $access; }
/** * Method to get the field input markup. * * @return string The html field markup */ protected function getInput() { // Add the script to the document head. $script = $this->getJavascript(); JFactory::getDocument()->addScriptDeclaration(implode("\n", $script)); if (!is_array($this->value)) { $this->value = array(); } $project = (int) $this->form->getValue('project_id'); $hidden = '<input type="hidden" name="' . $this->name . '[]" value="" />'; if (!$project) { $project = PFApplicationHelper::getActiveProjectId(); } if (!$project) { return '<span class="readonly">' . JText::_('COM_PROJECTFORK_FIELD_PROJECT_REQ') . '</span>' . $hidden; } $html = $this->getHTML($project); return implode("\n", $html); }
/** * Init the helper class and populates member vars * * @param object $params The module params * @param integer $id The module id * * @return void */ public static function init($params, $id) { $user = JFactory::getUser(); $config = JFactory::getConfig(); $date_now = new JDate('now', 'UTC'); $date_now->setTimezone(new DateTimeZone($user->getParam('timezone', $config->get('offset')))); self::$time_today = floor($date_now->toUnix() / 86400) * 86400; self::$params = $params; self::$id = (int) $id; if ($params->get('mode')) { self::$project = (int) $params->get('project'); } else { self::$project = (int) PFApplicationHelper::getActiveProjectId(); } // Get project dates $dates = modPFganttHelperProjects::getDateRange(); self::$project_start = $dates[0]; self::$project_end = $dates[1]; }
/** * Init the helper class and populates member vars * * @param object $params The module params * @param integer $id The module id * * @return void */ public static function init($params, $id) { $user = JFactory::getUser(); $config = JFactory::getConfig(); $date = JFactory::getDate('now', 'UTC'); $date->setTimezone(new DateTimeZone($user->getParam('timezone', $config->get('offset')))); self::$time_today = floor(strtotime($date->format('Y-m-d H:i:s', true, false)) / 86400) * 86400; self::$params = $params; self::$id = (int) $id; if ($params->get('mode')) { self::$project = (int) $params->get('project'); } else { self::$project = (int) PFApplicationHelper::getActiveProjectId(); } // Get project dates $dates = modPFcalendarHelperProjects::getDateRange(); self::$project_start = $dates[0]; self::$project_end = $dates[1]; }
/** * Method to get a list of tasks * * @return array $items The tasks */ public static function getItems($params) { $user = JFactory::getUser(); JLoader::register('PFtimeModelTimesheet', JPATH_SITE . '/components/com_pftime/models/timesheet.php'); $model = JModelLegacy::getInstance('Timesheet', 'PFtimeModel', array('ignore_request' => true)); // Set application parameters in model $app = JFactory::getApplication(); $appParams = $app->getParams(); $model->setState('params', $appParams); if (intval($params->get('filter_own')) == 1) { $model->setState('filter.author', $user->get('id')); } // Set the filters based on the module params $model->setState('list.start', 0); $model->setState('list.limit', (int) $params->get('count', 5)); $project = PFApplicationHelper::getActiveProjectId(); $model->setState('filter.project', $project); $items = $model->getItems(); return $items; }
/** * Method to auto-populate the model state. * Note. Calling getState in this method will result in recursion. * * @return void */ protected function populateState() { $app = JFactory::getApplication(); $pk = JRequest::getUInt('id'); $parent = JRequest::getUInt('filter_parent_id'); $option = JRequest::getVar('option'); $return = JRequest::getVar('return', null, 'default', 'base64'); $project = PFApplicationHelper::getActiveProjectId(); // Set primary key $this->setState($this->getName() . '.id', $pk); // Set return page $this->setState('return_page', base64_decode($return)); // Set params $params = $app->getParams(); $this->setState('params', $params); // Set layout $this->setState('layout', JRequest::getCmd('layout')); // Set parent id $this->setState($this->getName() . '.parent_id', $parent); // Set project $this->setState($this->getName() . '.project', $project); }
/** * 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') { // Initialise variables. $app = JFactory::getApplication(); // Adjust the context to support modal layouts. if ($layout = JRequest::getVar('layout')) { $this->context .= '.' . $layout; } // Filter - Search $search = $this->getUserStateFromRequest($this->context . '.filter.search', 'filter_search'); $this->setState('filter.search', $search); // Filter - Author $author_id = $app->getUserStateFromRequest($this->context . '.filter.author_id', 'filter_author_id'); $this->setState('filter.author_id', $author_id); // Filter - State $published = $this->getUserStateFromRequest($this->context . '.filter.published', 'filter_published', ''); $this->setState('filter.published', $published); // Filter - Access $access = $this->getUserStateFromRequest($this->context . '.filter.access', 'filter_access', ''); $this->setState('filter.access', $access); // Filter - Topic $topic_id = $app->getUserStateFromRequest($this->context . '.filter.topic_id', 'filter_topic'); $this->setState('filter.topic', $topic_id); $project = PFApplicationHelper::getActiveProjectId('filter_project'); if (!$project && $topic_id > 0) { $query = $this->_db->getQuery(true); $query->select('project_id')->from('#__pf_topics')->where('id = ' . $this->_db->quote((int) $topic_id)); $this->_db->setQuery($query); $project = (int) $this->_db->loadResult(); PFApplicationHelper::setActiveProject($project); } $this->setState('filter.project', $project); // Disable author filter if no project or topic is selected if ($project <= 0 || $topic_id <= 0) { $this->setState('filter.author_id', ''); } // List state information. 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($ordering = 'a.ordering', $direction = 'asc') { // Initialise variables. $app = JFactory::getApplication(); // Adjust the context to support modal layouts. if ($layout = JRequest::getVar('layout')) { $this->context .= '.' . $layout; } $search = $this->getUserStateFromRequest($this->context . '.filter.search', 'filter_search'); $this->setState('filter.search', $search); $manager_id = $app->getUserStateFromRequest($this->context . '.filter.author_id', 'filter_author_id'); $this->setState('filter.author_id', $manager_id); $published = $this->getUserStateFromRequest($this->context . '.filter.published', 'filter_published', ''); $this->setState('filter.published', $published); $album = $this->getUserStateFromRequest($this->context . '.filter.album', 'filter_album', ''); $this->setState('filter.album', $album); $access = $this->getUserStateFromRequest($this->context . '.filter.access', 'filter_access', ''); $this->setState('filter.access', $access); $project = PFApplicationHelper::getActiveProjectId('filter_project'); $this->setState('filter.project', $project); // List state information. 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($ordering = 'project_title, a.title', $direction = 'ASC') { $app = JFactory::getApplication(); $access = PFmilestonesHelper::getActions(); // 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. 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); // Filter - Labels $labels = JRequest::getVar('filter_label', array()); $this->setState('filter.labels', $labels); // Do not allow to filter by author if no project is selected if (!is_numeric($project) || intval($project) == 0) { $this->setState('filter.author', ''); $this->setState('filter.labels', array()); $author = ''; $labels = array(); } if (!is_array($labels)) { $labels = array(); } // Filter - Is set $this->setState('filter.isset', is_numeric($state) || !empty($search) || is_numeric($author) || count($labels)); // Call parent method parent::populateState($ordering, $direction); }
/** * Method to save a record. * * @param string $key The name of the primary key of the URL variable. * @param string $urlVar The name of the URL variable if different from the primary key (sometimes required to avoid router collisions). * * @return boolean True if successful, false otherwise. */ public function save($key = null, $urlVar = null) { // Check for request forgeries. JSession::checkToken() or jexit(JText::_('JINVALID_TOKEN')); // Initialise variables. $app = JFactory::getApplication(); $model = $this->getModel(); $table = $model->getTable(); $data = JRequest::getVar('jform', array(), 'post', 'array'); $context = $this->option . ".edit." . $this->context; $layout = JRequest::getVar('layout'); $file_form = JRequest::getVar('jform', '', 'files', 'array'); $files = array(); // Determine the name of the primary key for the data. if (empty($key)) { $key = $table->getKeyName(); } // To avoid data collisions the urlVar may be different from the primary key. if (empty($urlVar)) { $urlVar = $key; } // Setup redirect links $record_id = JRequest::getInt($urlVar); $link_base = 'index.php?option=' . $this->option . '&view='; $link_list = $link_base . $this->view_list . $this->getRedirectToListAppend(); $link_item = $link_base . $this->view_item . $this->getRedirectToItemAppend($record_id, $urlVar); // Check edit id if (!$this->checkEditId($context, $record_id)) { // Somehow the person just went to the form and tried to save it. We don't allow that. $this->setError(JText::sprintf('JLIB_APPLICATION_ERROR_UNHELD_ID', $record_id)); $this->setMessage($this->getError(), 'error'); $this->setRedirect(JRoute::_($layout != 'modal' ? $link_item : $link_list, false)); return false; } // Get file info $files = $this->getFormFiles($file_form); // Check for upload errors if (!$this->checkFileError($files, $record_id)) { $this->setRedirect(JRoute::_($layout != 'modal' ? $link_item : $link_list, false)); return false; } // Upload file if we have any if (count($files) && !empty($files[0]['tmp_name'])) { $file = $files[0]; // Upload the file $result = $model->upload($file, isset($data['project_id']) ? $data['project_id'] : PFApplicationHelper::getActiveProjectId()); if (is_array($result)) { $data['file'] = $result; } else { $error = $model->getError(); $this->setError($error); $this->setMessage($error, 'error'); $this->setRedirect(JRoute::_($layout != 'modal' ? $link_item : $link_list, false)); return false; } } if (version_compare(JVERSION, '3.0.0', 'ge')) { $this->input->post->set('jform', $data); } else { JRequest::setVar('jform', $data, 'post'); } return parent::save($key, $urlVar); }
/** * Method to get the data that should be injected in the form. * * @return mixed The data for the form. */ protected function loadFormData() { // Check the session for previously entered form data. $app = JFactory::getApplication(); $data = $app->getUserState('com_pftasks.edit.' . $this->getName() . '.data', array()); if (empty($data)) { $data = $this->getItem(); // Set default values if ($this->getState($this->getName() . '.id') == 0) { $active_id = PFApplicationHelper::getActiveProjectId(); $milestone = $app->getUserStateFromRequest('com_pftasks.tasks.filter.milestone', 'milestone_id', ''); $state = $app->getUserStateFromRequest('com_pftasks.tasks.filter.published', 'filter_published', ''); $data->set('project_id', $active_id); if (!empty($milestone)) { $data->set('milestone_id', (int) $milestone); } if (!empty($state) || $state === '0') { $data->set('state', (int) $state); } } } return $data; }
/** * 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') { // Initialise variables. $app = JFactory::getApplication(); $user = JFactory::getUser(); // Adjust the context to support modal layouts. if ($layout = JRequest::getVar('layout')) { $this->context .= '.' . $layout; } // Filter - Search $search = $this->getUserStateFromRequest($this->context . '.filter.search', 'filter_search'); $this->setState('filter.search', $search); // Filter - State $published = $this->getUserStateFromRequest($this->context . '.filter.published', 'filter_published', ''); $this->setState('filter.published', $published); // Filter - Access $access = $this->getUserStateFromRequest($this->context . '.filter.access', 'filter_access', ''); $this->setState('filter.access', $access); // Filter - Project $project = PFApplicationHelper::getActiveProjectId('filter_project'); $this->setState('filter.project', $project); // Filter - Author $author_id = $app->getUserStateFromRequest($this->context . '.filter.author_id', 'filter_author_id'); $this->setState('filter.author_id', $author_id); // Filter - Assigned User $assigned = $app->getUserStateFromRequest($this->context . '.filter.assigned_id', 'filter_assigned_id', ''); $this->setState('filter.assigned_id', $assigned); // Filter - List $task_list = $app->getUserStateFromRequest($this->context . '.filter.tasklist', 'filter_tasklist', ''); $this->setState('filter.tasklist', $task_list); // Filter - Milestone $milestone = $app->getUserStateFromRequest($this->context . '.filter.milestone', 'filter_milestone', ''); $this->setState('filter.milestone', $milestone); // 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); // Do not allow these filters if no project is selected if (!$project) { $this->setState('filter.tasklist', ''); $this->setState('filter.milestone', ''); if ($author_id != $user->id) { $this->setState('filter.author_id', ''); } if ($assigned != $user->id) { $this->setState('filter.assigned_id', ''); } } // List state information. 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($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); }
/** * Method to get the data that should be injected in the form. * * @return mixed The data for the form. */ protected function loadFormData() { // Check the session for previously entered form data. $data = JFactory::getApplication()->getUserState('com_pfforum.edit.' . $this->getName() . '.data', array()); if (empty($data)) { $data = $this->getItem(); // Set default values if ($this->getState($this->getName() . '.id') == 0) { $active_id = PFApplicationHelper::getActiveProjectId(); $data->set('project_id', $active_id); } } return $data; }
/** * Method to auto-populate the model state. * Note. Calling getState in this method will result in recursion. * * @return void */ protected function populateState($ordering = 'a.lft', $direction = 'ASC') { $app = JFactory::getApplication(); // Query limit $this->setState('list.limit', 0); // Query limit start $this->setState('list.start', 0); // Query order field $this->setState('list.ordering', $ordering); // Query order direction $this->setState('list.direction', $direction); // Params $value = $app->getParams(); $this->setState('params', $value); // State $this->setState('filter.published', 1); // Filter - Project $value = PFApplicationHelper::getActiveProjectId(); $this->setState('filter.project', $value); // Filter - Context $value = $app->getUserStateFromRequest($this->context . '.filter.context', 'filter_context', ''); $this->setState('filter.context', $value); // Filter - Item ID $value = $app->getUserStateFromRequest($this->context . '.filter.item_id', 'filter_item_id', ''); $this->setState('filter.item_id', $value); // View Layout $this->setState('layout', JRequest::getCmd('layout')); }
/** * Method to auto-populate the model state. * Note: Calling getState in this method will result in recursion. * * @return void */ protected function populateState() { // Initialise variables. $app = JFactory::getApplication(); $table = $this->getTable(); $key = $table->getKeyName(); // Get the pk of the record from the request. $pk = JRequest::getUInt($key); $option = JRequest::getVar('option'); $this->setState($this->getName() . '.id', $pk); if ($pk && $option == $this->option) { $table = $this->getTable(); if ($table->load($pk)) { $project = (int) $table->project_id; $this->setState($this->getName() . '.project', $project); PFApplicationHelper::setActiveProject($project); $parent_id = (int) $table->parent_id; $this->setState($this->getName() . '.parent_id', $parent_id); } } else { $parent_id = JRequest::getUInt('filter_parent_id', 0); $this->setState($this->getName() . '.parent_id', $parent_id); $project = PFApplicationHelper::getActiveProjectId('filter_project'); if ($project) { $this->setState($this->getName() . '.project', $project); } } // Load the parameters. $value = JComponentHelper::getParams($this->option); $this->setState('params', $value); }
/** * Method to auto-populate the model state. * Note. Calling getState in this method will result in recursion. * * @return void */ protected function populateState($ordering = 'project_title, a.title', $direction = 'ASC') { $app = JFactory::getApplication(); $access = PFmilestonesHelper::getActions(); // 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; // Params $value = $app->getParams(); $this->setState('params', $value); // 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 - Author $author = $app->getUserStateFromRequest($this->context . '.filter.author', 'filter_author', ''); $this->setState('filter.author', $author); // Filter - Labels $labels = JRequest::getVar('filter_label', array()); $this->setState('filter.labels', $labels); // Do not allow to filter by author if no project is selected if (!is_numeric($project) || intval($project) == 0) { $this->setState('filter.author', ''); $this->setState('filter.labels', array()); $author = ''; $labels = array(); } if (!is_array($labels)) { $labels = array(); } // Filter - Is set $this->setState('filter.isset', is_numeric($state) || !empty($search) || is_numeric($author) || count($labels)); // 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); }
public function save($key = null, $urlVar = null) { $rdata = array(); $rdata['success'] = true; $rdata['messages'] = array(); $rdata['data'] = array(); $rdata['file'] = ''; $files_data = JRequest::getVar('qqfile', null, 'files'); $get_data = JRequest::getVar('qqfile', null, 'get'); $dir = JRequest::getUInt('filter_parent_id', JRequest::getUInt('dir_id')); $project = JRequest::getUInt('filter_project', PFApplicationHelper::getActiveProjectId()); $method = null; // Determine the upload method if ($files_data) { $method = 'form'; $file = $files_data; } elseif ($get_data) { $method = 'xhr'; $file = array('name' => $get_data, 'tmp_name' => $get_data, 'error' => 0); } else { $rdata['success'] = false; $rdata['messages'][] = JText::_('COM_PROJECTFORK_WARNING_FILE_UPLOAD_ERROR_4'); $this->sendResponse($rdata); } // Access check. if (!$this->allowSave($d = array()) || defined('PFDEMO')) { $rdata['success'] = false; $rdata['messages'][] = JText::_('JLIB_APPLICATION_ERROR_SAVE_NOT_PERMITTED'); $this->sendResponse($rdata); } // Check for upload error if ($file['error']) { $error = PFrepoHelper::getFileErrorMsg($file['error'], $file['name']); $rdata['success'] = false; $rdata['messages'][] = $error; $this->sendResponse($rdata); } // Find file with the same name in the same dir $db = JFactory::getDbo(); $query = $db->getQuery(true); $name = JFile::makeSafe($file['name']); $query->select('id')->from('#__pf_repo_files')->where('dir_id = ' . (int) $dir)->where('file_name = ' . $db->quote($name)); $db->setQuery($query, 0, 1); $parent_id = (int) $db->loadResult(); $model = $this->getModel(); $result = $model->upload($file, $dir, $method == 'xhr' ? true : false, $parent_id); if (!$result) { $rdata['success'] = false; $rdata['messages'][] = $model->getError(); $this->sendResponse($rdata); } // Prepare data for saving $data = array(); $data['project_id'] = $project; $data['dir_id'] = $dir; $data['file'] = $result; $data['title'] = $result['name']; if ($parent_id) { $data['id'] = $parent_id; } if (!$model->save($data)) { $rdata['success'] = false; $rdata['messages'][] = $model->getError(); $this->sendResponse($rdata); } $this->sendResponse($rdata); }
/** * 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); }
/** * 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') { // Initialise variables. $app = JFactory::getApplication(); // Adjust the context to support modal layouts. if ($layout = JRequest::getVar('layout')) { $this->context .= '.' . $layout; } $project = PFApplicationHelper::getActiveProjectId('filter_project'); $this->setState('filter.project', $project); // List state information. parent::populateState($ordering, $direction); }