Merge pull request #4979 from xurizaemon/codingstandards-12
[civicrm-core.git] / CRM / Contact / Page / View / CustomData.php
CommitLineData
6a488035
TO
1<?php
2/*
3 +--------------------------------------------------------------------+
39de6fd5 4 | CiviCRM version 4.6 |
6a488035 5 +--------------------------------------------------------------------+
06b69b18 6 | Copyright CiviCRM LLC (c) 2004-2014 |
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 +--------------------------------------------------------------------+
26*/
27
28/**
29 *
30 * @package CRM
06b69b18 31 * @copyright CiviCRM LLC (c) 2004-2014
6a488035
TO
32 * $Id$
33 *
34 */
35
36/**
37 * Page for displaying custom data
38 *
39 */
40class CRM_Contact_Page_View_CustomData extends CRM_Core_Page {
41
42 /**
100fef9d 43 * The id of the object being viewed (note/relationship etc)
6a488035
TO
44 *
45 * @int
6a488035
TO
46 */
47 public $_groupId;
48
49 /**
100fef9d 50 * Class constructor
6a488035
TO
51 *
52 * @return CRM_Contact_Page_View_CustomData
53 */
54 public function __construct() {
55 parent::__construct();
56 }
57
58 /**
100fef9d 59 * Add a few specific things to view contact
6a488035
TO
60 *
61 * @return void
6a488035 62 */
00be9182 63 public function preProcess() {
6a488035
TO
64 $this->_contactId = CRM_Utils_Request::retrieve('cid', 'Positive', $this, TRUE);
65 $this->assign('contactId', $this->_contactId);
66
67 // check logged in url permission
68 CRM_Contact_Page_View::checkUserPermission($this);
69
70 $this->_action = CRM_Utils_Request::retrieve('action', 'String', $this, FALSE, 'browse');
71 $this->assign('action', $this->_action);
72
73 $this->_groupId = CRM_Utils_Request::retrieve('gid', 'Positive', $this, TRUE);
74 $this->assign('groupId', $this->_groupId);
e41f4660
PJ
75
76 $this->_multiRecordDisplay = CRM_Utils_Request::retrieve('multiRecordDisplay', 'String', $this, FALSE);
77 $this->_cgcount = CRM_Utils_Request::retrieve('cgcount', 'Positive', $this, FALSE);
78 $this->_recId = CRM_Utils_Request::retrieve('recId', 'Positive', $this, FALSE);
6a488035
TO
79 }
80
81 /**
82 * Run the page.
83 *
84 * This method is called after the page is created. It checks for the
85 * type of action and executes that action.
86 *
6a488035 87 *
355ba699 88 * @return void
6a488035 89 */
00be9182 90 public function run() {
6a488035
TO
91 $this->preProcess();
92
93 //set the userContext stack
94 $doneURL = 'civicrm/contact/view';
95 $session = CRM_Core_Session::singleton();
96 $session->pushUserContext(CRM_Utils_System::url($doneURL, 'action=browse&selectedChild=custom_' . $this->_groupId), FALSE);
97
98 // get permission detail view or edit
87177cd2
DL
99 // use a comtact id specific function which gives us much better granularity
100 // CRM-12646
101 $editCustomData = CRM_Contact_BAO_Contact_Permission::allow($this->_contactId, CRM_Core_Permission::EDIT);
6a488035
TO
102 $this->assign('editCustomData', $editCustomData);
103
104 //allow to edit own customdata CRM-5518
105 $editOwnCustomData = FALSE;
106 if ($session->get('userID') == $this->_contactId) {
107 $editOwnCustomData = TRUE;
108 }
109 $this->assign('editOwnCustomData', $editOwnCustomData);
110
111 if ($this->_action == CRM_Core_Action::BROWSE) {
112 //Custom Groups Inline
353ffa53 113 $entityType = CRM_Contact_BAO_Contact::getContactType($this->_contactId);
6a488035 114 $entitySubType = CRM_Contact_BAO_Contact::getContactSubType($this->_contactId);
353ffa53 115 $groupTree = &CRM_Core_BAO_CustomGroup::getTree($entityType, $this, $this->_contactId,
6a488035
TO
116 $this->_groupId, $entitySubType
117 );
e41f4660
PJ
118
119 $displayStyle = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_CustomGroup',
120 $this->_groupId,
121 'style'
122 );
123
eaf756c0 124 if ($this->_multiRecordDisplay != 'single') {
bd470b69
PJ
125 $id = "custom_{$this->_groupId}";
126 $this->ajaxResponse['tabCount'] = CRM_Contact_BAO_Contact::getCountComponent($id, $this->_contactId, $groupTree[$this->_groupId]['table_name']);
eaf756c0
CW
127 }
128
129 if ($displayStyle === 'Tab with table' && $this->_multiRecordDisplay != 'single') {
e41f4660
PJ
130 $ctype = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Contact',
131 $this->_contactId,
132 'contact_type'
133 );
134
135 $this->assign('displayStyle', 'tableOriented');
136 // here the multi custom data listing code will go
137 $multiRecordFieldListing = TRUE;
138 $page = new CRM_Profile_Page_MultipleRecordFieldsListing();
139 $page->set('contactId', $this->_contactId);
140 $page->set('customGroupId', $this->_groupId);
141 $page->set('action', CRM_Core_Action::BROWSE);
142 $page->set('multiRecordFieldListing', $multiRecordFieldListing);
143 $page->set('pageViewType', 'customDataView');
144 $page->set('contactType', $ctype);
145 $page->run();
146 }
147 else {
148 $recId = NULL;
149 if ($this->_multiRecordDisplay == 'single') {
525faea3
PJ
150 $groupTitle = CRM_Core_BAO_CustomGroup::getTitle($this->_groupId);
151 CRM_Utils_System::setTitle(ts('View %1 Record', array(1 => $groupTitle)));
152
e41f4660
PJ
153 $recId = $this->_recId;
154 $this->assign('multiRecordDisplay', $this->_multiRecordDisplay);
155 $this->assign('skipTitle', 1);
156 }
157 CRM_Core_BAO_CustomGroup::buildCustomDataView($this, $groupTree, FALSE, NULL, NULL, $recId);
158 }
6a488035
TO
159 }
160 else {
161
162 $controller = new CRM_Core_Controller_Simple('CRM_Contact_Form_CustomData',
163 ts('Custom Data'),
164 $this->_action
165 );
166 $controller->setEmbedded(TRUE);
167
168 $controller->set('tableId', $this->_contactId);
169 $controller->set('groupId', $this->_groupId);
170 $controller->set('entityType', CRM_Contact_BAO_Contact::getContactType($this->_contactId));
171 $controller->set('entitySubType', CRM_Contact_BAO_Contact::getContactSubType($this->_contactId, ','));
172 $controller->process();
173 $controller->run();
174 }
175 return parent::run();
176 }
6c8f6e67 177}