3 +--------------------------------------------------------------------+
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2018 |
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-2018
35 * Page for displaying custom data.
37 class CRM_Contact_Page_View_CustomData
extends CRM_Core_Page
{
40 * The id of the object being viewed (note/relationship etc).
49 * @return CRM_Contact_Page_View_CustomData
51 public function __construct() {
52 parent
::__construct();
56 * Add a few specific things to view contact.
58 public function preProcess() {
59 $this->_contactId
= CRM_Utils_Request
::retrieve('cid', 'Positive', $this, TRUE);
60 $this->assign('contactId', $this->_contactId
);
62 // check logged in url permission
63 CRM_Contact_Page_View
::checkUserPermission($this);
65 $this->_action
= CRM_Utils_Request
::retrieve('action', 'String', $this, FALSE, 'browse');
66 $this->assign('action', $this->_action
);
68 $this->_groupId
= CRM_Utils_Request
::retrieve('gid', 'Positive', $this, TRUE);
69 $this->assign('groupId', $this->_groupId
);
71 $this->_multiRecordDisplay
= CRM_Utils_Request
::retrieve('multiRecordDisplay', 'String', $this, FALSE);
72 $this->_cgcount
= CRM_Utils_Request
::retrieve('cgcount', 'Positive', $this, FALSE);
73 $this->_recId
= CRM_Utils_Request
::retrieve('recId', 'Positive', $this, FALSE);
79 * This method is called after the page is created. It checks for the
80 * type of action and executes that action.
82 public function run() {
85 //set the userContext stack
86 $doneURL = 'civicrm/contact/view';
87 $session = CRM_Core_Session
::singleton();
88 $session->pushUserContext(CRM_Utils_System
::url($doneURL, 'action=browse&selectedChild=custom_' . $this->_groupId
), FALSE);
90 // Get permission detail - view or edit.
91 // use a contact id specific function which gives us much better granularity
93 $editCustomData = CRM_Contact_BAO_Contact_Permission
::allow($this->_contactId
, CRM_Core_Permission
::EDIT
);
94 $this->assign('editCustomData', $editCustomData);
96 // Allow to edit own custom data CRM-5518.
97 $editOwnCustomData = FALSE;
98 if ($session->get('userID') == $this->_contactId
) {
99 $editOwnCustomData = TRUE;
101 $this->assign('editOwnCustomData', $editOwnCustomData);
103 if ($this->_action
== CRM_Core_Action
::BROWSE
) {
105 $displayStyle = CRM_Core_DAO
::getFieldValue('CRM_Core_DAO_CustomGroup',
110 if ($this->_multiRecordDisplay
!= 'single') {
111 $id = "custom_{$this->_groupId}";
112 $tableName = CRM_Core_DAO
::getFieldValue('CRM_Core_DAO_CustomGroup', $this->_groupId
, 'table_name');
113 $this->ajaxResponse
['tabCount'] = CRM_Contact_BAO_Contact
::getCountComponent($id, $this->_contactId
, $tableName);
116 if ($displayStyle === 'Tab with table' && $this->_multiRecordDisplay
!= 'single') {
117 $ctype = CRM_Core_DAO
::getFieldValue('CRM_Contact_DAO_Contact',
122 $this->assign('displayStyle', 'tableOriented');
123 // here the multi custom data listing code will go
124 $multiRecordFieldListing = TRUE;
125 $page = new CRM_Profile_Page_MultipleRecordFieldsListing();
126 $page->set('contactId', $this->_contactId
);
127 $page->set('customGroupId', $this->_groupId
);
128 $page->set('action', CRM_Core_Action
::BROWSE
);
129 $page->set('multiRecordFieldListing', $multiRecordFieldListing);
130 $page->set('pageViewType', 'customDataView');
131 $page->set('contactType', $ctype);
132 $page->_headersOnly
= TRUE;
136 //Custom Groups Inline
137 $entityType = CRM_Contact_BAO_Contact
::getContactType($this->_contactId
);
138 $entitySubType = CRM_Contact_BAO_Contact
::getContactSubType($this->_contactId
);
140 if ($this->_multiRecordDisplay
== 'single') {
141 $groupTitle = CRM_Core_BAO_CustomGroup
::getTitle($this->_groupId
);
142 CRM_Utils_System
::setTitle(ts('View %1 Record', array(1 => $groupTitle)));
143 $groupTree = CRM_Core_BAO_CustomGroup
::getTree($entityType, NULL, $this->_contactId
,
144 $this->_groupId
, $entitySubType, NULL, TRUE, NULL, FALSE, TRUE, $this->_cgcount
147 $recId = $this->_recId
;
148 $this->assign('multiRecordDisplay', $this->_multiRecordDisplay
);
149 $this->assign('skipTitle', 1);
152 $groupTree = CRM_Core_BAO_CustomGroup
::getTree($entityType, NULL, $this->_contactId
,
153 $this->_groupId
, $entitySubType
156 CRM_Core_BAO_CustomGroup
::buildCustomDataView($this, $groupTree, FALSE, NULL, NULL, $recId, $this->_contactId
);
161 $controller = new CRM_Core_Controller_Simple('CRM_Contact_Form_CustomData',
165 $controller->setEmbedded(TRUE);
167 $controller->set('tableId', $this->_contactId
);
168 $controller->set('groupId', $this->_groupId
);
169 $controller->set('entityType', CRM_Contact_BAO_Contact
::getContactType($this->_contactId
));
170 $controller->set('entitySubType', CRM_Contact_BAO_Contact
::getContactSubType($this->_contactId
, ','));
171 $controller->process();
174 return parent
::run();