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