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