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 | ||
19 | /** | |
20 | * Main page for viewing contact. | |
21 | * | |
22 | */ | |
23 | class CRM_Profile_Page_View extends CRM_Core_Page { | |
24 | ||
25 | /** | |
fe482240 | 26 | * The id of the contact. |
6a488035 TO |
27 | * |
28 | * @var int | |
29 | */ | |
30 | protected $_id; | |
31 | ||
32 | /** | |
fe482240 | 33 | * The group id that we are editing. |
6a488035 TO |
34 | * |
35 | * @var int | |
36 | */ | |
37 | protected $_gid; | |
38 | ||
39 | /** | |
40 | * Heart of the viewing process. The runner gets all the meta data for | |
41 | * the contact and calls the appropriate type of page to view. | |
42 | * | |
f9d8a5d1 | 43 | */ |
00be9182 | 44 | public function preProcess() { |
6a488035 TO |
45 | $this->_id = CRM_Utils_Request::retrieve('id', 'Positive', |
46 | $this, FALSE | |
47 | ); | |
48 | if (!$this->_id) { | |
49 | $session = CRM_Core_Session::singleton(); | |
50 | $this->_id = $session->get('userID'); | |
51 | if (!$this->_id) { | |
79e11805 | 52 | CRM_Core_Error::statusBounce(ts('Could not find the required contact id parameter (id=) for viewing a contact record with a Profile.')); |
6a488035 TO |
53 | } |
54 | } | |
55 | $this->assign('cid', $this->_id); | |
56 | ||
57 | $gids = explode(',', CRM_Utils_Request::retrieve('gid', 'String', CRM_Core_DAO::$_nullObject, FALSE, 0, 'GET')); | |
58 | ||
be2fb01f | 59 | $profileIds = []; |
6a488035 TO |
60 | if (count($gids) > 1) { |
61 | if (!empty($gids)) { | |
62 | foreach ($gids as $pfId) { | |
63 | $profileIds[] = CRM_Utils_Type::escape($pfId, 'Positive'); | |
64 | } | |
65 | } | |
66 | ||
67 | // check if we are rendering mixed profiles | |
68 | if (CRM_Core_BAO_UFGroup::checkForMixProfiles($profileIds)) { | |
79e11805 | 69 | CRM_Core_Error::statusBounce(ts('You cannot combine profiles of multiple types.')); |
6a488035 TO |
70 | } |
71 | ||
72 | $this->_gid = $profileIds[0]; | |
73 | } | |
74 | ||
75 | if (!$this->_gid) { | |
76 | $this->_gid = CRM_Utils_Request::retrieve('gid', 'Positive', $this, FALSE, 0, 'GET'); | |
77 | } | |
78 | ||
79 | $anyContent = TRUE; | |
80 | if ($this->_gid) { | |
81 | $page = new CRM_Profile_Page_Dynamic($this->_id, $this->_gid, 'Profile', FALSE, $profileIds); | |
be2fb01f | 82 | $profileGroup = []; |
6a488035 TO |
83 | $profileGroup['title'] = NULL; |
84 | $profileGroup['content'] = $page->run(); | |
85 | if (empty($profileGroup['content'])) { | |
86 | $anyContent = FALSE; | |
87 | } | |
88 | $profileGroups[] = $profileGroup; | |
89 | ||
90 | $gidString = $this->_gid; | |
91 | if (!empty($profileIds)) { | |
92 | $gidString = implode(',', $profileIds); | |
93 | } | |
94 | ||
95 | $map = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_UFGroup', $this->_gid, 'is_map'); | |
96 | if ($map) { | |
97 | $this->assign('mapURL', | |
98 | CRM_Utils_System::url("civicrm/profile/map", | |
99 | "reset=1&pv=1&cid={$this->_id}&gid={$gidString}" | |
100 | ) | |
101 | ); | |
102 | } | |
103 | if (CRM_Core_Permission::ufGroupValid($this->_gid, | |
353ffa53 TO |
104 | CRM_Core_Permission::SEARCH |
105 | ) | |
106 | ) { | |
6a488035 TO |
107 | $this->assign('listingURL', |
108 | CRM_Utils_System::url("civicrm/profile", | |
109 | "force=1&gid={$gidString}" | |
110 | ) | |
111 | ); | |
112 | } | |
113 | } | |
114 | else { | |
115 | $ufGroups = CRM_Core_BAO_UFGroup::getModuleUFGroup('Profile'); | |
116 | ||
be2fb01f | 117 | $profileGroups = []; |
6a488035 TO |
118 | foreach ($ufGroups as $groupid => $group) { |
119 | $page = new CRM_Profile_Page_Dynamic($this->_id, $groupid, 'Profile', FALSE, $profileIds); | |
be2fb01f | 120 | $profileGroup = []; |
6a488035 TO |
121 | $profileGroup['title'] = $group['title']; |
122 | $profileGroup['content'] = $page->run(); | |
123 | if (empty($profileGroup['content'])) { | |
124 | $anyContent = FALSE; | |
125 | } | |
126 | $profileGroups[] = $profileGroup; | |
127 | } | |
128 | $this->assign('listingURL', | |
129 | CRM_Utils_System::url("civicrm/profile", | |
130 | "force=1" | |
131 | ) | |
132 | ); | |
133 | } | |
134 | ||
135 | $this->assign('groupID', $this->_gid); | |
136 | ||
137 | $this->assign('profileGroups', $profileGroups); | |
138 | $this->assign('recentlyViewed', FALSE); | |
139 | ||
140 | // do not set title if there is no content | |
141 | // CRM-6081 | |
142 | if (!$anyContent) { | |
143 | CRM_Utils_System::setTitle(''); | |
144 | } | |
145 | } | |
146 | ||
147 | /** | |
abdd5e3e | 148 | * Build the outcome basing on the CRM_Profile_Page_Dynamic's HTML. |
6a488035 | 149 | * |
6a488035 | 150 | */ |
00be9182 | 151 | public function run() { |
6a488035 TO |
152 | $this->preProcess(); |
153 | return parent::run(); | |
154 | } | |
155 | ||
ffd93213 EM |
156 | /** |
157 | * @param string $suffix | |
158 | * | |
159 | * @return null|string | |
160 | */ | |
00be9182 | 161 | public function checkTemplateFileExists($suffix = '') { |
6a488035 TO |
162 | if ($this->_gid) { |
163 | $templateFile = "CRM/Profile/Page/{$this->_gid}/View.{$suffix}tpl"; | |
164 | $template = CRM_Core_Page::getTemplate(); | |
165 | if ($template->template_exists($templateFile)) { | |
166 | return $templateFile; | |
167 | } | |
168 | ||
169 | // lets see if we have customized by name | |
170 | $ufGroupName = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_UFGroup', $this->_gid, 'name'); | |
171 | if ($ufGroupName) { | |
172 | $templateFile = "CRM/Profile/Page/{$ufGroupName}/View.{$suffix}tpl"; | |
173 | if ($template->template_exists($templateFile)) { | |
174 | return $templateFile; | |
175 | } | |
176 | } | |
177 | } | |
178 | return NULL; | |
179 | } | |
180 | ||
ffd93213 | 181 | /** |
fe482240 | 182 | * Use the form name to create the tpl file name. |
ffd93213 EM |
183 | * |
184 | * @return string | |
ffd93213 | 185 | */ |
00be9182 | 186 | public function getTemplateFileName() { |
6a488035 TO |
187 | $fileName = $this->checkTemplateFileExists(); |
188 | return $fileName ? $fileName : parent::getTemplateFileName(); | |
189 | } | |
190 | ||
ffd93213 EM |
191 | /** |
192 | * Default extra tpl file basically just replaces .tpl with .extra.tpl | |
193 | * i.e. we dont override | |
194 | * | |
195 | * @return string | |
ffd93213 | 196 | */ |
00be9182 | 197 | public function overrideExtraTemplateFileName() { |
6a488035 TO |
198 | $fileName = $this->checkTemplateFileExists('extra.'); |
199 | return $fileName ? $fileName : parent::overrideExtraTemplateFileName(); | |
200 | } | |
96025800 | 201 | |
6a488035 | 202 | } |