Merge pull request #14599 from eileenmcnaughton/record_partial_1
[civicrm-core.git] / CRM / Core / Page / EntityPageTrait.php
CommitLineData
6921a820
MWMC
1<?php
2/*
3 +--------------------------------------------------------------------+
4 | CiviCRM version 5 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2019 |
7 +--------------------------------------------------------------------+
8 | This file is a part of CiviCRM. |
9 | |
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. |
13 | |
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. |
18 | |
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 +--------------------------------------------------------------------+
26 */
27
28/**
29 *
30 * @package CRM
31 * @copyright CiviCRM LLC (c) 2004-2019
32 */
33trait CRM_Core_Page_EntityPageTrait {
34
35 /**
36 * Pages MUST declare the following functions:
37 * public function getDefaultEntity() {
38 */
39
40 /**
41 * Page MAY want to override the following functions:
42 * public function getDefaultContext()
43 */
44
45 /**
46 * The id of the contact.
47 *
48 * @var int
49 */
50 protected $_id;
51
52 /**
53 * The mode of operation for this page
54 *
55 * @var int
56 */
57 protected $_action;
58
59 /**
60 * The context that we are working on.
61 *
62 * @var string
63 */
64 protected $_context;
65
66 /**
67 * Contact ID of the contact on the page.
68 *
69 * @var int
70 */
71 public $_contactID = NULL;
72
73 /**
74 * Contact ID of the contact on the page.
75 *
76 * @var int
77 * @deprecated Historically pages alternate between $_contactID and $_contactId. We'll standardise on one
78 */
79 public $_contactId = NULL;
80
81 /**
82 * @var int
83 */
84 public $_permission = NULL;
85
86 /**
87 * The action links that we need to display for the browse screen.
88 *
89 * @var array
90 */
91 public static $_links = NULL;
92
93 /**
94 * Get the entity id being edited.
95 *
96 * @return int|null
97 */
98 public function getEntityId() {
99 return $this->_id;
100 }
101
102 /**
103 * Get the context we are working in
104 *
105 * @return string
106 */
107 public function getContext() {
108 return $this->_context;
109 }
110
111 /**
112 * Get the contact ID
113 *
114 * @return int
115 */
116 public function getContactId() {
117 return $this->_contactID;
118 }
119
120 /**
121 * Set the contact ID
122 *
123 * @param $contactId
124 */
125 public function setContactId($contactId) {
126 $this->_contactID = $contactId;
127 $this->_contactId = $contactId;
128 }
129
130 public function getAction() {
131 return $this->_action;
132 }
133
134 /**
135 * Explicitly declare the form context.
136 *
137 * @return string|null
138 */
139 public function getDefaultContext() {
140 return NULL;
141 }
142
143 public function preProcessQuickEntityPage() {
144 $this->_action = CRM_Utils_Request::retrieve('action', 'String', $this, FALSE, 'browse');
145 $this->assign('action', $this->getAction());
146
147 $this->_id = CRM_Utils_Request::retrieve('id', 'Positive', $this);
148 $this->setContactId(CRM_Utils_Request::retrieve('cid', 'Positive', $this, TRUE));
149 $this->assign('contactId', $this->getContactId());
150
151 $this->_context = CRM_Utils_Request::retrieve('context', 'Alphanumeric', $this, FALSE, $this->getDefaultContext());
152 $this->assign('context', $this->_context);
153
154 // check logged in url permission
155 CRM_Contact_Page_View::checkUserPermission($this);
156
157 $this->assign('entityInClassFormat', strtolower(str_replace('_', '-', $this->getDefaultEntity())));
158 }
159
160 /**
161 * Is the form being used in the context of a deletion.
162 *
163 * (For some reason rather than having separate forms Civi overloads one form).
164 *
165 * @return bool
166 */
167 protected function isDeleteContext() {
168 return ($this->getAction() & CRM_Core_Action::DELETE);
169 }
170
171 /**
172 * Is the form being used in the context of a view.
173 *
174 * @return bool
175 */
176 protected function isViewContext() {
177 return ($this->getAction() & CRM_Core_Action::VIEW);
178 }
179
180 /**
181 * Is the form being used in the context of a edit.
182 *
183 * @return bool
184 */
185 protected function isEditContext() {
186 return ($this->getAction() & (CRM_Core_Action::UPDATE | CRM_Core_Action::ADD));
187 }
188
189}