3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.7 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2015 |
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-2015
35 abstract class CRM_Core_Page_Basic
extends CRM_Core_Page
{
40 * Define all the abstract functions here.
44 * Name of the BAO to perform various DB manipulations.
48 abstract protected function getBAOName();
51 * An array of action links.
56 abstract protected function &links();
59 * Name of the edit form class.
63 abstract protected function editForm();
70 abstract protected function editName();
73 * UserContext to pop back to.
76 * Mode that we are in.
80 abstract protected function userContext($mode = NULL);
83 * Get userContext params.
86 * Mode that we are in.
90 public function userContextParams($mode = NULL) {
91 return 'reset=1&action=browse';
95 * Allow objects to be added based on permission.
98 * The id of the object.
100 * The name or title of the object.
103 * permission value if permission is granted, else null
105 public function checkPermission($id, $name) {
106 return CRM_Core_Permission
::EDIT
;
110 * Allows the derived class to add some more state variables to
111 * the controller. By default does nothing, and hence is abstract
113 * @param CRM_Core_Controller $controller
114 * The controller object.
118 public function addValues($controller) {
124 * @param string $title
129 * @return \CRM_Core_Page_Basic
131 public function __construct($title = NULL, $mode = NULL) {
132 parent
::__construct($title, $mode);
136 * Run the basic page (run essentially starts execution for that page).
140 public function run() {
142 // dont see args or pageArgs being used, so we should
143 // consider eliminating them in a future version
144 $n = func_num_args();
145 $args = ($n > 0) ?
func_get_arg(0) : NULL;
146 $pageArgs = ($n > 1) ?
func_get_arg(1) : NULL;
147 $sort = ($n > 2) ?
func_get_arg(2) : NULL;
148 // what action do we want to perform ? (store it for smarty too.. :)
150 $this->_action
= CRM_Utils_Request
::retrieve('action', 'String', $this, FALSE, 'browse');
151 $this->assign('action', $this->_action
);
153 // get 'id' if present
154 $id = CRM_Utils_Request
::retrieve('id', 'Positive', $this, FALSE, 0);
156 require_once str_replace('_', DIRECTORY_SEPARATOR
, $this->getBAOName()) . ".php";
159 if (!$this->checkPermission($id, NULL)) {
160 CRM_Core_Error
::fatal(ts('You do not have permission to make changes to the record'));
164 if ($this->_action
& (CRM_Core_Action
::VIEW |
165 CRM_Core_Action
::ADD |
166 CRM_Core_Action
::UPDATE |
167 CRM_Core_Action
::COPY |
168 CRM_Core_Action
::ENABLE |
169 CRM_Core_Action
::DISABLE |
170 CRM_Core_Action
::DELETE
173 // use edit form for view, add or update or delete
174 $this->edit($this->_action
, $id);
177 // if no action or browse
178 $this->browse(NULL, $sort);
181 return parent
::run();
187 public function superRun() {
188 return parent
::run();
192 * Browse all entities.
196 public function browse() {
197 $n = func_num_args();
198 $action = ($n > 0) ?
func_get_arg(0) : NULL;
199 $sort = ($n > 0) ?
func_get_arg(1) : NULL;
200 $links = &$this->links();
201 if ($action == NULL) {
202 if (!empty($links)) {
203 $action = array_sum(array_keys($links));
206 if ($action & CRM_Core_Action
::DISABLE
) {
207 $action -= CRM_Core_Action
::DISABLE
;
209 if ($action & CRM_Core_Action
::ENABLE
) {
210 $action -= CRM_Core_Action
::ENABLE
;
212 $baoString = $this->getBAOName();
213 $object = new $baoString();
217 // lets make sure we get the stuff sorted by name if it exists
218 $fields = &$object->fields();
220 if (!empty($fields['title'])) {
223 elseif (!empty($fields['label'])) {
226 elseif (!empty($fields['name'])) {
231 $object->orderBy($sort);
234 $object->orderBy($key . ' asc');
237 //@todo FIXME - using the CRM_Core_DAO::VALUE_SEPARATOR creates invalid html - if you can find the form
238 // this is loaded onto then replace with something like '__' & test
239 $separator = CRM_Core_DAO
::VALUE_SEPARATOR
;
240 $contactTypes = CRM_Contact_BAO_ContactType
::getSelectElements(FALSE, TRUE, $separator);
243 while ($object->fetch()) {
244 if (!isset($object->mapping_type_id
) ||
245 // "1 for Search Builder"
246 $object->mapping_type_id
!= 1
248 $permission = CRM_Core_Permission
::EDIT
;
250 $permission = $this->checkPermission($object->id
, $object->$key);
253 $values[$object->id
] = array();
254 CRM_Core_DAO
::storeValues($object, $values[$object->id
]);
256 if (is_a($object, 'CRM_Contact_DAO_RelationshipType')) {
257 $values[$object->id
]['contact_type_a_display'] = $contactTypes[$values[$object->id
]['contact_type_a']];
258 $values[$object->id
]['contact_type_b_display'] = $contactTypes[$values[$object->id
]['contact_type_b']];
261 // populate action links
262 $this->action($object, $action, $values[$object->id
], $links, $permission);
264 if (isset($object->mapping_type_id
)) {
265 $mappintTypes = CRM_Core_PseudoConstant
::get('CRM_Core_DAO_Mapping', 'mapping_type_id');
266 $values[$object->id
]['mapping_type'] = $mappintTypes[$object->mapping_type_id
];
271 $this->assign('rows', $values);
275 * Given an object, get the actions that can be associated with this
276 * object. Check the is_active and is_required flags to display valid
279 * @param CRM_Core_DAO $object
280 * The object being considered.
282 * The base set of actions.
283 * @param array $values
284 * The array of values that we send to the template.
285 * @param array $links
286 * The array of links.
287 * @param string $permission
288 * The permission assigned to this object.
290 * @param bool $forceAction
294 public function action(&$object, $action, &$values, &$links, $permission, $forceAction = FALSE) {
295 $values['class'] = '';
296 $newAction = $action;
297 $hasDelete = $hasDisable = TRUE;
299 if (!empty($values['name']) && in_array($values['name'], array(
305 static $caseCount = NULL;
306 if (!isset($caseCount)) {
307 $caseCount = CRM_Case_BAO_Case
::caseCount(NULL, FALSE);
309 if ($caseCount > 0) {
310 $hasDelete = $hasDisable = FALSE;
315 if (array_key_exists('is_reserved', $object) && $object->is_reserved
) {
316 $values['class'] = 'reserved';
317 // check if object is relationship type
318 $object_type = get_class($object);
321 'CRM_Contact_BAO_RelationshipType',
322 'CRM_Core_BAO_LocationType',
323 'CRM_Badge_BAO_Layout',
326 if (in_array($object_type, $exceptions)) {
327 $newAction = CRM_Core_Action
::VIEW + CRM_Core_Action
::UPDATE
;
331 $values['action'] = '';
336 if (array_key_exists('is_active', $object)) {
337 if ($object->is_active
) {
339 $newAction +
= CRM_Core_Action
::DISABLE
;
343 $newAction +
= CRM_Core_Action
::ENABLE
;
349 //CRM-4418, handling edit and delete separately.
350 $permissions = array($permission);
351 if ($hasDelete && ($permission == CRM_Core_Permission
::EDIT
)) {
352 //previously delete was subset of edit
353 //so for consistency lets grant delete also.
354 $permissions[] = CRM_Core_Permission
::DELETE
;
357 // make sure we only allow those actions that the user is permissioned for
358 $newAction = $newAction & CRM_Core_Action
::mask($permissions);
360 $values['action'] = CRM_Core_Action
::formLink($links, $newAction, array('id' => $object->id
));
367 * What mode for the form ?.
369 * Id of the entity (for update, view operations).
371 * @param bool $imageUpload
372 * @param bool $pushUserContext
376 public function edit($mode, $id = NULL, $imageUpload = FALSE, $pushUserContext = TRUE) {
377 $controller = new CRM_Core_Controller_Simple($this->editForm(),
383 // set the userContext stack
384 if ($pushUserContext) {
385 $session = CRM_Core_Session
::singleton();
386 $session->pushUserContext(CRM_Utils_System
::url($this->userContext($mode), $this->userContextParams($mode)));
389 $controller->set('id', $id);
391 $controller->set('BAOName', $this->getBAOName());
392 $this->addValues($controller);
393 $controller->setEmbedded(TRUE);
394 $controller->process();