Commit | Line | Data |
---|---|---|
6a488035 TO |
1 | <?php |
2 | /* | |
3 | +--------------------------------------------------------------------+ | |
fee14197 | 4 | | CiviCRM version 5 | |
6a488035 | 5 | +--------------------------------------------------------------------+ |
8c9251b3 | 6 | | Copyright CiviCRM LLC (c) 2004-2018 | |
6a488035 TO |
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 | +--------------------------------------------------------------------+ | |
d25dd0ee | 26 | */ |
6a488035 TO |
27 | |
28 | /** | |
29 | * | |
30 | * @package CRM | |
8c9251b3 | 31 | * @copyright CiviCRM LLC (c) 2004-2018 |
6a488035 TO |
32 | */ |
33 | class CRM_Contact_Page_View_Relationship extends CRM_Core_Page { | |
34 | ||
35 | /** | |
fe482240 | 36 | * The action links that we need to display for the browse screen. |
6a488035 TO |
37 | * |
38 | * @var array | |
6a488035 TO |
39 | */ |
40 | static $_links = NULL; | |
41 | ||
42 | /** | |
fe482240 | 43 | * Casid set if called from case context. |
6a488035 TO |
44 | * |
45 | * @var int | |
46 | */ | |
47 | public $_caseId = NULL; | |
48 | ||
49 | public $_permission = NULL; | |
50 | public $_contactId = NULL; | |
51 | ||
52 | /** | |
fe482240 | 53 | * View details of a relationship. |
6a488035 | 54 | */ |
00be9182 | 55 | public function view() { |
6a488035 TO |
56 | $viewRelationship = CRM_Contact_BAO_Relationship::getRelationship($this->_contactId, NULL, NULL, NULL, $this->_id); |
57 | //To check whether selected contact is a contact_id_a in | |
58 | //relationship type 'a_b' in relationship table, if yes then | |
59 | //revert the permissionship text in template | |
60 | $relationship = new CRM_Contact_DAO_Relationship(); | |
61 | $relationship->id = $viewRelationship[$this->_id]['id']; | |
62 | ||
63 | if ($relationship->find(TRUE)) { | |
64 | if (($viewRelationship[$this->_id]['rtype'] == 'a_b') && ($this->_contactId == $relationship->contact_id_a)) { | |
65 | $this->assign("is_contact_id_a", TRUE); | |
66 | } | |
67 | } | |
68 | $relType = $viewRelationship[$this->_id]['civicrm_relationship_type_id']; | |
69 | $this->assign('viewRelationship', $viewRelationship); | |
70 | ||
71 | $employerId = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Contact', $this->_contactId, 'employer_id'); | |
72 | $this->assign('isCurrentEmployer', FALSE); | |
05802b8e DG |
73 | |
74 | $relTypes = CRM_Utils_Array::index(array('name_a_b'), CRM_Core_PseudoConstant::relationshipType('name')); | |
a7ac519a | 75 | |
6a488035 TO |
76 | if ($viewRelationship[$this->_id]['employer_id'] == $this->_contactId) { |
77 | $this->assign('isCurrentEmployer', TRUE); | |
78 | } | |
05802b8e | 79 | elseif ($relType == $relTypes['Employee of']['id'] && |
6a488035 TO |
80 | ($viewRelationship[$this->_id]['cid'] == $employerId) |
81 | ) { | |
82 | // make sure we are viewing employee of relationship | |
83 | $this->assign('isCurrentEmployer', TRUE); | |
84 | } | |
85 | ||
86 | $viewNote = CRM_Core_BAO_Note::getNote($this->_id); | |
87 | $this->assign('viewNote', $viewNote); | |
88 | ||
0b330e6d | 89 | $groupTree = CRM_Core_BAO_CustomGroup::getTree('Relationship', NULL, $this->_id, 0, $relType); |
e34e6979 | 90 | CRM_Core_BAO_CustomGroup::buildCustomDataView($this, $groupTree, FALSE, NULL, NULL, NULL, $this->_id); |
6a488035 TO |
91 | |
92 | $rType = CRM_Utils_Array::value('rtype', $viewRelationship[$this->_id]); | |
93 | // add viewed contribution to recent items list | |
94 | $url = CRM_Utils_System::url('civicrm/contact/view/rel', | |
95 | "action=view&reset=1&id={$viewRelationship[$this->_id]['id']}&cid={$this->_contactId}&context=home" | |
96 | ); | |
97 | ||
6a488035 TO |
98 | $session = CRM_Core_Session::singleton(); |
99 | $recentOther = array(); | |
100 | ||
101 | if (($session->get('userID') == $this->_contactId) || | |
102 | CRM_Contact_BAO_Contact_Permission::allow($this->_contactId, CRM_Core_Permission::EDIT) | |
103 | ) { | |
104 | $recentOther = array( | |
105 | 'editUrl' => CRM_Utils_System::url('civicrm/contact/view/rel', | |
106 | "action=update&reset=1&id={$viewRelationship[$this->_id]['id']}&cid={$this->_contactId}&rtype={$rType}&context=home" | |
107 | ), | |
108 | 'deleteUrl' => CRM_Utils_System::url('civicrm/contact/view/rel', | |
109 | "action=delete&reset=1&id={$viewRelationship[$this->_id]['id']}&cid={$this->_contactId}&rtype={$rType}&context=home" | |
110 | ), | |
111 | ); | |
112 | } | |
113 | ||
114 | $displayName = CRM_Contact_BAO_Contact::displayName($this->_contactId); | |
115 | $this->assign('displayName', $displayName); | |
116 | CRM_Utils_System::setTitle(ts('View Relationship for') . ' ' . $displayName); | |
117 | ||
118 | $title = $displayName . ' (' . $viewRelationship[$this->_id]['relation'] . ' ' . CRM_Contact_BAO_Contact::displayName($viewRelationship[$this->_id]['cid']) . ')'; | |
119 | ||
120 | // add the recently viewed Relationship | |
121 | CRM_Utils_Recent::add($title, | |
122 | $url, | |
123 | $viewRelationship[$this->_id]['id'], | |
124 | 'Relationship', | |
125 | $this->_contactId, | |
126 | NULL, | |
127 | $recentOther | |
128 | ); | |
129 | } | |
130 | ||
131 | /** | |
fe482240 | 132 | * called when action is browse. |
6a488035 | 133 | * |
6a488035 | 134 | */ |
00be9182 | 135 | public function browse() { |
40458f6c | 136 | // do nothing :) we are using datatable for rendering relationship selectors |
6a488035 TO |
137 | } |
138 | ||
139 | /** | |
fe482240 | 140 | * called when action is update or new. |
6a488035 | 141 | * |
6a488035 | 142 | */ |
00be9182 | 143 | public function edit() { |
6a488035 TO |
144 | $controller = new CRM_Core_Controller_Simple('CRM_Contact_Form_Relationship', ts('Contact Relationships'), $this->_action); |
145 | $controller->setEmbedded(TRUE); | |
146 | ||
147 | // set the userContext stack | |
148 | $session = CRM_Core_Session::singleton(); | |
149 | ||
150 | // if this is called from case view, we need to redirect back to same page | |
151 | if ($this->_caseId) { | |
152 | $url = CRM_Utils_System::url('civicrm/contact/view/case', "action=view&reset=1&cid={$this->_contactId}&id={$this->_caseId}"); | |
153 | } | |
154 | else { | |
155 | $url = CRM_Utils_System::url('civicrm/contact/view', "action=browse&selectedChild=rel&reset=1&cid={$this->_contactId}"); | |
156 | } | |
157 | ||
158 | $session->pushUserContext($url); | |
159 | ||
1273d77c | 160 | if (CRM_Utils_Request::retrieve('confirmed', 'Boolean')) { |
6a488035 TO |
161 | if ($this->_caseId) { |
162 | //create an activity for case role removal.CRM-4480 | |
163 | CRM_Case_BAO_Case::createCaseRoleActivity($this->_caseId, $this->_id); | |
164 | CRM_Core_Session::setStatus(ts('Case Role has been deleted successfully.'), ts('Record Deleted'), 'success'); | |
165 | } | |
166 | ||
167 | // delete relationship | |
168 | CRM_Contact_BAO_Relationship::del($this->_id); | |
169 | ||
170 | CRM_Utils_System::redirect($url); | |
171 | } | |
172 | ||
173 | $controller->set('contactId', $this->_contactId); | |
174 | $controller->set('id', $this->_id); | |
175 | $controller->process(); | |
176 | $controller->run(); | |
177 | } | |
178 | ||
00be9182 | 179 | public function preProcess() { |
6a488035 TO |
180 | $this->_id = CRM_Utils_Request::retrieve('id', 'Positive', $this); |
181 | $this->_contactId = CRM_Utils_Request::retrieve('cid', 'Positive', $this, TRUE); | |
182 | $this->assign('contactId', $this->_contactId); | |
183 | ||
184 | // check logged in url permission | |
185 | CRM_Contact_Page_View::checkUserPermission($this); | |
186 | ||
6a488035 TO |
187 | $this->_action = CRM_Utils_Request::retrieve('action', 'String', $this, FALSE, 'browse'); |
188 | $this->assign('action', $this->_action); | |
189 | } | |
190 | ||
191 | /** | |
dc195289 | 192 | * the main function that is called when the page loads, |
6a488035 TO |
193 | * it decides the which action has to be taken for the page. |
194 | * | |
76e7a76c | 195 | * @return null |
6a488035 | 196 | */ |
00be9182 | 197 | public function run() { |
6a488035 TO |
198 | $this->preProcess(); |
199 | ||
200 | $this->setContext(); | |
201 | ||
202 | $this->_caseId = CRM_Utils_Request::retrieve('caseID', 'Integer', $this); | |
203 | ||
204 | if ($this->_action & CRM_Core_Action::VIEW) { | |
205 | $this->view(); | |
206 | } | |
207 | elseif ($this->_action & (CRM_Core_Action::UPDATE | CRM_Core_Action::ADD | CRM_Core_Action::DELETE)) { | |
208 | $this->edit(); | |
209 | } | |
6a488035 TO |
210 | |
211 | // if this is called from case view, suppress browse relationships form | |
babae7c3 | 212 | else { |
6a488035 TO |
213 | $this->browse(); |
214 | } | |
215 | ||
216 | return parent::run(); | |
217 | } | |
218 | ||
00be9182 | 219 | public function setContext() { |
edc80cda | 220 | $context = CRM_Utils_Request::retrieve('context', 'Alphanumeric', |
6a488035 TO |
221 | $this, FALSE, 'search' |
222 | ); | |
223 | ||
224 | if ($context == 'dashboard') { | |
225 | $cid = CRM_Utils_Request::retrieve('cid', 'Integer', | |
226 | $this, FALSE | |
227 | ); | |
228 | $url = CRM_Utils_System::url('civicrm/user', | |
229 | "reset=1&id={$cid}" | |
230 | ); | |
231 | } | |
232 | else { | |
233 | $url = CRM_Utils_System::url('civicrm/contact/view', 'action=browse&selectedChild=rel'); | |
234 | } | |
235 | $session = CRM_Core_Session::singleton(); | |
236 | $session->pushUserContext($url); | |
237 | } | |
238 | ||
239 | /** | |
fe482240 | 240 | * called to delete the relationship of a contact. |
6a488035 | 241 | * |
6a488035 | 242 | */ |
00be9182 | 243 | public function delete() { |
6a488035 TO |
244 | // calls a function to delete relationship |
245 | CRM_Contact_BAO_Relationship::del($this->_id); | |
246 | } | |
247 | ||
248 | /** | |
fe482240 | 249 | * Get action links. |
6a488035 | 250 | * |
a6c01b45 CW |
251 | * @return array |
252 | * (reference) of action links | |
6a488035 | 253 | */ |
00be9182 | 254 | public static function &links() { |
6a488035 | 255 | if (!(self::$_links)) { |
6a488035 TO |
256 | self::$_links = array( |
257 | CRM_Core_Action::VIEW => array( | |
258 | 'name' => ts('View'), | |
259 | 'url' => 'civicrm/contact/view/rel', | |
260 | 'qs' => 'action=view&reset=1&cid=%%cid%%&id=%%id%%&rtype=%%rtype%%&selectedChild=rel', | |
261 | 'title' => ts('View Relationship'), | |
262 | ), | |
263 | CRM_Core_Action::UPDATE => array( | |
264 | 'name' => ts('Edit'), | |
265 | 'url' => 'civicrm/contact/view/rel', | |
266 | 'qs' => 'action=update&reset=1&cid=%%cid%%&id=%%id%%&rtype=%%rtype%%', | |
267 | 'title' => ts('Edit Relationship'), | |
268 | ), | |
269 | CRM_Core_Action::ENABLE => array( | |
270 | 'name' => ts('Enable'), | |
41b47b8a | 271 | 'ref' => 'crm-enable-disable', |
6a488035 TO |
272 | 'title' => ts('Enable Relationship'), |
273 | ), | |
274 | CRM_Core_Action::DISABLE => array( | |
275 | 'name' => ts('Disable'), | |
41b47b8a | 276 | 'ref' => 'crm-enable-disable', |
6a488035 TO |
277 | 'title' => ts('Disable Relationship'), |
278 | ), | |
279 | CRM_Core_Action::DELETE => array( | |
280 | 'name' => ts('Delete'), | |
281 | 'url' => 'civicrm/contact/view/rel', | |
282 | 'qs' => 'action=delete&reset=1&cid=%%cid%%&id=%%id%%&rtype=%%rtype%%', | |
6a488035 TO |
283 | 'title' => ts('Delete Relationship'), |
284 | ), | |
285 | // FIXME: Not sure what to put as the key. | |
286 | // We want to use it differently later anyway (see CRM_Contact_BAO_Relationship::getRelationship). NONE should make it hidden by default. | |
287 | CRM_Core_Action::NONE => array( | |
288 | 'name' => ts('Manage Case'), | |
289 | 'url' => 'civicrm/contact/view/case', | |
290 | 'qs' => 'action=view&reset=1&cid=%%clientid%%&id=%%caseid%%', | |
291 | 'title' => ts('Manage Case'), | |
292 | ), | |
293 | ); | |
294 | } | |
295 | return self::$_links; | |
296 | } | |
96025800 | 297 | |
6a488035 | 298 | } |