コード例 #1
0
ファイル: PledgeBlock.php プロジェクト: nielosz/civicrm-core
 /**
  * Add pledgeBlock.
  *
  * @param array $params
  *   Reference array contains the values submitted by the form.
  *
  *
  * @return object
  */
 public static function add(&$params)
 {
     if (!empty($params['id'])) {
         CRM_Utils_Hook::pre('edit', 'PledgeBlock', $params['id'], $params);
     } else {
         CRM_Utils_Hook::pre('create', 'PledgeBlock', NULL, $params);
     }
     $pledgeBlock = new CRM_Pledge_DAO_PledgeBlock();
     // fix for pledge_frequency_unit
     $freqUnits = CRM_Utils_Array::value('pledge_frequency_unit', $params);
     if ($freqUnits && is_array($freqUnits)) {
         unset($params['pledge_frequency_unit']);
         $newFreqUnits = array();
         foreach ($freqUnits as $k => $v) {
             if ($v) {
                 $newFreqUnits[$k] = $v;
             }
         }
         $freqUnits = $newFreqUnits;
         if (is_array($freqUnits) && !empty($freqUnits)) {
             $freqUnits = implode(CRM_Core_DAO::VALUE_SEPARATOR, array_keys($freqUnits));
             $pledgeBlock->pledge_frequency_unit = $freqUnits;
         } else {
             $pledgeBlock->pledge_frequency_unit = '';
         }
     }
     $pledgeBlock->copyValues($params);
     $result = $pledgeBlock->save();
     if (!empty($params['id'])) {
         CRM_Utils_Hook::post('edit', 'PledgeBlock', $pledgeBlock->id, $pledgeBlock);
     } else {
         CRM_Utils_Hook::post('create', 'Pledge', $pledgeBlock->id, $pledgeBlock);
     }
     return $result;
 }
コード例 #2
0
 /**
  * function to add pledgeBlock
  *
  * @param array $params reference array contains the values submitted by the form
  *
  * @access public
  * @static 
  * @return object
  */
 static function add(&$params)
 {
     require_once 'CRM/Utils/Hook.php';
     if (CRM_Utils_Array::value('id', $params)) {
         CRM_Utils_Hook::pre('edit', 'PledgeBlock', $params['id'], $params);
     } else {
         CRM_Utils_Hook::pre('create', 'PledgeBlock', null, $params);
     }
     $pledgeBlock = new CRM_Pledge_DAO_PledgeBlock();
     //fix for pledge_frequency_unit
     require_once 'CRM/Core/BAO/CustomOption.php';
     $freqUnits = CRM_Utils_Array::value('pledge_frequency_unit', $params);
     if ($freqUnits && is_array($freqUnits)) {
         unset($params['pledge_frequency_unit']);
         $newFreqUnits = array();
         foreach ($freqUnits as $k => $v) {
             if ($v) {
                 $newFreqUnits[$k] = $v;
             }
         }
         $freqUnits = $newFreqUnits;
         if (is_array($freqUnits) && !empty($freqUnits)) {
             $freqUnits = implode(CRM_Core_BAO_CustomOption::VALUE_SEPERATOR, array_keys($freqUnits));
             $pledgeBlock->pledge_frequency_unit = $freqUnits;
         } else {
             $pledgeBlock->pledge_frequency_unit = '';
         }
     }
     $pledgeBlock->copyValues($params);
     $result = $pledgeBlock->save();
     if (CRM_Utils_Array::value('id', $params)) {
         CRM_Utils_Hook::post('edit', 'PledgeBlock', $pledgeBlock->id, $pledgeBlock);
     } else {
         CRM_Utils_Hook::post('create', 'Pledge', $pledgeBlock->id, $pledgeBlock);
     }
     return $result;
 }