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;
55 * @return string Classname of BAO.
57 function getBAOName() {
64 * @return array (reference) of action links
67 if (!(self
::$_links)) {
68 // helper variable for nicer formatting
71 $view = array_search(CRM_Core_Action
::VIEW
, CRM_Core_Action
::$_names);
72 $update = array_search(CRM_Core_Action
::UPDATE
, CRM_Core_Action
::$_names);
73 $delete = array_search(CRM_Core_Action
::DELETE
, CRM_Core_Action
::$_names);
75 $links[CRM_Core_Action
::VIEW
] = array(
77 'url' => 'civicrm/profile/view',
78 'qs' => "reset=1&id=%%id%%&recordId=%%recordId%%&gid=%%gid%%&multiRecord={$view}&snippet=1&context=multiProfileDialog&onPopupClose=%%onPopupClose%%",
79 'title' => ts('View %1', array( 1 => $this->_customGroupTitle
. ' record')),
82 $links[CRM_Core_Action
::UPDATE
] = array(
84 'url' => 'civicrm/profile/edit',
85 'qs' => "reset=1&id=%%id%%&recordId=%%recordId%%&gid=%%gid%%&multiRecord={$update}&snippet=1&context=multiProfileDialog&onPopupClose=%%onPopupClose%%",
86 'title' => ts('Edit %1', array( 1 => $this->_customGroupTitle
. ' record')),
89 $links[CRM_Core_Action
::DELETE
] = array(
90 'name' => ts('Delete'),
91 'url' => 'civicrm/profile/edit',
92 'qs' => "reset=1&id=%%id%%&recordId=%%recordId%%&gid=%%gid%%&multiRecord={$delete}&snippet=1&context=multiProfileDialog&onPopupClose=%%onPopupClose%%",
93 'title' => ts('Delete %1', array( 1 => $this->_customGroupTitle
. ' record')),
96 self
::$_links = $links;
104 * This method is called after the page is created. It checks for the type
105 * of action and executes that action. Finally it calls the parent's run
113 // get the requested action, default to 'browse'
114 $action = CRM_Utils_Request
::retrieve('action', 'String', $this, FALSE, FALSE);
115 $this->_onPopupClose
= CRM_Utils_Request
::retrieve('onPopupClose', 'String', $this);
117 // assign vars to templates
118 $this->assign('action', $action);
119 $profileId = CRM_Utils_Request
::retrieve('profileId', 'Positive', $this, FALSE);
120 if (!is_array($profileId) && is_numeric($profileId)) {
121 $this->_profileId
= $profileId;
124 $recid = CRM_Utils_Request
::retrieve('recid', 'Positive', $this, FALSE, 0);
126 $groupId = CRM_Utils_Request
::retrieve('groupId', 'Positive', $this, FALSE, 0);
128 $this->_contactId
= CRM_Utils_Request
::retrieve('contactId', 'Positive', $this, FALSE);
130 if ($action & CRM_Core_Action
::BROWSE
) {
136 return parent
::run();
146 if ($this->_profileId
) {
147 $fields = CRM_Core_BAO_UFGroup
::getFields($this->_profileId
, FALSE, NULL,
152 CRM_Core_Permission
::EDIT
154 $multiRecordFields = array( );
157 $multiRecordFieldsWithSummaryListing = CRM_Core_BAO_UFGroup
::shiftMultiRecordFields($fields, $multiRecordFields, TRUE);
159 $multiFieldId = CRM_Core_BAO_CustomField
::getKeyID(key($multiRecordFields));
160 $customGroupId = CRM_Core_DAO
::getFieldValue('CRM_Core_DAO_CustomField', $multiFieldId, 'custom_group_id');
161 $reached = CRM_Core_BAO_CustomGroup
::hasReachedMaxLimit($customGroupId, $this->_contactId
);
163 $this->assign('contactId', $this->_contactId
);
164 $this->assign('gid', $this->_profileId
);
166 $this->assign('reachedMax', $reached);
168 if ($multiRecordFieldsWithSummaryListing && !empty($multiRecordFieldsWithSummaryListing)) {
169 $fieldIDs = array_keys($multiRecordFieldsWithSummaryListing);
173 if ($fieldIDs && !empty($fieldIDs) && $this->_contactId
) {
175 $returnProperities = array('html_type', 'data_type', 'date_format', 'time_format');
176 foreach ($fieldIDs as $key => $fieldID) {
177 $fieldIDs[$key] = CRM_Core_BAO_CustomField
::getKeyID($fieldID);
178 $param = array('id' => $fieldIDs[$key]);
179 $returnValues = array( );
180 CRM_Core_DAO
::commonRetrieve('CRM_Core_DAO_CustomField', $param, $returnValues, $returnProperities);
182 $optionValuePairs = CRM_Core_BAO_CustomOption
::getCustomOption($fieldIDs[$key]);
183 if (!empty($optionValuePairs)) {
184 foreach ($optionValuePairs as $optionPairs) {
185 $options[$fieldIDs[$key]][$optionPairs['value']] = $optionPairs['label'];
189 $options[$fieldIDs[$key]]['attributes']['html_type'] = $returnValues['html_type'];
190 $options[$fieldIDs[$key]]['attributes']['data_type'] = $returnValues['data_type'];
192 $options[$fieldIDs[$key]]['attributes']['format'] =
193 $options[$fieldIDs[$key]]['attributes']['date_format'] = CRM_Utils_Array
::value('date_format', $returnValues);
194 $options[$fieldIDs[$key]]['attributes']['time_format'] = CRM_Utils_Array
::value('time_format', $returnValues);
197 $result = CRM_Core_BAO_CustomValueTable
::getEntityValues($this->_contactId
, NULL, $fieldIDs, TRUE);
199 if (!empty($fieldIDs)) {
200 //get the group info of multi rec fields in listing view
201 $fieldInput = $fieldIDs;
202 $fieldIdInput = $fieldIDs[0];
204 //if no listing fields exist, take the group title for display
205 $nonListingFieldIds = array_keys($multiRecordFields);
206 $singleField = CRM_Core_BAO_CustomField
::getKeyID($nonListingFieldIds[0]);
207 $fieldIdInput = $singleField;
208 $singleField = array($singleField);
209 $fieldInput = $singleField;
211 $customGroupInfo = CRM_Core_BAO_CustomGroup
::getGroupTitles($fieldInput);
212 $this->_customGroupTitle
= $customGroupInfo[$fieldIdInput]['groupTitle'];
214 if ($result && !empty($result)) {
215 $links = self
::links();
216 $pageCheckSum = $this->get('pageCheckSum');
218 foreach ($links as $key => $link) {
219 $links[$key] = $link['qs'] . "&cs=%%cs%%";
222 $linkAction = array_sum(array_keys($this->links()));
224 foreach ($result as $recId => &$value) {
225 foreach ($value as $fieldId => &$val) {
226 if (is_numeric($fieldId)) {
227 $customValue = &$val;
228 $customValue = CRM_Core_BAO_CustomField
::getDisplayValue($customValue, $fieldId, $options);
232 $actionParams = array('recordId' => $recId, 'gid' => $this->_profileId
,
233 'id' => $this->_contactId
, 'onPopupClose' => $this->_onPopupClose
);
235 $actionParams['cs'] = $pageCheckSum;
238 CRM_Core_Action
::formLink($links, $linkAction, $actionParams);
246 if (!empty($fieldIDs)) {
247 foreach ($fieldIDs as $fieldID) {
248 $headers[$fieldID] = $customGroupInfo[$fieldID]['fieldLabel'];
251 $this->assign('customGroupTitle', $this->_customGroupTitle
);
252 $this->assign('headers', $headers);
253 $this->assign('records', $result);
257 * Get name of edit form
259 * @return string classname of edit form
261 function editForm() {
268 * @return string name of this page
270 function editName() {
277 * @return string user context
279 function userContext($mode = NULL) {