Commit | Line | Data |
---|---|---|
6a488035 TO |
1 | <?php |
2 | /* | |
3 | +--------------------------------------------------------------------+ | |
bc77d7c0 | 4 | | Copyright CiviCRM LLC. All rights reserved. | |
6a488035 | 5 | | | |
bc77d7c0 TO |
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 | | |
6a488035 | 9 | +--------------------------------------------------------------------+ |
d25dd0ee | 10 | */ |
6a488035 TO |
11 | |
12 | /** | |
13 | * | |
14 | * @package CRM | |
ca5cec67 | 15 | * @copyright CiviCRM LLC https://civicrm.org/licensing |
6a488035 TO |
16 | */ |
17 | ||
18 | /** | |
2f854d0b | 19 | * Page for displaying custom data. |
6a488035 TO |
20 | */ |
21 | class CRM_Contact_Page_View_CustomData extends CRM_Core_Page { | |
22 | ||
23 | /** | |
e8854d68 | 24 | * Custom group id. |
6a488035 | 25 | * |
69078420 | 26 | * @var int |
6a488035 TO |
27 | */ |
28 | public $_groupId; | |
29 | ||
30 | /** | |
fe482240 | 31 | * Class constructor. |
6a488035 TO |
32 | * |
33 | * @return CRM_Contact_Page_View_CustomData | |
34 | */ | |
35 | public function __construct() { | |
36 | parent::__construct(); | |
37 | } | |
38 | ||
39 | /** | |
fe482240 | 40 | * Add a few specific things to view contact. |
6a488035 | 41 | */ |
00be9182 | 42 | public function preProcess() { |
e8854d68 CW |
43 | $this->_groupId = CRM_Utils_Request::retrieve('gid', 'Positive', $this, TRUE); |
44 | $this->assign('groupId', $this->_groupId); | |
45 | ||
46 | $this->_contactId = CRM_Utils_Request::retrieve('cid', 'Positive', $this); | |
47 | $this->_recId = CRM_Utils_Request::retrieve('recId', 'Positive', $this); | |
48 | ||
49 | // If no cid supplied, look it up | |
50 | if (!$this->_contactId && $this->_recId) { | |
51 | $tableName = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_CustomGroup', $this->_groupId, 'table_name'); | |
52 | if ($tableName) { | |
53 | $this->_contactId = CRM_Core_DAO::singleValueQuery("SELECT entity_id FROM `$tableName` WHERE id = %1", [1 => [$this->_recId, 'Integer']]); | |
54 | } | |
55 | } | |
56 | if (!$this->_contactId) { | |
57 | throw new CRM_Core_Exception(ts('Could not find valid value for %1', [1 => 'cid'])); | |
58 | } | |
59 | ||
6a488035 TO |
60 | $this->assign('contactId', $this->_contactId); |
61 | ||
62 | // check logged in url permission | |
63 | CRM_Contact_Page_View::checkUserPermission($this); | |
64 | ||
65 | $this->_action = CRM_Utils_Request::retrieve('action', 'String', $this, FALSE, 'browse'); | |
66 | $this->assign('action', $this->_action); | |
67 | ||
e41f4660 PJ |
68 | $this->_multiRecordDisplay = CRM_Utils_Request::retrieve('multiRecordDisplay', 'String', $this, FALSE); |
69 | $this->_cgcount = CRM_Utils_Request::retrieve('cgcount', 'Positive', $this, FALSE); | |
6a488035 TO |
70 | } |
71 | ||
72 | /** | |
73 | * Run the page. | |
74 | * | |
75 | * This method is called after the page is created. It checks for the | |
76 | * type of action and executes that action. | |
6a488035 | 77 | */ |
00be9182 | 78 | public function run() { |
6a488035 TO |
79 | $this->preProcess(); |
80 | ||
81 | //set the userContext stack | |
82 | $doneURL = 'civicrm/contact/view'; | |
83 | $session = CRM_Core_Session::singleton(); | |
84 | $session->pushUserContext(CRM_Utils_System::url($doneURL, 'action=browse&selectedChild=custom_' . $this->_groupId), FALSE); | |
85 | ||
2f854d0b EM |
86 | // Get permission detail - view or edit. |
87 | // use a contact id specific function which gives us much better granularity | |
87177cd2 DL |
88 | // CRM-12646 |
89 | $editCustomData = CRM_Contact_BAO_Contact_Permission::allow($this->_contactId, CRM_Core_Permission::EDIT); | |
6a488035 TO |
90 | $this->assign('editCustomData', $editCustomData); |
91 | ||
2f854d0b | 92 | // Allow to edit own custom data CRM-5518. |
6a488035 TO |
93 | $editOwnCustomData = FALSE; |
94 | if ($session->get('userID') == $this->_contactId) { | |
95 | $editOwnCustomData = TRUE; | |
96 | } | |
97 | $this->assign('editOwnCustomData', $editOwnCustomData); | |
98 | ||
99 | if ($this->_action == CRM_Core_Action::BROWSE) { | |
e41f4660 PJ |
100 | |
101 | $displayStyle = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_CustomGroup', | |
102 | $this->_groupId, | |
103 | 'style' | |
104 | ); | |
105 | ||
eaf756c0 | 106 | if ($this->_multiRecordDisplay != 'single') { |
bd470b69 | 107 | $id = "custom_{$this->_groupId}"; |
9082df1a | 108 | $tableName = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_CustomGroup', $this->_groupId, 'table_name'); |
109 | $this->ajaxResponse['tabCount'] = CRM_Contact_BAO_Contact::getCountComponent($id, $this->_contactId, $tableName); | |
eaf756c0 CW |
110 | } |
111 | ||
112 | if ($displayStyle === 'Tab with table' && $this->_multiRecordDisplay != 'single') { | |
e41f4660 PJ |
113 | $ctype = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Contact', |
114 | $this->_contactId, | |
115 | 'contact_type' | |
116 | ); | |
117 | ||
118 | $this->assign('displayStyle', 'tableOriented'); | |
119 | // here the multi custom data listing code will go | |
120 | $multiRecordFieldListing = TRUE; | |
121 | $page = new CRM_Profile_Page_MultipleRecordFieldsListing(); | |
122 | $page->set('contactId', $this->_contactId); | |
123 | $page->set('customGroupId', $this->_groupId); | |
124 | $page->set('action', CRM_Core_Action::BROWSE); | |
125 | $page->set('multiRecordFieldListing', $multiRecordFieldListing); | |
126 | $page->set('pageViewType', 'customDataView'); | |
127 | $page->set('contactType', $ctype); | |
f1eae8d1 | 128 | $page->_headersOnly = TRUE; |
e41f4660 PJ |
129 | $page->run(); |
130 | } | |
131 | else { | |
9082df1a | 132 | //Custom Groups Inline |
133 | $entityType = CRM_Contact_BAO_Contact::getContactType($this->_contactId); | |
134 | $entitySubType = CRM_Contact_BAO_Contact::getContactSubType($this->_contactId); | |
e41f4660 PJ |
135 | $recId = NULL; |
136 | if ($this->_multiRecordDisplay == 'single') { | |
525faea3 | 137 | $groupTitle = CRM_Core_BAO_CustomGroup::getTitle($this->_groupId); |
be2fb01f | 138 | CRM_Utils_System::setTitle(ts('View %1 Record', [1 => $groupTitle])); |
0b330e6d | 139 | $groupTree = CRM_Core_BAO_CustomGroup::getTree($entityType, NULL, $this->_contactId, |
e1d48b72 | 140 | $this->_groupId, $entitySubType, NULL, TRUE, NULL, FALSE, TRUE, $this->_cgcount |
141 | ); | |
525faea3 | 142 | |
e41f4660 PJ |
143 | $recId = $this->_recId; |
144 | $this->assign('multiRecordDisplay', $this->_multiRecordDisplay); | |
145 | $this->assign('skipTitle', 1); | |
146 | } | |
e1d48b72 | 147 | else { |
0b330e6d | 148 | $groupTree = CRM_Core_BAO_CustomGroup::getTree($entityType, NULL, $this->_contactId, |
e1d48b72 | 149 | $this->_groupId, $entitySubType |
150 | ); | |
151 | } | |
e7cf1b90 | 152 | CRM_Core_BAO_CustomGroup::buildCustomDataView($this, $groupTree, FALSE, NULL, NULL, $recId, $this->_contactId); |
e41f4660 | 153 | } |
6a488035 TO |
154 | } |
155 | else { | |
156 | ||
157 | $controller = new CRM_Core_Controller_Simple('CRM_Contact_Form_CustomData', | |
158 | ts('Custom Data'), | |
159 | $this->_action | |
160 | ); | |
161 | $controller->setEmbedded(TRUE); | |
162 | ||
163 | $controller->set('tableId', $this->_contactId); | |
164 | $controller->set('groupId', $this->_groupId); | |
165 | $controller->set('entityType', CRM_Contact_BAO_Contact::getContactType($this->_contactId)); | |
166 | $controller->set('entitySubType', CRM_Contact_BAO_Contact::getContactSubType($this->_contactId, ',')); | |
167 | $controller->process(); | |
168 | $controller->run(); | |
169 | } | |
170 | return parent::run(); | |
171 | } | |
96025800 | 172 | |
6c8f6e67 | 173 | } |