/** * 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; }
/** * 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; } } return true; }
<?php /** * @package Projectfork Timesheet Module * * @author ANGEK DESIGN (Kon Angelopoulos) * @copyright Copyright (C) 2013 - 2015 ANGEK DESIGN. All rights reserved. * @license http://www.gnu.org/licenses/gpl.html GNU/GPL, see LICENSE.txt **/ defined('_JEXEC') or die; if (!jimport('projectfork.framework')) { echo JText::_('MOD_PF_TIME_PROJECTFORK_LIB_NOT_INSTALLED'); return; } if (!PFApplicationHelper::exists('com_projectfork')) { echo JText::_('MOD_PF_TIME_PROJECTFORK_NOT_INSTALLED'); return; } require_once dirname(__FILE__) . '/helper.php'; $action = JRequest::getVar('action', null); if ($action) { if ($action == 'export') { modPFtimeHelper::exportCSV(); } elseif ($action == 'filter') { modPFtimeHelper::displayData(); } } // Include layout $moduleclass_sfx = htmlspecialchars($params->get('moduleclass_sfx')); require JModuleHelper::getLayoutPath('mod_pf_time', $params->get('layout', 'default'));
/** * Method to save the form data. * * @param array The form data * * @return boolean True on success */ public function save($data) { $record = $this->getTable(); $key = $record->getKeyName(); $pk = !empty($data[$key]) ? $data[$key] : (int) $this->getState($this->getName() . '.id'); $is_new = true; if ($pk > 0) { if ($record->load($pk)) { $is_new = false; } } if (!$is_new) { $data['project_id'] = $record->project_id; } // Make sure the title and alias are always unique $data['alias'] = ''; list($title, $alias) = $this->generateNewTitle($data['title'], $data['project_id'], $data['alias'], $pk); $data['title'] = $title; $data['alias'] = $alias; // Handle permissions and access level if (isset($data['rules'])) { $access = PFAccessHelper::getViewLevelFromRules($data['rules'], intval($data['access'])); if ($access) { $data['access'] = $access; } } else { if ($is_new) { // Let the table class find the correct access level $data['access'] = 0; } else { // Keep the existing access in the table if (isset($data['access'])) { unset($data['access']); } } } // Make item published by default if new if (!isset($data['state']) && $is_new) { $data['state'] = 1; } // Store the record if (parent::save($data)) { $id = $this->getState($this->getName() . '.id'); // Load the just updated row $updated = $this->getTable(); if ($updated->load($id) === false) { return false; } // Set the active project PFApplicationHelper::setActiveProject($updated->project_id); // Add to watch list if ($is_new) { $cid = array($id); if (!$this->watch($cid, 1)) { return false; } } // Store the attachments if (isset($data['attachment']) && PFApplicationHelper::exists('com_pfrepo')) { $attachments = $this->getInstance('Attachments', 'PFrepoModel'); if (!$attachments->getState('item.type')) { $attachments->setState('item.type', 'com_pfforum.topic'); } if ($attachments->getState('item.id') == 0) { $attachments->setState('item.id', $id); } if ((int) $attachments->getState('item.project') == 0) { $attachments->setState('item.project', $updated->project_id); } if (!$attachments->save($data['attachment'])) { $this->setError($attachments->getError()); return false; } } // Store the labels if (isset($data['labels'])) { $labels = $this->getInstance('Labels', 'PFModel'); if ((int) $labels->getState('item.project') == 0) { $labels->setState('item.project', $updated->project_id); } $labels->setState('item.type', 'com_pfforum.topic'); $labels->setState('item.id', $id); if (!$labels->saveRefs($data['labels'])) { return false; } } return true; } return false; }
/** * @package Projectfork Pro * @subpackage Designs * * @author Tobias Kuhn (eaxs) * @copyright Copyright (C) 2006-2013 Tobias Kuhn. All rights reserved. * @license http://www.gnu.org/licenses/gpl.html GNU/GPL, see LICENSE.txt */ defined('_JEXEC') or die; jimport('joomla.application.component.modeladmin'); jimport('joomla.filesystem.folder'); jimport('joomla.filesystem.file'); jimport('projectfork.application.helper'); jimport('projectfork.access.helper'); if (PFApplicationHelper::exists('com_pfrepo')) { JLoader::register('PFrepoHelper', JPATH_ADMINISTRATOR . '/components/com_pfrepo/helpers/pfrepo.php'); } /** * Item Model for a design album form. * */ class PFdesignsModelAlbum extends JModelAdmin { /** * The prefix to use with controller messages. * * @var string */ protected $text_prefix = 'COM_PROJECTFORK_DESIGN_ALBUM'; /**
/** * Method to save the form data. * * @param array The form data * * @return boolean True on success */ public function save($data) { $table = $this->getTable(); $key = $table->getKeyName(); $pk = !empty($data[$key]) ? $data[$key] : (int) $this->getState($this->getName() . '.id'); $is_new = true; // Include the content plugins for the on save events. JPluginHelper::importPlugin('content'); $dispatcher = JDispatcher::getInstance(); try { if ($pk > 0) { if ($table->load($pk)) { $is_new = false; } } if (!$is_new) { $data['project_id'] = $table->project_id; } if (!PFApplicationHelper::enabled('com_pfmilestones')) { $data['milestone_id'] = $is_new ? 0 : $table->milestone_id; } // Handle task completition meta info if (isset($data['complete'])) { $date = new JDate(); if ($is_new && $data['complete'] == '1') { $data['completed'] = $date->toSql(); $data['completed_by'] = JFactory::getUser()->id; } if (!$is_new) { if ($data['complete'] == '0') { $data['completed'] = JFactory::getDbo()->getNullDate(); $data['completed_by'] = '0'; } else { if (JFactory::getUser()->id != $table->completed_by) { $data['completed'] = $date->toSql(); $data['completed_by'] = JFactory::getUser()->id; } } } } // Make sure the title and alias are always unique $data['alias'] = ''; list($title, $alias) = $this->generateNewTitle($data['title'], $data['project_id'], $data['milestone_id'], $data['list_id'], $data['alias'], $pk); $data['title'] = $title; $data['alias'] = $alias; // Handle permissions and access level if (isset($data['rules'])) { $access = PFAccessHelper::getViewLevelFromRules($data['rules'], intval($data['access'])); if ($access) { $data['access'] = $access; } } else { if ($is_new) { // Let the table class find the correct access level $data['access'] = 0; } else { // Keep the existing access in the table if (isset($data['access'])) { unset($data['access']); } } } // Try to convert estimate string to time if (isset($data['estimate'])) { if (!is_numeric($data['estimate'])) { $estimate_time = strtotime($data['estimate']); if ($estimate_time === false || $estimate_time <= 0) { $data['estimate'] = 1; } else { $data['estimate'] = $estimate_time - time(); } } else { // not a literal time, so convert minutes to secs $data['estimate'] = $data['estimate'] * 60; } } // Make item published by default if new if (!isset($data['state']) && $is_new) { $data['state'] = 1; } // Make item priority 1 by default if not set if (!isset($data['priority']) && $is_new) { $data['priority'] = 1; } // Bind the data. if (!$table->bind($data)) { $this->setError($table->getError()); return false; } // Prepare the row for saving $this->prepareTable($table); // Check the data. if (!$table->check()) { $this->setError($table->getError()); return false; } // Trigger the onContentBeforeSave event. $result = $dispatcher->trigger($this->event_before_save, array($this->option . '.' . $this->name, &$table, $is_new)); if (in_array(false, $result, true)) { $this->setError($table->getError()); return false; } // Store the data. if (!$table->store()) { $this->setError($table->getError()); return false; } $pk_name = $table->getKeyName(); if (isset($table->{$pk_name})) { $this->setState($this->getName() . '.id', $table->{$pk_name}); } $this->setState($this->getName() . '.new', $is_new); $id = $this->getState($this->getName() . '.id'); // Load the just updated row $updated = $this->getTable(); if ($updated->load($id) === false) { return false; } // Set the active project PFApplicationHelper::setActiveProject($updated->project_id); // Store entered rate in session if (isset($data['rate']) && !empty($data['rate']) && $data['rate'] != '0.00') { JFactory::getApplication()->setUserState('com_projectfork.jform_rate', $data['rate']); } // Add to watch list if ($is_new) { $cid = array($id); if (!$this->watch($cid, 1)) { return false; } } // Store the attachments if (isset($data['attachment']) && PFApplicationHelper::exists('com_pfrepo')) { $attachments = $this->getInstance('Attachments', 'PFrepoModel'); if (!$attachments->getState('item.type')) { $attachments->setState('item.type', 'com_pftasks.task'); } if ($attachments->getState('item.id') == 0) { $attachments->setState('item.id', $this->getState($this->getName() . '.id')); } if ((int) $attachments->getState('item.project') == 0) { $attachments->setState('item.project', $updated->project_id); } if (!$attachments->save($data['attachment'])) { $this->setError($attachments->getError()); return false; } } // Store the labels if (isset($data['labels'])) { $labels = $this->getInstance('Labels', 'PFModel'); if ((int) $labels->getState('item.project') == 0) { $labels->setState('item.project', $updated->project_id); } $labels->setState('item.type', 'com_pftasks.task'); $labels->setState('item.id', $id); if (!$labels->saveRefs($data['labels'])) { return false; } } // Store the dependencies if (isset($data['dependency'])) { $taskrefs = $this->getInstance('TaskRefs', 'PFtasksModel'); if ((int) $taskrefs->getState('item.project') == 0) { $taskrefs->setState('item.project', $updated->project_id); } $taskrefs->setState('item.id', $id); if (!$taskrefs->save($data['dependency'])) { return false; } } // Store users if (isset($data['users'])) { $this->saveUsers($id, $data['users']); } // Clean the cache. $this->cleanCache(); // Trigger the onContentAfterSave event. $dispatcher->trigger($this->event_after_save, array($this->option . '.' . $this->name, &$table, $is_new)); } catch (Exception $e) { $this->setError($e->getMessage()); return false; } return true; }
/** * Method to save the form data. * * @param array The form data * @return boolean True on success */ public function save($data) { $table = $this->getTable(); $key = $table->getKeyName(); $pk = !empty($data[$key]) ? $data[$key] : (int) $this->getState($this->getName() . '.id'); $is_new = true; $old = null; // Include the content plugins for the on save events. JPluginHelper::importPlugin('content'); $dispatcher = JDispatcher::getInstance(); // Allow an exception to be thrown. try { if ($pk > 0) { if ($table->load($pk)) { $is_new = false; $old = clone $table; } } if (!$is_new) { $data['project_id'] = $table->project_id; } // Make sure the title and alias are always unique $data['alias'] = ''; list($title, $alias) = $this->generateNewTitle($data['title'], $data['project_id'], $data['alias'], $pk); $data['title'] = $title; $data['alias'] = $alias; // Handle permissions and access level if (isset($data['rules'])) { $access = PFAccessHelper::getViewLevelFromRules($data['rules'], intval($data['access'])); if ($access) { $data['access'] = $access; } } else { if ($is_new) { // Let the table class find the correct access level $data['access'] = 0; } else { // Keep the existing access in the table if (isset($data['access'])) { unset($data['access']); } } } // Make item published by default if new if (!isset($data['state']) && $is_new) { $data['state'] = 1; } // Bind the data. if (!$table->bind($data)) { $this->setError($table->getError()); return false; } // Prepare the row for saving $this->prepareTable($table); // Check the data. if (!$table->check()) { $this->setError($table->getError()); return false; } // Trigger the onContentBeforeSave event. $result = $dispatcher->trigger($this->event_before_save, array($this->option . '.' . $this->name, &$table, $is_new)); if (in_array(false, $result, true)) { $this->setError($table->getError()); return false; } // Store the data. if (!$table->store()) { $this->setError($table->getError()); return false; } $pk_name = $table->getKeyName(); if (isset($table->{$pk_name})) { $this->setState($this->getName() . '.id', $table->{$pk_name}); } $this->setState($this->getName() . '.new', $is_new); $id = $this->getState($this->getName() . '.id'); // Set the active project PFApplicationHelper::setActiveProject($table->project_id); // Add to watch list if ($is_new) { $cid = array($id); if (!$this->watch($cid, 1)) { return false; } } // Store the attachments if (isset($data['attachment']) && PFApplicationHelper::exists('com_pfrepo')) { $attachments = $this->getInstance('Attachments', 'PFrepoModel'); if (!$attachments->getState('item.type')) { $attachments->setState('item.type', 'com_pfmilestones.milestone'); } if ($attachments->getState('item.id') == 0) { $attachments->setState('item.id', $id); } if ((int) $attachments->getState('item.project') == 0) { $attachments->setState('item.project', $table->project_id); } if (!$attachments->save($data['attachment'])) { $this->setError($attachments->getError()); return false; } } // Store the labels if (isset($data['labels'])) { $labels = $this->getInstance('Labels', 'PFModel'); if ((int) $labels->getState('item.project') == 0) { $labels->setState('item.project', $table->project_id); } $labels->setState('item.type', 'com_pfmilestones.milestone'); $labels->setState('item.id', $id); if (!$labels->saveRefs($data['labels'])) { return false; } } // Clean the cache. $this->cleanCache(); // Trigger the onContentAfterSave event. $dispatcher->trigger($this->event_after_save, array($this->option . '.' . $this->name, &$table, $is_new)); } catch (Exception $e) { $this->setError($e->getMessage()); return false; } return true; }
/** * Method to save the form data. * * @param array The form data * * @return boolean True on success */ public function save($data) { $record = $this->getTable(); $key = $record->getKeyName(); $pk = !empty($data[$key]) ? $data[$key] : (int) $this->getState($this->getName() . '.id'); $is_new = true; if ($pk > 0) { if ($record->load($pk)) { $is_new = false; } } // Handle permissions and access level if (isset($data['rules'])) { $access = PFAccessHelper::getViewLevelFromRules($data['rules'], intval($data['access'])); if ($access) { $data['access'] = $access; } } else { if ($is_new) { // Let the table class find the correct access level $data['access'] = 0; } else { // Keep the existing access in the table if (isset($data['access'])) { unset($data['access']); } } } if (!$is_new) { $data['project_id'] = $record->project_id; $data['topic_id'] = $record->topic_id; } // Make item published by default if new if (!isset($data['state']) && $is_new) { $data['state'] = 1; } // On quick-save, access and publishing state are missing if ($this->getState('task') == 'quicksave' && isset($data['topic_id'])) { $db = JFactory::getDbo(); $query = $db->getQuery(true); $topic = (int) $data['topic_id']; if ($topic) { $query->select('state, access')->from('#__pf_topics')->where('id = ' . $db->quote($topic)); $db->setQuery((string) $query); $parent = $db->loadObject(); if ($parent) { $data['state'] = $parent->state; $data['access'] = $parent->access; } } } // Store the record if (parent::save($data)) { $id = $this->getState($this->getName() . '.id'); // Load the just updated row $updated = $this->getTable(); if ($updated->load($id) === false) { return false; } // Set the active project PFApplicationHelper::setActiveProject($updated->project_id); // Store the attachments if (isset($data['attachment']) && PFApplicationHelper::exists('com_pfrepo')) { $attachments = $this->getInstance('Attachments', 'PFrepoModel'); if (!$attachments->getState('item.type')) { $attachments->setState('item.type', 'com_pfforum.reply'); } if ($attachments->getState('item.id') == 0) { $attachments->setState('item.id', $id); } if ((int) $attachments->getState('item.project') == 0) { $attachments->setState('item.project', $updated->project_id); } if (!$attachments->save($data['attachment'])) { $this->setError($attachments->getError()); return false; } } return true; } return false; }
/** * Method to delete one or more records. * * @param array An array of record primary keys. * * @return boolean True if successful, false if an error occurs. */ public function delete(&$pks) { $pks = (array) $pks; $table = $this->getTable(); $query = $this->_db->getQuery(true); $active_id = PFApplicationHelper::getActiveProjectId(); $repo_exists = PFApplicationHelper::exists('com_pfrepo'); if ($repo_exists) { $base_path = PFrepoHelper::getBasePath(); } // Include the content plugins for the on delete events. $dispatcher = JDispatcher::getInstance(); JPluginHelper::importPlugin('content'); // Iterate the items to delete each one. foreach ($pks as $i => $pk) { // Try to load from the db if ($table->load($pk) === false) { $this->setError($table->getError()); return false; } // Check delete permission if (!$this->canDelete($table)) { unset($pks[$i]); $error = $this->getError(); if ($error) { JError::raiseWarning(500, $error); } else { JError::raiseWarning(403, JText::_('JLIB_APPLICATION_ERROR_DELETE_NOT_PERMITTED')); } return false; } // Trigger the onContentBeforeDelete event. $context = $this->option . '.' . $this->name; $result = $dispatcher->trigger($this->event_before_delete, array($context, $table)); if (in_array(false, $result, true)) { $this->setError($table->getError()); return false; } if ($repo_exists) { $params = new JRegistry(); $params->loadString($table->attribs); $repo_dir = (int) $params->get('repo_dir'); $query->clear()->select('path')->from('#__pf_repo_dirs')->where('id = ' . $repo_dir); $this->_db->setQuery($query); $repo_path = $this->_db->loadResult(); } // Delete the item if (!$table->delete($pk)) { $this->setError($table->getError()); return false; } // Delete the repo directory if ($repo_exists) { if ($repo_path && $repo_dir) { // Delete repo 4.1 $repo = $base_path . '/' . $repo_path; if (JFolder::exists($repo) && $repo != $base_path) { JFolder::delete($repo); } // Delete repo 4.0 $repo = $base_path . '/' . $pk; if (JFolder::exists($repo)) { JFolder::delete($repo); } // Delete repo 3.0 $repo = $base_path . '/project_' . $pk; if (JFolder::exists($repo)) { JFolder::delete($repo); } } } // Delete the logo $this->deleteLogo($pk); // Check if the currently active project is being deleted. // If so, clear it from the session if ($active_id == $pk) { $this->setActive(array('id' => 0)); } // Trigger the onContentAfterDelete event. $dispatcher->trigger($this->event_after_delete, array($context, $table)); } // Clear the component's cache $this->cleanCache(); return true; }
/** * 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]; }
/** * 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(); // Get the global params $global_params = JComponentHelper::getParams('com_pfforum', true); $repo_exists = PFApplicationHelper::exists('com_pfrepo'); if ($repo_exists) { $attachments = $this->getInstance('Attachments', 'PFrepoModel'); } foreach ($items as $i => &$item) { // Convert the parameter fields into objects. $params = new JRegistry(); $params->loadString($item->attribs); // Get Attachments if ($repo_exists && $attachments) { $item->attachment = $attachments->getItems('com_pfforum.reply', $item->id); } else { $item->attachment = array(); } $items[$i]->params = clone $this->getState('params'); // Create slugs $items[$i]->project_slug = $items[$i]->project_alias ? $items[$i]->project_id . ':' . $items[$i]->project_alias : $items[$i]->project_id; } return $items; }
/** * Method to get item data. * * @param integer The id of the item. * @return mixed Menu item data object on success, false on failure. */ public function &getItem($pk = null) { // Initialise variables. $pk = !empty($pk) ? $pk : (int) $this->getState($this->getName() . '.id'); if ($this->_item === null) { $this->_item = array(); } // Check if cached if (isset($this->_item[$pk])) { return $this->_item[$pk]; } try { $db = $this->getDbo(); $query = $db->getQuery(true); $query->select($this->getState('item.select', 'a.id, a.asset_id, a.project_id, a.milestone_id, a.list_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.ordering, a.start_date, a.end_date')); $query->from('#__pf_tasks AS a'); // Join on project table. $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 on milestone table. $query->select('m.title AS milestone_title, m.alias AS milestone_alias'); $query->join('LEFT', '#__pf_milestones AS m on m.id = a.milestone_id'); // Join on task lists table. $query->select('l.title AS list_title, l.alias AS list_alias'); $query->join('LEFT', '#__pf_task_lists AS l on l.id = a.list_id'); // Join on user table. $query->select('u.name AS author'); $query->join('LEFT', '#__users AS u on u.id = a.created_by'); $query->where('a.id = ' . (int) $pk); // Filter by published state. $published = $this->getState('filter.published'); $archived = $this->getState('filter.archived'); if (is_numeric($published)) { $query->where('(a.state = ' . (int) $published . ' OR a.state =' . (int) $archived . ')'); } $db->setQuery($query); $item = $db->loadObject(); // Check for error if ($error = $db->getErrorMsg()) { throw new Exception($error); } // Check if we have a record if (empty($item)) { return JError::raiseError(404, JText::_('COM_PROJECTFORK_ERROR_TASK_NOT_FOUND')); } // get tasks' labels $item->labels = null; $model_labels = $this->getInstance('Labels', 'PFModel'); $item->labels = $model_labels->getConnections('com_pftasks.task', $item->id); // Check for published state if filter set. if ((is_numeric($published) || is_numeric($archived)) && ($item->state != $published && $item->state != $archived)) { return JError::raiseError(404, JText::_('COM_PROJECTFORK_ERROR_TASK_NOT_FOUND')); } // Convert parameter fields to objects. $registry = new JRegistry(); $registry->loadString($item->attribs); $item->params = clone $this->getState('params'); $item->params->merge($registry); // Get assigned users $ref = JModelLegacy::getInstance('UserRefs', 'PFusersModel'); $item->users = $ref->getItems('com_pftasks.task', $item->id); // Get the attachments if (PFApplicationHelper::exists('com_pfrepo')) { $attachments = $this->getInstance('Attachments', 'PFrepoModel'); $item->attachments = $attachments->getItems('com_pftasks.task', $item->id); $item->attachment = $item->attachments; } else { $item->attachments = array(); $item->attachment = array(); } // Generate slugs $item->slug = $item->alias ? $item->id . ':' . $item->alias : $item->id; $item->project_slug = $item->project_alias ? $item->project_id . ':' . $item->project_alias : $item->project_id; $item->milestone_slug = $item->milestone_alias ? $item->milestone_id . ':' . $item->milestone_alias : $item->milestone_id; $item->list_slug = $item->list_alias ? $item->list_id . ':' . $item->list_alias : $item->list_id; // 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')); } $this->_item[$pk] = $item; } 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]; }
protected function copyContent($old_table, $new_table) { // Copy milestones if (PFApplicationHelper::exists('com_pfmilestones')) { $milestones = $this->copyMilestones($old_table, $new_table); } else { $milestones = array(); } // Copy lists and tasks if (PFApplicationHelper::exists('com_pftasks')) { $lists = $this->copyLists($old_table, $new_table, $milestones); $tasks = $this->copyTasks($old_table, $new_table, $milestones, $lists); $this->copyTaskDependencies($old_table->id, $new_table->id, $tasks); } else { $lists = array(); $tasks = array(); } // Copy label references $this->copyLabelRefs($old_table->id, $new_table->id, $milestones, $tasks); // Copy observers $this->copyObservers($old_table->id, $new_table->id, $milestones, $tasks); }