3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.3 |
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' => "id=%%id%%&recordId=%%recordId%%&gid=%%gid%%&multiRecord={$view}&snippet=1&context=multiProfileDialog",
79 'title' => ts('View %1', array( 1 => $this->_customGroupTitle
. ' record')),
82 $links[CRM_Core_Action
::UPDATE
] = array(
84 'url' => 'civicrm/profile/edit',
85 'qs' => "id=%%id%%&recordId=%%recordId%%&gid=%%gid%%&multiRecord={$update}&snippet=1&context=multiProfileDialog",
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' => "id=%%id%%&recordId=%%recordId%%&gid=%%gid%%&multiRecord={$delete}&snippet=1&context=multiProfileDialog",
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);
116 // assign vars to templates
117 $this->assign('action', $action);
118 $profileId = CRM_Utils_Request
::retrieve('profileId', 'Positive', $this, FALSE);
119 if (!is_array($profileId) && is_numeric($profileId)) {
120 $this->_profileId
= $profileId;
123 $recid = CRM_Utils_Request
::retrieve('recid', 'Positive', $this, FALSE, 0);
125 $groupId = CRM_Utils_Request
::retrieve('groupId', 'Positive', $this, FALSE, 0);
127 $this->_contactId
= CRM_Utils_Request
::retrieve('contactId', 'Positive', $this, FALSE);
129 if ($action & CRM_Core_Action
::BROWSE
) {
135 return parent
::run();
145 if ($this->_profileId
) {
146 $fields = CRM_Core_BAO_UFGroup
::getFields($this->_profileId
, FALSE, NULL,
151 CRM_Core_Permission
::EDIT
153 $multiRecordFields = array( );
156 $multiRecordFieldsWithSummaryListing = CRM_Core_BAO_UFGroup
::shiftMultiRecordFields($fields, $multiRecordFields, TRUE);
158 $multiFieldId = CRM_Core_BAO_CustomField
::getKeyID(key($multiRecordFields));
159 $customGroupId = CRM_Core_DAO
::getFieldValue('CRM_Core_DAO_CustomField', $multiFieldId, 'custom_group_id');
160 $reached = CRM_Core_BAO_CustomGroup
::hasReachedMaxLimit($customGroupId, $this->_contactId
);
162 $this->assign('contactId', $this->_contactId
);
163 $this->assign('gid', $this->_profileId
);
165 $this->assign('reachedMax', $reached);
167 if ($multiRecordFieldsWithSummaryListing && !empty($multiRecordFieldsWithSummaryListing)) {
168 $fieldIDs = array_keys($multiRecordFieldsWithSummaryListing);
172 if ($fieldIDs && !empty($fieldIDs) && $this->_contactId
) {
174 $returnProperities = array('html_type', 'data_type', 'date_format', 'time_format');
175 foreach ($fieldIDs as $key => $fieldID) {
176 $fieldIDs[$key] = CRM_Core_BAO_CustomField
::getKeyID($fieldID);
177 $param = array('id' => $fieldIDs[$key]);
178 $returnValues = array( );
179 CRM_Core_DAO
::commonRetrieve('CRM_Core_DAO_CustomField', $param, $returnValues, $returnProperities);
181 $optionValuePairs = CRM_Core_BAO_CustomOption
::getCustomOption($fieldIDs[$key]);
182 if (!empty($optionValuePairs)) {
183 foreach ($optionValuePairs as $optionPairs) {
184 $options[$fieldIDs[$key]][$optionPairs['value']] = $optionPairs['label'];
188 $options[$fieldIDs[$key]]['attributes']['html_type'] = $returnValues['html_type'];
189 $options[$fieldIDs[$key]]['attributes']['data_type'] = $returnValues['data_type'];
191 $options[$fieldIDs[$key]]['attributes']['format'] =
192 $options[$fieldIDs[$key]]['attributes']['date_format'] = CRM_Utils_Array
::value('date_format', $returnValues);
193 $options[$fieldIDs[$key]]['attributes']['time_format'] = CRM_Utils_Array
::value('time_format', $returnValues);
196 $result = CRM_Core_BAO_CustomValueTable
::getEntityValues($this->_contactId
, NULL, $fieldIDs, TRUE);
198 if (!empty($fieldIDs)) {
199 //get the group info of multi rec fields in listing view
200 $fieldInput = $fieldIDs;
201 $fieldIdInput = $fieldIDs[0];
203 //if no listing fields exist, take the group title for display
204 $nonListingFieldIds = array_keys($multiRecordFields);
205 $singleField = CRM_Core_BAO_CustomField
::getKeyID($nonListingFieldIds[0]);
206 $fieldIdInput = $singleField;
207 $singleField = array($singleField);
208 $fieldInput = $singleField;
210 $customGroupInfo = CRM_Core_BAO_CustomGroup
::getGroupTitles($fieldInput);
211 $this->_customGroupTitle
= $customGroupInfo[$fieldIdInput]['groupTitle'];
213 if ($result && !empty($result)) {
214 $links = self
::links();
215 $pageCheckSum = $this->get('pageCheckSum');
217 foreach ($links as $key => $link) {
218 $links[$key] = $link['qs'] . "&cs=%%cs%%";
221 $linkAction = array_sum(array_keys($this->links()));
223 foreach ($result as $recId => &$value) {
224 foreach ($value as $fieldId => &$val) {
225 if (is_numeric($fieldId)) {
226 $customValue = &$val;
227 $customValue = CRM_Core_BAO_CustomField
::getDisplayValue($customValue, $fieldId, $options);
231 $actionParams = array('recordId' => $recId, 'gid' => $this->_profileId
,
232 'id' => $this->_contactId
);
234 $actionParams['cs'] = $pageCheckSum;
237 CRM_Core_Action
::formLink($links, $linkAction, $actionParams);
245 if (!empty($fieldIDs)) {
246 foreach ($fieldIDs as $fieldID) {
247 $headers[$fieldID] = $customGroupInfo[$fieldID]['fieldLabel'];
250 $this->assign('customGroupTitle', $this->_customGroupTitle
);
251 $this->assign('headers', $headers);
252 $this->assign('records', $result);
256 * Get name of edit form
258 * @return string classname of edit form
260 function editForm() {
267 * @return string name of this page
269 function editName() {
276 * @return string user context
278 function userContext($mode = NULL) {