コード例 #1
0
 /**
  * Takes a bunch of params that are needed to match certain criteria and
  * retrieves the relevant objects. Typically the valid params are only
  * contact_id. We'll tweak this function to be more full featured over a period
  * of time. This is the inverse function of create. It also stores all the retrieved
  * values in the default array
  *
  * @param array $params   (reference ) an assoc array of name/value pairs
  * @param array $defaults (reference ) an assoc array to hold the flattened values
  *
  * @return object CRM_Core_BAO_CustomOption object
  * @access public
  * @static
  */
 static function retrieve(&$params, &$defaults)
 {
     $customOption = new CRM_Core_DAO_OptionValue();
     $customOption->copyValues($params);
     if ($customOption->find(TRUE)) {
         CRM_Core_DAO::storeValues($customOption, $defaults);
         return $customOption;
     }
     return NULL;
 }
コード例 #2
0
ファイル: CustomOption.php プロジェクト: bhirsch/voipdev
 /**
  * Takes a bunch of params that are needed to match certain criteria and
  * retrieves the relevant objects. Typically the valid params are only
  * contact_id. We'll tweak this function to be more full featured over a period
  * of time. This is the inverse function of create. It also stores all the retrieved
  * values in the default array
  *
  * @param array $params   (reference ) an assoc array of name/value pairs
  * @param array $defaults (reference ) an assoc array to hold the flattened values
  *
  * @return object CRM_Core_BAO_CustomOption object
  * @access public
  * @static
  */
 static function retrieve(&$params, &$defaults)
 {
     require_once 'CRM/Core/DAO/OptionValue.php';
     $customOption = new CRM_Core_DAO_OptionValue();
     $customOption->copyValues($params);
     if ($customOption->find(true)) {
         CRM_Core_DAO::storeValues($customOption, $defaults);
         return $customOption;
     }
     return null;
 }
コード例 #3
0
ファイル: OptionValue.php プロジェクト: kidaa30/yes
 /**
  * Add an Option Value.
  *
  * @param array $params
  *   Reference array contains the values submitted by the form.
  * @param array $ids
  *   Reference array contains the id.
  *
  *
  * @return CRM_Core_DAO_OptionValue
  */
 public static function add(&$params, &$ids)
 {
     // CRM-10921: do not reset attributes to default if this is an update
     //@todo consider if defaults are being set in the right place. 'dumb' defaults like
     // these would be usefully set @ the api layer so they are visible to api users
     // complex defaults like the domain id below would make sense in the setDefauls function
     // but unclear what other ways this function is being used
     if (empty($ids['optionValue'])) {
         $params['is_active'] = CRM_Utils_Array::value('is_active', $params, FALSE);
         $params['is_default'] = CRM_Utils_Array::value('is_default', $params, FALSE);
         $params['is_optgroup'] = CRM_Utils_Array::value('is_optgroup', $params, FALSE);
         $params['filter'] = CRM_Utils_Array::value('filter', $params, FALSE);
     }
     // action is taken depending upon the mode
     $optionValue = new CRM_Core_DAO_OptionValue();
     $optionValue->copyValues($params);
     if (!empty($params['is_default'])) {
         $query = 'UPDATE civicrm_option_value SET is_default = 0 WHERE  option_group_id = %1';
         // tweak default reset, and allow multiple default within group.
         if ($resetDefaultFor = CRM_Utils_Array::value('reset_default_for', $params)) {
             if (is_array($resetDefaultFor)) {
                 $colName = key($resetDefaultFor);
                 $colVal = $resetDefaultFor[$colName];
                 $query .= " AND ( {$colName} IN (  {$colVal} ) )";
             }
         }
         $p = array(1 => array($params['option_group_id'], 'Integer'));
         CRM_Core_DAO::executeQuery($query, $p);
     }
     // CRM-13814 : evalute option group id
     if (!array_key_exists('option_group_id', $params) && !empty($ids['optionValue'])) {
         $groupId = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_OptionValue', $ids['optionValue'], 'option_group_id', 'id');
     } else {
         $groupId = $params['option_group_id'];
     }
     $groupName = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_OptionGroup', $groupId, 'name', 'id');
     if (in_array($groupName, CRM_Core_OptionGroup::$_domainIDGroups)) {
         $optionValue->domain_id = CRM_Utils_Array::value('domain_id', $params, CRM_Core_Config::domainID());
     }
     $optionValue->id = CRM_Utils_Array::value('optionValue', $ids);
     $optionValue->save();
     CRM_Core_PseudoConstant::flush();
     return $optionValue;
 }
コード例 #4
0
ファイル: PdfFormat.php プロジェクト: kidaa30/yes
 /**
  * Retrieve DB object based on input parameters.
  *
  * It also stores all the retrieved values in the default array.
  *
  * @param array $params
  *   (reference ) an assoc array of name/value pairs.
  * @param array $values
  *   (reference ) an assoc array to hold the flattened values.
  *
  * @return CRM_Core_DAO_OptionValue
  */
 public static function retrieve(&$params, &$values)
 {
     $optionValue = new CRM_Core_DAO_OptionValue();
     $optionValue->copyValues($params);
     $optionValue->option_group_id = self::_getGid();
     if ($optionValue->find(TRUE)) {
         // Extract fields that have been serialized in the 'value' column of the Option Value table.
         $values = json_decode($optionValue->value, TRUE);
         // Add any new fields that don't yet exist in the saved values.
         foreach (self::$optionValueFields as $name => $field) {
             if (!isset($values[$name])) {
                 $values[$name] = $field['default'];
                 if (isset($field['metric']) && $field['metric']) {
                     $values[$name] = CRM_Utils_PDF_Utils::convertMetric($field['default'], self::$optionValueFields['metric']['default'], $values['metric'], 3);
                 }
             }
         }
         // Add fields from the OptionValue base class
         CRM_Core_DAO::storeValues($optionValue, $values);
         return $optionValue;
     }
     return NULL;
 }
コード例 #5
0
ファイル: Step3.php プロジェクト: prashantgajare/civicrm-core
 /**
  * This function preserve the civicrm_domain.email_name and civicrm_domain.email_address
  * as a default option value into "from_email_address" option group
  * and drop these columns from civicrm_domain table.
  * @access public
  *
  * @return void
  */
 function upgradeDomainFromEmail()
 {
     $query = "\nSELECT id\n  FROM civicrm_option_group\n WHERE name = 'from_Email_address'";
     $fmaGroup = CRM_Core_DAO::executeQuery($query, CRM_Core_DAO::$_nullArray);
     $fmaGroupId = NULL;
     if ($fmaGroup->fetch()) {
         $fmaGroupId = $fmaGroup->id;
     } else {
         //insert 'from_mailing_address' option group.
         $query = "\nINSERT INTO civicrm_option_group ( name, description, is_reserved, is_active )\nVALUES ('from_email_address', 'From Email Address', 0, 1)";
         CRM_Core_DAO::executeQuery($query, CRM_Core_DAO::$_nullArray);
         //get the group id.
         $query = "\nSELECT id\n  FROM civicrm_option_group\n WHERE name = 'from_email_address'";
         $dao = CRM_Core_DAO::executeQuery($query, CRM_Core_DAO::$_nullArray);
         if ($dao->fetch()) {
             $fmaGroupId = $dao->id;
         }
     }
     if ($fmaGroupId) {
         //get domain from email address and name as default value.
         $domain = CRM_Core_BAO_Domain::getDomain();
         $domain->selectAdd();
         $domain->selectAdd('email_name', 'email_address');
         $domain->find(TRUE);
         $formEmailAddress = '"' . $domain->email_name . '"<' . $domain->email_address . '>';
         //first check given domain email address exist in option
         //value, if yes make it as domain email address by making
         //it as default from email address..
         //get the existing from email address.
         $optionValues = array();
         $grpParams['name'] = 'from_email_address';
         CRM_Core_OptionValue::getValues($grpParams, $optionValues);
         $maxVal = $maxWt = 1;
         $insertEmailAddress = TRUE;
         if (!empty($optionValues)) {
             //make existing is_default = 0
             $query = "\nUPDATE  civicrm_option_value\n   SET  is_default = 0\n WHERE  option_group_id = %1";
             $params = array(1 => array($fmaGroupId, 'Integer'));
             CRM_Core_DAO::executeQuery($query, $params);
             //if domain from name and email exist as name or label in option value
             //table need to preserve that name and label  and take care that label
             //and name both remain unique in db.
             $labelValues = $nameValues = array();
             foreach ($optionValues as $id => $value) {
                 if ($value['label'] == $formEmailAddress) {
                     $labelValues = $value;
                 } elseif ($value['name'] == $formEmailAddress) {
                     $nameValues = $value;
                 }
             }
             //as we consider label so label should preserve.
             $updateValues = array();
             if (!empty($labelValues)) {
                 $updateValues = $labelValues;
             }
             //if matching name found need to preserve it.
             if (!empty($nameValues)) {
                 //copy domain from email address as label.
                 if (empty($updateValues)) {
                     $updateValues = $nameValues;
                     $updateValues['label'] = $formEmailAddress;
                 } else {
                     //since name is also imp so preserve it
                     //as name for domain email address record.
                     $updateValues['name'] = $nameValues['name'];
                     //name is unique so drop name value record.
                     //since we transfer this name to found label record.
                     CRM_Core_BAO_OptionValue::del($nameValues['id']);
                 }
             }
             if (!empty($updateValues)) {
                 $insertEmailAddress = FALSE;
                 //update label/name found record w/ manupulated values.
                 $updateValues['is_active'] = $updateValues['is_default'] = 1;
                 $optionValue = new CRM_Core_DAO_OptionValue();
                 $optionValue->copyValues($updateValues);
                 $optionValue->save();
             }
             //get the max value and wt.
             if ($insertEmailAddress) {
                 $query = "\nSELECT   max(ROUND(civicrm_option_value.value)) as maxVal,\n         max(civicrm_option_value.weight) as maxWt\n    FROM civicrm_option_value, civicrm_option_group\n   WHERE civicrm_option_group.name = 'from_Email_address'\n     AND civicrm_option_value.option_group_id = civicrm_option_group.id\nGROUP BY civicrm_option_group.id";
                 $dao = CRM_Core_DAO::executeQuery($query, CRM_Core_DAO::$_nullArray);
                 if ($dao->fetch()) {
                     $maxWt += $dao->maxWt;
                     $maxVal += $dao->maxVal;
                 }
             }
         }
         if ($insertEmailAddress) {
             //insert domain from email address and name.
             $query = "\nINSERT INTO  `civicrm_option_value`\n             (`option_group_id`, `label`, `value`, `name` , `grouping`, `filter`, `is_default`,\n              `weight`, `description`, `is_optgroup`, `is_reserved`, `is_active`, `component_id`)\n     VALUES  ( %1, %2, %3, %2, NULL, 0, 1, %4, 'Default domain email address and from name.', 0, 0, 1, NULL)";
             $params = array(1 => array($fmaGroupId, 'Integer'), 2 => array($formEmailAddress, 'String'), 3 => array($maxVal, 'Integer'), 4 => array($maxWt, 'Integer'));
             CRM_Core_DAO::executeQuery($query, $params);
         }
         //drop civicrm_domain.email_name and
         //civicrm_domain.email_address.
         $query = "\nALTER TABLE `civicrm_domain`\n       DROP `email_name`,\n       DROP `email_address`";
         CRM_Core_DAO::executeQuery($query, CRM_Core_DAO::$_nullArray);
     }
 }
コード例 #6
0
 /**
  * Function to add an Option Value
  *
  * @param array $params reference array contains the values submitted by the form
  * @param array $ids    reference array contains the id
  *
  * @access public
  * @static
  *
  * @return object
  */
 static function add(&$params, &$ids)
 {
     $params['is_active'] = CRM_Utils_Array::value('is_active', $params, FALSE);
     $params['is_default'] = CRM_Utils_Array::value('is_default', $params, FALSE);
     $params['is_optgroup'] = CRM_Utils_Array::value('is_optgroup', $params, FALSE);
     $params['filter'] = CRM_Utils_Array::value('filter', $params, FALSE);
     // action is taken depending upon the mode
     $optionValue = new CRM_Core_DAO_OptionValue();
     $optionValue->copyValues($params);
     if (CRM_Utils_Array::value('is_default', $params)) {
         $query = 'UPDATE civicrm_option_value SET is_default = 0 WHERE  option_group_id = %1';
         // tweak default reset, and allow multiple default within group.
         if ($resetDefaultFor = CRM_Utils_Array::value('reset_default_for', $params)) {
             if (is_array($resetDefaultFor)) {
                 $colName = key($resetDefaultFor);
                 $colVal = $resetDefaultFor[$colName];
                 $query .= " AND ( {$colName} IN (  {$colVal} ) )";
             }
         }
         $p = array(1 => array($params['option_group_id'], 'Integer'));
         CRM_Core_DAO::executeQuery($query, $p);
     }
     $groupName = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_OptionGroup', $params['option_group_id'], 'name', 'id');
     if (in_array($groupName, CRM_Core_OptionGroup::$_domainIDGroups)) {
         $optionValue->domain_id = CRM_Core_Config::domainID();
     }
     $optionValue->id = CRM_Utils_Array::value('optionValue', $ids);
     $optionValue->save();
     return $optionValue;
 }