3 +--------------------------------------------------------------------+
4 | Copyright CiviCRM LLC. All rights reserved. |
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 |
9 +--------------------------------------------------------------------+
15 * @copyright CiviCRM LLC https://civicrm.org/licensing
20 * Main page for viewing contact.
23 class CRM_Profile_Page_View
extends CRM_Core_Page
{
26 * The id of the contact.
33 * The group id that we are editing.
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.
44 public function preProcess() {
45 $this->_id
= CRM_Utils_Request
::retrieve('id', 'Positive',
49 $session = CRM_Core_Session
::singleton();
50 $this->_id
= $session->get('userID');
52 CRM_Core_Error
::statusBounce(ts('Could not find the required contact id parameter (id=) for viewing a contact record with a Profile.'));
55 $this->assign('cid', $this->_id
);
57 $gids = explode(',', CRM_Utils_Request
::retrieve('gid', 'String', CRM_Core_DAO
::$_nullObject, FALSE, 0, 'GET'));
60 if (count($gids) > 1) {
62 foreach ($gids as $pfId) {
63 $profileIds[] = CRM_Utils_Type
::escape($pfId, 'Positive');
67 // check if we are rendering mixed profiles
68 if (CRM_Core_BAO_UFGroup
::checkForMixProfiles($profileIds)) {
69 CRM_Core_Error
::statusBounce(ts('You cannot combine profiles of multiple types.'));
72 $this->_gid
= $profileIds[0];
76 $this->_gid
= CRM_Utils_Request
::retrieve('gid', 'Positive', $this, FALSE, 0, 'GET');
81 $page = new CRM_Profile_Page_Dynamic($this->_id
, $this->_gid
, 'Profile', FALSE, $profileIds);
83 $profileGroup['title'] = NULL;
84 $profileGroup['content'] = $page->run();
85 if (empty($profileGroup['content'])) {
88 $profileGroups[] = $profileGroup;
90 $gidString = $this->_gid
;
91 if (!empty($profileIds)) {
92 $gidString = implode(',', $profileIds);
95 $map = CRM_Core_DAO
::getFieldValue('CRM_Core_DAO_UFGroup', $this->_gid
, 'is_map');
97 $this->assign('mapURL',
98 CRM_Utils_System
::url("civicrm/profile/map",
99 "reset=1&pv=1&cid={$this->_id}&gid={$gidString}"
103 if (CRM_Core_Permission
::ufGroupValid($this->_gid
,
104 CRM_Core_Permission
::SEARCH
107 $this->assign('listingURL',
108 CRM_Utils_System
::url("civicrm/profile",
109 "force=1&gid={$gidString}"
115 $ufGroups = CRM_Core_BAO_UFGroup
::getModuleUFGroup('Profile');
118 foreach ($ufGroups as $groupid => $group) {
119 $page = new CRM_Profile_Page_Dynamic($this->_id
, $groupid, 'Profile', FALSE, $profileIds);
121 $profileGroup['title'] = $group['title'];
122 $profileGroup['content'] = $page->run();
123 if (empty($profileGroup['content'])) {
126 $profileGroups[] = $profileGroup;
128 $this->assign('listingURL',
129 CRM_Utils_System
::url("civicrm/profile",
135 $this->assign('groupID', $this->_gid
);
137 $this->assign('profileGroups', $profileGroups);
138 $this->assign('recentlyViewed', FALSE);
140 // do not set title if there is no content
143 CRM_Utils_System
::setTitle('');
148 * Build the outcome basing on the CRM_Profile_Page_Dynamic's HTML.
151 public function run() {
153 return parent
::run();
157 * @param string $suffix
159 * @return null|string
161 public function checkTemplateFileExists($suffix = '') {
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;
169 // lets see if we have customized by name
170 $ufGroupName = CRM_Core_DAO
::getFieldValue('CRM_Core_DAO_UFGroup', $this->_gid
, 'name');
172 $templateFile = "CRM/Profile/Page/{$ufGroupName}/View.{$suffix}tpl";
173 if ($template->template_exists($templateFile)) {
174 return $templateFile;
182 * Use the form name to create the tpl file name.
186 public function getTemplateFileName() {
187 $fileName = $this->checkTemplateFileExists();
188 return $fileName ?
$fileName : parent
::getTemplateFileName();
192 * Default extra tpl file basically just replaces .tpl with .extra.tpl
193 * i.e. we dont override
197 public function overrideExtraTemplateFileName() {
198 $fileName = $this->checkTemplateFileExists('extra.');
199 return $fileName ?
$fileName : parent
::overrideExtraTemplateFileName();