/** * 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; }
/** * Creates a link to a user item view * * @param string $id The user slug * * @return string $link The link */ public static function getUserRoute($id) { static $dest = null; if (is_null($dest)) { $params = JComponentHelper::getParams('com_projectfork'); $dest = $params->get('user_profile_link'); } $link = null; switch ($dest) { case 'cb': $link = self::getCBRoute($id); break; case 'js': $link = self::getJSRoute($id); break; case 'kunena': $link = self::getKRoute($id); break; } if (!empty($link)) { return $link; } // Default - Projectfork Profile $link = 'index.php?option=com_pfusers&view=user'; $link .= '&id=' . $id; $needles = array('id' => array((int) $id)); if ($item = PFApplicationHelper::itemRoute($needles, 'com_pfusers.user')) { $link .= '&Itemid=' . $item; } elseif ($item = PFApplicationHelper::itemRoute(null, 'com_pfusers.users')) { $link .= '&Itemid=' . $item; } return $link; }
/** * 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; }
/** * 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); }
/** * Called before any type of action * * @param string $route Which action is happening (install|uninstall|discover_install) * @param jadapterinstance $adapter The object responsible for running this script * * @return boolean True on success */ public function preflight($route, JAdapterInstance $adapter) { if (strtolower($route) == 'install' || strtolower($route) == 'update') { if (!defined('PF_LIBRARY')) { jimport('projectfork.library'); } $name = htmlspecialchars($adapter->get('manifest')->name, ENT_QUOTES, 'UTF-8'); // Check if the library is installed if (!defined('PF_LIBRARY')) { JError::raiseWarning(1, JText::_('This extension (' . $name . ') requires the Projectfork Library to be installed!')); return false; } // Check if the projectfork component is installed if (!PFApplicationHelper::exists('com_projectfork')) { JError::raiseWarning(1, JText::_('This extension (' . $name . ') requires the Projectfork Component to be installed!')); return false; } } if (strtolower($route) == 'uninstall') { $dest = JPATH_SITE . "/plugins/system/pftaskexpirynotifier/cron_pf_notifier.php"; $src = JPATH_SITE . "/cli/cron_pf_notifier.php"; //move the file back into its plugin folder otherwise the installer will complain when uninstalling. JFile::move($src, $dest); } return true; }
protected function getButtons() { $components = PFapplicationHelper::getComponents(); $buttons = array(); foreach ($components as $component) { if (!PFApplicationHelper::enabled($component->element)) { continue; } $helper = JPATH_ADMINISTRATOR . '/components/' . $component->element . '/helpers/dashboard.php'; $class = str_replace('com_pf', 'PF', $component->element) . 'HelperDashboard'; if (!JFile::exists($helper)) { continue; } JLoader::register($class, $helper); if (class_exists($class)) { if (in_array('getAdminButtons', get_class_methods($class))) { $com_buttons = (array) call_user_func(array($class, 'getAdminButtons')); $buttons[$component->element] = array(); foreach ($com_buttons as $button) { $buttons[$component->element][] = $button; } } } } return $buttons; }
/** * Configure the Linkbar. * * @param string $view The name of the active view. * * @return void */ public static function addSubmenu($view) { $is_j3 = version_compare(JVERSION, '3.0.0', 'ge'); $forms = array('project', 'category'); if (in_array($view, $forms) && $is_j3) { return; } $components = PFApplicationHelper::getComponents(); $option = JFactory::getApplication()->input->get('option'); $class = $is_j3 ? 'JHtmlSidebar' : 'JSubMenuHelper'; foreach ($components as $component) { if ($component->enabled == '0') { continue; } $title = JText::_($component->element); $parts = explode('-', $title, 2); if (count($parts) == 2) { $title = trim($parts[1]); } call_user_func(array($class, 'addEntry'), $title, 'index.php?option=' . $component->element, $option == $component->element); if ($component->element == self::$extension && ($view == 'projects' || $view == 'categories')) { call_user_func(array($class, 'addEntry'), JText::_('COM_PROJECTFORK_SUBMENU_CATEGORIES'), 'index.php?option=com_categories&extension=' . $component->element, $view == 'categories'); } } }
/** * 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; }
/** * 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 get a list of available buttons * * @return array $buttons The available buttons */ public static function getButtons() { $components = PFApplicationHelper::getComponents(); $buttons = array(); foreach ($components as $component) { if (!PFApplicationHelper::enabled($component->element)) { continue; } // Register component route helper if exists $router = JPATH_SITE . '/components/' . $component->element . '/helpers/route.php'; $class = str_replace('com_pf', 'PF', $component->element) . 'HelperRoute'; if (JFile::exists($router)) { JLoader::register($class, $router); } // Register component dashboard helper if exists $helper = JPATH_ADMINISTRATOR . '/components/' . $component->element . '/helpers/dashboard.php'; $class = str_replace('com_pf', 'PF', $component->element) . 'HelperDashboard'; if (!JFile::exists($helper)) { continue; } JLoader::register($class, $helper); // Get the dashboard button if (class_exists($class)) { if (in_array('getSiteButtons', get_class_methods($class))) { $com_buttons = (array) call_user_func(array($class, 'getSiteButtons')); $buttons[$component->element] = array(); foreach ($com_buttons as $button) { $buttons[$component->element][] = $button; } } } } return $buttons; }
/** * 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; }
/** * Method to get the user field input markup. * * @return string The field input markup. */ protected function getInput() { static $js_loaded = false; if ($js_loaded === false) { // Make sure the JS is loaded only once $js_loaded = true; $script = $this->getJavascript(); JFactory::getDocument()->addScriptDeclaration(implode("\n", $script)); } $task_id = (int) $this->form->getValue('task_id'); $id = (int) $this->form->getValue('id'); if ($task_id && (!$this->value || $this->value == '0.00')) { $db = JFactory::getDbo(); $query = $db->getQuery(true); $query->select('rate')->from('#__pf_tasks')->where('id = ' . $task_id); $db->setQuery($query); $task_rate = $db->loadResult(); if ($task_rate) { $this->value = $task_rate; } } // Setup field values if ($this->value) { $v1 = substr($this->value, 0, -3); $v2 = substr($this->value, -2); } else { $this->value = '0.00'; $v1 = '0'; $v2 = '00'; // Pre-fill from previously entered value if (empty($id) || $id === '0') { $cached = JFactory::getApplication()->getUserState('com_projectfork.' . $this->id); if ($cached && $cached != '0.00') { $this->value = $cached; $v1 = substr($this->value, 0, -3); $v2 = substr($this->value, -2); } } } // Get params $params = PFApplicationHelper::getProjectParams(); // Initialize some field attributes. $attribs = array(); $attribs['readonly'] = (string) $this->element['readonly'] == 'true' ? ' readonly="readonly"' : ''; $attribs['disabled'] = (string) $this->element['disabled'] == 'true' ? ' disabled="disabled"' : ''; $attribs['maxlength'] = (int) $this->element['maxlength'] != '' ? $this->element['maxlength'] : 4; $attribs['currency'] = $params->get('currency_sign'); $attribs['decimal'] = $params->get('decimal_delimiter'); $attribs['position'] = $params->get('currency_position'); if ($attribs['readonly'] == '' && $attribs['disabled'] == '') { $attribs['onchange'] = ' onchange="setMoneyFieldValue(\'' . $this->id . '\');"'; } else { $attribs['onchange'] = ''; } // Get HTML $html = $this->getHTML($v1, $v2, $attribs); // Return HTML return implode("\n", $html); }
/** * Creates a link to the projects overview * * @return string $link The link */ public static function getProjectsRoute() { $link = 'index.php?option=com_pfprojects&view=projects'; if ($item = PFApplicationHelper::itemRoute(null, 'com_pfprojects.projects')) { $link .= '&Itemid=' . $item; } return $link; }
public function __construct() { $pcfg = PFApplicationHelper::getProjectParams(); $this->curr_code = $pcfg->get('currency_code'); $this->curr_sign = $pcfg->get('currency_sign'); $this->curr_pos = $pcfg->get('currency_position'); $cid = (int) JRequest::getVar('cid', null); $this->pid = $cid; }
public static function getProjectEditRoute($project) { $link = 'index.php?option=com_pfprojects&task=form.edit&id=' . $project; if ($item = PFApplicationHelper::itemRoute(null, 'com_pfprojects.form')) { $link .= '&Itemid=' . $item; } elseif ($item = PFApplicationHelper::itemRoute(null, 'com_pfprojects.projects')) { $link .= '&Itemid=' . $item; } return $link; }
/** * Method to get a list of items. * Overriden to inject convert the attribs field into a JParameter object. * * @return mixed $items An array of objects on success, false on failure. */ public function getItems() { $items = parent::getItems(); $base_path = JPATH_ROOT . '/media/com_projectfork/repo/0/logo'; $base_url = JURI::root(true) . '/media/com_projectfork/repo/0/logo'; $tasks_exists = PFApplicationHelper::enabled('com_pftasks'); $repo_exists = PFApplicationHelper::enabled('com_pfrepo'); $pks = JArrayHelper::getColumn($items, 'id'); // Get aggregate data $progress = array(); $total_tasks = array(); $completed_tasks = array(); $total_files = array(); if ($tasks_exists) { JLoader::register('PFtasksModelTasks', JPATH_SITE . '/components/com_pftasks/models/tasks.php'); $tmodel = JModelLegacy::getInstance('Tasks', 'PFtasksModel', array('ignore_request' => true)); $progress = $tmodel->getAggregatedProgress($pks, 'project_id'); $total_tasks = $tmodel->getAggregatedTotal($pks, 'project_id'); $completed_tasks = $tmodel->getAggregatedTotal($pks, 'project_id', 1); } if ($repo_exists) { JLoader::register('PFrepoModelFiles', JPATH_SITE . '/components/com_pfrepo/models/files.php'); $fmodel = JModelLegacy::getInstance('Files', 'PFrepoModel', array('ignore_request' => true)); $total_files = $fmodel->getProjectCount($pks); } // Loop over each row to inject data foreach ($items as $i => &$item) { $params = new JRegistry(); $params->loadString($item->attribs); // Convert the parameter fields into objects. $items[$i]->params = clone $this->getState('params'); // Create slug $items[$i]->slug = $items[$i]->alias ? $items[$i]->id . ':' . $items[$i]->alias : $items[$i]->id; // Try to find the logo img $items[$i]->logo_img = null; if (JFile::exists($base_path . '/' . $item->id . '.jpg')) { $items[$i]->logo_img = $base_url . '/' . $item->id . '.jpg'; } elseif (JFile::exists($base_path . '/' . $item->id . '.jpeg')) { $items[$i]->logo_img = $base_url . '/' . $item->id . '.jpeg'; } elseif (JFile::exists($base_path . '/' . $item->id . '.png')) { $items[$i]->logo_img = $base_url . '/' . $item->id . '.png'; } elseif (JFile::exists($base_path . '/' . $item->id . '.gif')) { $items[$i]->logo_img = $base_url . '/' . $item->id . '.gif'; } // Inject task count $items[$i]->tasks = isset($total_tasks[$item->id]) ? $total_tasks[$item->id] : 0; // Inject completed task count $items[$i]->completed_tasks = isset($completed_tasks[$item->id]) ? $completed_tasks[$item->id] : 0; // Inject progress $items[$i]->progress = isset($progress[$item->id]) ? $progress[$item->id] : 0; // Inject attached files $items[$i]->attachments = isset($total_files[$item->id]) ? $total_files[$item->id] : 0; } return $items; }
/** * Creates a link to the albums overview * * @return string $link The link */ public static function getAlbumsRoute($project = '') { $link = 'index.php?option=com_pfdesigns&view=albums'; if ($project) { $link .= '&filter_project=' . $project; } if ($item = PFApplicationHelper::itemRoute(null, 'com_pfdesigns.albums')) { $link .= '&Itemid=' . $item; } return $link; }
/** * Creates a link to a milestone item view * * @param string $id The milestone slug * @param string $project The project slug. Optional * * @return string $link The link */ public static function getMilestoneRoute($id, $project = '') { $link = 'index.php?option=com_pfmilestones&view=milestone&filter_project=' . $project . '&id=' . $id; $needles = array('id' => array((int) $id)); if ($item = PFApplicationHelper::itemRoute($needles, 'com_pfmilestones.milestone')) { $link .= '&Itemid=' . $item; } elseif ($item = PFApplicationHelper::itemRoute(null, 'com_pfmilestones.milestones')) { $link .= '&Itemid=' . $item; } return $link; }
/** * Creates a link to the timesheet overview * * @param string $project The project slug. Optional * * @return string $link The link */ public static function getTimesheetRoute($project = '') { $link = 'index.php?option=com_pftime&view=timesheet'; $link .= '&filter_project=' . $project; $needles = array('filter_project' => array((int) $project)); if ($item = PFApplicationHelper::itemRoute($needles, 'com_pftime.timesheet')) { $link .= '&Itemid=' . $item; } elseif ($item = PFApplicationHelper::itemRoute(null, 'com_pftime.timesheet')) { $link .= '&Itemid=' . $item; } return $link; }
/** * Creates a link to a topic item view * * @param string $id The topic slug * @param string $project The project slug. Optional * * @return string $link The link */ public static function getRepliesRoute($id, $project = '') { $link = 'index.php?option=com_pfforum&view=replies'; $link .= '&filter_project=' . $project; $link .= '&filter_topic=' . $id; $needles = array('id' => array((int) $id)); if ($item = PFApplicationHelper::itemRoute($needles, 'com_pfforum.topics')) { $link .= '&Itemid=' . $item; } elseif ($item = PFApplicationHelper::itemRoute(null, 'com_pfforum.topics')) { $link .= '&Itemid=' . $item; } return $link; }
/** * 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; }
/** * Creates a link to a task item view * * @param string $id The task slug * @param string $project The project slug. Optional * @param string $milestone The milestone slug. Optional * @param string $list The list slug. Optional * * @return string $link The link */ public static function getTaskRoute($id, $project = '', $milestone = '', $list = '') { $link = 'index.php?option=com_pftasks&view=task'; $link .= '&filter_project=' . $project; $link .= '&filter_milestone=' . $milestone; $link .= '&filter_tasklist=' . $list; $link .= '&id=' . $id; $needles = array('id' => array((int) $id)); if ($item = PFApplicationHelper::itemRoute($needles, 'com_pftasks.task')) { $link .= '&Itemid=' . $item; } elseif ($item = PFApplicationHelper::itemRoute(null, 'com_pftasks.tasks')) { $link .= '&Itemid=' . $item; } return $link; }
/** * Configure the Linkbar. * * @param string $view The name of the active view. * * @return void */ public static function addSubmenu($view) { $components = PFApplicationHelper::getComponents(); $option = JFactory::getApplication()->input->get('option'); foreach ($components as $component) { if ($component->enabled == '0') { continue; } $title = JText::_($component->element); $parts = explode('-', $title, 2); if (count($parts) == 2) { $title = trim($parts[1]); } JSubMenuHelper::addEntry($title, 'index.php?option=' . $component->element, $option == $component->element); } }
/** * 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')); } } }
/** * Formats the logged time into hours and seconds * * @param integer $secs The seconds spent * @param string $style (Optional) Format style * * @return string The formatted time string */ public static function format($secs = 0, $style = 'literal') { static $nf_dec = null; static $nf_th = null; if ($nf_dec == null) { $params = PFApplicationHelper::getProjectParams(0); $nf_dec = $params->get('decimal_delimiter', '.'); $nf_th = $params->get('thousands_delimiter', ','); } $secs = intval($secs); $format = ''; if (!$secs) { return $format; } $minutes = $secs / 60; $hours = floor($minutes / 60); // Literal style switch (strtolower($style)) { case 'decimal': if ($minutes > 0) { $format = number_format($minutes / 60, 1, $nf_dec, $nf_th); } else { $format = 0.0; } break; case 'literal': default: if ($hours > 0) { $minutes = $minutes - $hours * 60; } $minutes = floor($minutes); if ($hours) { $format .= $hours . ' ' . ($hours > 1 ? JText::_('COM_PROJECTFORK_TIME_HOURS') : JText::_('COM_PROJECTFORK_TIME_HOUR')); } if ($minutes) { if ($hours) { $format .= ' '; } $format .= $minutes . ' ' . ($minutes > 1 ? JText::_('COM_PROJECTFORK_TIME_MINUTES') : JText::_('COM_PROJECTFORK_TIME_MINUTE')); } if (!$minutes && !$hours) { $format .= '0 ' . JText::_('COM_PROJECTFORK_TIME_MINUTES'); } break; } return $format; }
/** * Method to format a floating point value according the configured monetary settings * * @param float $value The amount of money * @param int $project Optional project id from which to use the settings * * @return array $options The object list */ public static function money($value = 0.0, $project = 0) { $value = (double) $value; $params = PFApplicationHelper::getProjectParams((int) $project); $nf_dec = $params->get('decimal_delimiter', '.'); $nf_th = $params->get('thousands_delimiter', ','); $currency = $params->get('currency_sign', '$'); $html = array(); if ($params->get('currency_position') == '0') { $html[] = $currency . ' '; } $html[] = number_format($value, 2, $nf_dec, $nf_th); if ($params->get('currency_position') == '1') { $html[] = ' ' . $currency; } return implode('', $html); }
/** * 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; }
/** * 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]; }