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
33 class CRM_Contact_Page_View_Relationship
extends CRM_Core_Page
{
36 * The action links that we need to display for the browse screen.
40 static $_links = NULL;
43 * Casid set if called from case context.
47 public $_caseId = NULL;
49 public $_permission = NULL;
50 public $_contactId = NULL;
53 * View details of a relationship.
55 public function view() {
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'];
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);
68 $relType = $viewRelationship[$this->_id
]['civicrm_relationship_type_id'];
69 $this->assign('viewRelationship', $viewRelationship);
71 $employerId = CRM_Core_DAO
::getFieldValue('CRM_Contact_DAO_Contact', $this->_contactId
, 'employer_id');
72 $this->assign('isCurrentEmployer', FALSE);
74 $relTypes = CRM_Utils_Array
::index(array('name_a_b'), CRM_Core_PseudoConstant
::relationshipType('name'));
76 if ($viewRelationship[$this->_id
]['employer_id'] == $this->_contactId
) {
77 $this->assign('isCurrentEmployer', TRUE);
79 elseif ($relType == $relTypes['Employee of']['id'] &&
80 ($viewRelationship[$this->_id
]['cid'] == $employerId)
82 // make sure we are viewing employee of relationship
83 $this->assign('isCurrentEmployer', TRUE);
86 $viewNote = CRM_Core_BAO_Note
::getNote($this->_id
);
87 $this->assign('viewNote', $viewNote);
89 $groupTree = CRM_Core_BAO_CustomGroup
::getTree('Relationship', $this, $this->_id
, 0, $relType);
90 CRM_Core_BAO_CustomGroup
::buildCustomDataView($this, $groupTree);
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"
98 $session = CRM_Core_Session
::singleton();
99 $recentOther = array();
101 if (($session->get('userID') == $this->_contactId
) ||
102 CRM_Contact_BAO_Contact_Permission
::allow($this->_contactId
, CRM_Core_Permission
::EDIT
)
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"
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"
114 $displayName = CRM_Contact_BAO_Contact
::displayName($this->_contactId
);
115 $this->assign('displayName', $displayName);
116 CRM_Utils_System
::setTitle(ts('View Relationship for') . ' ' . $displayName);
118 $title = $displayName . ' (' . $viewRelationship[$this->_id
]['relation'] . ' ' . CRM_Contact_BAO_Contact
::displayName($viewRelationship[$this->_id
]['cid']) . ')';
120 // add the recently viewed Relationship
121 CRM_Utils_Recent
::add($title,
123 $viewRelationship[$this->_id
]['id'],
132 * called when action is browse.
135 public function browse() {
136 // do nothing :) we are using datatable for rendering relationship selectors
140 * called when action is update or new.
143 public function edit() {
144 $controller = new CRM_Core_Controller_Simple('CRM_Contact_Form_Relationship', ts('Contact Relationships'), $this->_action
);
145 $controller->setEmbedded(TRUE);
147 // set the userContext stack
148 $session = CRM_Core_Session
::singleton();
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}");
155 $url = CRM_Utils_System
::url('civicrm/contact/view', "action=browse&selectedChild=rel&reset=1&cid={$this->_contactId}");
158 $session->pushUserContext($url);
160 if (CRM_Utils_Request
::retrieve('confirmed', 'Boolean',
161 CRM_Core_DAO
::$_nullObject
164 if ($this->_caseId
) {
165 //create an activity for case role removal.CRM-4480
166 CRM_Case_BAO_Case
::createCaseRoleActivity($this->_caseId
, $this->_id
);
167 CRM_Core_Session
::setStatus(ts('Case Role has been deleted successfully.'), ts('Record Deleted'), 'success');
170 // delete relationship
171 CRM_Contact_BAO_Relationship
::del($this->_id
);
173 CRM_Utils_System
::redirect($url);
176 $controller->set('contactId', $this->_contactId
);
177 $controller->set('id', $this->_id
);
178 $controller->process();
182 public function preProcess() {
183 $this->_id
= CRM_Utils_Request
::retrieve('id', 'Positive', $this);
184 $this->_contactId
= CRM_Utils_Request
::retrieve('cid', 'Positive', $this, TRUE);
185 $this->assign('contactId', $this->_contactId
);
187 // check logged in url permission
188 CRM_Contact_Page_View
::checkUserPermission($this);
190 $this->_action
= CRM_Utils_Request
::retrieve('action', 'String', $this, FALSE, 'browse');
191 $this->assign('action', $this->_action
);
195 * the main function that is called when the page loads,
196 * it decides the which action has to be taken for the page.
200 public function run() {
205 $this->_caseId
= CRM_Utils_Request
::retrieve('caseID', 'Integer', $this);
207 if ($this->_action
& CRM_Core_Action
::VIEW
) {
210 elseif ($this->_action
& (CRM_Core_Action
::UPDATE | CRM_Core_Action
::ADD | CRM_Core_Action
::DELETE
)) {
214 // if this is called from case view, suppress browse relationships form
219 return parent
::run();
222 public function setContext() {
223 $context = CRM_Utils_Request
::retrieve('context', 'String',
224 $this, FALSE, 'search'
227 if ($context == 'dashboard') {
228 $cid = CRM_Utils_Request
::retrieve('cid', 'Integer',
231 $url = CRM_Utils_System
::url('civicrm/user',
236 $url = CRM_Utils_System
::url('civicrm/contact/view', 'action=browse&selectedChild=rel');
238 $session = CRM_Core_Session
::singleton();
239 $session->pushUserContext($url);
243 * called to delete the relationship of a contact.
246 public function delete() {
247 // calls a function to delete relationship
248 CRM_Contact_BAO_Relationship
::del($this->_id
);
255 * (reference) of action links
257 public static function &links() {
258 if (!(self
::$_links)) {
259 self
::$_links = array(
260 CRM_Core_Action
::VIEW
=> array(
261 'name' => ts('View'),
262 'url' => 'civicrm/contact/view/rel',
263 'qs' => 'action=view&reset=1&cid=%%cid%%&id=%%id%%&rtype=%%rtype%%&selectedChild=rel',
264 'title' => ts('View Relationship'),
266 CRM_Core_Action
::UPDATE
=> array(
267 'name' => ts('Edit'),
268 'url' => 'civicrm/contact/view/rel',
269 'qs' => 'action=update&reset=1&cid=%%cid%%&id=%%id%%&rtype=%%rtype%%',
270 'title' => ts('Edit Relationship'),
272 CRM_Core_Action
::ENABLE
=> array(
273 'name' => ts('Enable'),
274 'ref' => 'crm-enable-disable',
275 'title' => ts('Enable Relationship'),
277 CRM_Core_Action
::DISABLE
=> array(
278 'name' => ts('Disable'),
279 'ref' => 'crm-enable-disable',
280 'title' => ts('Disable Relationship'),
282 CRM_Core_Action
::DELETE
=> array(
283 'name' => ts('Delete'),
284 'url' => 'civicrm/contact/view/rel',
285 'qs' => 'action=delete&reset=1&cid=%%cid%%&id=%%id%%&rtype=%%rtype%%',
286 'title' => ts('Delete Relationship'),
288 // FIXME: Not sure what to put as the key.
289 // We want to use it differently later anyway (see CRM_Contact_BAO_Relationship::getRelationship). NONE should make it hidden by default.
290 CRM_Core_Action
::NONE
=> array(
291 'name' => ts('Manage Case'),
292 'url' => 'civicrm/contact/view/case',
293 'qs' => 'action=view&reset=1&cid=%%clientid%%&id=%%caseid%%',
294 'title' => ts('Manage Case'),
298 return self
::$_links;