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
19 * Main page for viewing contact.
22 class CRM_Profile_Page_View
extends CRM_Core_Page
{
25 * The id of the contact.
32 * The group id that we are editing.
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.
43 public function preProcess() {
44 $this->_id
= CRM_Utils_Request
::retrieve('id', 'Positive',
48 $session = CRM_Core_Session
::singleton();
49 $this->_id
= $session->get('userID');
51 CRM_Core_Error
::statusBounce(ts('Could not find the required contact id parameter (id=) for viewing a contact record with a Profile.'));
54 $this->assign('cid', $this->_id
);
56 $gids = explode(',', CRM_Utils_Request
::retrieve('gid', 'String', CRM_Core_DAO
::$_nullObject, FALSE, 0, 'GET'));
59 if (count($gids) > 1) {
61 foreach ($gids as $pfId) {
62 $profileIds[] = CRM_Utils_Type
::escape($pfId, 'Positive');
66 // check if we are rendering mixed profiles
67 if (CRM_Core_BAO_UFGroup
::checkForMixProfiles($profileIds)) {
68 CRM_Core_Error
::statusBounce(ts('You cannot combine profiles of multiple types.'));
71 $this->_gid
= $profileIds[0];
75 $this->_gid
= CRM_Utils_Request
::retrieve('gid', 'Positive', $this, FALSE, 0, 'GET');
80 $page = new CRM_Profile_Page_Dynamic($this->_id
, $this->_gid
, 'Profile', FALSE, $profileIds);
82 $profileGroup['title'] = NULL;
83 $profileGroup['content'] = $page->run();
84 if (empty($profileGroup['content'])) {
87 $profileGroups[] = $profileGroup;
89 $gidString = $this->_gid
;
90 if (!empty($profileIds)) {
91 $gidString = implode(',', $profileIds);
94 $map = CRM_Core_DAO
::getFieldValue('CRM_Core_DAO_UFGroup', $this->_gid
, 'is_map');
96 $this->assign('mapURL',
97 CRM_Utils_System
::url("civicrm/profile/map",
98 "reset=1&pv=1&cid={$this->_id}&gid={$gidString}"
102 if (CRM_Core_Permission
::ufGroupValid($this->_gid
,
103 CRM_Core_Permission
::SEARCH
106 $this->assign('listingURL',
107 CRM_Utils_System
::url("civicrm/profile",
108 "force=1&gid={$gidString}"
114 $ufGroups = CRM_Core_BAO_UFGroup
::getModuleUFGroup('Profile');
117 foreach ($ufGroups as $groupid => $group) {
118 $page = new CRM_Profile_Page_Dynamic($this->_id
, $groupid, 'Profile', FALSE, $profileIds);
120 $profileGroup['title'] = $group['title'];
121 $profileGroup['content'] = $page->run();
122 if (empty($profileGroup['content'])) {
125 $profileGroups[] = $profileGroup;
127 $this->assign('listingURL',
128 CRM_Utils_System
::url("civicrm/profile",
134 $this->assign('groupID', $this->_gid
);
136 $this->assign('profileGroups', $profileGroups);
137 $this->assign('recentlyViewed', FALSE);
139 // do not set title if there is no content
142 CRM_Utils_System
::setTitle('');
147 * Build the outcome basing on the CRM_Profile_Page_Dynamic's HTML.
150 public function run() {
152 return parent
::run();
156 * @param string $suffix
158 * @return null|string
160 public function checkTemplateFileExists($suffix = '') {
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;
168 // lets see if we have customized by name
169 $ufGroupName = CRM_Core_DAO
::getFieldValue('CRM_Core_DAO_UFGroup', $this->_gid
, 'name');
171 $templateFile = "CRM/Profile/Page/{$ufGroupName}/View.{$suffix}tpl";
172 if ($template->template_exists($templateFile)) {
173 return $templateFile;
181 * Use the form name to create the tpl file name.
185 public function getTemplateFileName() {
186 $fileName = $this->checkTemplateFileExists();
187 return $fileName ?
$fileName : parent
::getTemplateFileName();
191 * Default extra tpl file basically just replaces .tpl with .extra.tpl
192 * i.e. we dont override
196 public function overrideExtraTemplateFileName() {
197 $fileName = $this->checkTemplateFileExists('extra.');
198 return $fileName ?
$fileName : parent
::overrideExtraTemplateFileName();