Exemple #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
  * pledge 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_Pledge_BAO_Pledge object
  * @access public
  * @static
  */
 static function retrieve(&$params, &$defaults)
 {
     $pledge = new CRM_Pledge_DAO_Pledge();
     $pledge->copyValues($params);
     if ($pledge->find(true)) {
         CRM_Core_DAO::storeValues($pledge, $defaults);
         return $pledge;
     }
     return null;
 }
Exemple #2
0
 /**
  * function to add pledge
  *
  * @param array $params reference array contains the values submitted by the form
  *
  * @access public
  * @static
  *
  * @return object
  */
 static function add(&$params)
 {
     if (CRM_Utils_Array::value('id', $params)) {
         CRM_Utils_Hook::pre('edit', 'Pledge', $params['id'], $params);
     } else {
         CRM_Utils_Hook::pre('create', 'Pledge', NULL, $params);
     }
     $pledge = new CRM_Pledge_DAO_Pledge();
     // if pledge is complete update end date as current date
     if ($pledge->status_id == 1) {
         $pledge->end_date = date('Ymd');
     }
     $pledge->copyValues($params);
     // set currency for CRM-1496
     if (!isset($pledge->currency)) {
         $config = CRM_Core_Config::singleton();
         $pledge->currency = $config->defaultCurrency;
     }
     $result = $pledge->save();
     if (CRM_Utils_Array::value('id', $params)) {
         CRM_Utils_Hook::post('edit', 'Pledge', $pledge->id, $pledge);
     } else {
         CRM_Utils_Hook::post('create', 'Pledge', $pledge->id, $pledge);
     }
     return $result;
 }