Exemplo n.º 1
0
 public function createEntry($id, $key)
 {
     $e = self::$_extensions;
     $ids = array();
     $groupId = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_OptionGroup', self::OPTION_GROUP_NAME, 'id', 'name');
     $params = array('option_group_id' => $groupId, 'weight' => CRM_Utils_Weight::getDefaultWeight('CRM_Core_DAO_OptionValue', array('option_group_id' => $groupId)), 'label' => $e['per_id'][$id]['label'], 'name' => $e['per_id'][$id]['label'], 'value' => $key, 'grouping' => $e['per_id'][$id]['type'], 'is_active' => 1);
     $optionValue = CRM_Core_BAO_OptionValue::add($params, $ids);
 }
Exemplo n.º 2
0
 public function install()
 {
     if (array_key_exists($this->ext->key, $this->customSearches)) {
         CRM_Core_Error::fatal('This custom search is already registered.');
     }
     $weight = CRM_Utils_Weight::getDefaultWeight('CRM_Core_DAO_OptionValue', array('option_group_id' => $this->groupId));
     $params = array('option_group_id' => $this->groupId, 'weight' => $weight, 'description' => $this->ext->label . ' (' . $this->ext->key . ')', 'name' => $this->ext->key, 'value' => max($this->customSearches) + 1, 'label' => $this->ext->key, 'is_active' => 1);
     $ids = array();
     $optionValue = CRM_Core_BAO_OptionValue::add($params, $ids);
 }
Exemplo n.º 3
0
 /**
  * Create option value - note that the create function calls 'add' but
  * has more business logic
  *
  * @param array $params
  *   Input parameters.
  *
  * @return object
  */
 public static function create($params)
 {
     if (empty($params['id'])) {
         self::setDefaults($params);
     }
     $ids = array();
     if (!empty($params['id'])) {
         $ids = array('optionValue' => $params['id']);
     }
     return CRM_Core_BAO_OptionValue::add($params, $ids);
 }
Exemplo n.º 4
0
 /**
  * @param CRM_Extension_Info $info
  *
  * @return bool
  * @throws Exception
  */
 public function onPreInstall(CRM_Extension_Info $info)
 {
     $customSearchesByName = $this->getCustomSearchesByName();
     if (array_key_exists($info->key, $customSearchesByName)) {
         CRM_Core_Error::fatal('This custom search is already registered.');
     }
     $weight = CRM_Utils_Weight::getDefaultWeight('CRM_Core_DAO_OptionValue', array('option_group_id' => $this->groupId));
     $params = array('option_group_id' => $this->groupId, 'weight' => $weight, 'description' => $info->label . ' (' . $info->key . ')', 'name' => $info->key, 'value' => max($customSearchesByName) + 1, 'label' => $info->key, 'is_active' => 1);
     $ids = array();
     $optionValue = CRM_Core_BAO_OptionValue::add($params, $ids);
     return $optionValue ? TRUE : FALSE;
 }
Exemplo n.º 5
0
 public function install()
 {
     if (array_key_exists($this->ext->key, $this->customReports)) {
         CRM_Core_Error::fatal('This report is already registered.');
     }
     if ($this->ext->typeInfo['component'] === 'Contact') {
         $compId = 'null';
     } else {
         $comp = CRM_Core_Component::get($this->ext->typeInfo['component']);
         $compId = $comp->componentID;
     }
     if (empty($compId)) {
         CRM_Core_Error::fatal("Component for which you're trying to install the extension (" . $this->ext->typeInfo['component'] . ") is currently disabled.");
     }
     $weight = CRM_Utils_Weight::getDefaultWeight('CRM_Core_DAO_OptionValue', array('option_group_id' => $this->groupId));
     $ids = array();
     $params = array('label' => $this->ext->label . ' (' . $this->ext->key . ')', 'value' => $this->ext->typeInfo['reportUrl'], 'name' => $this->ext->key, 'weight' => $weight, 'description' => $this->ext->label . ' (' . $this->ext->key . ')', 'component_id' => $compId, 'option_group_id' => $this->groupId, 'is_active' => 1);
     $optionValue = CRM_Core_BAO_OptionValue::add($params, $ids);
 }
/**
 *  Add a OptionValue. OptionValues are used to classify CRM entities (including Contacts, Groups and Actions).
 *
 * Allowed @params array keys are:
 *
 * {@example OptionValueCreate.php}
 *
 * @return array of newly created option_value property values.
 * {@getfields OptionValue_create}
 * @access public
 */
function civicrm_api3_option_value_create($params)
{
    $weight = 0;
    if (!array_key_exists('label', $params) && array_key_exists('name', $params)) {
        // no idea why that's a "mandatory" field
        $params['label'] = $params['name'];
    }
    if (!CRM_Utils_Array::value('value', $params) && array_key_exists('option_group_id', $params)) {
        require_once 'CRM/Utils/Weight.php';
        $fieldValues = array('option_group_id' => $params['option_group_id']);
        // use the next available value
        /* CONVERT(value, DECIMAL) is used to convert varchar
           field 'value' to decimal->integer                    */
        $params['value'] = (int) CRM_Utils_Weight::getDefaultWeight('CRM_Core_DAO_OptionValue', $fieldValues, 'CONVERT(value, DECIMAL)');
        $weight = $params['value'];
    }
    if (!array_key_exists('weight', $params) && array_key_exists('value', $params)) {
        // no idea why that's a "mandatory" field
        $params['weight'] = $params['value'];
    } elseif (array_key_exists('weight', $params) && $params['weight'] == 'next') {
        // weight is numeric, so it's safe-ish to treat symbol 'next' as magical value
        $params['weight'] = CRM_Utils_Weight::getDefaultWeight('CRM_Core_DAO_OptionValue', array('option_group_id' => $params['option_group_id']));
    }
    if (array_key_exists('component', $params)) {
        if (empty($params['component'])) {
            $params['component_id'] = '';
        } else {
            $params['component_id'] = array_search($params['component'], CRM_Core_PseudoConstant::component());
        }
        unset($params['component']);
    }
    if (CRM_Utils_Array::value('id', $params)) {
        $ids = array('optionValue' => $params['id']);
    }
    $optionValueBAO = CRM_Core_BAO_OptionValue::add($params, $ids);
    civicrm_api('option_value', 'getfields', array('version' => 3, 'cache_clear' => 1));
    $values = array();
    _civicrm_api3_object_to_array($optionValueBAO, $values[$optionValueBAO->id]);
    return civicrm_api3_create_success($values, $params);
}
Exemplo n.º 7
0
 /**
  * Add/edit option-value of a particular group
  *
  * @param array $params
  *   Array containing exported values from the invoking form.
  * @param array $groupParams
  *   Array containing group fields whose option-values is to retrieved/saved.
  * @param $action
  * @param int $optionValueID Has the id of the optionValue being edited, disabled ..etc.
  *   Has the id of the optionValue being edited, disabled ..etc.
  *
  * @return CRM_Core_DAO_OptionValue
  *
  */
 public static function addOptionValue(&$params, &$groupParams, &$action, &$optionValueID)
 {
     $ids = array();
     $params['is_active'] = CRM_Utils_Array::value('is_active', $params, FALSE);
     // checking if the group name with the given id or name (in $groupParams) exists
     if (!empty($groupParams)) {
         $config = CRM_Core_Config::singleton();
         $groupParams['is_active'] = 1;
         $optionGroup = CRM_Core_BAO_OptionGroup::retrieve($groupParams, $defaults);
     }
     // if the corresponding group doesn't exist, create one, provided $groupParams has 'name' in it.
     if (!$optionGroup->id) {
         if ($groupParams['name']) {
             $newOptionGroup = CRM_Core_BAO_OptionGroup::add($groupParams, $defaults);
             $params['weight'] = 1;
             $optionGroupID = $newOptionGroup->id;
         }
     } else {
         $optionGroupID = $optionGroup->id;
         $oldWeight = NULL;
         if ($optionValueID) {
             $oldWeight = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_OptionValue', $optionValueID, 'weight', 'id');
         }
         $fieldValues = array('option_group_id' => $optionGroupID);
         $params['weight'] = CRM_Utils_Weight::updateOtherWeights('CRM_Core_DAO_OptionValue', $oldWeight, CRM_Utils_Array::value('weight', $params), $fieldValues);
     }
     $params['option_group_id'] = $optionGroupID;
     if ($action & CRM_Core_Action::ADD && empty($params['value'])) {
         $fieldValues = array('option_group_id' => $optionGroupID);
         // use the next available value
         /* CONVERT(value, DECIMAL) is used to convert varchar
            field 'value' to decimal->integer                    */
         $params['value'] = (int) CRM_Utils_Weight::getDefaultWeight('CRM_Core_DAO_OptionValue', $fieldValues, 'CONVERT(value, DECIMAL)');
     }
     if (!$params['label'] && $params['name']) {
         $params['label'] = $params['name'];
     }
     // set name to label if it's not set - but *only* for ADD action (CRM-3522)
     if ($action & CRM_Core_Action::ADD && empty($params['name']) && $params['label']) {
         $params['name'] = $params['label'];
     }
     if ($action & CRM_Core_Action::UPDATE) {
         $ids['optionValue'] = $optionValueID;
     }
     $optionValue = CRM_Core_BAO_OptionValue::add($params, $ids);
     return $optionValue;
 }
Exemplo n.º 8
0
 private function _createExtensionEntry()
 {
     $groupId = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_OptionGroup', self::OPTION_GROUP_NAME, 'id', 'name');
     $weight = CRM_Utils_Weight::getDefaultWeight('CRM_Core_DAO_OptionValue', array('option_group_id' => $groupId));
     $params = array('option_group_id' => $groupId, 'weight' => $weight, 'label' => $this->label, 'name' => $this->name, 'value' => $this->key, 'grouping' => $this->type, 'description' => $this->file, 'is_active' => 1);
     $ids = array();
     $optionValue = CRM_Core_BAO_OptionValue::add($params, $ids);
 }
Exemplo n.º 9
0
 /**
  * Function to process the form
  *
  * @access public
  * @return None
  */
 public function postProcess()
 {
     $params = $this->exportValues();
     require_once 'CRM/Core/BAO/OptionValue.php';
     if ($this->_action & CRM_Core_Action::DELETE) {
         CRM_Core_BAO_OptionValue::del($this->_id);
         CRM_Core_Session::setStatus(ts('Selected option value has been deleted.'));
     } else {
         $params = $ids = array();
         // store the submitted values in an array
         $params = $this->exportValues();
         $params['option_group_id'] = $this->_gid;
         if ($this->_action & CRM_Core_Action::UPDATE) {
             $ids['optionValue'] = $this->_id;
         }
         //set defaultGreeting option in params to save default value as per contactOption-defaultValue mapping
         if (CRM_Utils_Array::value('contactOptions', $params)) {
             $params['filter'] = CRM_Utils_Array::value('contactOptions', $params);
             $params['defaultGreeting'] = 1;
         }
         $optionValue = CRM_Core_BAO_OptionValue::add($params, $ids);
         CRM_Core_Session::setStatus(ts('The Option Value \'%1\' has been saved.', array(1 => $optionValue->label)));
     }
 }
Exemplo n.º 10
0
 /**
  * Function to process the form
  *
  * @access public
  *
  * @return None
  */
 public function postProcess()
 {
     CRM_Utils_System::flushCache();
     $params = $this->exportValues();
     if ($this->_action & CRM_Core_Action::DELETE) {
         CRM_Core_BAO_OptionValue::del($this->_id);
         CRM_Core_Session::setStatus(ts('Selected option value has been deleted.'), ts('Record Deleted'), 'success');
     } else {
         $params = $ids = array();
         // store the submitted values in an array
         $params = $this->exportValues();
         $params['option_group_id'] = $this->_gid;
         if ($this->_action & CRM_Core_Action::UPDATE) {
             $ids['optionValue'] = $this->_id;
         }
         //set defaultGreeting option in params to save default value as per contactOption-defaultValue mapping
         if (CRM_Utils_Array::value('contactOptions', $params)) {
             $params['filter'] = CRM_Utils_Array::value('contactOptions', $params);
             $params['defaultGreeting'] = 1;
         }
         $optionValue = CRM_Core_BAO_OptionValue::add($params, $ids);
         // CRM-11516
         if (CRM_Utils_Array::value('financial_account_id', $params)) {
             $relationTypeId = key(CRM_Core_PseudoConstant::accountOptionValues('account_relationship', NULL, " AND v.name LIKE 'Asset Account is' "));
             $params = array('entity_table' => 'civicrm_option_value', 'entity_id' => $optionValue->id, 'account_relationship' => $relationTypeId, 'financial_account_id' => $params['financial_account_id']);
             CRM_Financial_BAO_FinancialTypeAccount::add($params);
         }
         CRM_Core_Session::setStatus(ts('The Option Value \'%1\' has been saved.', array(1 => $optionValue->label)), ts('Saved'), 'success');
     }
 }