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