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 | ||
6a488035 | 30 | /** |
fe482240 | 31 | * Add a few specific things to view contact. |
6a488035 | 32 | */ |
00be9182 | 33 | public function preProcess() { |
e8854d68 CW |
34 | $this->_groupId = CRM_Utils_Request::retrieve('gid', 'Positive', $this, TRUE); |
35 | $this->assign('groupId', $this->_groupId); | |
36 | ||
37 | $this->_contactId = CRM_Utils_Request::retrieve('cid', 'Positive', $this); | |
38 | $this->_recId = CRM_Utils_Request::retrieve('recId', 'Positive', $this); | |
39 | ||
40 | // If no cid supplied, look it up | |
41 | if (!$this->_contactId && $this->_recId) { | |
42 | $tableName = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_CustomGroup', $this->_groupId, 'table_name'); | |
43 | if ($tableName) { | |
44 | $this->_contactId = CRM_Core_DAO::singleValueQuery("SELECT entity_id FROM `$tableName` WHERE id = %1", [1 => [$this->_recId, 'Integer']]); | |
45 | } | |
46 | } | |
47 | if (!$this->_contactId) { | |
48 | throw new CRM_Core_Exception(ts('Could not find valid value for %1', [1 => 'cid'])); | |
49 | } | |
50 | ||
6a488035 TO |
51 | $this->assign('contactId', $this->_contactId); |
52 | ||
53 | // check logged in url permission | |
54 | CRM_Contact_Page_View::checkUserPermission($this); | |
55 | ||
56 | $this->_action = CRM_Utils_Request::retrieve('action', 'String', $this, FALSE, 'browse'); | |
57 | $this->assign('action', $this->_action); | |
58 | ||
e41f4660 PJ |
59 | $this->_multiRecordDisplay = CRM_Utils_Request::retrieve('multiRecordDisplay', 'String', $this, FALSE); |
60 | $this->_cgcount = CRM_Utils_Request::retrieve('cgcount', 'Positive', $this, FALSE); | |
6a488035 TO |
61 | } |
62 | ||
63 | /** | |
64 | * Run the page. | |
65 | * | |
66 | * This method is called after the page is created. It checks for the | |
67 | * type of action and executes that action. | |
6a488035 | 68 | */ |
00be9182 | 69 | public function run() { |
6a488035 TO |
70 | $this->preProcess(); |
71 | ||
72 | //set the userContext stack | |
73 | $doneURL = 'civicrm/contact/view'; | |
74 | $session = CRM_Core_Session::singleton(); | |
75 | $session->pushUserContext(CRM_Utils_System::url($doneURL, 'action=browse&selectedChild=custom_' . $this->_groupId), FALSE); | |
76 | ||
317103ab CW |
77 | // Check permission to edit this contact |
78 | $editPermission = CRM_Contact_BAO_Contact_Permission::allow($this->_contactId, CRM_Core_Permission::EDIT); | |
79 | $this->assign('editPermission', $editPermission); | |
6a488035 TO |
80 | |
81 | if ($this->_action == CRM_Core_Action::BROWSE) { | |
e41f4660 PJ |
82 | |
83 | $displayStyle = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_CustomGroup', | |
84 | $this->_groupId, | |
85 | 'style' | |
86 | ); | |
87 | ||
eaf756c0 | 88 | if ($this->_multiRecordDisplay != 'single') { |
bd470b69 | 89 | $id = "custom_{$this->_groupId}"; |
a8f9f382 | 90 | $this->ajaxResponse['tabCount'] = CRM_Contact_BAO_Contact::getCountComponent($id, $this->_contactId); |
eaf756c0 CW |
91 | } |
92 | ||
93 | if ($displayStyle === 'Tab with table' && $this->_multiRecordDisplay != 'single') { | |
e41f4660 PJ |
94 | $ctype = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Contact', |
95 | $this->_contactId, | |
96 | 'contact_type' | |
97 | ); | |
98 | ||
99 | $this->assign('displayStyle', 'tableOriented'); | |
100 | // here the multi custom data listing code will go | |
101 | $multiRecordFieldListing = TRUE; | |
102 | $page = new CRM_Profile_Page_MultipleRecordFieldsListing(); | |
103 | $page->set('contactId', $this->_contactId); | |
104 | $page->set('customGroupId', $this->_groupId); | |
105 | $page->set('action', CRM_Core_Action::BROWSE); | |
106 | $page->set('multiRecordFieldListing', $multiRecordFieldListing); | |
107 | $page->set('pageViewType', 'customDataView'); | |
108 | $page->set('contactType', $ctype); | |
f1eae8d1 | 109 | $page->_headersOnly = TRUE; |
e41f4660 PJ |
110 | $page->run(); |
111 | } | |
112 | else { | |
9082df1a | 113 | //Custom Groups Inline |
114 | $entityType = CRM_Contact_BAO_Contact::getContactType($this->_contactId); | |
115 | $entitySubType = CRM_Contact_BAO_Contact::getContactSubType($this->_contactId); | |
e41f4660 PJ |
116 | $recId = NULL; |
117 | if ($this->_multiRecordDisplay == 'single') { | |
525faea3 | 118 | $groupTitle = CRM_Core_BAO_CustomGroup::getTitle($this->_groupId); |
be2fb01f | 119 | CRM_Utils_System::setTitle(ts('View %1 Record', [1 => $groupTitle])); |
0b330e6d | 120 | $groupTree = CRM_Core_BAO_CustomGroup::getTree($entityType, NULL, $this->_contactId, |
317103ab | 121 | $this->_groupId, $entitySubType, NULL, TRUE, NULL, FALSE, CRM_Core_Permission::VIEW, $this->_cgcount |
e1d48b72 | 122 | ); |
525faea3 | 123 | |
e41f4660 PJ |
124 | $recId = $this->_recId; |
125 | $this->assign('multiRecordDisplay', $this->_multiRecordDisplay); | |
126 | $this->assign('skipTitle', 1); | |
127 | } | |
e1d48b72 | 128 | else { |
0b330e6d | 129 | $groupTree = CRM_Core_BAO_CustomGroup::getTree($entityType, NULL, $this->_contactId, |
317103ab | 130 | $this->_groupId, $entitySubType, NULL, TRUE, NULL, FALSE, CRM_Core_Permission::VIEW |
e1d48b72 | 131 | ); |
132 | } | |
317103ab | 133 | CRM_Core_BAO_CustomGroup::buildCustomDataView($this, $groupTree, FALSE, NULL, NULL, $recId, $this->_contactId, TRUE); |
e41f4660 | 134 | } |
6a488035 TO |
135 | } |
136 | else { | |
137 | ||
138 | $controller = new CRM_Core_Controller_Simple('CRM_Contact_Form_CustomData', | |
139 | ts('Custom Data'), | |
140 | $this->_action | |
141 | ); | |
142 | $controller->setEmbedded(TRUE); | |
143 | ||
144 | $controller->set('tableId', $this->_contactId); | |
145 | $controller->set('groupId', $this->_groupId); | |
146 | $controller->set('entityType', CRM_Contact_BAO_Contact::getContactType($this->_contactId)); | |
147 | $controller->set('entitySubType', CRM_Contact_BAO_Contact::getContactSubType($this->_contactId, ',')); | |
148 | $controller->process(); | |
149 | $controller->run(); | |
150 | } | |
151 | return parent::run(); | |
152 | } | |
96025800 | 153 | |
6c8f6e67 | 154 | } |