3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.4 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2013 |
7 +--------------------------------------------------------------------+
8 | This file is a part of CiviCRM. |
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. |
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. |
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 +--------------------------------------------------------------------+
31 * @copyright CiviCRM LLC (c) 2004-2013
35 class CRM_Profile_Page_MultipleRecordFieldsListing
extends CRM_Core_Page_Basic
{
38 * The action links that we need to display for the browse screen
43 static $_links = NULL;
45 protected $_fields = NULL;
47 protected $_profileId = NULL;
49 protected $_contactId = NULL;
51 protected $_customGroupTitle = NULL;
53 protected $_pageViewType = NULL;
55 protected $_contactType = NULL;
59 * @return string Classname of BAO.
61 function getBAOName() {
68 * @return array (reference) of action links
71 if (!(self
::$_links[$this->_pageViewType
])) {
72 // helper variable for nicer formatting
75 $view = array_search(CRM_Core_Action
::VIEW
, CRM_Core_Action
::$_names);
76 $update = array_search(CRM_Core_Action
::UPDATE
, CRM_Core_Action
::$_names);
77 $delete = array_search(CRM_Core_Action
::DELETE
, CRM_Core_Action
::$_names);
79 $links[CRM_Core_Action
::VIEW
] = array(
81 'title' => ts('View %1', array( 1 => $this->_customGroupTitle
. ' record')),
84 if ($this->_pageViewType
== 'profileDataView') {
85 $links[CRM_Core_Action
::VIEW
]['url'] = 'civicrm/profile/view';
86 $links[CRM_Core_Action
::VIEW
]['qs'] = "reset=1&id=%%id%%&recordId=%%recordId%%&gid=%%gid%%&multiRecord={$view}&snippet=1&context=multiProfileDialog&onPopupClose=%%onPopupClose%%";
88 elseif ($this->_pageViewType
== 'customDataView') {
89 // custom data specific view links
90 $links[CRM_Core_Action
::VIEW
]['url'] = 'civicrm/contact/view/cd';
91 $links[CRM_Core_Action
::VIEW
]['qs'] = 'reset=1&snippet=1&gid=%%gid%%&cid=%%cid%%&recId=%%recId%%&multiRecordDisplay=single';
94 $links[CRM_Core_Action
::UPDATE
] = array(
96 'title' => ts('Edit %1', array( 1 => $this->_customGroupTitle
. ' record')),
99 if ($this->_pageViewType
== 'profileDataView') {
100 $links[CRM_Core_Action
::UPDATE
]['url'] = 'civicrm/profile/edit';
101 $links[CRM_Core_Action
::UPDATE
]['qs'] = "reset=1&id=%%id%%&recordId=%%recordId%%&gid=%%gid%%&multiRecord={$update}&snippet=1&context=multiProfileDialog&onPopupClose=%%onPopupClose%%";
103 elseif ($this->_pageViewType
== 'customDataView') {
104 // custom data specific update links
105 $links[CRM_Core_Action
::UPDATE
]['url'] = 'civicrm/contact/view/cd/edit';
106 $links[CRM_Core_Action
::UPDATE
]['qs'] = 'reset=1&snippet=1&type=%%type%%&groupID=%%groupID%%&entityID=%%entityID%%&cgcount=%%cgcount%%&multiRecordDisplay=single';
109 $links[CRM_Core_Action
::DELETE
] = array(
110 'name' => ts('Delete'),
111 'title' => ts('Delete %1', array( 1 => $this->_customGroupTitle
. ' record')),
114 if ($this->_pageViewType
== 'profileDataView') {
115 $links[CRM_Core_Action
::DELETE
]['url'] = 'civicrm/profile/edit';
116 $links[CRM_Core_Action
::DELETE
]['qs'] = "reset=1&id=%%id%%&recordId=%%recordId%%&gid=%%gid%%&multiRecord={$delete}&snippet=1&context=multiProfileDialog&onPopupClose=%%onPopupClose%%";
118 // NOTE : links for DELETE action for customDataView is handled in browse
120 self
::$_links[$this->_pageViewType
] = $links;
122 return self
::$_links[$this->_pageViewType
];
128 * This method is called after the page is created. It checks for the type
129 * of action and executes that action. Finally it calls the parent's run
137 // get the requested action, default to 'browse'
138 $action = CRM_Utils_Request
::retrieve('action', 'String', $this, FALSE, FALSE);
139 $this->_onPopupClose
= CRM_Utils_Request
::retrieve('onPopupClose', 'String', $this);
141 // assign vars to templates
142 $this->assign('action', $action);
143 $profileId = CRM_Utils_Request
::retrieve('profileId', 'Positive', $this, FALSE);
144 if (!is_array($profileId) && is_numeric($profileId)) {
145 $this->_profileId
= $profileId;
148 $this->_contactId
= CRM_Utils_Request
::retrieve('contactId', 'Positive', $this, FALSE);
149 $this->_pageViewType
= CRM_Utils_Request
::retrieve('pageViewType', 'Positive', $this, FALSE, 'profileDataView');
150 $this->_customGroupId
= CRM_Utils_Request
::retrieve('customGroupId', 'Positive', $this, FALSE, 0);
151 $this->_contactType
= CRM_Utils_Request
::retrieve('contactType', 'String', $this, FALSE);
152 if ($action & CRM_Core_Action
::BROWSE
) {
158 return parent
::run();
168 if ($this->_pageViewType
== 'profileDataView' && $this->_profileId
) {
169 $fields = CRM_Core_BAO_UFGroup
::getFields($this->_profileId
, FALSE, NULL,
174 CRM_Core_Permission
::EDIT
176 $multiRecordFields = array( );
179 $multiRecordFieldsWithSummaryListing = CRM_Core_BAO_UFGroup
::shiftMultiRecordFields($fields, $multiRecordFields, TRUE);
181 $multiFieldId = CRM_Core_BAO_CustomField
::getKeyID(key($multiRecordFields));
182 $customGroupId = CRM_Core_DAO
::getFieldValue('CRM_Core_DAO_CustomField', $multiFieldId, 'custom_group_id');
183 $reached = CRM_Core_BAO_CustomGroup
::hasReachedMaxLimit($customGroupId, $this->_contactId
);
185 $this->assign('contactId', $this->_contactId
);
186 $this->assign('gid', $this->_profileId
);
188 $this->assign('reachedMax', $reached);
190 if ($multiRecordFieldsWithSummaryListing && !empty($multiRecordFieldsWithSummaryListing)) {
191 $fieldIDs = array_keys($multiRecordFieldsWithSummaryListing);
194 elseif ($this->_pageViewType
== 'customDataView') {
195 // require custom group id for _pageViewType of customDataView
196 $customGroupId = $this->_customGroupId
;
197 $reached = CRM_Core_BAO_CustomGroup
::hasReachedMaxLimit($customGroupId, $this->_contactId
);
199 $this->assign('contactId', $this->_contactId
);
200 $this->assign('customGroupId', $customGroupId);
201 $this->assign('ctype', $this->_contactType
);
203 $this->assign('reachedMax', $reached);
204 // custom group info : this consists of the field title of group fields
205 $groupDetail = CRM_Core_BAO_CustomGroup
::getGroupDetail($customGroupId, NULL, CRM_Core_DAO
::$_nullObject, TRUE);
206 // field ids of fields in_selector for the custom group id provided
207 $fieldIDs = array_keys($groupDetail[$customGroupId]['fields']);
208 // field labels for headers
209 $fieldLabels = $groupDetail[$customGroupId]['fields'];
211 // from the above customGroupInfo we can get $this->_customGroupTitle
212 $this->_customGroupTitle
= $groupDetail[$customGroupId]['title'];
214 if ($fieldIDs && !empty($fieldIDs) && $this->_contactId
) {
216 $returnProperities = array('html_type', 'data_type', 'date_format', 'time_format');
217 foreach ($fieldIDs as $key => $fieldID) {
218 $fieldIDs[$key] = !is_numeric($fieldID) ? CRM_Core_BAO_CustomField
::getKeyID($fieldID) : $fieldID;
219 $param = array('id' => $fieldIDs[$key]);
220 $returnValues = array( );
221 CRM_Core_DAO
::commonRetrieve('CRM_Core_DAO_CustomField', $param, $returnValues, $returnProperities);
223 $optionValuePairs = CRM_Core_BAO_CustomOption
::getCustomOption($fieldIDs[$key]);
224 if (!empty($optionValuePairs)) {
225 foreach ($optionValuePairs as $optionPairs) {
226 $options[$fieldIDs[$key]][$optionPairs['value']] = $optionPairs['label'];
230 $options[$fieldIDs[$key]]['attributes']['html_type'] = $returnValues['html_type'];
231 $options[$fieldIDs[$key]]['attributes']['data_type'] = $returnValues['data_type'];
233 $options[$fieldIDs[$key]]['attributes']['format'] =
234 $options[$fieldIDs[$key]]['attributes']['date_format'] = CRM_Utils_Array
::value('date_format', $returnValues);
235 $options[$fieldIDs[$key]]['attributes']['time_format'] = CRM_Utils_Array
::value('time_format', $returnValues);
238 // commonly used for both views i.e profile listing view (profileDataView) and custom data listing view (customDataView)
239 $result = CRM_Core_BAO_CustomValueTable
::getEntityValues($this->_contactId
, NULL, $fieldIDs, TRUE);
241 if ($this->_pageViewType
== 'profileDataView') {
242 if (!empty($fieldIDs)) {
243 //get the group info of multi rec fields in listing view
244 $fieldInput = $fieldIDs;
245 $fieldIdInput = $fieldIDs[0];
248 //if no listing fields exist, take the group title for display
249 $nonListingFieldIds = array_keys($multiRecordFields);
250 $singleField = CRM_Core_BAO_CustomField
::getKeyID($nonListingFieldIds[0]);
251 $fieldIdInput = $singleField;
252 $singleField = array($singleField);
253 $fieldInput = $singleField;
255 $customGroupInfo = CRM_Core_BAO_CustomGroup
::getGroupTitles($fieldInput);
256 $this->_customGroupTitle
= $customGroupInfo[$fieldIdInput]['groupTitle'];
258 // $cgcount is defined before 'if' condition as enitiy may have no record
259 // and $cgcount is used to build new record url
261 if ($result && !empty($result)) {
262 $links = self
::links();
263 if ($this->_pageViewType
== 'profileDataView') {
264 $pageCheckSum = $this->get('pageCheckSum');
266 foreach ($links as $key => $link) {
267 $links[$key] = $link['qs'] . "&cs=%%cs%%";
271 $linkAction = array_sum(array_keys($this->links()));
272 foreach ($result as $recId => &$value) {
273 foreach ($value as $fieldId => &$val) {
274 if (is_numeric($fieldId)) {
275 $customValue = &$val;
276 $customValue = CRM_Core_BAO_CustomField
::getDisplayValue($customValue, $fieldId, $options);
282 if ($this->_pageViewType
== 'profileDataView') {
283 $actionParams = array('recordId' => $recId, 'gid' => $this->_profileId
,
284 'id' => $this->_contactId
, 'onPopupClose' => $this->_onPopupClose
);
285 $op = 'profile.multiValue.row';
288 // different set of url params
289 $actionParams['gid'] = $actionParams['groupID'] = $this->_customGroupId
;
290 $actionParams['cid'] = $actionParams['entityID'] = $this->_contactId
;
291 $actionParams['recId'] = $recId;
292 $actionParams['type'] = $this->_contactType
;
293 $actionParams['cgcount'] = $cgcount;
295 // DELETE action links
296 $links[CRM_Core_Action
::DELETE
]['url'] = '#';
297 $links[CRM_Core_Action
::DELETE
]['extra'] = " onclick='showDeleteInDialog({$recId}, {$this->_customGroupId}, {$this->_contactId})' ";
298 $links[CRM_Core_Action
::DELETE
]['class'] = 'ignore-jshref';
300 if (!empty($pageCheckSum)) {
301 $actionParams['cs'] = $pageCheckSum;
304 $value['action'] = CRM_Core_Action
::formLink(
312 $fieldId // not ideal, but the one thing not sent in $actionParams
322 if (!empty($fieldIDs)) {
323 foreach ($fieldIDs as $fieldID) {
324 $headers[$fieldID] = ($this->_pageViewType
== 'profileDataView') ?
$customGroupInfo[$fieldID]['fieldLabel'] : $fieldLabels[$fieldID]['label'];
327 $this->assign('cgcount', $cgcount);
328 $this->assign('customGroupTitle', $this->_customGroupTitle
);
329 $this->assign('headers', $headers);
330 $this->assign('records', $result);
334 * Get name of edit form
336 * @return string classname of edit form
338 function editForm() {
345 * @return string name of this page
347 function editName() {
354 * @return string user context
356 function userContext($mode = NULL) {