Beispiel #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_Grant_BAO_ManageGrant object
  * @access public
  * @static
  */
 static function retrieve(&$params, &$defaults)
 {
     $grant = new CRM_Grant_DAO_Grant();
     $grant->copyValues($params);
     if ($grant->find(true)) {
         CRM_Core_DAO::storeValues($grant, $defaults);
         return $grant;
     }
     return null;
 }
Beispiel #2
0
 /**
  * Add grant.
  *
  * @param array $params
  *   Reference array contains the values submitted by the form.
  * @param array $ids
  *   Reference array contains the id.
  *
  *
  * @return object
  */
 public static function add(&$params, &$ids)
 {
     if (!empty($ids['grant_id'])) {
         CRM_Utils_Hook::pre('edit', 'Grant', $ids['grant_id'], $params);
     } else {
         CRM_Utils_Hook::pre('create', 'Grant', NULL, $params);
     }
     // first clean up all the money fields
     $moneyFields = array('amount_total', 'amount_granted', 'amount_requested');
     foreach ($moneyFields as $field) {
         if (isset($params[$field])) {
             $params[$field] = CRM_Utils_Rule::cleanMoney($params[$field]);
         }
     }
     // convert dates to mysql format
     $dates = array('application_received_date', 'decision_date', 'money_transfer_date', 'grant_due_date');
     foreach ($dates as $d) {
         if (isset($params[$d])) {
             $params[$d] = CRM_Utils_Date::processDate($params[$d], NULL, TRUE);
         }
     }
     $grant = new CRM_Grant_DAO_Grant();
     $grant->id = CRM_Utils_Array::value('grant_id', $ids);
     $grant->copyValues($params);
     // set currency for CRM-1496
     if (!isset($grant->currency)) {
         $config = CRM_Core_Config::singleton();
         $grant->currency = $config->defaultCurrency;
     }
     $result = $grant->save();
     $url = CRM_Utils_System::url('civicrm/contact/view/grant', "action=view&reset=1&id={$grant->id}&cid={$grant->contact_id}&context=home");
     $grantTypes = CRM_Core_PseudoConstant::get('CRM_Grant_DAO_Grant', 'grant_type_id');
     if (empty($params['skipRecentView'])) {
         if (!isset($grant->contact_id) || !isset($grant->grant_type_id)) {
             $grant->find(TRUE);
         }
         $title = CRM_Contact_BAO_Contact::displayName($grant->contact_id) . ' - ' . ts('Grant') . ': ' . $grantTypes[$grant->grant_type_id];
         $recentOther = array();
         if (CRM_Core_Permission::checkActionPermission('CiviGrant', CRM_Core_Action::UPDATE)) {
             $recentOther['editUrl'] = CRM_Utils_System::url('civicrm/contact/view/grant', "action=update&reset=1&id={$grant->id}&cid={$grant->contact_id}&context=home");
         }
         if (CRM_Core_Permission::checkActionPermission('CiviGrant', CRM_Core_Action::DELETE)) {
             $recentOther['deleteUrl'] = CRM_Utils_System::url('civicrm/contact/view/grant', "action=delete&reset=1&id={$grant->id}&cid={$grant->contact_id}&context=home");
         }
         // add the recently created Grant
         CRM_Utils_Recent::add($title, $url, $grant->id, 'Grant', $grant->contact_id, NULL, $recentOther);
     }
     if (!empty($ids['grant'])) {
         CRM_Utils_Hook::post('edit', 'Grant', $grant->id, $grant);
     } else {
         CRM_Utils_Hook::post('create', 'Grant', $grant->id, $grant);
     }
     return $result;
 }
Beispiel #3
0
 /**
  * function to add grant
  *
  * @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)
 {
     require_once 'CRM/Utils/Hook.php';
     if (CRM_Utils_Array::value('grant', $ids)) {
         CRM_Utils_Hook::pre('edit', 'Grant', $ids['grant_id'], $params);
     } else {
         CRM_Utils_Hook::pre('create', 'Grant', null, $params);
     }
     // first clean up all the money fields
     $moneyFields = array('amount_total', 'amount_granted', 'amount_requested');
     foreach ($moneyFields as $field) {
         if (isset($params[$field])) {
             $params[$field] = CRM_Utils_Rule::cleanMoney($params[$field]);
         }
     }
     $grant = new CRM_Grant_DAO_Grant();
     $grant->id = CRM_Utils_Array::value('grant', $ids);
     $grant->copyValues($params);
     // set currency for CRM-1496
     if (!isset($grant->currency)) {
         $config =& CRM_Core_Config::singleton();
         $grant->currency = $config->defaultCurrency;
     }
     $result = $grant->save();
     require_once 'CRM/Utils/Recent.php';
     require_once 'CRM/Grant/PseudoConstant.php';
     require_once 'CRM/Contact/BAO/Contact.php';
     $url = CRM_Utils_System::url('civicrm/contact/view/grant', "action=view&reset=1&id={$grant->id}&cid={$grant->contact_id}&context=home");
     $grantTypes = CRM_Grant_PseudoConstant::grantType();
     $title = CRM_Contact_BAO_Contact::displayName($grant->contact_id) . ' - ' . ts('Grant') . ': ' . $grantTypes[$grant->grant_type_id];
     $recentOther = array();
     if (CRM_Core_Permission::checkActionPermission('CiviGrant', CRM_Core_Action::UPDATE)) {
         $recentOther['editUrl'] = CRM_Utils_System::url('civicrm/contact/view/grant', "action=update&reset=1&id={$grant->id}&cid={$grant->contact_id}&context=home");
     }
     if (CRM_Core_Permission::checkActionPermission('CiviGrant', CRM_Core_Action::DELETE)) {
         $recentOther['deleteUrl'] = CRM_Utils_System::url('civicrm/contact/view/grant', "action=delete&reset=1&id={$grant->id}&cid={$grant->contact_id}&context=home");
     }
     // add the recently created Grant
     CRM_Utils_Recent::add($title, $url, $grant->id, 'Grant', $grant->contact_id, null, $recentOther);
     if (CRM_Utils_Array::value('grant', $ids)) {
         CRM_Utils_Hook::post('edit', 'Grant', $grant->id, $grant);
     } else {
         CRM_Utils_Hook::post('create', 'Grant', $grant->id, $grant);
     }
     return $result;
 }