/** * @return array */ public function checkOptionGroupValues() { $messages = array(); $problemValues = array(); $optionGroups = civicrm_api3('OptionGroup', 'get', array('sequential' => 1, 'data_type' => array('IS NOT NULL' => 1), 'options' => array('limit' => 0))); if ($optionGroups['count'] > 0) { foreach ($optionGroups['values'] as $optionGroup) { $values = CRM_Core_BAO_OptionValue::getOptionValuesArray($optionGroup['id']); if (count($values) > 0) { foreach ($values as $value) { $validate = CRM_Utils_Type::validate($value['value'], $optionGroup['data_type'], FALSE); if (!$validate) { $problemValues[] = array('group_name' => $optionGroup['title'], 'value_name' => $value['label']); } } } } } if (!empty($problemValues)) { $strings = ''; foreach ($problemValues as $problemValue) { $strings .= ts('<tr><td> "%1" </td><td> "%2" </td></tr>', array(1 => $problemValue['group_name'], 2 => $problemValue['value_name'])); } $messages[] = new CRM_Utils_Check_Message(__FUNCTION__, ts('The Following Option Values contain value fields that do not match the Data Type of the Option Group</p> <p><table><tbody><th>Option Group</th><th>Option Value</th></tbody><tbody>') . $strings . ts('</tbody></table></p>'), ts('Option Values with problematic Values'), \Psr\Log\LogLevel::NOTICE, 'fa-server'); } return $messages; }
/** * Returns all active options ordered by weight for a given field * * @param int $fieldId field whose options are needed * @param boolean $inactiveNeeded do we need inactive options ? * * @return array $customOption all active options for fieldId * @static */ static function getCustomOption($fieldID, $inactiveNeeded = FALSE) { $options = array(); if (!$fieldID) { return $options; } $field = CRM_Core_BAO_CustomField::getFieldObject($fieldID); // get the option group id $optionGroupID = $field->option_group_id; if (!$optionGroupID) { return $options; } $optionValues = CRM_Core_BAO_OptionValue::getOptionValuesArray($optionGroupID); foreach ($optionValues as $id => $value) { if (!$inactiveNeeded && empty($value['is_active'])) { continue; } $options[$id] = array(); $options[$id]['id'] = $id; $options[$id]['label'] = $value['label']; $options[$id]['value'] = $value['value']; } CRM_Utils_Hook::customFieldOptions($fieldID, $options, TRUE); return $options; }
function buildQuickForm() { $this->addButtons(array(array('type' => 'next', 'name' => ts('Save'), 'isDefault' => TRUE), array('type' => 'cancel', 'name' => ts('Cancel')))); $optionGroupId = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_OptionGroup', 'hrjc_hours_type', 'id', 'name'); $optionGroupIds = CRM_Core_BAO_OptionValue::getOptionValuesArray($optionGroupId); foreach ($optionGroupIds as $key => $value) { $this->_optionValue[$value['value']] = $value['label']; $this->_id[$key] = $value['value']; } $this->assign('optionGroupIds', $optionGroupIds); $this->addElement('select', 'hour_type_select', ts('Select Hour Type'), array('' => ts('- select -')) + $this->_optionValue); $this->add('text', 'hour_value', ts('Value')); $this->addFormRule(array('CRM_Hrjobcontract_Form_EditHourOption', 'formRule'), $this); }