3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.5 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2014 |
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-2014
35 class CRM_Contact_Page_View_Relationship
extends CRM_Core_Page
{
38 * The action links that we need to display for the browse screen
43 static $_links = NULL;
46 * casid set if called from case context
50 public $_caseId = NULL;
52 public $_permission = NULL;
53 public $_contactId = NULL;
56 * View details of a relationship
63 $viewRelationship = CRM_Contact_BAO_Relationship
::getRelationship($this->_contactId
, NULL, NULL, NULL, $this->_id
);
64 //To check whether selected contact is a contact_id_a in
65 //relationship type 'a_b' in relationship table, if yes then
66 //revert the permissionship text in template
67 $relationship = new CRM_Contact_DAO_Relationship();
68 $relationship->id
= $viewRelationship[$this->_id
]['id'];
70 if ($relationship->find(TRUE)) {
71 if (($viewRelationship[$this->_id
]['rtype'] == 'a_b') && ($this->_contactId
== $relationship->contact_id_a
)) {
72 $this->assign("is_contact_id_a", TRUE);
75 $relType = $viewRelationship[$this->_id
]['civicrm_relationship_type_id'];
76 $this->assign('viewRelationship', $viewRelationship);
78 $employerId = CRM_Core_DAO
::getFieldValue('CRM_Contact_DAO_Contact', $this->_contactId
, 'employer_id');
79 $this->assign('isCurrentEmployer', FALSE);
81 $relTypes = CRM_Utils_Array
::index(array('name_a_b'), CRM_Core_PseudoConstant
::relationshipType('name'));
83 if ($viewRelationship[$this->_id
]['employer_id'] == $this->_contactId
) {
84 $this->assign('isCurrentEmployer', TRUE);
86 elseif ($relType == $relTypes['Employee of']['id'] &&
87 ($viewRelationship[$this->_id
]['cid'] == $employerId)
89 // make sure we are viewing employee of relationship
90 $this->assign('isCurrentEmployer', TRUE);
93 $viewNote = CRM_Core_BAO_Note
::getNote($this->_id
);
94 $this->assign('viewNote', $viewNote);
96 $groupTree = CRM_Core_BAO_CustomGroup
::getTree('Relationship', $this, $this->_id
, 0, $relType);
97 CRM_Core_BAO_CustomGroup
::buildCustomDataView($this, $groupTree);
99 $rType = CRM_Utils_Array
::value('rtype', $viewRelationship[$this->_id
]);
100 // add viewed contribution to recent items list
101 $url = CRM_Utils_System
::url('civicrm/contact/view/rel',
102 "action=view&reset=1&id={$viewRelationship[$this->_id]['id']}&cid={$this->_contactId}&context=home"
106 $session = CRM_Core_Session
::singleton();
107 $recentOther = array();
109 if (($session->get('userID') == $this->_contactId
) ||
110 CRM_Contact_BAO_Contact_Permission
::allow($this->_contactId
, CRM_Core_Permission
::EDIT
)
112 $recentOther = array(
113 'editUrl' => CRM_Utils_System
::url('civicrm/contact/view/rel',
114 "action=update&reset=1&id={$viewRelationship[$this->_id]['id']}&cid={$this->_contactId}&rtype={$rType}&context=home"
116 'deleteUrl' => CRM_Utils_System
::url('civicrm/contact/view/rel',
117 "action=delete&reset=1&id={$viewRelationship[$this->_id]['id']}&cid={$this->_contactId}&rtype={$rType}&context=home"
122 $displayName = CRM_Contact_BAO_Contact
::displayName($this->_contactId
);
123 $this->assign('displayName', $displayName);
124 CRM_Utils_System
::setTitle(ts('View Relationship for') . ' ' . $displayName);
126 $title = $displayName . ' (' . $viewRelationship[$this->_id
]['relation'] . ' ' . CRM_Contact_BAO_Contact
::displayName($viewRelationship[$this->_id
]['cid']) . ')';
128 // add the recently viewed Relationship
129 CRM_Utils_Recent
::add($title,
131 $viewRelationship[$this->_id
]['id'],
140 * This function is called when action is browse
146 // do nothing :) we are using datatable for rendering relationship selectors
150 * This function is called when action is update or new
156 $controller = new CRM_Core_Controller_Simple('CRM_Contact_Form_Relationship', ts('Contact Relationships'), $this->_action
);
157 $controller->setEmbedded(TRUE);
159 // set the userContext stack
160 $session = CRM_Core_Session
::singleton();
162 // if this is called from case view, we need to redirect back to same page
163 if ($this->_caseId
) {
164 $url = CRM_Utils_System
::url('civicrm/contact/view/case', "action=view&reset=1&cid={$this->_contactId}&id={$this->_caseId}");
167 $url = CRM_Utils_System
::url('civicrm/contact/view', "action=browse&selectedChild=rel&reset=1&cid={$this->_contactId}");
170 $session->pushUserContext($url);
172 if (CRM_Utils_Request
::retrieve('confirmed', 'Boolean',
173 CRM_Core_DAO
::$_nullObject
175 if ($this->_caseId
) {
176 //create an activity for case role removal.CRM-4480
177 CRM_Case_BAO_Case
::createCaseRoleActivity($this->_caseId
, $this->_id
);
178 CRM_Core_Session
::setStatus(ts('Case Role has been deleted successfully.'), ts('Record Deleted'), 'success');
181 // delete relationship
182 CRM_Contact_BAO_Relationship
::del($this->_id
);
184 CRM_Utils_System
::redirect($url);
187 $controller->set('contactId', $this->_contactId
);
188 $controller->set('id', $this->_id
);
189 $controller->process();
193 function preProcess() {
194 $this->_id
= CRM_Utils_Request
::retrieve('id', 'Positive', $this);
195 $this->_contactId
= CRM_Utils_Request
::retrieve('cid', 'Positive', $this, TRUE);
196 $this->assign('contactId', $this->_contactId
);
198 // check logged in url permission
199 CRM_Contact_Page_View
::checkUserPermission($this);
201 $this->_action
= CRM_Utils_Request
::retrieve('action', 'String', $this, FALSE, 'browse');
202 $this->assign('action', $this->_action
);
206 * This function is the main function that is called when the page loads,
207 * it decides the which action has to be taken for the page.
217 $this->_caseId
= CRM_Utils_Request
::retrieve('caseID', 'Integer', $this);
219 if ($this->_action
& CRM_Core_Action
::VIEW
) {
222 elseif ($this->_action
& (CRM_Core_Action
::UPDATE | CRM_Core_Action
::ADD | CRM_Core_Action
::DELETE
)) {
225 elseif ($this->_action
& CRM_Core_Action
::DISABLE
) {
226 CRM_Contact_BAO_Relationship
::disableEnableRelationship($this->_id
, CRM_Core_Action
::DISABLE
);
227 CRM_Contact_BAO_Relationship
::setIsActive($this->_id
, 0);
228 $session = CRM_Core_Session
::singleton();
229 CRM_Utils_System
::redirect($session->popUserContext());
231 elseif ($this->_action
& CRM_Core_Action
::ENABLE
) {
232 CRM_Contact_BAO_Relationship
::disableEnableRelationship($this->_id
, CRM_Core_Action
::ENABLE
);
233 CRM_Contact_BAO_Relationship
::setIsActive($this->_id
, 1);
234 $session = CRM_Core_Session
::singleton();
235 CRM_Utils_System
::redirect($session->popUserContext());
238 // if this is called from case view, suppress browse relationships form
243 return parent
::run();
246 function setContext() {
247 $context = CRM_Utils_Request
::retrieve('context', 'String',
248 $this, FALSE, 'search'
251 if ($context == 'dashboard') {
252 $cid = CRM_Utils_Request
::retrieve('cid', 'Integer',
255 $url = CRM_Utils_System
::url('civicrm/user',
260 $url = CRM_Utils_System
::url('civicrm/contact/view', 'action=browse&selectedChild=rel');
262 $session = CRM_Core_Session
::singleton();
263 $session->pushUserContext($url);
267 * This function is called to delete the relationship of a contact
273 // calls a function to delete relationship
274 CRM_Contact_BAO_Relationship
::del($this->_id
);
280 * @return array (reference) of action links
283 static function &links() {
284 if (!(self
::$_links)) {
285 self
::$_links = array(
286 CRM_Core_Action
::VIEW
=> array(
287 'name' => ts('View'),
288 'url' => 'civicrm/contact/view/rel',
289 'qs' => 'action=view&reset=1&cid=%%cid%%&id=%%id%%&rtype=%%rtype%%&selectedChild=rel',
290 'title' => ts('View Relationship'),
292 CRM_Core_Action
::UPDATE
=> array(
293 'name' => ts('Edit'),
294 'url' => 'civicrm/contact/view/rel',
295 'qs' => 'action=update&reset=1&cid=%%cid%%&id=%%id%%&rtype=%%rtype%%',
296 'title' => ts('Edit Relationship'),
298 CRM_Core_Action
::ENABLE
=> array(
299 'name' => ts('Enable'),
300 'ref' => 'crm-enable-disable',
301 'title' => ts('Enable Relationship'),
303 CRM_Core_Action
::DISABLE
=> array(
304 'name' => ts('Disable'),
305 'ref' => 'crm-enable-disable',
306 'title' => ts('Disable Relationship'),
308 CRM_Core_Action
::DELETE
=> array(
309 'name' => ts('Delete'),
310 'url' => 'civicrm/contact/view/rel',
311 'qs' => 'action=delete&reset=1&cid=%%cid%%&id=%%id%%&rtype=%%rtype%%',
312 'title' => ts('Delete Relationship'),
314 // FIXME: Not sure what to put as the key.
315 // We want to use it differently later anyway (see CRM_Contact_BAO_Relationship::getRelationship). NONE should make it hidden by default.
316 CRM_Core_Action
::NONE
=> array(
317 'name' => ts('Manage Case'),
318 'url' => 'civicrm/contact/view/case',
319 'qs' => 'action=view&reset=1&cid=%%clientid%%&id=%%caseid%%',
320 'title' => ts('Manage Case'),
324 return self
::$_links;