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


PHP CRM_Core_OptionValue::addOptionValue方法代码示例

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


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

示例1: civicrm_api3_activity_type_create

/**
 * Create activity type.
 *
 * @param array $params
 *
 * @return array
 *   created / updated activity type
 *
 * @deprecated use the OptionValue api instead
 */
function civicrm_api3_activity_type_create($params)
{
    $action = 1;
    $groupParams = array('name' => 'activity_type');
    if ($optionValueID = CRM_Utils_Array::value('option_value_id', $params)) {
        $action = 2;
    }
    $activityObject = CRM_Core_OptionValue::addOptionValue($params, $groupParams, $action, $optionValueID);
    $activityType = array();
    _civicrm_api3_object_to_array($activityObject, $activityType[$activityObject->id]);
    return civicrm_api3_create_success($activityType, $params, 'activity_type', 'create');
}
开发者ID:kcristiano,项目名称:civicrm-core,代码行数:22,代码来源:ActivityType.php

示例2: civicrm_activity_type_create

/**
 * Function to create activity type
 *
 * @param array   $params  associated array of fields
 *                 $params['option_value_id'] is required for updation of activity type
 *
 * @return array $activityType created / updated activity type
 *
 * @access public
 */
function civicrm_activity_type_create($params)
{
    require_once 'CRM/Core/OptionGroup.php';
    if (!isset($params['label']) || !isset($params['weight'])) {
        return civicrm_create_error(ts('Required parameter "label / weight" not found'));
    }
    $action = 1;
    $groupParams = array('name' => 'activity_type');
    if ($optionValueID = CRM_Utils_Array::value('option_value_id', $params)) {
        $action = 2;
    }
    require_once 'CRM/Core/OptionValue.php';
    $activityObject = CRM_Core_OptionValue::addOptionValue($params, $groupParams, $action, $optionValueID);
    $activityType = array();
    _civicrm_object_to_array($activityObject, $activityType);
    return $activityType;
}
开发者ID:peteainsworth,项目名称:civicrm-4.2.9-drupal,代码行数:27,代码来源:ActivityType.php

示例3: upgrade

 function upgrade($rev)
 {
     // fix CRM-5270: if civicrm_report_instance.description is localised,
     // recreate it based on the first locale’s description_xx_YY contents
     // and drop all the description_xx_YY columns
     if (!CRM_Core_DAO::checkFieldExists('civicrm_report_instance', 'description')) {
         require_once 'CRM/Core/DAO/Domain.php';
         $domain = new CRM_Core_DAO_Domain();
         $domain->find(true);
         $locales = explode(CRM_Core_DAO::VALUE_SEPARATOR, $domain->locales);
         CRM_Core_DAO::executeQuery("ALTER TABLE civicrm_report_instance ADD description VARCHAR(255)");
         CRM_Core_DAO::executeQuery("UPDATE civicrm_report_instance SET description = description_{$locales[0]}");
         CRM_Core_DAO::executeQuery("DROP TRIGGER civicrm_report_instance_before_insert");
         foreach ($locales as $locale) {
             CRM_Core_DAO::executeQuery("DROP VIEW civicrm_report_instance_{$locale}");
             CRM_Core_DAO::executeQuery("ALTER TABLE civicrm_report_instance DROP description_{$locale}");
         }
     }
     //We execute some part of php after sql and then again sql
     //So using conditions for skipping some part of sql CRM-4575
     $upgrade =& new CRM_Upgrade_Form();
     //Run the SQL file (1)
     $upgrade->processSQL($rev);
     //replace  with ; in report instance
     $sql = "UPDATE civicrm_report_instance \n                       SET form_values = REPLACE(form_values,'#',';') ";
     CRM_Core_DAO::executeQuery($sql, CRM_Core_DAO::$_nullArray);
     //delete unnecessary activities
     $bulkEmailID = CRM_Core_OptionGroup::getValue('activity_type', 'Bulk Email', 'name');
     if ($bulkEmailID) {
         $mailingActivityIds = array();
         $query = " \n            SELECT max( ca.id ) as aid, \n                   ca.source_record_id sid\n            FROM civicrm_activity ca\n            WHERE ca.activity_type_id = %1 \n            GROUP BY ca.source_record_id";
         $params = array(1 => array($bulkEmailID, 'Integer'));
         $dao = CRM_Core_DAO::executeQuery($query, $params);
         while ($dao->fetch()) {
             $updateQuery = "\n                UPDATE civicrm_activity_target cat, civicrm_activity ca \n                    SET cat.activity_id = {$dao->aid}  \n                WHERE ca.source_record_id IS NOT NULL   AND\n                      ca.activity_type_id = %1          AND \n                      ca.id <> {$dao->aid}              AND \n                      ca.source_record_id = {$dao->sid} AND \n                      ca.id = cat.activity_id";
             $updateParams = array(1 => array($bulkEmailID, 'Integer'));
             CRM_Core_DAO::executeQuery($updateQuery, $updateParams);
             $deleteQuery = " \n                DELETE ca.* \n                FROM civicrm_activity ca \n                WHERE ca.source_record_id IS NOT NULL  AND \n                      ca.activity_type_id = %1         AND \n                      ca.id <> {$dao->aid}             AND \n                      ca.source_record_id = {$dao->sid}";
             $deleteParams = array(1 => array($bulkEmailID, 'Integer'));
             CRM_Core_DAO::executeQuery($deleteQuery, $deleteParams);
         }
     }
     //CRM-4453
     //lets insert column in civicrm_aprticipant table
     $query = "\n        ALTER TABLE `civicrm_participant` \n            ADD `fee_currency` VARCHAR( 64 ) CHARACTER SET utf8 COLLATE utf8_unicode_ci NULL COMMENT '3 character string, value derived from config setting.' AFTER `discount_id`";
     CRM_Core_DAO::executeQuery($query);
     //get currency from contribution table if exists/default
     //insert currency when fee_amount != NULL or event is paid.
     $query = "\n        SELECT  civicrm_participant.id \n        FROM    civicrm_participant\n            LEFT JOIN  civicrm_event \n                   ON ( civicrm_participant.event_id = civicrm_event.id )\n        WHERE  civicrm_participant.fee_amount IS NOT NULL OR \n               civicrm_event.is_monetary = 1";
     $participant = CRM_Core_DAO::executeQuery($query);
     while ($participant->fetch()) {
         $query = "\n            SELECT civicrm_contribution.currency \n            FROM   civicrm_contribution, \n                   civicrm_participant_payment\n            WHERE  civicrm_contribution.id = civicrm_participant_payment.contribution_id AND  \n                   civicrm_participant_payment.participant_id = {$participant->id}";
         $currencyID = CRM_Core_DAO::singleValueQuery($query);
         if (!$currencyID) {
             $config =& CRM_Core_Config::singleton();
             $currencyID = $config->defaultCurrency;
         }
         //finally update participant record.
         CRM_Core_DAO::setFieldValue('CRM_Event_DAO_Participant', $participant->id, 'fee_currency', $currencyID);
     }
     //CRM-4575
     //check whether {contact.name} is set in mailing labels
     require_once 'CRM/Core/BAO/Preferences.php';
     $mailingFormat = CRM_Core_BAO_Preferences::value('mailing_format');
     $addNewAddressee = true;
     if (strpos($mailingFormat, '{contact.contact_name}') === false) {
         $addNewAddressee = false;
     } else {
         //else compare individual name format with default individual addressee.
         $individualNameFormat = CRM_Core_BAO_Preferences::value('individual_name_format');
         $defaultAddressee = CRM_Core_OptionGroup::values('addressee', false, false, false, " AND v.filter = 1 AND v.is_default =  1", 'label');
         if (array_search($individualNameFormat, $defaultAddressee) !== false) {
             $addNewAddressee = false;
         }
     }
     require_once 'CRM/Utils/System.php';
     $docURL = CRM_Utils_System::docURL2('Update Greetings and Address Data for Contacts', false, null, null, 'color: white; text-decoration: underline;');
     if ($addNewAddressee) {
         //otherwise insert new token in addressee and set as a default
         $addresseeGroupId = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_OptionGroup', 'addressee', 'id', 'name');
         $optionValueParams = array('label' => $individualNameFormat, 'is_active' => 1, 'contactOptions' => 1, 'filter' => 1, 'is_default' => 1, 'reset_default_for' => array('filter' => "0, 1"));
         $action = CRM_Core_Action::ADD;
         $addresseeGroupParams = array('name' => 'addressee');
         $fieldValues = array('option_group_id' => $addresseeGroupId);
         $weight = CRM_Utils_Weight::getDefaultWeight('CRM_Core_DAO_OptionValue', $fieldValues);
         $optionValueParams['weight'] = $weight;
         $addresseeToken = CRM_Core_OptionValue::addOptionValue($optionValueParams, $addresseeGroupParams, $action, $optionId = null);
         $afterUpgradeMessage = ts("During this upgrade, Postal Addressee values have been stored for each contact record using the system default format - %2.You will need to run the included command-line script to update your Individual contact records to use the \"Individual Name Format\" previously specified for your site %1", array(1 => $docURL, 2 => array_pop($defaultAddressee)));
     } else {
         $afterUpgradeMessage = ts("Email Greeting, Postal Greeting and Postal Addressee values have been stored for all contact records based on the system default formats. If you want to use a different format for any of these contact fields - you can run the provided command line script to update contacts to a different format %1 ", array(1 => $docURL));
     }
     //replace contact.contact_name with contact.addressee in civicrm_preference.mailing_format
     $updateQuery = "\n        UPDATE civicrm_preferences \n               SET `mailing_format` = \n                    replace(`mailing_format`, '{contact.contact_name}','{contact.addressee}')";
     CRM_Core_DAO::executeQuery($updateQuery);
     //drop column individual_name_format
     $alterQuery = "\n        ALTER TABLE `civicrm_preferences`\n              DROP `individual_name_format`";
     CRM_Core_DAO::executeQuery($alterQuery);
     //set status message for default greetings
     $template =& CRM_Core_Smarty::singleton();
     $template->assign('afterUpgradeMessage', $afterUpgradeMessage);
//.........这里部分代码省略.........
开发者ID:bhirsch,项目名称:voipdev,代码行数:101,代码来源:ThreeZero.php

示例4: postProcess

 /**
  * Process the form submission.
  */
 public function postProcess()
 {
     if ($this->_action & CRM_Core_Action::DELETE) {
         $fieldValues = array('option_group_id' => $this->_gid);
         $wt = CRM_Utils_Weight::delWeight('CRM_Core_DAO_OptionValue', $this->_id, $fieldValues);
         if (CRM_Core_BAO_OptionValue::del($this->_id)) {
             if ($this->_gName == 'phone_type') {
                 CRM_Core_BAO_Phone::setOptionToNull(CRM_Utils_Array::value('value', $this->_defaultValues));
             }
             CRM_Core_Session::setStatus(ts('Selected %1 type has been deleted.', array(1 => $this->_gLabel)), ts('Record Deleted'), 'success');
         } else {
             CRM_Core_Session::setStatus(ts('Selected %1 type has not been deleted.', array(1 => $this->_gLabel)), ts('Sorry'), 'error');
             CRM_Utils_Weight::correctDuplicateWeights('CRM_Core_DAO_OptionValue', $fieldValues);
         }
     } else {
         $params = $ids = array();
         $params = $this->exportValues();
         // allow multiple defaults within group.
         $allowMultiDefaults = array('email_greeting', 'postal_greeting', 'addressee', 'from_email_address');
         if (in_array($this->_gName, $allowMultiDefaults)) {
             if ($this->_gName == 'from_email_address') {
                 $params['reset_default_for'] = array('domain_id' => CRM_Core_Config::domainID());
             } elseif ($filter = CRM_Utils_Array::value('contactOptions', $params)) {
                 $params['filter'] = $filter;
                 $params['reset_default_for'] = array('filter' => "0, " . $params['filter']);
             }
             //make sure we should has to have space, CRM-6977
             if ($this->_gName == 'from_email_address') {
                 $params['label'] = str_replace('"<', '" <', $params['label']);
             }
         }
         // set value of filter if not present in params
         if ($this->_id && !array_key_exists('filter', $params)) {
             if ($this->_gName == 'participant_role') {
                 $params['filter'] = 0;
             } else {
                 $params['filter'] = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_OptionValue', $this->_id, 'filter', 'id');
             }
         }
         $groupParams = array('name' => $this->_gName);
         $optionValue = CRM_Core_OptionValue::addOptionValue($params, $groupParams, $this->_action, $this->_id);
         // CRM-11516
         if (!empty($params['financial_account_id'])) {
             $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 %1 \'%2\' has been saved.', array(1 => $this->_gLabel, 2 => $optionValue->label)), ts('Saved'), 'success');
     }
 }
开发者ID:nielosz,项目名称:civicrm-core,代码行数:53,代码来源:Options.php

示例5: postProcess

 /**
  * Process the form when submitted
  *
  * @return void
  * @access public
  */
 public function postProcess()
 {
     require_once 'CRM/Core/BAO/Domain.php';
     $params = array();
     $params = $this->exportValues();
     $params['entity_id'] = $this->_id;
     $params['entity_table'] = CRM_Core_BAO_Domain::getTableName();
     $domain = CRM_Core_BAO_Domain::edit($params, $this->_id);
     require_once 'CRM/Core/BAO/LocationType.php';
     $defaultLocationType =& CRM_Core_BAO_LocationType::getDefault();
     $location = array();
     $params['address'][1]['location_type_id'] = $defaultLocationType->id;
     $params['phone'][1]['location_type_id'] = $defaultLocationType->id;
     $params['email'][1]['location_type_id'] = $defaultLocationType->id;
     $location = CRM_Core_BAO_Location::create($params, true, 'domain');
     $params['loc_block_id'] = $location['id'];
     require_once 'CRM/Core/BAO/Domain.php';
     CRM_Core_BAO_Domain::edit($params, $this->_id);
     //set domain from email address, CRM-3552
     $emailName = '"' . $params['email_name'] . '"<' . $params['email_address'] . '>';
     $emailParams = array('label' => $emailName, 'description' => $params['description'], 'is_active' => 1, 'is_default' => 1);
     $groupParams = array('name' => 'from_email_address');
     //get the option value wt.
     if ($this->_fromEmailId) {
         $action = $this->_action;
         $emailParams['weight'] = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_OptionValue', $this->_fromEmailId, 'weight');
     } else {
         //add from email address.
         $action = CRM_Core_Action::ADD;
         require_once 'CRM/Utils/Weight.php';
         $grpId = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_OptionGroup', 'from_email_address', 'id', 'name');
         $fieldValues = array('option_group_id' => $grpId);
         $emailParams['weight'] = CRM_Utils_Weight::getDefaultWeight('CRM_Core_DAO_OptionValue', $fieldValues);
     }
     require_once 'CRM/Core/OptionValue.php';
     //reset default within domain.
     $emailParams['reset_default_for'] = array('domain_id' => CRM_Core_Config::domainID());
     CRM_Core_OptionValue::addOptionValue($emailParams, $groupParams, $action, $this->_fromEmailId);
     CRM_Core_Session::setStatus(ts('Domain information for \'%1\' has been saved.', array(1 => $domain->name)));
     $session =& CRM_Core_Session::singleton();
     $session->replaceUserContext(CRM_Utils_System::url('civicrm/admin', 'reset=1'));
 }
开发者ID:bhirsch,项目名称:voipdev,代码行数:48,代码来源:Domain.php

示例6: postProcess

 /**
  * Function to process the form
  *
  * @access public
  *
  * @return None
  */
 public function postProcess()
 {
     if ($this->_action & CRM_Core_Action::DELETE) {
         if (CRM_Core_BAO_OptionValue::del($this->_id)) {
             CRM_Core_Session::setStatus(ts('Selected %1 Report has been deleted.', array(1 => $this->_GName)));
             CRM_Utils_System::redirect(CRM_Utils_System::url('civicrm/admin/report/options/report_template', "reset=1"));
         } else {
             CRM_Core_Session::setStatus(ts('Selected %1 type has not been deleted.', array(1 => $this->_GName)));
             CRM_Utils_Weight::correctDuplicateWeights('CRM_Core_DAO_OptionValue', $fieldValues);
         }
     } else {
         // get the submitted form values.
         $params = $this->controller->exportValues($this->_name);
         $ids = array();
         $groupParams = array('name' => 'report_template');
         $optionValue = CRM_Core_OptionValue::addOptionValue($params, $groupParams, $this->_action, $this->_id);
         CRM_Core_Session::setStatus(ts('The %1 \'%2\' has been saved.', array(1 => 'Report Template', 2 => $optionValue->label)));
         CRM_Utils_System::redirect(CRM_Utils_System::url('civicrm/admin/report/options/report_template', "reset=1"));
     }
 }
开发者ID:peteainsworth,项目名称:civicrm-4.2.9-drupal,代码行数:27,代码来源:Register.php

示例7: postProcess

 /**
  * Process the form when submitted.
  *
  * @return void
  */
 public function postProcess()
 {
     $params = $this->exportValues();
     $params['entity_id'] = $this->_id;
     $params['entity_table'] = CRM_Core_BAO_Domain::getTableName();
     $domain = CRM_Core_BAO_Domain::edit($params, $this->_id);
     $defaultLocationType = CRM_Core_BAO_LocationType::getDefault();
     if (isset($this->_locationDefaults['address'][1]['location_type_id'])) {
         $params['address'][1]['location_type_id'] = $this->_locationDefaults['address'][1]['location_type_id'];
     } else {
         $params['address'][1]['location_type_id'] = $defaultLocationType->id;
     }
     if (isset($this->_locationDefaults['phone'][1]['location_type_id'])) {
         $params['phone'][1]['location_type_id'] = $this->_locationDefaults['phone'][1]['location_type_id'];
     } else {
         $params['phone'][1]['location_type_id'] = $defaultLocationType->id;
     }
     if (isset($this->_locationDefaults['email'][1]['location_type_id'])) {
         $params['email'][1]['location_type_id'] = $this->_locationDefaults['email'][1]['location_type_id'];
     } else {
         $params['email'][1]['location_type_id'] = $defaultLocationType->id;
     }
     $params += array('contact_id' => $this->_contactId);
     $contactParams = array('sort_name' => $domain->name, 'display_name' => $domain->name, 'legal_name' => $domain->name, 'organization_name' => $domain->name, 'contact_id' => $this->_contactId, 'contact_type' => 'Organization');
     if ($this->_contactId) {
         $contactParams['contact_sub_type'] = CRM_Contact_BAO_Contact::getContactSubType($this->_contactId);
     }
     CRM_Contact_BAO_Contact::add($contactParams);
     CRM_Core_BAO_Location::create($params, TRUE);
     CRM_Core_BAO_Domain::edit($params, $this->_id);
     //set domain from email address, CRM-3552
     $emailName = '"' . $params['email_name'] . '" <' . $params['email_address'] . '>';
     $emailParams = array('label' => $emailName, 'description' => $params['description'], 'is_active' => 1, 'is_default' => 1);
     $groupParams = array('name' => 'from_email_address');
     //get the option value wt.
     if ($this->_fromEmailId) {
         $action = $this->_action;
         $emailParams['weight'] = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_OptionValue', $this->_fromEmailId, 'weight');
     } else {
         //add from email address.
         $action = CRM_Core_Action::ADD;
         $grpId = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_OptionGroup', 'from_email_address', 'id', 'name');
         $fieldValues = array('option_group_id' => $grpId);
         $emailParams['weight'] = CRM_Utils_Weight::getDefaultWeight('CRM_Core_DAO_OptionValue', $fieldValues);
     }
     //reset default within domain.
     $emailParams['reset_default_for'] = array('domain_id' => CRM_Core_Config::domainID());
     CRM_Core_OptionValue::addOptionValue($emailParams, $groupParams, $action, $this->_fromEmailId);
     CRM_Core_Session::setStatus(ts("Domain information for '%1' has been saved.", array(1 => $domain->name)), ts('Saved'), 'success');
     $session = CRM_Core_Session::singleton();
     $session->replaceUserContext(CRM_Utils_System::url('civicrm/admin', 'reset=1'));
 }
开发者ID:rajeshrhino,项目名称:civicrm-core,代码行数:57,代码来源:Domain.php

示例8: postProcess

 /**
  * Function to process the form
  *
  * @access public
  *
  * @return void
  */
 public function postProcess()
 {
     if ($this->_action & CRM_Core_Action::DELETE) {
         $fieldValues = array('option_group_id' => $this->_gid);
         $wt = CRM_Utils_Weight::delWeight('CRM_Core_DAO_OptionValue', $this->_id, $fieldValues);
         if (CRM_Core_BAO_OptionValue::del($this->_id)) {
             CRM_Core_Session::setStatus(ts('Selected Survey type has been deleted.'), ts('Record Deleted'), 'success');
         }
     } else {
         $params = $ids = array();
         $params = $this->exportValues();
         // set db value of filter in params if filter is non editable
         if ($this->_id && !array_key_exists('filter', $params)) {
             $params['filter'] = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_OptionValue', $this->_id, 'filter', 'id');
         }
         $groupParams = array('name' => $this->_gName);
         $params['component_id'] = CRM_Core_Component::getComponentID('CiviCampaign');
         $optionValue = CRM_Core_OptionValue::addOptionValue($params, $groupParams, $this->_action, $this->_id);
         CRM_Core_Session::setStatus(ts('The Survey type \'%1\' has been saved.', array(1 => $optionValue->label)), ts('Saved'), 'success');
     }
 }
开发者ID:prashantgajare,项目名称:civicrm-core,代码行数:28,代码来源:SurveyType.php

示例9: postProcess

 /**
  * Process the form
  * 
  * @param null
  * 
  * @return void
  * @access public
  */
 public function postProcess()
 {
     require_once 'CRM/Core/OptionValue.php';
     if ($this->_action == CRM_Core_Action::DELETE) {
         $fieldValues = array('option_group_id' => $this->_ogId);
         $wt = CRM_Utils_Weight::delWeight('CRM_Core_DAO_OptionValue', $this->_oid, $fieldValues);
         $label = CRM_Core_DAO::getFieldValue("CRM_Core_DAO_OptionValue", $this->_oid, 'label', 'id');
         if (CRM_Core_BAO_OptionValue::del($this->_oid)) {
             CRM_Core_Session::setStatus(ts('%1 option has been deleted.', array(1 => $label)));
         }
         return;
     } else {
         $params = $ids = array();
         $params = $this->controller->exportValues('Option');
         $fieldLabel = CRM_Core_DAO::getFieldValue('CRM_Price_DAO_Field', $this->_fid, 'label');
         $params['description'] = $fieldLabel . ' - ' . $params['label'];
         $params['value'] = CRM_Utils_Rule::cleanMoney(trim($params['value']));
         $groupParams = array('id' => $this->_ogId);
         // make name value consistant.
         $params['name'] = $params['value'];
         $optionValue = CRM_Core_OptionValue::addOptionValue($params, $groupParams, $this->_action, $this->_oid);
         CRM_Core_Session::setStatus(ts('The option \'%1\' has been saved.', array(1 => $params['label'])));
     }
 }
开发者ID:bhirsch,项目名称:voipdev,代码行数:32,代码来源:Option.php

示例10: civicrm_api3_sepa_transaction_group_toaccgroup

/**
 * This API call creates a corresponding accounting batch for a SEPA group
 * 
 * @param txgroup_id
 * @author endres -at- systopia.de
 */
function civicrm_api3_sepa_transaction_group_toaccgroup($params)
{
    // first, load the txgroup
    $txgroup_id = $params['txgroup_id'];
    $txgroup = civicrm_api('SepaTransactionGroup', 'getsingle', array('id' => $txgroup_id, 'version' => 3));
    if (isset($txgroup['is_error']) && $txgroup['is_error']) {
        return civicrm_api3_create_error("Cannot read transaction group " . $txgroup_id);
    }
    if (isset($txgroup['sdd_file_id'])) {
        $sdd_file = civicrm_api('SepaSddFile', 'getsingle', array('id' => $txgroup['sdd_file_id'], 'version' => 3));
        if (isset($sdd_file['is_error']) && $sdd_file['is_error']) {
            return civicrm_api3_create_error("Cannot read sdd file " . $txgroup['sdd_file_id']);
        }
    } else {
        $sdd_file = array('created_id' => CRM_Core_Session::singleton()->get('userID'), 'created_date' => date('YmdHis'));
    }
    // gather information on the group
    $contributions_query_sql = "\n  SELECT\n    contribution.total_amount     AS amount,\n    entity_trxn.financial_trxn_id AS financial_trxn_id,\n    contribution.id               AS contribution_id\n  FROM civicrm_sdd_contribution_txgroup   AS txgroup_contrib\n  LEFT JOIN civicrm_contribution          AS contribution ON txgroup_contrib.contribution_id = contribution.id\n  LEFT JOIN civicrm_entity_financial_trxn AS entity_trxn  ON entity_trxn.entity_id = contribution.id AND entity_trxn.entity_table='civicrm_contribution'\n  WHERE txgroup_contrib.txgroup_id = {$txgroup_id}\n  GROUP BY contribution.id;";
    $contributions_query = CRM_Core_DAO::executeQuery($contributions_query_sql);
    $transactions = array();
    $contributions_missing_transaction = array();
    $total = 0.0;
    while ($contributions_query->fetch()) {
        if ($contributions_query->financial_trxn_id) {
            array_push($transactions, $contributions_query->financial_trxn_id);
            $total += $contributions_query->amount;
        } else {
            array_push($contributions_missing_transaction, $contributions_query->contribution_id);
        }
    }
    // find a name
    $name = $wanted_name = 'SEPA ' . $txgroup['reference'];
    $counter = 0;
    while (CRM_Core_DAO::executeQuery("SELECT id FROM civicrm_batch WHERE title='{$name}';")->fetch()) {
        $counter++;
        $name = $wanted_name . '_' . $counter;
    }
    // get type id
    $type_id = (int) CRM_Core_OptionGroup::getValue('batch_type', 'SEPA DD Transaction Batch', 'name');
    if (!$type_id) {
        // create SEPA type entry if not exists
        $value_spec = array('name' => 'SEPA DD Transaction Batch', 'label' => ts('SEPA DD Transaction Batch'), 'is_active' => 1);
        $group_spec = array('name' => 'batch_type');
        $action = CRM_Core_Action::ADD;
        $type_id = CRM_Core_OptionValue::addOptionValue($value_spec, $group_spec, $action)->value;
    }
    // then, finally, create the accounting group
    $description = sprintf(ts('This group corresponds to <a href="%s">SEPA transaction group [%s]</a>'), CRM_Utils_System::url('civicrm/sepa/listgroup', "group_id={$txgroup_id}"), $txgroup_id);
    $batch = array('title' => $name, 'description' => $description, 'created_id' => $sdd_file['created_id'], 'created_date' => $txgroup['created_date'], 'modified_id' => CRM_Core_Session::singleton()->get('userID'), 'modified_date' => date('YmdHis'), 'status_id' => $txgroup['status_id'], 'type_id' => $type_id, 'mode_id' => (int) CRM_Core_OptionGroup::getValue('batch_mode', 'Automatic Batch', 'name'), 'total' => $total, 'item_count' => count($transactions), 'payment_instrument_id' => (int) CRM_Core_OptionGroup::getValue('payment_instrument', $txgroup['type'], 'name'), 'exported_date' => $sdd_file['created_date'], 'version' => 3);
    $batch_create = civicrm_api('Batch', 'create', $batch);
    if (isset($batch_create['is_error']) && $batch_create['is_error']) {
        return civicrm_api3_create_error("Cannot create batch for SEPA transaction group " . $txgroup_id);
    } else {
        $batch_id = $batch_create['id'];
        if (count($contributions_missing_transaction)) {
            $batch_create['contributions_missing_transaction'] = $contributions_missing_transaction;
        }
    }
    // add all the financial transactions to the group
    foreach ($transactions as $trxn_id) {
        CRM_Core_DAO::executeQuery("INSERT IGNORE INTO civicrm_entity_batch ( entity_table, entity_id, batch_id ) VALUES ('civicrm_financial_trxn', {$trxn_id}, {$batch_id});");
    }
    return civicrm_api3_create_success($batch_create, $params);
}
开发者ID:FundingWorks,项目名称:org.project60.sepa,代码行数:70,代码来源:SepaTransactionGroup.php

示例11: postProcess

 /**
  * Function to process the form
  *
  * @access public
  * @return None
  */
 public function postProcess()
 {
     if ($this->_action & CRM_Core_Action::DELETE) {
         $fieldValues = array('option_group_id' => $this->_gid);
         $wt = CRM_Utils_Weight::delWeight('CRM_Core_DAO_OptionValue', $this->_id, $fieldValues);
         if (CRM_Core_BAO_OptionValue::del($this->_id)) {
             if ($this->_gName == 'phone_type') {
                 require_once 'CRM/Core/BAO/Phone.php';
                 CRM_Core_BAO_Phone::setOptionToNull(CRM_Utils_Array::value('value', $this->_defaultValues));
             }
             CRM_Core_Session::setStatus(ts('Selected %1 type has been deleted.', array(1 => $this->_GName)));
         } else {
             CRM_Core_Session::setStatus(ts('Selected %1 type has not been deleted.', array(1 => $this->_GName)));
             CRM_Utils_Weight::correctDuplicateWeights('CRM_Core_DAO_OptionValue', $fieldValues);
         }
     } else {
         $params = $ids = array();
         $params = $this->exportValues();
         // allow multiple defaults within group.
         $allowMultiDefaults = array('email_greeting', 'postal_greeting', 'addressee', 'from_email_address');
         if (CRM_Utils_Array::value('is_default', $params) && in_array($this->_gName, $allowMultiDefaults)) {
             if ($this->_gName == 'from_email_address') {
                 $params['reset_default_for'] = array('domain_id' => CRM_Core_Config::domainID());
             } else {
                 if ($filter = CRM_Utils_Array::value('contactOptions', $params)) {
                     $params['filter'] = $filter;
                     $params['reset_default_for'] = array('filter' => "0, " . $params['filter']);
                 }
             }
         }
         $groupParams = array('name' => $this->_gName);
         require_once 'CRM/Core/OptionValue.php';
         $optionValue = CRM_Core_OptionValue::addOptionValue($params, $groupParams, $this->_action, $this->_id);
         CRM_Core_Session::setStatus(ts('The %1 \'%2\' has been saved.', array(1 => $this->_GName, 2 => $optionValue->label)));
     }
 }
开发者ID:bhirsch,项目名称:voipdev,代码行数:42,代码来源:Options.php

示例12: postProcess

 /**
  * Function to process the form
  *
  * @access public
  * @return None
  */
 public function postProcess()
 {
     if ($this->_action & CRM_Core_Action::DELETE) {
         $fieldValues = array('option_group_id' => $this->_gid);
         $wt = CRM_Utils_Weight::delWeight('CRM_Core_DAO_OptionValue', $this->_id, $fieldValues);
         if (CRM_Core_BAO_OptionValue::del($this->_id)) {
             if ($this->_gName == 'phone_type') {
                 require_once 'CRM/Core/BAO/Phone.php';
                 CRM_Core_BAO_Phone::setOptionToNull(CRM_Utils_Array::value('value', $this->_defaultValues));
             }
             CRM_Core_Session::setStatus(ts('Selected %1 type has been deleted.', array(1 => $this->_GName)));
         } else {
             CRM_Core_Session::setStatus(ts('Selected %1 type has not been deleted.', array(1 => $this->_GName)));
             CRM_Utils_Weight::correctDuplicateWeights('CRM_Core_DAO_OptionValue', $fieldValues);
         }
     } else {
         $params = $ids = array();
         $params = $this->exportValues();
         //set defaultGreeting option in params as per contact type
         if (CRM_Utils_Array::value('contactOptions', $params)) {
             $params['filter'] = CRM_Utils_Array::value('contactOptions', $params);
             $params['defaultGreeting'] = 1;
         }
         $groupParams = array('name' => $this->_gName);
         require_once 'CRM/Core/OptionValue.php';
         $optionValue = CRM_Core_OptionValue::addOptionValue($params, $groupParams, $this->_action, $this->_id);
         CRM_Core_Session::setStatus(ts('The %1 \'%2\' has been saved.', array(1 => $this->_GName, 2 => $optionValue->label)));
     }
 }
开发者ID:ksecor,项目名称:civicrm,代码行数:35,代码来源:Options.php

示例13: postProcess

 /**
  * Function to process the form
  *
  * @access public
  *
  * @return None
  */
 public function postProcess()
 {
     if ($this->_action & CRM_Core_Action::DELETE) {
         $fieldValues = array('option_group_id' => $this->_gid);
         $wt = CRM_Utils_Weight::delWeight('CRM_Core_DAO_OptionValue', $this->_id, $fieldValues);
         if (CRM_Core_BAO_OptionValue::del($this->_id)) {
             if ($this->_gName == 'phone_type') {
                 CRM_Core_BAO_Phone::setOptionToNull(CRM_Utils_Array::value('value', $this->_defaultValues));
             }
             CRM_Core_Session::setStatus(ts('Selected %1 type has been deleted.', array(1 => $this->_GName)));
         } else {
             CRM_Core_Session::setStatus(ts('Selected %1 type has not been deleted.', array(1 => $this->_GName)));
             CRM_Utils_Weight::correctDuplicateWeights('CRM_Core_DAO_OptionValue', $fieldValues);
         }
     } else {
         $params = $ids = array();
         $params = $this->exportValues();
         // allow multiple defaults within group.
         $allowMultiDefaults = array('email_greeting', 'postal_greeting', 'addressee', 'from_email_address');
         if (in_array($this->_gName, $allowMultiDefaults)) {
             if ($this->_gName == 'from_email_address') {
                 $params['reset_default_for'] = array('domain_id' => CRM_Core_Config::domainID());
             } elseif ($filter = CRM_Utils_Array::value('contactOptions', $params)) {
                 $params['filter'] = $filter;
                 $params['reset_default_for'] = array('filter' => "0, " . $params['filter']);
             }
             //make sure we should has to have space, CRM-6977
             if ($this->_gName == 'from_email_address') {
                 $params['label'] = str_replace('"<', '" <', $params['label']);
             }
         }
         // set db value of filter in params if filter is non editable
         if ($this->_id && !array_key_exists('filter', $params) && !$this->_gName == 'participant_role') {
             $params['filter'] = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_OptionValue', $this->_id, 'filter', 'id');
         }
         $groupParams = array('name' => $this->_gName);
         $optionValue = CRM_Core_OptionValue::addOptionValue($params, $groupParams, $this->_action, $this->_id);
         CRM_Core_Session::setStatus(ts('The %1 \'%2\' has been saved.', array(1 => $this->_GName, 2 => $optionValue->label)));
     }
 }
开发者ID:peteainsworth,项目名称:civicrm-4.2.9-drupal,代码行数:47,代码来源:Options.php


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