ts('View'), 'url' => 'civicrm/profile/view', 'qs' => "reset=1&id=%%id%%&recordId=%%recordId%%&gid=%%gid%%&multiRecord={$view}&snippet=1&context=multiProfileDialog&onPopupClose=%%onPopupClose%%", 'title' => ts('View %1', array( 1 => $this->_customGroupTitle . ' record')), ); $links[CRM_Core_Action::UPDATE] = array( 'name' => ts('Edit'), 'url' => 'civicrm/profile/edit', 'qs' => "reset=1&id=%%id%%&recordId=%%recordId%%&gid=%%gid%%&multiRecord={$update}&snippet=1&context=multiProfileDialog&onPopupClose=%%onPopupClose%%", 'title' => ts('Edit %1', array( 1 => $this->_customGroupTitle . ' record')), ); $links[CRM_Core_Action::DELETE] = array( 'name' => ts('Delete'), 'url' => 'civicrm/profile/edit', 'qs' => "reset=1&id=%%id%%&recordId=%%recordId%%&gid=%%gid%%&multiRecord={$delete}&snippet=1&context=multiProfileDialog&onPopupClose=%%onPopupClose%%", 'title' => ts('Delete %1', array( 1 => $this->_customGroupTitle . ' record')), ); self::$_links = $links; } return self::$_links; } /** * Run the page * * This method is called after the page is created. It checks for the type * of action and executes that action. Finally it calls the parent's run * method. * * @return void * @access public * */ function run() { // get the requested action, default to 'browse' $action = CRM_Utils_Request::retrieve('action', 'String', $this, FALSE, FALSE); $this->_onPopupClose = CRM_Utils_Request::retrieve('onPopupClose', 'String', $this); // assign vars to templates $this->assign('action', $action); $profileId = CRM_Utils_Request::retrieve('profileId', 'Positive', $this, FALSE); if (!is_array($profileId) && is_numeric($profileId)) { $this->_profileId = $profileId; } //record id $recid = CRM_Utils_Request::retrieve('recid', 'Positive', $this, FALSE, 0); //custom group id $groupId = CRM_Utils_Request::retrieve('groupId', 'Positive', $this, FALSE, 0); $this->_contactId = CRM_Utils_Request::retrieve('contactId', 'Positive', $this, FALSE); if ($action & CRM_Core_Action::BROWSE) { //browse $this->browse(); return; } // parent run return parent::run(); } /** * Browse the listing * * @return void * @access public */ function browse() { if ($this->_profileId) { $fields = CRM_Core_BAO_UFGroup::getFields($this->_profileId, FALSE, NULL, NULL, NULL, FALSE, NULL, FALSE, NULL, CRM_Core_Permission::EDIT ); $multiRecordFields = array( ); $fieldIDs = NULL; $result = NULL; $multiRecordFieldsWithSummaryListing = CRM_Core_BAO_UFGroup::shiftMultiRecordFields($fields, $multiRecordFields, TRUE); $multiFieldId = CRM_Core_BAO_CustomField::getKeyID(key($multiRecordFields)); $customGroupId = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_CustomField', $multiFieldId, 'custom_group_id'); $reached = CRM_Core_BAO_CustomGroup::hasReachedMaxLimit($customGroupId, $this->_contactId); if (!$reached) { $this->assign('contactId', $this->_contactId); $this->assign('gid', $this->_profileId); } $this->assign('reachedMax', $reached); if ($multiRecordFieldsWithSummaryListing && !empty($multiRecordFieldsWithSummaryListing)) { $fieldIDs = array_keys($multiRecordFieldsWithSummaryListing); } } if ($fieldIDs && !empty($fieldIDs) && $this->_contactId) { $options = array( ); $returnProperities = array('html_type', 'data_type', 'date_format', 'time_format'); foreach ($fieldIDs as $key => $fieldID) { $fieldIDs[$key] = CRM_Core_BAO_CustomField::getKeyID($fieldID); $param = array('id' => $fieldIDs[$key]); $returnValues = array( ); CRM_Core_DAO::commonRetrieve('CRM_Core_DAO_CustomField', $param, $returnValues, $returnProperities); $optionValuePairs = CRM_Core_BAO_CustomOption::getCustomOption($fieldIDs[$key]); if (!empty($optionValuePairs)) { foreach ($optionValuePairs as $optionPairs) { $options[$fieldIDs[$key]][$optionPairs['value']] = $optionPairs['label']; } } $options[$fieldIDs[$key]]['attributes']['html_type'] = $returnValues['html_type']; $options[$fieldIDs[$key]]['attributes']['data_type'] = $returnValues['data_type']; $options[$fieldIDs[$key]]['attributes']['format'] = $options[$fieldIDs[$key]]['attributes']['date_format'] = CRM_Utils_Array::value('date_format', $returnValues); $options[$fieldIDs[$key]]['attributes']['time_format'] = CRM_Utils_Array::value('time_format', $returnValues); } $result = CRM_Core_BAO_CustomValueTable::getEntityValues($this->_contactId, NULL, $fieldIDs, TRUE); if (!empty($fieldIDs)) { //get the group info of multi rec fields in listing view $fieldInput = $fieldIDs; $fieldIdInput = $fieldIDs[0]; } else { //if no listing fields exist, take the group title for display $nonListingFieldIds = array_keys($multiRecordFields); $singleField = CRM_Core_BAO_CustomField::getKeyID($nonListingFieldIds[0]); $fieldIdInput = $singleField; $singleField = array($singleField); $fieldInput = $singleField; } $customGroupInfo = CRM_Core_BAO_CustomGroup::getGroupTitles($fieldInput); $this->_customGroupTitle = $customGroupInfo[$fieldIdInput]['groupTitle']; if ($result && !empty($result)) { $links = self::links(); $pageCheckSum = $this->get('pageCheckSum'); if ($pageCheckSum) { foreach ($links as $key => $link) { $links[$key] = $link['qs'] . "&cs=%%cs%%"; } } $linkAction = array_sum(array_keys($this->links())); foreach ($result as $recId => &$value) { foreach ($value as $fieldId => &$val) { if (is_numeric($fieldId)) { $customValue = &$val; $customValue = CRM_Core_BAO_CustomField::getDisplayValue($customValue, $fieldId, $options); if (!$customValue) { $customValue = ""; } $actionParams = array('recordId' => $recId, 'gid' => $this->_profileId, 'id' => $this->_contactId, 'onPopupClose' => $this->_onPopupClose); if ($pageCheckSum) { $actionParams['cs'] = $pageCheckSum; } $value['action'] = CRM_Core_Action::formLink($links, $linkAction, $actionParams); } } } } } $headers = array( ); if (!empty($fieldIDs)) { foreach ($fieldIDs as $fieldID) { $headers[$fieldID] = $customGroupInfo[$fieldID]['fieldLabel']; } } $this->assign('customGroupTitle', $this->_customGroupTitle); $this->assign('headers', $headers); $this->assign('records', $result); } /** * Get name of edit form * * @return string classname of edit form */ function editForm() { return ''; } /** * Get edit form name * * @return string name of this page */ function editName() { return ''; } /** * Get user context * * @return string user context */ function userContext($mode = NULL) { return ''; } }