示例#1
0
 /**  
  * Function to set variables up before form is built  
  *                                                            
  * @return void  
  * @access public  
  */
 public function preProcess()
 {
     $this->_contactID = CRM_Utils_Request::retrieve('cid', 'Positive', $this);
     $this->_id = CRM_Utils_Request::retrieve('id', 'Positive', $this);
     $context = CRM_Utils_Request::retrieve('context', 'String', $this);
     $this->assign('context', $context);
     $values = array();
     $params['id'] = $this->_id;
     require_once 'CRM/Grant/BAO/Grant.php';
     CRM_Grant_BAO_Grant::retrieve($params, $values);
     require_once 'CRM/Grant/PseudoConstant.php';
     $grantType = CRM_Grant_PseudoConstant::grantType();
     $grantStatus = CRM_Grant_PseudoConstant::grantStatus();
     $this->assign('grantType', $grantType[$values['grant_type_id']]);
     $this->assign('grantStatus', $grantStatus[$values['status_id']]);
     $grantTokens = array('amount_total', 'amount_requested', 'amount_granted', 'rationale', 'grant_report_received', 'application_received_date', 'decision_date', 'money_transfer_date', 'grant_due_date');
     foreach ($grantTokens as $token) {
         $this->assign($token, CRM_Utils_Array::value($token, $values));
     }
     if (isset($this->_id)) {
         require_once 'CRM/Core/BAO/Note.php';
         $noteDAO = new CRM_Core_BAO_Note();
         $noteDAO->entity_table = 'civicrm_grant';
         $noteDAO->entity_id = $this->_id;
         if ($noteDAO->find(true)) {
             $this->_noteId = $noteDAO->id;
         }
     }
     if (isset($this->_noteId)) {
         $this->assign('note', CRM_Core_DAO::getFieldValue('CRM_Core_DAO_Note', $this->_noteId, 'note'));
     }
     // add Grant to Recent Items
     require_once 'CRM/Utils/Recent.php';
     require_once 'CRM/Contact/BAO/Contact.php';
     require_once 'CRM/Utils/Money.php';
     $url = CRM_Utils_System::url('civicrm/contact/view/grant', "action=view&reset=1&id={$values['id']}&cid={$values['contact_id']}&context=home");
     $title = CRM_Contact_BAO_Contact::displayName($values['contact_id']) . ' - ' . ts('Grant') . ': ' . CRM_Utils_Money::format($values['amount_total']) . ' (' . $grantType[$values['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={$values['id']}&cid={$values['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={$values['id']}&cid={$values['contact_id']}&context=home");
     }
     CRM_Utils_Recent::add($title, $url, $values['id'], 'Grant', $values['contact_id'], null, $recentOther);
     require_once 'CRM/Core/BAO/File.php';
     $attachment = CRM_Core_BAO_File::attachmentInfo('civicrm_grant', $this->_id);
     $this->assign('attachment', $attachment);
     $groupTree =& CRM_Core_BAO_CustomGroup::getTree("Grant", $this, $this->_id, 0);
     CRM_Core_BAO_CustomGroup::buildCustomDataView($this, $groupTree);
     $this->assign('id', $this->_id);
 }
示例#2
0
 function setDefaultValues()
 {
     $defaults = array();
     $defaults = parent::setDefaultValues();
     if ($this->_action & CRM_Core_Action::DELETE) {
         return $defaults;
     }
     $params['id'] = $this->_id;
     if ($this->_noteId) {
         $defaults['note'] = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_Note', $this->_noteId, 'note');
     }
     if ($this->_id) {
         CRM_Grant_BAO_Grant::retrieve($params, $defaults);
         // fix the display of the monetary value, CRM-4038
         require_once 'CRM/Utils/Money.php';
         if (isset($defaults['amount_total'])) {
             $defaults['amount_total'] = CRM_Utils_Money::format($defaults['amount_total'], null, '%a');
         }
         if (isset($defaults['amount_requested'])) {
             $defaults['amount_requested'] = CRM_Utils_Money::format($defaults['amount_requested'], null, '%a');
         }
         if (isset($defaults['amount_granted'])) {
             $defaults['amount_granted'] = CRM_Utils_Money::format($defaults['amount_granted'], null, '%a');
         }
         $dates = array('application_received_date', 'decision_date', 'money_transfer_date', 'grant_due_date');
         foreach ($dates as $key) {
             if (CRM_Utils_Array::value($key, $defaults)) {
                 list($defaults[$key]) = CRM_Utils_Date::setDateDefaults($defaults[$key]);
             }
         }
     } else {
         require_once 'CRM/Utils/Date.php';
         list($defaults['application_received_date']) = CRM_Utils_Date::setDateDefaults();
     }
     // custom data set defaults
     $defaults += CRM_Custom_Form_Customdata::setDefaultValues($this);
     return $defaults;
 }
示例#3
0
 /**
  * @return array
  */
 public function setDefaultValues()
 {
     if ($this->_cdType) {
         return CRM_Custom_Form_CustomData::setDefaultValues($this);
     }
     $defaults = parent::setDefaultValues();
     if ($this->_action & CRM_Core_Action::DELETE) {
         return $defaults;
     }
     $params['id'] = $this->_id;
     if ($this->_noteId) {
         $defaults['note'] = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_Note', $this->_noteId, 'note');
     }
     if ($this->_id) {
         CRM_Grant_BAO_Grant::retrieve($params, $defaults);
         // fix the display of the monetary value, CRM-4038
         if (isset($defaults['amount_total'])) {
             $defaults['amount_total'] = CRM_Utils_Money::format($defaults['amount_total'], NULL, '%a');
         }
         if (isset($defaults['amount_requested'])) {
             $defaults['amount_requested'] = CRM_Utils_Money::format($defaults['amount_requested'], NULL, '%a');
         }
         if (isset($defaults['amount_granted'])) {
             $defaults['amount_granted'] = CRM_Utils_Money::format($defaults['amount_granted'], NULL, '%a');
         }
         $dates = array('application_received_date', 'decision_date', 'money_transfer_date', 'grant_due_date');
         foreach ($dates as $key) {
             if (!empty($defaults[$key])) {
                 list($defaults[$key]) = CRM_Utils_Date::setDateDefaults($defaults[$key]);
             }
         }
     } else {
         list($defaults['application_received_date']) = CRM_Utils_Date::setDateDefaults();
     }
     return $defaults;
 }