3 +--------------------------------------------------------------------+
4 | Copyright CiviCRM LLC. All rights reserved. |
6 | This work is published under the GNU AGPLv3 license with some |
7 | permitted exceptions and without any warranty. For full license |
8 | and copyright information, see https://civicrm.org/licensing |
9 +--------------------------------------------------------------------+
15 * @copyright CiviCRM LLC https://civicrm.org/licensing
17 class CRM_Contact_Page_View_Relationship
extends CRM_Core_Page
{
19 use CRM_Core_Page_EntityPageTrait
;
22 * Casid set if called from case context.
26 public $_caseId = NULL;
31 public function setCaseId($caseId) {
32 $this->_caseId
= $caseId;
38 public function getCaseId() {
39 return $this->_caseId
;
43 * Explicitly declare the entity api name.
47 public function getDefaultEntity() {
48 return 'Relationship';
52 * Explicitly declare the form context.
56 public function getDefaultContext() {
61 * View details of a relationship.
63 public function view() {
64 $viewRelationship = CRM_Contact_BAO_Relationship
::getRelationship($this->getContactId(), NULL, NULL, NULL, $this->getEntityId());
65 //To check whether selected contact is a contact_id_a in
66 //relationship type 'a_b' in relationship table, if yes then
67 //revert the permissionship text in template
68 $relationship = new CRM_Contact_DAO_Relationship();
69 $relationship->id
= $viewRelationship[$this->getEntityId()]['id'];
71 if ($relationship->find(TRUE)) {
72 if (($viewRelationship[$this->getEntityId()]['rtype'] == 'a_b') && ($this->getContactId() == $relationship->contact_id_a
)) {
73 $this->assign("is_contact_id_a", TRUE);
76 $relType = $viewRelationship[$this->getEntityId()]['civicrm_relationship_type_id'];
77 $this->assign('viewRelationship', $viewRelationship);
79 $employerId = CRM_Core_DAO
::getFieldValue('CRM_Contact_DAO_Contact', $this->getContactId(), 'employer_id');
80 $this->assign('isCurrentEmployer', FALSE);
82 $relTypes = CRM_Utils_Array
::index(array('name_a_b'), CRM_Core_PseudoConstant
::relationshipType('name'));
84 if ($viewRelationship[$this->getEntityId()]['employer_id'] == $this->getContactId()) {
85 $this->assign('isCurrentEmployer', TRUE);
87 elseif ($relType == $relTypes['Employee of']['id'] &&
88 ($viewRelationship[$this->getEntityId()]['cid'] == $employerId)
90 // make sure we are viewing employee of relationship
91 $this->assign('isCurrentEmployer', TRUE);
94 $viewNote = CRM_Core_BAO_Note
::getNote($this->getEntityId());
95 $this->assign('viewNote', $viewNote);
97 $groupTree = CRM_Core_BAO_CustomGroup
::getTree('Relationship', NULL, $this->getEntityId(), 0, $relType,
98 NULL, TRUE, NULL, FALSE, CRM_Core_Permission
::VIEW
);
99 CRM_Core_BAO_CustomGroup
::buildCustomDataView($this, $groupTree, FALSE, NULL, NULL, NULL, $this->getEntityId());
101 $rType = CRM_Utils_Array
::value('rtype', $viewRelationship[$this->getEntityId()]);
102 // add viewed contribution to recent items list
103 $url = CRM_Utils_System
::url('civicrm/contact/view/rel',
104 "action=view&reset=1&id={$viewRelationship[$this->getEntityId()]['id']}&cid={$this->getContactId()}&context=home"
107 $session = CRM_Core_Session
::singleton();
110 if (($session->get('userID') == $this->getContactId()) ||
111 CRM_Contact_BAO_Contact_Permission
::allow($this->getContactId(), CRM_Core_Permission
::EDIT
)
113 $recentOther = array(
114 'editUrl' => CRM_Utils_System
::url('civicrm/contact/view/rel',
115 "action=update&reset=1&id={$viewRelationship[$this->getEntityId()]['id']}&cid={$this->getContactId()}&rtype={$rType}&context=home"
117 'deleteUrl' => CRM_Utils_System
::url('civicrm/contact/view/rel',
118 "action=delete&reset=1&id={$viewRelationship[$this->getEntityId()]['id']}&cid={$this->getContactId()}&rtype={$rType}&context=home"
123 $displayName = CRM_Contact_BAO_Contact
::displayName($this->getContactId());
124 $this->assign('displayName', $displayName);
125 CRM_Utils_System
::setTitle(ts('View Relationship for') . ' ' . $displayName);
127 $title = $displayName . ' (' . $viewRelationship[$this->getEntityId()]['relation'] . ' ' . CRM_Contact_BAO_Contact
::displayName($viewRelationship[$this->getEntityId()]['cid']) . ')';
129 // add the recently viewed Relationship
130 CRM_Utils_Recent
::add($title,
132 $viewRelationship[$this->getEntityId()]['id'],
134 $this->getContactId(),
141 * called when action is browse.
144 public function browse() {
145 // do nothing :) we are using datatable for rendering relationship selectors
146 $columnHeaders = CRM_Contact_BAO_Relationship
::getColumnHeaders();
147 $contactRelationships = $selector = NULL;
148 CRM_Utils_Hook
::searchColumns('relationship.columns', $columnHeaders, $contactRelationships, $selector);
149 $this->assign('columnHeaders', $columnHeaders);
153 * called when action is update or new.
156 public function edit() {
157 $controller = new CRM_Core_Controller_Simple('CRM_Contact_Form_Relationship', ts('Contact Relationships'), $this->getAction());
158 $controller->setEmbedded(TRUE);
160 // set the userContext stack
161 $session = CRM_Core_Session
::singleton();
163 // if this is called from case view, we need to redirect back to same page
164 if ($this->getCaseId()) {
165 $url = CRM_Utils_System
::url('civicrm/contact/view/case', "action=view&reset=1&cid={$this->getContactId()}&id={$this->getCaseId()}");
168 $url = CRM_Utils_System
::url('civicrm/contact/view', "action=browse&selectedChild=rel&reset=1&cid={$this->getContactId()}");
171 $session->pushUserContext($url);
173 if (CRM_Utils_Request
::retrieve('confirmed', 'Boolean')) {
174 if ($this->getCaseId()) {
175 //create an activity for case role removal.CRM-4480
176 CRM_Case_BAO_Case
::createCaseRoleActivity($this->getCaseId(), $this->getEntityId());
177 CRM_Core_Session
::setStatus(ts('Case Role has been deleted successfully.'), ts('Record Deleted'), 'success');
180 // delete relationship
181 CRM_Contact_BAO_Relationship
::del($this->getEntityId());
183 CRM_Utils_System
::redirect($url);
186 $controller->set('contactId', $this->getContactId());
187 $controller->set('id', $this->getEntityId());
188 $controller->process();
193 * the main function that is called when the page loads,
194 * it decides the which action has to be taken for the page.
197 * @throws \CRM_Core_Exception
199 public function run() {
200 $this->assign('entityInClassFormat', 'relationship');
201 $this->preProcessQuickEntityPage();
205 $this->setCaseId(CRM_Utils_Request
::retrieve('caseID', 'Integer', $this));
207 if ($this->isViewContext()) {
210 elseif ($this->isEditContext() ||
$this->isDeleteContext()) {
214 // if this is called from case view, suppress browse relationships form
219 return parent
::run();
222 public function setContext() {
223 if ($this->getContext() == 'dashboard') {
224 $url = CRM_Utils_System
::url('civicrm/user', "reset=1&id={$this->getContactId()}");
227 $url = CRM_Utils_System
::url('civicrm/contact/view', 'action=browse&selectedChild=rel');
229 $session = CRM_Core_Session
::singleton();
230 $session->pushUserContext($url);
234 * called to delete the relationship of a contact.
237 public function delete() {
238 // calls a function to delete relationship
239 CRM_Contact_BAO_Relationship
::del($this->getEntityId());
246 * (reference) of action links
248 public static function &links() {
249 if (!(self
::$_links)) {
250 self
::$_links = array(
251 CRM_Core_Action
::VIEW
=> array(
252 'name' => ts('View'),
253 'url' => 'civicrm/contact/view/rel',
254 'qs' => 'action=view&reset=1&cid=%%cid%%&id=%%id%%&rtype=%%rtype%%&selectedChild=rel',
255 'title' => ts('View Relationship'),
257 CRM_Core_Action
::UPDATE
=> array(
258 'name' => ts('Edit'),
259 'url' => 'civicrm/contact/view/rel',
260 'qs' => 'action=update&reset=1&cid=%%cid%%&id=%%id%%&rtype=%%rtype%%',
261 'title' => ts('Edit Relationship'),
263 CRM_Core_Action
::ENABLE
=> array(
264 'name' => ts('Enable'),
265 'ref' => 'crm-enable-disable',
266 'title' => ts('Enable Relationship'),
268 CRM_Core_Action
::DISABLE
=> array(
269 'name' => ts('Disable'),
270 'ref' => 'crm-enable-disable',
271 'title' => ts('Disable Relationship'),
273 CRM_Core_Action
::DELETE
=> array(
274 'name' => ts('Delete'),
275 'url' => 'civicrm/contact/view/rel',
276 'qs' => 'action=delete&reset=1&cid=%%cid%%&id=%%id%%&rtype=%%rtype%%',
277 'title' => ts('Delete Relationship'),
279 // FIXME: Not sure what to put as the key.
280 // We want to use it differently later anyway (see CRM_Contact_BAO_Relationship::getRelationship). NONE should make it hidden by default.
281 CRM_Core_Action
::NONE
=> array(
282 'name' => ts('Manage Case'),
283 'url' => 'civicrm/contact/view/case',
284 'qs' => 'action=view&reset=1&cid=%%clientid%%&id=%%caseid%%',
285 'title' => ts('Manage Case'),
289 return self
::$_links;