/** * Get the action links for this page. * * @return array * array of action links that we need to display for the browse screen */ public static function &actionLinks() { if (!isset(self::$_actionLinks)) { self::$_actionLinks = array(CRM_Core_Action::UPDATE => array('name' => ts('Edit Option'), 'url' => 'civicrm/admin/custom/group/field/option', 'qs' => 'reset=1&action=update&id=%%id%%&fid=%%fid%%&gid=%%gid%%', 'title' => ts('Edit Multiple Choice Option')), CRM_Core_Action::VIEW => array('name' => ts('View'), 'url' => 'civicrm/admin/custom/group/field/option', 'qs' => 'action=view&id=%%id%%&fid=%%fid%%', 'title' => ts('View Multiple Choice Option')), CRM_Core_Action::DISABLE => array('name' => ts('Disable'), 'ref' => 'crm-enable-disable', 'title' => ts('Disable Mutliple Choice Option')), CRM_Core_Action::ENABLE => array('name' => ts('Enable'), 'ref' => 'crm-enable-disable', 'title' => ts('Enable Mutliple Choice Option')), CRM_Core_Action::DELETE => array('name' => ts('Delete'), 'url' => 'civicrm/admin/custom/group/field/option', 'qs' => 'action=delete&id=%%id%%&fid=%%fid%%', 'title' => ts('Disable Multiple Choice Option'))); } return self::$_actionLinks; }
/** * Get the action links for this page. * * @param null * * @return array array of action links that we need to display for the browse screen * @access public */ function &actionLinks() { if (!isset(self::$_actionLinks)) { self::$_actionLinks = array(CRM_Core_Action::UPDATE => array('name' => ts('Edit Option'), 'url' => 'civicrm/admin/custom/group/field/option', 'qs' => 'reset=1&action=update&id=%%id%%&fid=%%fid%%&gid=%%gid%%', 'title' => ts('Edit Multiple Choice Option')), CRM_Core_Action::VIEW => array('name' => ts('View'), 'url' => 'civicrm/admin/custom/group/field/option', 'qs' => 'action=view&id=%%id%%', 'title' => ts('View Multiple Choice Option')), CRM_Core_Action::DISABLE => array('name' => ts('Disable'), 'extra' => 'onclick = "enableDisable( %%id%%,\'' . 'CRM_Core_BAO_OptionValue' . '\',\'' . 'enable-disable' . '\' );"', 'ref' => 'disable-action', 'title' => ts('Disable Mutliple Choice Option')), CRM_Core_Action::ENABLE => array('name' => ts('Enable'), 'extra' => 'onclick = "enableDisable( %%id%%,\'' . 'CRM_Core_BAO_OptionValue' . '\',\'' . 'disable-enable' . '\' );"', 'ref' => 'enable-action', 'title' => ts('Enable Mutliple Choice Option')), CRM_Core_Action::DELETE => array('name' => ts('Delete'), 'url' => 'civicrm/admin/custom/group/field/option', 'qs' => 'action=delete&id=%%id%%', 'title' => ts('Disable Multiple Choice Option'))); } return self::$_actionLinks; }
/** * wrapper for ajax option selector. * * @param array $params * Associated array for params record id. * * @return array * associated array of option list * -rp = rowcount * -page= offset */ public static function getOptionListSelector(&$params) { $options = array(); //get the default value from custom fields $customFieldBAO = new CRM_Core_BAO_CustomField(); $customFieldBAO->id = $params['fid']; if ($customFieldBAO->find(TRUE)) { $defaultValue = $customFieldBAO->default_value; $fieldHtmlType = $customFieldBAO->html_type; } else { CRM_Core_Error::fatal(); } $defVal = explode(CRM_Core_DAO::VALUE_SEPARATOR, substr($defaultValue, 1, -1)); // format the params $params['offset'] = ($params['page'] - 1) * $params['rp']; $params['rowCount'] = $params['rp']; $field = CRM_Core_BAO_CustomField::getFieldObject($params['fid']); // get the option group id $optionGroupID = $field->option_group_id; if (!$optionGroupID) { return $options; } $queryParams = array(1 => array($optionGroupID, 'Integer')); $total = "SELECT COUNT(*) FROM civicrm_option_value WHERE option_group_id = %1"; $params['total'] = CRM_Core_DAO::singleValueQuery($total, $queryParams); $limit = " LIMIT {$params['offset']}, {$params['rowCount']} "; $orderBy = ' ORDER BY options.weight asc'; $query = "SELECT * FROM civicrm_option_value as options WHERE option_group_id = %1 {$orderBy} {$limit}"; $dao = CRM_Core_DAO::executeQuery($query, $queryParams); $links = CRM_Custom_Page_Option::actionLinks(); $fields = array('id', 'label', 'value'); $config = CRM_Core_Config::singleton(); while ($dao->fetch()) { $options[$dao->id] = array(); foreach ($fields as $k) { $options[$dao->id][$k] = $dao->{$k}; } $action = array_sum(array_keys($links)); $class = 'crm-entity'; // update enable/disable links depending on custom_field properties. if ($dao->is_active) { $action -= CRM_Core_Action::ENABLE; } else { $class .= ' disabled'; $action -= CRM_Core_Action::DISABLE; } if ($fieldHtmlType == 'CheckBox' || $fieldHtmlType == 'AdvMulti-Select' || $fieldHtmlType == 'Multi-Select') { if (in_array($dao->value, $defVal)) { $options[$dao->id]['is_default'] = '<img src="' . $config->resourceBase . 'i/check.gif" />'; } else { $options[$dao->id]['is_default'] = ''; } } else { if ($defaultValue == $dao->value) { $options[$dao->id]['is_default'] = '<img src="' . $config->resourceBase . 'i/check.gif" />'; } else { $options[$dao->id]['is_default'] = ''; } } $options[$dao->id]['class'] = $dao->id . ',' . $class; $options[$dao->id]['is_active'] = !empty($dao->is_active) ? 'Yes' : 'No'; $options[$dao->id]['links'] = CRM_Core_Action::formLink($links, $action, array('id' => $dao->id, 'fid' => $params['fid'], 'gid' => $params['gid']), ts('more'), FALSE, 'customOption.row.actions', 'customOption', $dao->id); } return $options; }
/** * Browse all custom group fields. * * @param null * * @return void * @access public */ function browse() { $customOption = array(); $customOptionBAO =& new CRM_Core_BAO_CustomOption(); // fkey is fid //$customOptionBAO->custom_field_id = $this->_fid; $customOptionBAO->entity_id = $this->_fid; $customOptionBAO->entity_table = 'civicrm_custom_field'; $customOptionBAO->orderBy('weight, label'); $customOptionBAO->find(); //get the default value from custom fields $customFieldBAO =& new CRM_Core_BAO_CustomField(); $customFieldBAO->id = $this->_fid; $customFieldBAO->find(); while ($customFieldBAO->fetch()) { $defaultValue = $customFieldBAO->default_value; $fieldHtmlType = $customFieldBAO->html_type; } $defVal = explode(CRM_CORE_BAO_CUSTOMOPTION_VALUE_SEPERATOR, $defaultValue); while ($customOptionBAO->fetch()) { $customOption[$customOptionBAO->id] = array(); CRM_Core_DAO::storeValues($customOptionBAO, $customOption[$customOptionBAO->id]); $action = array_sum(array_keys($this->actionLinks())); // update enable/disable links depending on custom_field properties. if ($customOptionBAO->is_active) { $action -= CRM_CORE_ACTION_ENABLE; } else { $action -= CRM_CORE_ACTION_DISABLE; } if ($fieldHtmlType == 'CheckBox' || $fieldHtmlType == 'Multi-Select') { if (in_array($customOptionBAO->value, $defVal)) { $customOption[$customOptionBAO->id]['default_value'] = '[x]'; } else { $customOption[$customOptionBAO->id]['default_value'] = ''; } } else { if ($defaultValue == $customOptionBAO->value) { $customOption[$customOptionBAO->id]['default_value'] = '[x]'; } else { $customOption[$customOptionBAO->id]['default_value'] = ''; } } $customOption[$customOptionBAO->id]['action'] = CRM_Core_Action::formLink(CRM_Custom_Page_Option::actionLinks(), $action, array('id' => $customOptionBAO->id, 'fid' => $this->_fid, 'gid' => $this->_gid)); } $this->assign('customOption', $customOption); }