当前位置: 首页>>代码示例>>PHP>>正文


PHP CRM_Core_DAO_OptionValue类代码示例

本文整理汇总了PHP中CRM_Core_DAO_OptionValue的典型用法代码示例。如果您正苦于以下问题:PHP CRM_Core_DAO_OptionValue类的具体用法?PHP CRM_Core_DAO_OptionValue怎么用?PHP CRM_Core_DAO_OptionValue使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了CRM_Core_DAO_OptionValue类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: deleteEntry

 public function deleteEntry($id, $key)
 {
     $e = self::$_extensions;
     if ($e['per_id'][$id]['status'] === 'enabled') {
         require_once 'CRM/Core/DAO/OptionValue.php';
         $optionValue = new CRM_Core_DAO_OptionValue();
         $optionValue->id = $id;
         return $optionValue->delete();
     }
     return false;
 }
开发者ID:hampelm,项目名称:Ginsberg-CiviDemo,代码行数:11,代码来源:ExtensionType.php

示例2: create

 /**
  * Takes an associative array and creates a custom field object.
  *
  * This function is invoked from within the web form layer and also from the api layer
  *
  * @param array $params
  *   (reference) an assoc array of name/value pairs.
  *
  * @return CRM_Core_DAO_CustomField
  */
 public static function create(&$params)
 {
     $origParams = array_merge(array(), $params);
     if (!isset($params['id'])) {
         if (!isset($params['column_name'])) {
             // if add mode & column_name not present, calculate it.
             $params['column_name'] = strtolower(CRM_Utils_String::munge($params['label'], '_', 32));
         }
         if (!isset($params['name'])) {
             $params['name'] = CRM_Utils_String::munge($params['label'], '_', 64);
         }
     } else {
         $params['column_name'] = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_CustomField', $params['id'], 'column_name');
     }
     $columnName = $params['column_name'];
     $indexExist = FALSE;
     //as during create if field is_searchable we had created index.
     if (!empty($params['id'])) {
         $indexExist = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_CustomField', $params['id'], 'is_searchable');
     }
     switch (CRM_Utils_Array::value('html_type', $params)) {
         case 'Select Date':
             if (empty($params['date_format'])) {
                 $config = CRM_Core_Config::singleton();
                 $params['date_format'] = $config->dateInputFormat;
             }
             break;
         case 'CheckBox':
         case 'AdvMulti-Select':
         case 'Multi-Select':
             if (isset($params['default_checkbox_option'])) {
                 $tempArray = array_keys($params['default_checkbox_option']);
                 $defaultArray = array();
                 foreach ($tempArray as $k => $v) {
                     if ($params['option_value'][$v]) {
                         $defaultArray[] = $params['option_value'][$v];
                     }
                 }
                 if (!empty($defaultArray)) {
                     // also add the separator before and after the value per new convention (CRM-1604)
                     $params['default_value'] = CRM_Core_DAO::VALUE_SEPARATOR . implode(CRM_Core_DAO::VALUE_SEPARATOR, $defaultArray) . CRM_Core_DAO::VALUE_SEPARATOR;
                 }
             } else {
                 if (!empty($params['default_option']) && isset($params['option_value'][$params['default_option']])) {
                     $params['default_value'] = $params['option_value'][$params['default_option']];
                 }
             }
             break;
     }
     $transaction = new CRM_Core_Transaction();
     // create any option group & values if required
     if ($params['html_type'] != 'Text' && in_array($params['data_type'], array('String', 'Int', 'Float', 'Money'))) {
         $tableName = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_CustomGroup', $params['custom_group_id'], 'table_name');
         //CRM-16659: if option_value then create an option group for this custom field.
         if ($params['option_type'] == 1 && (empty($params['option_group_id']) || !empty($params['option_value']))) {
             // first create an option group for this custom group
             $optionGroup = new CRM_Core_DAO_OptionGroup();
             $optionGroup->name = "{$columnName}_" . date('YmdHis');
             $optionGroup->title = $params['label'];
             $optionGroup->is_active = 1;
             $optionGroup->save();
             $params['option_group_id'] = $optionGroup->id;
             if (!empty($params['option_value']) && is_array($params['option_value'])) {
                 foreach ($params['option_value'] as $k => $v) {
                     if (strlen(trim($v))) {
                         $optionValue = new CRM_Core_DAO_OptionValue();
                         $optionValue->option_group_id = $optionGroup->id;
                         $optionValue->label = $params['option_label'][$k];
                         $optionValue->name = CRM_Utils_String::titleToVar($params['option_label'][$k]);
                         switch ($params['data_type']) {
                             case 'Money':
                                 $optionValue->value = CRM_Utils_Rule::cleanMoney($v);
                                 break;
                             case 'Int':
                                 $optionValue->value = intval($v);
                                 break;
                             case 'Float':
                                 $optionValue->value = floatval($v);
                                 break;
                             default:
                                 $optionValue->value = trim($v);
                         }
                         $optionValue->weight = $params['option_weight'][$k];
                         $optionValue->is_active = CRM_Utils_Array::value($k, $params['option_status'], FALSE);
                         $optionValue->save();
                     }
                 }
             }
         }
     }
//.........这里部分代码省略.........
开发者ID:Hack4Eugene,项目名称:Hack4Cause2016,代码行数:101,代码来源:CustomField.php

示例3: removeLegacyRegisteredReport

 /**  Remove all the report that registerd on GiftAid 1.0beta and 2.0beta
  **/
 static function removeLegacyRegisteredReport()
 {
     $reportClass = new CRM_Core_DAO_OptionValue();
     $reportClass->option_group_id = self::getReportTemplateGroupId();
     $reportClass->name = 'GiftAid_Report_Form_Contribute_GiftAid';
     if ($reportClass->find(TRUE)) {
         $reportClass->delete();
     }
 }
开发者ID:nishant-bhorodia,项目名称:uk.co.compucorp.civicrm.giftaid,代码行数:11,代码来源:Upgrader.php

示例4: updateCustomValues

 static function updateCustomValues($params)
 {
     $optionDAO = new CRM_Core_DAO_OptionValue();
     $optionDAO->id = $params['optionId'];
     $optionDAO->find(TRUE);
     $oldValue = $optionDAO->value;
     // get the table, column, html_type and data type for this field
     $query = "\nSELECT g.table_name  as tableName ,\n       f.column_name as columnName,\n       f.data_type   as dataType,\n       f.html_type   as htmlType\nFROM   civicrm_custom_group g,\n       civicrm_custom_field f\nWHERE  f.custom_group_id = g.id\n  AND  f.id = %1";
     $queryParams = array(1 => array($params['fieldId'], 'Integer'));
     $dao = CRM_Core_DAO::executeQuery($query, $queryParams);
     if ($dao->fetch()) {
         if ($dao->dataType == 'Money') {
             $params['value'] = CRM_Utils_Rule::cleanMoney($params['value']);
         }
         switch ($dao->htmlType) {
             case 'Autocomplete-Select':
             case 'Select':
             case 'Radio':
                 $query = "\nUPDATE {$dao->tableName}\nSET    {$dao->columnName} = %1\nWHERE  id = %2";
                 if ($dao->dataType == 'Auto-complete') {
                     $dataType = "String";
                 } else {
                     $dataType = $dao->dataType;
                 }
                 $queryParams = array(1 => array($params['value'], $dataType), 2 => array($params['optionId'], 'Integer'));
                 break;
             case 'AdvMulti-Select':
             case 'Multi-Select':
             case 'CheckBox':
                 $oldString = CRM_Core_DAO::VALUE_SEPARATOR . $oldValue . CRM_Core_DAO::VALUE_SEPARATOR;
                 $newString = CRM_Core_DAO::VALUE_SEPARATOR . $params['value'] . CRM_Core_DAO::VALUE_SEPARATOR;
                 $query = "\nUPDATE {$dao->tableName}\nSET    {$dao->columnName} = REPLACE( {$dao->columnName}, %1, %2 )";
                 $queryParams = array(1 => array($oldString, 'String'), 2 => array($newString, 'String'));
                 break;
             default:
                 CRM_Core_Error::fatal();
         }
         $dao = CRM_Core_DAO::executeQuery($query, $queryParams);
     }
 }
开发者ID:archcidburnziso,项目名称:civicrm-core,代码行数:40,代码来源:CustomOption.php

示例5: getOptionValuesArray

 /**
  * Get the values of all option values given an option group ID. Store in system cache
  * Does not take any filtering arguments. The object is to avoid hitting the DB and retrieve
  * from memory
  *
  * @param int $optionGroupID
  *   The option group for which we want the values from.
  *
  * @return array
  *   an array of array of values for this option group
  */
 public static function getOptionValuesArray($optionGroupID)
 {
     // check if we can get the field values from the system cache
     $cacheKey = "CRM_Core_BAO_OptionValue_OptionGroupID_{$optionGroupID}";
     $cache = CRM_Utils_Cache::singleton();
     $optionValues = $cache->get($cacheKey);
     if (empty($optionValues)) {
         $dao = new CRM_Core_DAO_OptionValue();
         $dao->option_group_id = $optionGroupID;
         $dao->orderBy('weight ASC, label ASC');
         $dao->find();
         $optionValues = array();
         while ($dao->fetch()) {
             $optionValues[$dao->id] = array();
             CRM_Core_DAO::storeValues($dao, $optionValues[$dao->id]);
         }
         $cache->set($cacheKey, $optionValues);
     }
     return $optionValues;
 }
开发者ID:kidaa30,项目名称:yes,代码行数:31,代码来源:OptionValue.php

示例6: del

 /**
  * Delete a PDF Page Format.
  *
  * @param int $id
  *   ID of the PDF Page Format to be deleted.
  *
  */
 public static function del($id)
 {
     if ($id) {
         $dao = new CRM_Core_DAO_OptionValue();
         $dao->id = $id;
         if ($dao->find(TRUE)) {
             if ($dao->option_group_id == self::_getGid()) {
                 $filter = array('option_group_id' => self::_getGid());
                 CRM_Utils_Weight::delWeight('CRM_Core_DAO_OptionValue', $id, $filter);
                 $dao->delete();
                 return;
             }
         }
     }
     CRM_Core_Error::fatal(ts('Invalid value passed to delete function.'));
 }
开发者ID:kidaa30,项目名称:yes,代码行数:23,代码来源:PdfFormat.php

示例7: postProcess

 /**
  * Process the form
  *
  * @param null
  *
  * @return void
  * @access public
  */
 public function postProcess()
 {
     // store the submitted values in an array
     $params = $this->controller->exportValues('Option');
     if ($this->_action == CRM_Core_Action::DELETE) {
         $fieldValues = array('option_group_id' => $this->_optionGroupID);
         $wt = CRM_Utils_Weight::delWeight('CRM_Core_DAO_OptionValue', $this->_id, $fieldValues);
         CRM_Core_BAO_CustomOption::del($this->_id);
         CRM_Core_Session::setStatus(ts('Your multiple choice option has been deleted'));
         return;
     }
     // set values for custom field properties and save
     $customOption = new CRM_Core_DAO_OptionValue();
     $customOption->label = $params['label'];
     $customOption->name = CRM_Utils_String::titleToVar($params['label']);
     $customOption->weight = $params['weight'];
     $customOption->value = $params['value'];
     $customOption->is_active = CRM_Utils_Array::value('is_active', $params, FALSE);
     $oldWeight = NULL;
     if ($this->_id) {
         $customOption->id = $this->_id;
         CRM_Core_BAO_CustomOption::updateCustomValues($params);
         $oldWeight = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_OptionValue', $this->_id, 'weight', 'id');
     }
     $fieldValues = array('option_group_id' => $this->_optionGroupID);
     $customOption->weight = CRM_Utils_Weight::updateOtherWeights('CRM_Core_DAO_OptionValue', $oldWeight, $params['weight'], $fieldValues);
     $customOption->option_group_id = $this->_optionGroupID;
     $customField = new CRM_Core_DAO_CustomField();
     $customField->id = $this->_fid;
     if ($customField->find(TRUE) && ($customField->html_type == 'CheckBox' || $customField->html_type == 'AdvMulti-Select' || $customField->html_type == 'Multi-Select')) {
         $defVal = explode(CRM_Core_DAO::VALUE_SEPARATOR, substr($customField->default_value, 1, -1));
         if (CRM_Utils_Array::value('default_value', $params)) {
             if (!in_array($customOption->value, $defVal)) {
                 if (empty($defVal[0])) {
                     $defVal = array($customOption->value);
                 } else {
                     $defVal[] = $customOption->value;
                 }
                 $customField->default_value = CRM_Core_DAO::VALUE_SEPARATOR . implode(CRM_Core_DAO::VALUE_SEPARATOR, $defVal) . CRM_Core_DAO::VALUE_SEPARATOR;
                 $customField->save();
             }
         } elseif (in_array($customOption->value, $defVal)) {
             $tempVal = array();
             foreach ($defVal as $v) {
                 if ($v != $customOption->value) {
                     $tempVal[] = $v;
                 }
             }
             $customField->default_value = CRM_Core_DAO::VALUE_SEPARATOR . implode(CRM_Core_DAO::VALUE_SEPARATOR, $tempVal) . CRM_Core_DAO::VALUE_SEPARATOR;
             $customField->save();
         }
     } else {
         switch ($customField->data_type) {
             case 'Money':
                 $customOption->value = CRM_Utils_Rule::cleanMoney($customOption->value);
                 break;
             case 'Int':
                 $customOption->value = intval($customOption->value);
                 break;
             case 'Float':
                 $customOption->value = floatval($customOption->value);
                 break;
         }
         if (CRM_Utils_Array::value('default_value', $params)) {
             $customField->default_value = $customOption->value;
             $customField->save();
         } elseif ($customField->find(TRUE) && $customField->default_value == $customOption->value) {
             // this is the case where this option is the current default value and we have been reset
             $customField->default_value = 'null';
             $customField->save();
         }
     }
     $customOption->save();
     CRM_Core_Session::setStatus(ts('Your multiple choice option \'%1\' has been saved', array(1 => $customOption->label)));
     $buttonName = $this->controller->getButtonName();
     $session = CRM_Core_Session::singleton();
     if ($buttonName == $this->getButtonName('next', 'new')) {
         CRM_Core_Session::setStatus(ts(' You can add another option.'));
         $session->replaceUserContext(CRM_Utils_System::url('civicrm/admin/custom/group/field/option', 'reset=1&action=add&fid=' . $this->_fid . '&gid=' . $this->_gid));
     }
 }
开发者ID:peteainsworth,项目名称:civicrm-4.2.9-drupal,代码行数:89,代码来源:Option.php

示例8: postProcess

 /**
  * Process the form
  * 
  * @param null
  * 
  * @return void
  * @access public
  */
 public function postProcess()
 {
     // store the submitted values in an array
     $params = $this->controller->exportValues($this->_name);
     $session = CRM_Core_Session::singleton();
     $params['last_modified_id'] = $session->get('userID');
     $params['last_modified_date'] = date('YmdHis');
     require_once 'CRM/Core/BAO/OptionValue.php';
     require_once 'CRM/Core/BAO/OptionGroup.php';
     $updateResultSet = false;
     if (CRM_Utils_Array::value('option_type', $params) == 2 && CRM_Utils_Array::value('option_group_id', $params)) {
         if ($params['option_group_id'] == CRM_Utils_Array::value('result_id', $this->_values)) {
             $updateResultSet = true;
         }
     }
     if ($this->_surveyId) {
         if ($this->_action & CRM_Core_Action::DELETE) {
             CRM_Campaign_BAO_Survey::del($this->_surveyId);
             CRM_Core_Session::setStatus(ts(' Survey has been deleted.'));
             $session->replaceUserContext(CRM_Utils_System::url('civicrm/campaign', 'reset=1&subPage=survey'));
             return;
         }
         $params['id'] = $this->_surveyId;
     } else {
         $params['created_id'] = $session->get('userID');
         $params['created_date'] = date('YmdHis');
     }
     $params['is_active'] = CRM_Utils_Array::value('is_active', $params, 0);
     $params['is_default'] = CRM_Utils_Array::value('is_default', $params, 0);
     $recontactInterval = array();
     if ($updateResultSet) {
         $optionValue = new CRM_Core_DAO_OptionValue();
         $optionValue->option_group_id = $this->_values['result_id'];
         $optionValue->delete();
         $params['result_id'] = $this->_values['result_id'];
     } else {
         $opGroupName = 'civicrm_survey_' . rand(10, 1000) . '_' . date('YmdHis');
         $optionGroup = new CRM_Core_DAO_OptionGroup();
         $optionGroup->name = $opGroupName;
         $optionGroup->label = $params['title'] . ' Response Set';
         $optionGroup->is_active = 1;
         $optionGroup->save();
         $params['result_id'] = $optionGroup->id;
     }
     foreach ($params['option_value'] as $k => $v) {
         if (strlen(trim($v))) {
             $optionValue = new CRM_Core_DAO_OptionValue();
             $optionValue->option_group_id = $params['result_id'];
             $optionValue->label = $params['option_label'][$k];
             $optionValue->name = CRM_Utils_String::titleToVar($params['option_label'][$k]);
             $optionValue->value = trim($v);
             $optionValue->weight = $params['option_weight'][$k];
             $optionValue->is_active = 1;
             if (CRM_Utils_Array::value('default_option', $params) && $params['default_option'] == $k) {
                 $optionValue->is_default = 1;
             }
             $optionValue->save();
             if (CRM_Utils_Array::value($k, $params['option_interval'])) {
                 $recontactInterval[$optionValue->label] = $params['option_interval'][$k];
             }
         }
     }
     $params['recontact_interval'] = serialize($recontactInterval);
     $surveyId = CRM_Campaign_BAO_Survey::create($params);
     if (CRM_Utils_Array::value('result_id', $this->_values) && !$updateResultSet) {
         $query = "SELECT COUNT(*) FROM civicrm_survey WHERE result_id = %1";
         $countSurvey = CRM_Core_DAO::singleValueQuery($query, array(1 => array($this->_values['result_id'], 'Integer')));
         // delete option group if no any survey is using it.
         if (!($countSurvey >= 1)) {
             CRM_Core_BAO_OptionGroup::del($this->_values['result_id']);
         }
     }
     require_once 'CRM/Core/BAO/UFJoin.php';
     // also update the ProfileModule tables
     $ufJoinParams = array('is_active' => 1, 'module' => 'CiviCampaign', 'entity_table' => 'civicrm_survey', 'entity_id' => $surveyId->id);
     // first delete all past entries
     if ($this->_surveyId) {
         CRM_Core_BAO_UFJoin::deleteAll($ufJoinParams);
     }
     if (CRM_Utils_Array::value('profile_id', $params)) {
         $ufJoinParams['weight'] = 1;
         $ufJoinParams['uf_group_id'] = $params['profile_id'];
         CRM_Core_BAO_UFJoin::create($ufJoinParams);
     }
     if (!is_a($surveyId, 'CRM_Core_Error')) {
         CRM_Core_Session::setStatus(ts('Survey %1 has been saved.', array(1 => $params['title'])));
     }
     if ($this->_context == 'dialog') {
         $returnArray = array('returnSuccess' => true);
         echo json_encode($returnArray);
         CRM_Utils_System::civiExit();
     }
//.........这里部分代码省略.........
开发者ID:hampelm,项目名称:Ginsberg-CiviDemo,代码行数:101,代码来源:Survey.php

示例9: postProcess

 /**
  * Process the form.
  */
 public function postProcess()
 {
     // store the submitted values in an array
     $status = '';
     $params = $this->controller->exportValues($this->_name);
     $params['id'] = $this->_surveyId;
     $updateResultSet = FALSE;
     $resultSetOptGrpId = NULL;
     if (CRM_Utils_Array::value('option_type', $params) == 2 && !empty($params['option_group_id'])) {
         $updateResultSet = TRUE;
         $resultSetOptGrpId = $params['option_group_id'];
     }
     $recontactInterval = array();
     if ($updateResultSet) {
         $optionValue = new CRM_Core_DAO_OptionValue();
         $optionValue->option_group_id = $resultSetOptGrpId;
         $optionValue->delete();
         $params['result_id'] = $resultSetOptGrpId;
     } else {
         $opGroupName = 'civicrm_survey_' . rand(10, 1000) . '_' . date('YmdHis');
         $optionGroup = new CRM_Core_DAO_OptionGroup();
         $optionGroup->name = $opGroupName;
         $optionGroup->title = $this->_values['title'] . ' Result Set';
         $optionGroup->is_active = 1;
         $optionGroup->save();
         $params['result_id'] = $optionGroup->id;
     }
     foreach ($params['option_value'] as $k => $v) {
         if (strlen(trim($v))) {
             $optionValue = new CRM_Core_DAO_OptionValue();
             $optionValue->option_group_id = $params['result_id'];
             $optionValue->label = $params['option_label'][$k];
             $optionValue->name = CRM_Utils_String::titleToVar($params['option_label'][$k]);
             $optionValue->value = trim($v);
             $optionValue->weight = $params['option_weight'][$k];
             $optionValue->is_active = 1;
             if (!empty($params['default_option']) && $params['default_option'] == $k) {
                 $optionValue->is_default = 1;
             }
             $optionValue->save();
             // using is_numeric since 0 is a valid value for option_interval
             if (is_numeric($params['option_interval'][$k])) {
                 $recontactInterval[$optionValue->label] = $params['option_interval'][$k];
             }
         }
     }
     $params['recontact_interval'] = serialize($recontactInterval);
     $survey = CRM_Campaign_BAO_Survey::create($params);
     // create report if required.
     if (!$this->_reportId && $survey->id && !empty($params['create_report'])) {
         $activityStatus = CRM_Core_PseudoConstant::activityStatus('name');
         $activityStatus = array_flip($activityStatus);
         $this->_params = array('name' => "survey_{$survey->id}", 'title' => $params['report_title'] ? $params['report_title'] : $this->_values['title'], 'status_id_op' => 'eq', 'status_id_value' => $activityStatus['Scheduled'], 'survey_id_value' => array($survey->id), 'description' => ts('Detailed report for canvassing, phone-banking, walk lists or other surveys.'));
         //Default value of order by
         $this->_params['order_bys'] = array(1 => array('column' => 'sort_name', 'order' => 'ASC'));
         // for WalkList or default
         $displayFields = array('id', 'sort_name', 'result', 'street_number', 'street_name', 'street_unit', 'survey_response');
         if (CRM_Core_OptionGroup::getValue('activity_type', 'WalkList') == $this->_values['activity_type_id']) {
             $this->_params['order_bys'] = array(1 => array('column' => 'street_name', 'order' => 'ASC'), 2 => array('column' => 'street_number_odd_even', 'order' => 'ASC'), 3 => array('column' => 'street_number', 'order' => 'ASC'), 4 => array('column' => 'sort_name', 'order' => 'ASC'));
         } elseif (CRM_Core_OptionGroup::getValue('activity_type', 'PhoneBank') == $this->_values['activity_type_id']) {
             array_push($displayFields, 'phone');
         } elseif (CRM_Core_OptionGroup::getValue('activity_type', 'Survey') == $this->_values['activity_type_id'] || CRM_Core_OptionGroup::getValue('activity_type', 'Canvass') == $this->_values['activity_type_id']) {
             array_push($displayFields, 'phone', 'city', 'state_province_id', 'postal_code', 'email');
         }
         foreach ($displayFields as $key) {
             $this->_params['fields'][$key] = 1;
         }
         $this->_createNew = TRUE;
         $this->_id = CRM_Report_Utils_Report::getInstanceIDForValue('survey/detail');
         CRM_Report_Form_Instance::postProcess($this, FALSE);
         $query = "SELECT MAX(id) FROM civicrm_report_instance WHERE name = %1";
         $reportID = CRM_Core_DAO::singleValueQuery($query, array(1 => array("survey_{$survey->id}", 'String')));
         if ($reportID) {
             $url = CRM_Utils_System::url("civicrm/report/instance/{$reportID}", 'reset=1');
             $status = ts("A Survey Detail Report <a href='%1'>%2</a> has been created.", array(1 => $url, 2 => $this->_params['title']));
         }
     }
     if ($status) {
         // reset status as we don't want status set by Instance::postProcess
         $session = CRM_Core_Session::singleton();
         $session->getStatus(TRUE);
         // set new status
         CRM_Core_Session::setStatus($status, ts('Saved'), 'success');
     }
     parent::endPostProcess();
 }
开发者ID:FundingWorks,项目名称:civicrm-core,代码行数:89,代码来源:Results.php

示例10: upgradeDomainFromEmail

 /**
  * 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'));
//.........这里部分代码省略.........
开发者ID:prashantgajare,项目名称:civicrm-core,代码行数:101,代码来源:Step3.php

示例11: getGrantStatuses

 static function getGrantStatuses()
 {
     $og = CRM_Grant_BAO_Grant::getGrantStatusOptGroup();
     require_once 'CRM/Core/BAO/OptionValue.php';
     $dao = new CRM_Core_DAO_OptionValue();
     $dao->option_group_id = $og->id;
     $dao->find();
     $statuses = array();
     while ($dao->fetch()) {
         $statuses[$dao->id] = $dao->label;
     }
     return $statuses;
 }
开发者ID:ksecor,项目名称:civicrm,代码行数:13,代码来源:Grant.php

示例12: del

 /**
  * Function to delete Option Group 
  * 
  * @param  int  $optionGroupId     Id of the Option Group to be deleted.
  * 
  * @return void
  * 
  * @access public
  * @static
  */
 static function del($optionGroupId)
 {
     // need to delete all option value field before deleting group
     require_once 'CRM/Core/DAO/OptionValue.php';
     $optionValue = new CRM_Core_DAO_OptionValue();
     $optionValue->option_group_id = $optionGroupId;
     $optionValue->delete();
     $optionGroup = new CRM_Core_DAO_OptionGroup();
     $optionGroup->id = $optionGroupId;
     $optionGroup->delete();
 }
开发者ID:hampelm,项目名称:Ginsberg-CiviDemo,代码行数:21,代码来源:OptionGroup.php

示例13: getFields

 /**
  * Check if there is a record with the same name in the db
  *
  * @param string $value     the value of the field we are checking
  * @param string $daoName   the dao object name
  * @param string $daoID     the id of the object being updated. u can change your name
  *                          as long as there is no conflict
  * @param string $fieldName the name of the field in the DAO
  *
  * @return boolean     true if object exists
  * @access public
  * @static
  */
 static function getFields($mode = '', $contactType = 'Individual')
 {
     $key = "{$mode} {$contactType}";
     if (empty(self::$_fields[$key]) || !self::$_fields[$key]) {
         self::$_fields[$key] = array();
         require_once "CRM/Core/DAO/OptionValue.php";
         $option = CRM_Core_DAO_OptionValue::import();
         foreach (array_keys($option) as $id) {
             $optionName = $option[$id];
         }
         $nameTitle = array();
         if ($mode == 'contribute') {
             $nameTitle = array('payment_instrument' => array('name' => 'payment_instrument', 'title' => 'Payment Instrument', 'headerPattern' => '/^payment|(p(ayment\\s)?instrument)$/i'));
         } else {
             if ($mode == '') {
                 //the fields email greeting and postal greeting are meant only for Individual and Household
                 //the field addressee is meant for all contact types, CRM-4575
                 if (in_array($contactType, array('Individual', 'Household', 'Organization', 'All'))) {
                     $nameTitle = array('addressee' => array('name' => 'addressee', 'title' => 'Addressee', 'headerPattern' => '/^addressee$/i'));
                 }
                 if ($contactType == 'Individual' || $contactType == 'Household' || $contactType == 'All') {
                     $title = array('email_greeting' => array('name' => 'email_greeting', 'title' => 'Email Greeting', 'headerPattern' => '/^email_greeting$/i'), 'postal_greeting' => array('name' => 'postal_greeting', 'title' => 'Postal Greeting', 'headerPattern' => '/^postal_greeting$/i'));
                     $nameTitle = array_merge($nameTitle, $title);
                 }
                 if ($contactType == 'Individual' || $contactType == 'All') {
                     $title = array('gender' => array('name' => 'gender', 'title' => 'Gender', 'headerPattern' => '/^gender$/i'), 'individual_prefix' => array('name' => 'individual_prefix', 'title' => 'Individual Prefix', 'headerPattern' => '/^(prefix|title)/i'), 'individual_suffix' => array('name' => 'individual_suffix', 'title' => 'Individual Suffix', 'headerPattern' => '/^suffix$/i'));
                     $nameTitle = array_merge($nameTitle, $title);
                 }
             }
         }
         if (is_array($nameTitle)) {
             foreach ($nameTitle as $name => $attribs) {
                 self::$_fields[$key][$name] = $optionName;
                 list($tableName, $fieldName) = explode('.', $optionName['where']);
                 // not sure of this fix, so keeping it commented for now
                 // this is from CRM-1541
                 // self::$_fields[$mode][$name]['where'] = $name . '.' . $fieldName;
                 self::$_fields[$key][$name]['where'] = "{$name}.label";
                 foreach ($attribs as $k => $val) {
                     self::$_fields[$key][$name][$k] = $val;
                 }
             }
         }
     }
     return self::$_fields[$key];
 }
开发者ID:ksecor,项目名称:civicrm,代码行数:59,代码来源:OptionValue.php

示例14: upgrade_3_3_beta1

 function upgrade_3_3_beta1($rev)
 {
     $upgrade = new CRM_Upgrade_Form();
     $upgrade->processSQL($rev);
     // CRM-6902
     // Add column price_field_value_id in civicrm_line_item.
     // Do not drop option_group_id column now since we need it to
     // update line items.
     $updateLineItem1 = "ALTER TABLE civicrm_line_item ADD COLUMN price_field_value_id int(10) unsigned default NULL;";
     CRM_Core_DAO::executeQuery($updateLineItem1);
     $priceFieldDAO = new CRM_Price_DAO_Field();
     $priceFieldDAO->find();
     $ids = array();
     while ($priceFieldDAO->fetch()) {
         $opGroupDAO = new CRM_Core_DAO_OptionGroup();
         $opGroupDAO->name = 'civicrm_price_field.amount.' . $priceFieldDAO->id;
         if (!$opGroupDAO->find(TRUE)) {
             $opGroupDAO->free();
             continue;
         }
         $opValueDAO = new CRM_Core_DAO_OptionValue();
         $opValueDAO->option_group_id = $opGroupDAO->id;
         $opValueDAO->find();
         while ($opValueDAO->fetch()) {
             // FIX ME: not migrating description(?), there will
             // be a field description for each option.
             $fieldValue = array('price_field_id' => $priceFieldDAO->id, 'label' => $opValueDAO->label, 'name' => CRM_Utils_String::munge($opValueDAO->label, '_', 64), 'amount' => $opValueDAO->name, 'weight' => $opValueDAO->weight, 'is_default' => $opValueDAO->is_default, 'is_active' => $opValueDAO->is_active);
             if ($priceFieldDAO->count) {
                 // Migrate Participant Counts on option level.
                 // count of each option will be the same
                 // as earlier field count.
                 $fieldValue['count'] = $priceFieldDAO->count;
             }
             $fieldValueDAO = CRM_Price_BAO_FieldValue::add($fieldValue, $ids);
             $lineItemDAO = new CRM_Price_DAO_LineItem();
             $lineItemDAO->option_group_id = $opGroupDAO->id;
             $lineItemDAO->label = $opValueDAO->label;
             $lineItemDAO->unit_price = $opValueDAO->name;
             $labelFound = $priceFound = FALSE;
             // check with label and amount
             if (!$lineItemDAO->find(TRUE)) {
                 $lineItemDAO->free();
                 $lineItemDAO = new CRM_Price_DAO_LineItem();
                 $lineItemDAO->option_group_id = $opGroupDAO->id;
                 $lineItemDAO->label = $opValueDAO->label;
                 // check with label only
                 if ($lineItemDAO->find(TRUE)) {
                     $labelFound = TRUE;
                 }
             } else {
                 $labelFound = TRUE;
                 $priceFound = TRUE;
             }
             $lineItemDAO->free();
             // update civicrm_line_item for price_field_value_id.
             // Used query to avoid line by line update.
             if ($labelFound || $priceFound) {
                 $lineItemParams = array(1 => array($fieldValueDAO->id, 'Integer'), 2 => array($opValueDAO->label, 'String'));
                 $updateLineItems = "UPDATE civicrm_line_item SET price_field_value_id = %1 WHERE label = %2";
                 if ($priceFound) {
                     $lineItemParams[3] = array($opValueDAO->name, 'Float');
                     $updateLineItems .= " AND unit_price = %3";
                 }
                 CRM_Core_DAO::executeQuery($updateLineItems, $lineItemParams);
             }
         }
         $opGroupDAO->delete();
         $opValueDAO->free();
         $opGroupDAO->free();
     }
     $priceFieldDAO->free();
     // Now drop option_group_id column from civicrm_line_item
     $updateLineItem2 = "ALTER TABLE civicrm_line_item DROP option_group_id,\n                           ADD CONSTRAINT `FK_civicrm_price_field_value_id` FOREIGN KEY (price_field_value_id) REFERENCES civicrm_price_field_value(id) ON DELETE SET NULL;";
     CRM_Core_DAO::executeQuery($updateLineItem2, array(), TRUE, NULL, FALSE, FALSE);
     $updatePriceField = "ALTER TABLE civicrm_price_field DROP count";
     CRM_Core_DAO::executeQuery($updatePriceField, array(), TRUE, NULL, FALSE, FALSE);
     // as the table 'civicrm_price_field' is localised and column 'count' is dropped
     // after the views are rebuild, we need to rebuild views to avoid invalid refrence of table.
     if ($upgrade->multilingual) {
         CRM_Core_I18n_Schema::rebuildMultilingualSchema($upgrade->locales, $rev);
     }
 }
开发者ID:peteainsworth,项目名称:civicrm-4.2.9-drupal,代码行数:82,代码来源:ThreeThree.php

示例15: getFields

 /**
  * Check if there is a record with the same name in the db.
  *
  * @param string $mode
  * @param string $contactType
  *
  * @return bool
  *   true if object exists
  */
 public static function getFields($mode = '', $contactType = 'Individual')
 {
     $key = "{$mode} {$contactType}";
     if (empty(self::$_fields[$key]) || !self::$_fields[$key]) {
         self::$_fields[$key] = array();
         $option = CRM_Core_DAO_OptionValue::import();
         foreach (array_keys($option) as $id) {
             $optionName = $option[$id];
         }
         $nameTitle = array();
         if ($mode == 'contribute') {
             $nameTitle = array('payment_instrument' => array('name' => 'payment_instrument', 'title' => ts('Payment Method'), 'headerPattern' => '/^payment|(p(ayment\\s)?instrument)$/i'));
         } elseif ($mode == '') {
             //the fields email greeting and postal greeting are meant only for Individual and Household
             //the field addressee is meant for all contact types, CRM-4575
             if (in_array($contactType, array('Individual', 'Household', 'Organization', 'All'))) {
                 $nameTitle = array('addressee' => array('name' => 'addressee', 'title' => ts('Addressee'), 'headerPattern' => '/^addressee$/i'));
                 $title = array('email_greeting' => array('name' => 'email_greeting', 'title' => ts('Email Greeting'), 'headerPattern' => '/^email_greeting$/i'), 'postal_greeting' => array('name' => 'postal_greeting', 'title' => ts('Postal Greeting'), 'headerPattern' => '/^postal_greeting$/i'));
                 $nameTitle = array_merge($nameTitle, $title);
             }
         }
         if (is_array($nameTitle)) {
             foreach ($nameTitle as $name => $attribs) {
                 self::$_fields[$key][$name] = $optionName;
                 list($tableName, $fieldName) = explode('.', $optionName['where']);
                 self::$_fields[$key][$name]['where'] = "{$name}.label";
                 foreach ($attribs as $k => $val) {
                     self::$_fields[$key][$name][$k] = $val;
                 }
             }
         }
     }
     return self::$_fields[$key];
 }
开发者ID:konadave,项目名称:civicrm-core,代码行数:43,代码来源:OptionValue.php


注:本文中的CRM_Core_DAO_OptionValue类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。