[ Index ] |
PHP Cross Reference of Joomla 4.2.2 documentation |
[Summary view] [Print] [Text view]
1 <?php 2 3 /** 4 * @package Joomla.Administrator 5 * @subpackage com_contact 6 * 7 * @copyright (C) 2008 Open Source Matters, Inc. <https://www.joomla.org> 8 * @license GNU General Public License version 2 or later; see LICENSE.txt 9 */ 10 11 namespace Joomla\Component\Contact\Administrator\Controller; 12 13 use Joomla\CMS\MVC\Controller\FormController; 14 use Joomla\CMS\MVC\Model\BaseDatabaseModel; 15 use Joomla\CMS\Router\Route; 16 use Joomla\CMS\Versioning\VersionableControllerTrait; 17 use Joomla\Utilities\ArrayHelper; 18 19 // phpcs:disable PSR1.Files.SideEffects 20 \defined('_JEXEC') or die; 21 // phpcs:enable PSR1.Files.SideEffects 22 23 /** 24 * Controller for a single contact 25 * 26 * @since 1.6 27 */ 28 class ContactController extends FormController 29 { 30 use VersionableControllerTrait; 31 32 /** 33 * Method override to check if you can add a new record. 34 * 35 * @param array $data An array of input data. 36 * 37 * @return boolean 38 * 39 * @since 1.6 40 */ 41 protected function allowAdd($data = array()) 42 { 43 $categoryId = ArrayHelper::getValue($data, 'catid', $this->input->getInt('filter_category_id'), 'int'); 44 45 if ($categoryId) { 46 // If the category has been passed in the URL check it. 47 return $this->app->getIdentity()->authorise('core.create', $this->option . '.category.' . $categoryId); 48 } 49 50 // In the absence of better information, revert to the component permissions. 51 return parent::allowAdd($data); 52 } 53 54 /** 55 * Method override to check if you can edit an existing record. 56 * 57 * @param array $data An array of input data. 58 * @param string $key The name of the key for the primary key. 59 * 60 * @return boolean 61 * 62 * @since 1.6 63 */ 64 protected function allowEdit($data = array(), $key = 'id') 65 { 66 $recordId = (int) isset($data[$key]) ? $data[$key] : 0; 67 68 // Since there is no asset tracking, fallback to the component permissions. 69 if (!$recordId) { 70 return parent::allowEdit($data, $key); 71 } 72 73 // Get the item. 74 $item = $this->getModel()->getItem($recordId); 75 76 // Since there is no item, return false. 77 if (empty($item)) { 78 return false; 79 } 80 81 $user = $this->app->getIdentity(); 82 83 // Check if can edit own core.edit.own. 84 $canEditOwn = $user->authorise('core.edit.own', $this->option . '.category.' . (int) $item->catid) && $item->created_by == $user->id; 85 86 // Check the category core.edit permissions. 87 return $canEditOwn || $user->authorise('core.edit', $this->option . '.category.' . (int) $item->catid); 88 } 89 90 /** 91 * Method to run batch operations. 92 * 93 * @param object $model The model. 94 * 95 * @return boolean True if successful, false otherwise and internal error is set. 96 * 97 * @since 2.5 98 */ 99 public function batch($model = null) 100 { 101 $this->checkToken(); 102 103 // Set the model 104 /** @var \Joomla\Component\Contact\Administrator\Model\ContactModel $model */ 105 $model = $this->getModel('Contact', 'Administrator', array()); 106 107 // Preset the redirect 108 $this->setRedirect(Route::_('index.php?option=com_contact&view=contacts' . $this->getRedirectToListAppend(), false)); 109 110 return parent::batch($model); 111 } 112 113 /** 114 * Function that allows child controller access to model data 115 * after the data has been saved. 116 * 117 * @param BaseDatabaseModel $model The data model object. 118 * @param array $validData The validated data. 119 * 120 * @return void 121 * 122 * @since 4.1.0 123 */ 124 protected function postSaveHook(BaseDatabaseModel $model, $validData = []) 125 { 126 if ($this->getTask() === 'save2menu') { 127 $editState = []; 128 129 $id = $model->getState('contact.id'); 130 131 $link = 'index.php?option=com_contact&view=contact'; 132 $type = 'component'; 133 134 $editState['id'] = $id; 135 $editState['link'] = $link; 136 $editState['title'] = $model->getItem($id)->name; 137 $editState['type'] = $type; 138 $editState['request']['id'] = $id; 139 140 $this->app->setUserState( 141 'com_menus.edit.item', 142 [ 143 'data' => $editState, 144 'type' => $type, 145 'link' => $link, 146 ] 147 ); 148 149 $this->setRedirect(Route::_('index.php?option=com_menus&view=item&client_id=0&menutype=mainmenu&layout=edit', false)); 150 } 151 } 152 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Wed Sep 7 05:41:13 2022 | Chilli.vc Blog - For Webmaster,Blog-Writer,System Admin and Domainer |