Source for file item.php
Documentation is available at item.php
* @package Joomla.Administrator
* @copyright Copyright (C) 2005 - 2013 Open Source Matters, Inc. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE.txt
* The Menu Item Controller
* @package Joomla.Administrator
* Method to add a new menu item.
* @return mixed True if the record can be added, a JError object if not.
$context =
'com_menus.edit.item';
$app->setUserState($context .
'.type', null);
$app->setUserState($context .
'.link', null);
$menuType =
$app->getUserStateFromRequest($this->context .
'.filter.menutype', 'menutype', 'mainmenu', 'cmd');
* Method to run batch operations.
* @param object $model The model.
* @return boolean True if successful, false otherwise and internal error is set.
public function batch($model =
null)
$model =
$this->getModel('Item', '', array());
return parent::batch($model);
* Method to cancel an edit.
* @param string $key The name of the primary key of the URL variable.
* @return boolean True if access level checks pass, false otherwise.
public function cancel($key =
null)
$context =
'com_menus.edit.item';
// Clear the ancillary data from the session.
$app->setUserState($context .
'.type', null);
$app->setUserState($context .
'.link', null);
* Method to edit an existing record.
* @param string $key The name of the primary key of the URL variable.
* @param string $urlVar The name of the URL variable if different from the primary key
* (sometimes required to avoid router collisions).
* @return boolean True if access level check and checkout passes, false otherwise.
public function edit($key =
null, $urlVar =
null)
$result =
parent::edit();
// Push the new ancillary data into the session.
$app->setUserState('com_menus.edit.item.type', null);
$app->setUserState('com_menus.edit.item.link', null);
* Method to save a record.
* @param string $key The name of the primary key of the URL variable.
* @param string $urlVar The name of the URL variable if different from the primary key (sometimes required to avoid router collisions).
* @return boolean True if successful, false otherwise.
public function save($key =
null, $urlVar =
null)
// Check for request forgeries.
$model =
$this->getModel('Item', '', array());
$data =
$this->input->post->get('jform', array(), 'array');
$context =
'com_menus.edit.item';
$recordId =
$this->input->getInt('id');
// Populate the row id from the session.
// The save2copy task needs to be handled slightly differently.
if ($task ==
'save2copy')
// Check-in the original row.
if ($model->checkin($data['id']) ===
false)
// Check-in failed, go back to the item and display a notice.
// Reset the ID and then treat the request as for Apply.
$data['associations'] =
array();
// Validate the posted data.
// This post is made up of two forms, one for the item and one for params.
$form =
$model->getForm($data);
if ($data['type'] ==
'url')
$data['link'] =
str_replace(array('"', '>', '<'), '', $data['link']);
if (strstr($data['link'], ':'))
$segments =
explode(':', $data['link']);
$scheme =
array('http', 'https', 'ftp', 'ftps', 'gopher', 'mailto', 'news', 'prospero', 'telnet', 'rlogin', 'tn3270', 'wais', 'url',
'mid', 'cid', 'nntp', 'tel', 'urn', 'ldap', 'file', 'fax', 'modem', 'git');
$app->enqueueMessage(JText::_('JLIB_APPLICATION_ERROR_SAVE_NOT_PERMITTED'), 'warning');
$data =
$model->validate($form, $data);
// Check for the special 'request' entry.
if ($data['type'] ==
'component' && isset
($data['request']) &&
is_array($data['request']) &&
!empty($data['request']))
// Preprocess request fields to ensure that we remove not set or empty request params
$request =
$form->getGroup('request');
foreach ($request as $field)
$fieldName =
$field->getAttribute('name');
if (!isset
($data['request'][$fieldName]) ||
$data['request'][$fieldName] ==
'')
$removeArgs[$fieldName] =
'';
// Parse the submitted link arguments.
// Merge in the user supplied request arguments.
// Remove the unused request params
if (!empty($args) &&
!empty($removeArgs))
// Check for validation errors.
// Get the validation messages.
$errors =
$model->getErrors();
// Push up to three validation messages out to the user.
for ($i =
0, $n =
count($errors); $i <
$n &&
$i <
3; $i++
)
if ($errors[$i] instanceof
Exception)
$app->enqueueMessage($errors[$i]->getMessage(), 'warning');
$app->enqueueMessage($errors[$i], 'warning');
// Save the data in the session.
$app->setUserState('com_menus.edit.item.data', $data);
// Redirect back to the edit screen.
// Attempt to save the data.
if (!$model->save($data))
// Save the data in the session.
$app->setUserState('com_menus.edit.item.data', $data);
// Redirect back to the edit screen.
// Save succeeded, check-in the row.
if ($model->checkin($data['id']) ===
false)
// Check-in failed, go back to the row and display a notice.
// Redirect the user and adjust session state based on the chosen task.
// Set the row data in the session.
$recordId =
$model->getState($this->context .
'.id');
$app->setUserState('com_menus.edit.item.data', null);
$app->setUserState('com_menus.edit.item.type', null);
$app->setUserState('com_menus.edit.item.link', null);
// Redirect back to the edit screen.
// Clear the row id and data in the session.
$app->setUserState('com_menus.edit.item.data', null);
$app->setUserState('com_menus.edit.item.type', null);
$app->setUserState('com_menus.edit.item.link', null);
$app->setUserState('com_menus.edit.item.menutype', $model->getState('item.menutype'));
// Redirect back to the edit screen.
// Clear the row id and data in the session.
$app->setUserState('com_menus.edit.item.data', null);
$app->setUserState('com_menus.edit.item.type', null);
$app->setUserState('com_menus.edit.item.link', null);
// Redirect to the list screen.
* Sets the type of the menu item currently being edited.
// Get the posted values from the request.
$data =
$this->input->post->get('jform', array(), 'array');
$title = isset
($type->title) ?
$type->title :
null;
$recordId = isset
($type->id) ?
$type->id :
0;
$specialTypes =
array('alias', 'separator', 'url', 'heading');
$app->setUserState('com_menus.edit.item.type', $title);
if ($title ==
'component')
if (isset
($type->request))
$data['component_id'] =
$component->id;
$app->setUserState('com_menus.edit.item.link', 'index.php?' .
JUri::buildQuery((array)
$type->request));
// If the type is alias you just need the item id from the menu item referenced.
elseif ($title ==
'alias')
$app->setUserState('com_menus.edit.item.link', 'index.php?Itemid=');
if ($this->input->get('fieldtype') ==
'type')
$data['link'] =
$app->getUserState('com_menus.edit.item.link');
//Save the data in the session.
$app->setUserState('com_menus.edit.item.data', $data);
* Gets the parent items of the menu location currently.
$menutype =
$this->input->get->get('menutype');
$model =
$this->getModel('Items', '', array());
$model->setState('filter.menutype', $menutype);
$model->setState('list.select', 'a.id, a.title, a.level');
$results =
$model->getItems();
// Pad the option text with spaces using depth level as a multiplier.
for ($i =
0, $n =
count($results); $i <
$n; $i++
)
$results[$i]->title =
str_repeat('- ', $results[$i]->level) .
$results[$i]->title;
Documentation generated on Tue, 19 Nov 2013 15:05:59 +0100 by phpDocumentor 1.4.3