本文整理汇总了PHP中PFApplicationHelper::setActiveProject方法的典型用法代码示例。如果您正苦于以下问题:PHP PFApplicationHelper::setActiveProject方法的具体用法?PHP PFApplicationHelper::setActiveProject怎么用?PHP PFApplicationHelper::setActiveProject使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PFApplicationHelper
的用法示例。
在下文中一共展示了PFApplicationHelper::setActiveProject方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: populateState
/**
* 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);
}
示例2: save
/**
* 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['milestone_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);
return true;
}
return false;
}
示例3: save
/**
* 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;
}
示例4: populateState
/**
* 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::getInt($key);
$this->setState($this->getName() . '.id', $pk);
if ($pk) {
$table = $this->getTable();
if ($table->load($pk)) {
$project = (int) $table->project_id;
$this->setState($this->getName() . '.project', $project);
PFApplicationHelper::setActiveProject($project);
}
} else {
$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);
}
示例5: display
function display($tpl = null)
{
// Initialise variables.
$app = JFactory::getApplication();
$dispatcher = JDispatcher::getInstance();
$user = JFactory::getUser();
$uid = $user->get('id');
$item = $this->get('Item');
$state = $this->get('State');
$print = JRequest::getBool('print');
// Check for errors.
if (count($errors = $this->get('Errors'))) {
JError::raiseWarning(500, implode("\n", $errors));
return false;
}
// Check the view access.
if (!$item->params->get('access-view')) {
JError::raiseWarning(403, JText::_('JERROR_ALERTNOAUTHOR'));
return false;
}
// Set active project
if (!PFApplicationHelper::setActiveProject($item->project_id)) {
JError::raiseWarning(403, JText::_('JERROR_ALERTNOAUTHOR'));
return false;
}
// Merge milestone params. If this is single-milestone view, menu params override milestone params
// Otherwise, milestone params override menu item params
$params = $state->get('params');
$active = $app->getMenu()->getActive();
$temp = clone $params;
// Check to see which parameters should take priority
if ($active) {
$current_link = $active->link;
if (strpos($current_link, 'view=milestone') && strpos($current_link, '&id=' . (string) $item->id)) {
$item->params->merge($temp);
// Load layout from active query (in case it is an alternative menu item)
if (isset($active->query['layout'])) {
$this->setLayout($active->query['layout']);
}
} else {
// Merge the menu item params with the milestone params so that the milestone params take priority
$temp->merge($item->params);
$item->params = $temp;
// Check for alternative layouts (since we are not in a single-milestone menu item)
if ($layout = $item->params->get('milestone_layout')) {
$this->setLayout($layout);
}
}
} else {
// Merge so that milestone params take priority
$temp->merge($item->params);
$item->params = $temp;
// Check for alternative layouts (since we are not in a single-milestone menu item)
if ($layout = $item->params->get('milestone_layout')) {
$this->setLayout($layout);
}
}
$offset = $state->get('list.offset');
// Fake some content item properties to avoid plugin issues
PFObjectHelper::toContentItem($item);
// Process the content plugins.
JPluginHelper::importPlugin('content');
$results = $dispatcher->trigger('onContentPrepare', array('com_pfmilestones.milestone', &$item, &$params, $offset));
$item->event = new stdClass();
$results = $dispatcher->trigger('onContentAfterTitle', array('com_pfmilestones.milestone', &$item, &$params, $offset));
$item->event->afterDisplayTitle = trim(implode("\n", $results));
$results = $dispatcher->trigger('onContentBeforeDisplay', array('com_pfmilestones.milestone', &$item, &$params, $offset));
$item->event->beforeDisplayContent = trim(implode("\n", $results));
$results = $dispatcher->trigger('onContentAfterDisplay', array('com_pfmilestones.milestone', &$item, &$params, $offset));
$item->event->afterDisplayContent = trim(implode("\n", $results));
// Escape strings for HTML output
$this->pageclass_sfx = htmlspecialchars($item->params->get('pageclass_sfx'));
// Assign references
$this->assignRef('params', $params);
$this->assignRef('state', $state);
$this->assignRef('user', $user);
$this->assignRef('item', $item);
$this->assignRef('print', $print);
$this->toolbar = $this->getToolbar();
$this->_prepareDocument();
parent::display($tpl);
}
示例6: save
//.........这里部分代码省略.........
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;
}
示例7: save
/**
* Method to save the form data.
*
* @param array $data The form data.
*
* @return boolean True on success, False on error.
*/
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;
$db = JFactory::getDbo();
$query = $db->getQuery(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']);
}
}
}
// Try to find the task title
if (isset($data['task_id']) && $is_new) {
$query->select('title')->from('#__pf_tasks')->where('id = ' . (int) $data['task_id']);
$db->setQuery($query);
$task_title = $db->loadResult();
if ($task_title) {
$data['task_title'] = $task_title;
}
}
// Try to convert estimate string to time
if (isset($data['log_time'])) {
if (!is_numeric($data['log_time'])) {
$log_time = strtotime($data['log_time']);
if ($log_time === false || $log_time <= 0) {
$data['log_time'] = 1;
} else {
$data['log_time'] = $log_time - time();
}
} else {
// not a literal time, so convert minutes to secs
$data['log_time'] = $data['log_time'] * 60;
}
}
// Make item published by default if new
if (!isset($data['state']) && $is_new) {
$data['state'] = 1;
}
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 entered rate in session
if (isset($data['rate']) && !empty($data['rate']) && $data['rate'] != '0.00' && $is_new) {
JFactory::getApplication()->setUserState('com_projectfork.jform_rate', $data['rate']);
}
return true;
}
return false;
}
示例8: populateState
/**
* 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();
// Load state from the request.
$pk = JRequest::getInt('id');
$this->setState($this->getName() . '.id', $pk);
$return = JRequest::getVar('return', null, 'default', 'base64');
$this->setState('return_page', base64_decode($return));
if ($pk) {
$table = $this->getTable();
if ($table->load($pk)) {
$project = (int) $table->project_id;
$this->setState($this->getName() . '.project', $project);
PFApplicationHelper::setActiveProject($project);
$dir_id = (int) $table->dir_id;
$this->setState($this->getName() . '.dir_id', $dir_id);
}
} else {
$dir_id = JRequest::getUInt('filter_parent_id', 0);
$this->setState($this->getName() . '.dir_id', $dir_id);
$project = (int) $app->getUserStateFromRequest('com_projectfork.project.active.id', 'filter_project', '');
if ($project) {
$this->setState($this->getName() . '.project', $project);
PFApplicationHelper::setActiveProject($project);
} elseif ($dir_id) {
$table = $this->getTable('Directory');
if ($table->load($dir_id)) {
$project = (int) $table->project_id;
$this->setState($this->getName() . '.project', $project);
PFApplicationHelper::setActiveProject($project);
}
}
}
// Load the parameters.
$params = $app->getParams();
$this->setState('params', $params);
$this->setState('layout', JRequest::getCmd('layout'));
}
示例9: populateState
/**
* 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();
// Load state from the request.
$pk = JRequest::getInt('id');
$this->setState($this->getName() . '.id', $pk);
$return = JRequest::getVar('return', null, 'default', 'base64');
$this->setState('return_page', base64_decode($return));
// Load the parameters.
$params = $app->getParams();
$this->setState('params', $params);
$this->setState('layout', JRequest::getCmd('layout'));
if ($pk) {
$table = $this->getTable();
if ($table->load($pk)) {
$project = (int) $table->project_id;
$this->setState($this->getName() . '.project', $project);
PFApplicationHelper::setActiveProject($project);
$topic = (int) $table->topic_id;
$this->setState($this->getName() . '.topic', $topic);
}
} else {
$topic = JRequest::getUInt('filter_topic', 0);
$this->setState($this->getName() . '.topic', $topic);
$project = PFApplicationHelper::getActiveProjectId('filter_project');
if ($project) {
$this->setState($this->getName() . '.project', $project);
} elseif ($topic) {
$table = $this->getTable('Topic');
if ($table->load($topic)) {
$project = (int) $table->project_id;
$this->setState($this->getName() . '.project', $project);
PFApplicationHelper::setActiveProject($project);
}
}
}
}
示例10: save
/**
* 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);
}
//.........这里部分代码省略.........
示例11: getForm
/**
* Method to get the record form.
*
* @param array Data for the form.
* @param boolean True if the form is to load its own data (default case), false if not.
*
* @return mixed A JForm object on success, false on failure
*/
public function getForm($data = array(), $loadData = true)
{
// Get the form.
$form = $this->loadForm('com_pfprojects.project', 'project', array('control' => 'jform', 'load_data' => $loadData));
if (empty($form)) {
return false;
}
$jinput = JFactory::getApplication()->input;
$user = JFactory::getUser();
$id = (int) $jinput->get('id', 0);
// Check for existing item.
// Modify the form based on Edit State access controls.
if ($id != 0 && !$user->authorise('core.edit.state', 'com_pfprojects.project.' . $id) || $id == 0 && !$user->authorise('core.edit.state', 'com_pfprojects')) {
// Disable fields for display.
$form->setFieldAttribute('state', 'disabled', 'true');
$form->setFieldAttribute('start_date', 'disabled', 'true');
$form->setFieldAttribute('end_date', 'disabled', 'true');
// Disable fields while saving.
$form->setFieldAttribute('state', 'filter', 'unset');
$form->setFieldAttribute('start_date', 'filter', 'unset');
$form->setFieldAttribute('end_date', 'filter', 'unset');
}
// Always disable these fields while saving
$form->setFieldAttribute('alias', 'filter', 'unset');
// Disable these fields if not an admin
if (!$user->authorise('core.admin', 'com_pfprojects') && !$user->authorise('core.manage', 'com_pfprojects')) {
$form->setFieldAttribute('access', 'disabled', 'true');
$form->setFieldAttribute('access', 'filter', 'unset');
$form->setFieldAttribute('rules', 'disabled', 'true');
$form->setFieldAttribute('rules', 'filter', 'unset');
}
if ($id) {
// Set the project as active when editing
PFApplicationHelper::setActiveProject($id);
}
return $form;
}
示例12: populateState
/**
* 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')
{
// Initialise variables.
$app = JFactory::getApplication();
$params = $app->getParams();
// Adjust the context to support modal layouts.
if ($layout = JRequest::getVar('layout')) {
$this->context .= '.' . $layout;
}
// Set Params
$this->setState('params', $params);
// Config - Count elements
$this->setState('list.count_elements', (int) $params->get('show_element_count'));
// Filter - Search
$search = $this->getUserStateFromRequest($this->context . '.filter.search', 'filter_search');
$this->setState('filter.search', $search);
// Filter - Access
$access = $this->getUserStateFromRequest($this->context . '.filter.access', 'filter_access', '');
$this->setState('filter.access', $access);
// Filter - Project
$project = PFApplicationHelper::getActiveProjectId('filter_project');
// Filter - Author
$author_id = $app->getUserStateFromRequest($this->context . '.filter.author_id', 'filter_author_id');
$this->setState('filter.author_id', $author_id);
// Filter - Labels
$labels = (array) JRequest::getVar('filter_label', array(), 'post', 'array');
$this->setState('filter.labels', $labels);
// Filter - Directory
$parent_id = JRequest::getVar('filter_parent_id');
// Get the path
$path = str_replace(':', '-', JRequest::getVar('path'));
if (!$parent_id && !empty($path) && $project > 0) {
// No parent folder given. Try to find it from the path
$dir = $this->getInstance('DirectoryForm', 'PFrepoModel', $config = array('ignore_request' => true));
$item = $dir->getItemFromProjectPath($project, $path);
if ($item) {
$parent_id = $item->id;
JRequest::setVar('filter_parent_id', $parent_id);
}
}
// If no parent folder is given, find the repo dir of the project
if (empty($parent_id) && $project > 0) {
$params = PFApplicationHelper::getProjectParams();
$repo = (int) $params->get('repo_dir');
if ($repo) {
$parent_id = (int) $repo;
}
} elseif (is_numeric($parent_id) && $project <= 0) {
// If a folder is selected, but no project, find the project id of the folder
if ($project === "") {
$parent_id = 1;
$project = 0;
} else {
$dir = $this->getInstance('DirectoryForm', 'PFrepoModel', $config = array('ignore_request' => true));
$item = $dir->getItem((int) $parent_id);
if ($item->id > 0) {
if ($item->parent_id == '1') {
$project = $item->project_id;
} else {
$parent_id = 1;
$project = 0;
}
} else {
$parent_id = 1;
$project = 0;
}
}
} elseif ($project <= 0 && empty($parent_id)) {
$parent_id = 1;
$project = 0;
}
if (JRequest::getVar('filter_project', null, 'post') === '0') {
$parent_id = 1;
$project = 0;
}
PFApplicationHelper::setActiveProject($project);
$this->setState('filter.project', $project);
$this->setState('filter.parent_id', $parent_id);
// Override the user input to control the other models
JRequest::setVar('filter_parent_id', $parent_id);
JRequest::setVar('filter_project', $project);
// Handle list limit
JRequest::setVar('limit', $app->getCfg('list_limit'));
// Do not allow to filter by author if no project is selected
if ($project <= 0) {
$this->setState('filter.labels', array());
$this->setState('filter.author_id', '');
$labels = array();
$author_id = '';
}
// Filter - Is set
$this->setState('filter.isset', !empty($search) || count($labels) || is_numeric($author_id));
// List state information.
parent::populateState($ordering, $direction);
//.........这里部分代码省略.........
示例13: array
/**
* 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];
}
示例14: populateState
/**
* 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')
{
// Initialise variables.
$params = JComponentHelper::getParams('com_pfrepo');
$app = JFactory::getApplication();
// Adjust the context to support modal layouts.
if ($layout = JRequest::getVar('layout')) {
$this->context .= '.' . $layout;
}
// Config - Count elements
$this->setState('list.count_elements', (int) $params->get('show_element_count'));
// Filter - Search
$search = $this->getUserStateFromRequest($this->context . '.filter.search', 'filter_search');
$this->setState('filter.search', $search);
// Filter - Access
$access = $this->getUserStateFromRequest($this->context . '.filter.access', 'filter_access', '');
$this->setState('filter.access', $access);
// Filter - Project
$project = PFApplicationHelper::getActiveProjectId('filter_project');
// Filter - Author
$author_id = $app->getUserStateFromRequest($this->context . '.filter.author_id', 'filter_author_id');
$this->setState('filter.author_id', $author_id);
// Filter - Directory
$parent_id = JRequest::getVar('filter_parent_id');
// If no parent folder is given (or in root), find the repo dir of the project
if ($parent_id <= 1 && $project) {
$params = PFApplicationHelper::getProjectParams();
$repo = (int) $params->get('repo_dir');
if ($repo) {
$parent_id = (int) $repo;
}
} elseif ($parent_id > 1 && !$project) {
// If a folder is selected, but no project active, find the project id of the folder
$query = $this->_db->getQuery(true);
$query->select('project_id')->from('#__pf_repo_dirs')->where('id = ' . (int) $parent_id);
$this->_db->setQuery($query);
$project = (int) $this->_db->loadResult();
// If no project was found, return to the repo root
if (!$project) {
$parent_id = 1;
}
} elseif (empty($parent_id) && !$project) {
$parent_id = 1;
$project = 0;
}
if (JRequest::getVar('filter_project', null, 'post') === '0') {
$parent_id = 1;
$project = 0;
}
PFApplicationHelper::setActiveProject($project);
$this->setState('filter.project', $project);
$this->setState('filter.parent_id', $parent_id);
// Override the user input to control the other models
JRequest::setVar('filter_parent_id', $parent_id);
JRequest::setVar('filter_project', $project);
// Handle list limit
if ($project) {
JRequest::setVar('limit', 0);
} else {
if (JRequest::getVar('limit') === null) {
JRequest::setVar('limit', $app->getCfg('list_limit'));
}
}
// List state information.
parent::populateState($ordering, $direction);
}
示例15: populateState
/**
* 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')
{
$app = JFactory::getApplication();
// 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 - Topic
$topic = JRequest::getCmd('filter_topic', '');
$this->setState('filter.topic', $topic);
// Filter - Project
$project = PFApplicationHelper::getActiveProjectId('filter_project');
if (!$project && $topic > 0) {
$db = JFactory::getDbo();
$query = $db->getQuery(true);
$query->select('project_id')->from('#__pf_topics')->where('id = ' . $db->quote((int) $topic));
$db->setQuery($query);
$project = (int) $db->loadResult();
PFApplicationHelper::setActiveProject($project);
}
$this->setState('filter.project', $project);
if ($topic) {
$access = PFforumHelper::getActions($topic);
} else {
$access = PFforumHelper::getReplyActions();
}
// 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
$value = JRequest::getString('filter_search', '');
$this->setState('filter.search', $value);
// Filter - Author
$author = $app->getUserStateFromRequest($this->context . '.filter.author', 'filter_author', '');
$this->setState('filter.author', $author);
// Do not allow to filter by author if no project is selected
if (!is_numeric($project) || intval($project) == 0) {
$this->setState('filter.author', '');
$author = '';
}
// Filter - Is set
$this->setState('filter.isset', is_numeric($state) || !empty($search) || is_numeric($author));
// Call parent method
parent::populateState($ordering, $direction);
}