3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.7 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2017 |
7 +--------------------------------------------------------------------+
8 | This file is a part of CiviCRM. |
10 | CiviCRM is free software; you can copy, modify, and distribute it |
11 | under the terms of the GNU Affero General Public License |
12 | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
14 | CiviCRM is distributed in the hope that it will be useful, but |
15 | WITHOUT ANY WARRANTY; without even the implied warranty of |
16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
17 | See the GNU Affero General Public License for more details. |
19 | You should have received a copy of the GNU Affero General Public |
20 | License and the CiviCRM Licensing Exception along |
21 | with this program; if not, contact CiviCRM LLC |
22 | at info[AT]civicrm[DOT]org. If you have questions about the |
23 | GNU Affero General Public License or the licensing of CiviCRM, |
24 | see the CiviCRM license FAQ at http://civicrm.org/licensing |
25 +--------------------------------------------------------------------+
31 * @copyright CiviCRM LLC (c) 2004-2017
33 abstract class CRM_Core_Page_Basic
extends CRM_Core_Page
{
38 * Define all the abstract functions here.
42 * Name of the BAO to perform various DB manipulations.
46 abstract protected function getBAOName();
49 * An array of action links.
54 abstract protected function &links();
57 * Name of the edit form class.
61 abstract protected function editForm();
68 abstract protected function editName();
71 * UserContext to pop back to.
74 * Mode that we are in.
78 abstract protected function userContext($mode = NULL);
81 * Get userContext params.
84 * Mode that we are in.
88 public function userContextParams($mode = NULL) {
89 return 'reset=1&action=browse';
93 * Allow objects to be added based on permission.
96 * The id of the object.
98 * The name or title of the object.
101 * permission value if permission is granted, else null
103 public function checkPermission($id, $name) {
104 return CRM_Core_Permission
::EDIT
;
108 * Allows the derived class to add some more state variables to
109 * the controller. By default does nothing, and hence is abstract
111 * @param CRM_Core_Controller $controller
112 * The controller object.
114 public function addValues($controller) {
120 * @param string $title
125 * @return \CRM_Core_Page_Basic
127 public function __construct($title = NULL, $mode = NULL) {
128 parent
::__construct($title, $mode);
132 * Run the basic page (run essentially starts execution for that page).
134 public function run() {
136 // do not see args or pageArgs being used, so we should
137 // consider eliminating them in a future version
138 $n = func_num_args();
139 $args = ($n > 0) ?
func_get_arg(0) : NULL;
140 $pageArgs = ($n > 1) ?
func_get_arg(1) : NULL;
141 $sort = ($n > 2) ?
func_get_arg(2) : NULL;
142 // what action do we want to perform ? (store it for smarty too.. :)
144 $this->_action
= CRM_Utils_Request
::retrieve('action', 'String', $this, FALSE, 'browse');
145 $this->assign('action', $this->_action
);
147 // get 'id' if present
148 $id = CRM_Utils_Request
::retrieve('id', 'Positive', $this, FALSE, 0);
150 require_once str_replace('_', DIRECTORY_SEPARATOR
, $this->getBAOName()) . ".php";
153 if (!$this->checkPermission($id, NULL)) {
154 CRM_Core_Error
::fatal(ts('You do not have permission to make changes to the record'));
158 if ($this->_action
& (CRM_Core_Action
::VIEW |
159 CRM_Core_Action
::ADD |
160 CRM_Core_Action
::UPDATE |
161 CRM_Core_Action
::COPY |
162 CRM_Core_Action
::ENABLE |
163 CRM_Core_Action
::DISABLE |
164 CRM_Core_Action
::DELETE
167 // use edit form for view, add or update or delete
168 $this->edit($this->_action
, $id);
171 // if no action or browse
172 $this->browse(NULL, $sort);
175 return parent
::run();
181 public function superRun() {
182 return parent
::run();
186 * Browse all entities.
188 public function browse() {
189 $n = func_num_args();
190 $action = ($n > 0) ?
func_get_arg(0) : NULL;
191 $sort = ($n > 0) ?
func_get_arg(1) : NULL;
192 $links = &$this->links();
193 if ($action == NULL) {
194 if (!empty($links)) {
195 $action = array_sum(array_keys($links));
198 if ($action & CRM_Core_Action
::DISABLE
) {
199 $action -= CRM_Core_Action
::DISABLE
;
201 if ($action & CRM_Core_Action
::ENABLE
) {
202 $action -= CRM_Core_Action
::ENABLE
;
204 $baoString = $this->getBAOName();
205 $object = new $baoString();
209 // lets make sure we get the stuff sorted by name if it exists
210 $fields = &$object->fields();
212 if (!empty($fields['title'])) {
215 elseif (!empty($fields['label'])) {
218 elseif (!empty($fields['name'])) {
223 $object->orderBy($sort);
226 $object->orderBy($key . ' asc');
229 $contactTypes = CRM_Contact_BAO_ContactType
::getSelectElements(FALSE, FALSE);
232 while ($object->fetch()) {
233 if (!isset($object->mapping_type_id
) ||
234 // "1 for Search Builder"
235 $object->mapping_type_id
!= 1
237 $permission = CRM_Core_Permission
::EDIT
;
239 $permission = $this->checkPermission($object->id
, $object->$key);
242 $values[$object->id
] = array();
243 CRM_Core_DAO
::storeValues($object, $values[$object->id
]);
245 if (is_a($object, 'CRM_Contact_DAO_RelationshipType')) {
246 if (isset($values[$object->id
]['contact_type_a'])) {
247 $values[$object->id
]['contact_type_a_display'] = $contactTypes[$values[$object->id
]['contact_type_a']];
249 if (isset($values[$object->id
]['contact_type_b'])) {
250 $values[$object->id
]['contact_type_b_display'] = $contactTypes[$values[$object->id
]['contact_type_b']];
254 // populate action links
255 $this->action($object, $action, $values[$object->id
], $links, $permission);
257 if (isset($object->mapping_type_id
)) {
258 $mappintTypes = CRM_Core_PseudoConstant
::get('CRM_Core_DAO_Mapping', 'mapping_type_id');
259 $values[$object->id
]['mapping_type'] = $mappintTypes[$object->mapping_type_id
];
264 $this->assign('rows', $values);
268 * Given an object, get the actions that can be associated with this
269 * object. Check the is_active and is_required flags to display valid
272 * @param CRM_Core_DAO $object
273 * The object being considered.
275 * The base set of actions.
276 * @param array $values
277 * The array of values that we send to the template.
278 * @param array $links
279 * The array of links.
280 * @param string $permission
281 * The permission assigned to this object.
283 * @param bool $forceAction
285 public function action(&$object, $action, &$values, &$links, $permission, $forceAction = FALSE) {
286 $values['class'] = '';
287 $newAction = $action;
288 $hasDelete = $hasDisable = TRUE;
290 if (!empty($values['name']) && in_array($values['name'], array(
296 static $caseCount = NULL;
297 if (!isset($caseCount)) {
298 $caseCount = CRM_Case_BAO_Case
::caseCount(NULL, FALSE);
300 if ($caseCount > 0) {
301 $hasDelete = $hasDisable = FALSE;
306 if (array_key_exists('is_reserved', $object) && $object->is_reserved
) {
307 $values['class'] = 'reserved';
308 // check if object is relationship type
309 $object_type = get_class($object);
312 'CRM_Contact_BAO_RelationshipType',
313 'CRM_Core_BAO_LocationType',
314 'CRM_Badge_BAO_Layout',
317 if (in_array($object_type, $exceptions)) {
318 $newAction = CRM_Core_Action
::VIEW + CRM_Core_Action
::UPDATE
;
322 $values['action'] = '';
327 if (array_key_exists('is_active', $object)) {
328 if ($object->is_active
) {
330 $newAction +
= CRM_Core_Action
::DISABLE
;
334 $newAction +
= CRM_Core_Action
::ENABLE
;
340 //CRM-4418, handling edit and delete separately.
341 $permissions = array($permission);
342 if ($hasDelete && ($permission == CRM_Core_Permission
::EDIT
)) {
343 //previously delete was subset of edit
344 //so for consistency lets grant delete also.
345 $permissions[] = CRM_Core_Permission
::DELETE
;
348 // make sure we only allow those actions that the user is permissioned for
349 $newAction = $newAction & CRM_Core_Action
::mask($permissions);
351 $values['action'] = CRM_Core_Action
::formLink($links, $newAction, array('id' => $object->id
));
358 * What mode for the form ?.
360 * Id of the entity (for update, view operations).
362 * @param bool $imageUpload
363 * @param bool $pushUserContext
365 public function edit($mode, $id = NULL, $imageUpload = FALSE, $pushUserContext = TRUE) {
366 $controller = new CRM_Core_Controller_Simple($this->editForm(),
372 // set the userContext stack
373 if ($pushUserContext) {
374 $session = CRM_Core_Session
::singleton();
375 $session->pushUserContext(CRM_Utils_System
::url($this->userContext($mode), $this->userContextParams($mode)));
378 $controller->set('id', $id);
380 $controller->set('BAOName', $this->getBAOName());
381 $this->addValues($controller);
382 $controller->setEmbedded(TRUE);
383 $controller->process();