Ejemplo n.º 1
0
 /**
  * Build the form
  *
  * @access public
  *
  * @return void
  */
 function buildQuickForm()
 {
     $grantStatus = CRM_Grant_PseudoConstant::grantStatus();
     $this->addElement('select', 'status_id', ts('Grant Status'), array('' => '') + $grantStatus);
     $this->addElement('text', 'amount_granted', ts('Amount Granted'));
     $this->addRule('amount_granted', ts('Please enter a valid amount.'), 'money');
     $this->addDate('decision_date', ts('Grant Decision'), FALSE, array('formatType' => 'custom'));
     $this->assign('elements', array('status_id', 'amount_granted', 'decision_date'));
     $this->assign('totalSelectedGrants', count($this->_grantIds));
     $this->addDefaultButtons(ts('Update Grants'), 'done');
 }
 /**
  * Get all the n grant types
  *
  * @access public
  *
  * @return array - array reference of all grant types if any
  * @static
  */
 public static function &grantType($id = NULL)
 {
     if (!self::$grantType) {
         self::$grantType = array();
         self::$grantType = CRM_Core_OptionGroup::values('grant_type');
     }
     if ($id) {
         return self::$grantType[$id];
     }
     return self::$grantType;
 }
Ejemplo n.º 3
0
 /**
  * Get all the n grant types
  *
  * @access public
  * @return array - array reference of all grant types if any
  * @static
  */
 public static function &grantType($id = null)
 {
     if (!self::$grantType) {
         self::$grantType = array();
         require_once "CRM/Core/OptionGroup.php";
         self::$grantType = CRM_Core_OptionGroup::values("grant_type");
     }
     if ($id) {
         return self::$grantType[$id];
     }
     return self::$grantType;
 }
Ejemplo n.º 4
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);
 }
Ejemplo n.º 5
0
 function alterDisplay(&$rows)
 {
     // custom code to alter rows
     $entryFound = false;
     foreach ($rows as $rowNum => $row) {
         if (array_key_exists('civicrm_grant_grant_type_id', $row)) {
             if ($value = $row['civicrm_grant_grant_type_id']) {
                 $rows[$rowNum]['civicrm_grant_grant_type_id'] = CRM_Grant_PseudoConstant::grantType($value);
             }
             $entryFound = true;
         }
         if (array_key_exists('civicrm_grant_status_id', $row)) {
             if ($value = $row['civicrm_grant_status_id']) {
                 $rows[$rowNum]['civicrm_grant_status_id'] = CRM_Grant_PseudoConstant::grantStatus($value);
             }
             $entryFound = true;
         }
         if (array_key_exists('civicrm_grant_grant_report_received', $row)) {
             if ($value = $row['civicrm_grant_grant_report_received']) {
                 if ($value == 1) {
                     $value = 'Yes';
                 } else {
                     $value = 'No';
                 }
                 $rows[$rowNum]['civicrm_grant_grant_report_received'] = $value;
             }
             $entryFound = true;
         }
         if (!$entryFound) {
             break;
         }
     }
 }
Ejemplo n.º 6
0
 function alterDisplay(&$rows)
 {
     // custom code to alter rows
     $entryFound = FALSE;
     foreach ($rows as $rowNum => $row) {
         // convert display name to links
         if (array_key_exists('civicrm_contact_sort_name', $row) && array_key_exists('civicrm_contact_id', $row)) {
             $url = CRM_Utils_System::url('civicrm/contact/view', 'reset=1&cid=' . $row['civicrm_contact_id'], $this->_absoluteUrl);
             $rows[$rowNum]['civicrm_contact_sort_name_link'] = $url;
             $rows[$rowNum]['civicrm_contact_sort_name_hover'] = ts("View contact details for this record.");
             $entryFound = TRUE;
         }
         if (array_key_exists('civicrm_grant_grant_type_id', $row)) {
             if ($value = $row['civicrm_grant_grant_type_id']) {
                 $rows[$rowNum]['civicrm_grant_grant_type_id'] = CRM_Grant_PseudoConstant::grantType($value);
             }
             $entryFound = TRUE;
         }
         if (array_key_exists('civicrm_grant_status_id', $row)) {
             if ($value = $row['civicrm_grant_status_id']) {
                 $rows[$rowNum]['civicrm_grant_status_id'] = CRM_Grant_PseudoConstant::grantStatus($value);
             }
             $entryFound = TRUE;
         }
         if (array_key_exists('civicrm_grant_grant_report_received', $row)) {
             if ($value = $row['civicrm_grant_grant_report_received']) {
                 if ($value == 1) {
                     $value = 'Yes';
                 } else {
                     $value = 'No';
                 }
                 $rows[$rowNum]['civicrm_grant_grant_report_received'] = $value;
             }
             $entryFound = TRUE;
         }
         if (!$entryFound) {
             break;
         }
     }
 }
Ejemplo n.º 7
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);
     $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}");
     $grantTypes = CRM_Grant_PseudoConstant::grantType();
     $title = CRM_Contact_BAO_Contact::displayName($grant->contact_id) . ' - ' . ts('Grant') . ': ' . $grantTypes[$grant->grant_type_id];
     // add the recently created Activity
     CRM_Utils_Recent::add($title, $url, $grant->id, 'Grant', $grant->contact_id, null);
     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;
 }
Ejemplo n.º 8
0
 /**
  * returns all the rows in the given offset and rowCount     *
  * @param enum   $action   the action being performed
  * @param int    $offset   the row number to start from
  * @param int    $rowCount the number of rows to return
  * @param string $sort     the sql string that describes the sort order
  * @param enum   $output   what should the result set include (web/email/csv)
  *
  * @return int   the total number of rows for this action
  */
 function &getRows($action, $offset, $rowCount, $sort, $output = null)
 {
     $result = $this->_query->searchQuery($offset, $rowCount, $sort, false, false, false, false, false, $this->_grantClause);
     // process the result of the query
     $rows = array();
     //CRM-4418 check for view, edit, delete
     $permissions = array(CRM_Core_Permission::VIEW);
     if (CRM_Core_Permission::check('edit grants')) {
         $permissions[] = CRM_Core_Permission::EDIT;
     }
     if (CRM_Core_Permission::check('delete in CiviGrant')) {
         $permissions[] = CRM_Core_Permission::DELETE;
     }
     $mask = CRM_Core_Action::mask($permissions);
     require_once 'CRM/Grant/PseudoConstant.php';
     $grantStatus = array();
     $grantStatus = CRM_Grant_PseudoConstant::grantStatus();
     $grantType = array();
     $grantType = CRM_Grant_PseudoConstant::grantType();
     while ($result->fetch()) {
         $row = array();
         // the columns we are interested in
         foreach (self::$_properties as $property) {
             if (isset($result->{$property})) {
                 $row[$property] = $result->{$property};
             }
         }
         //fix status display
         $row['grant_status'] = $grantStatus[$row['grant_status_id']];
         $row['grant_type'] = $grantType[$row['grant_type_id']];
         if ($this->_context == 'search') {
             $row['checkbox'] = CRM_Core_Form::CB_PREFIX . $result->grant_id;
         }
         $row['action'] = CRM_Core_Action::formLink(self::links(), $mask, array('id' => $result->grant_id, 'cid' => $result->contact_id, 'cxt' => $this->_context));
         require_once 'CRM/Contact/BAO/Contact/Utils.php';
         $row['contact_type'] = CRM_Contact_BAO_Contact_Utils::getImage($result->contact_sub_type ? $result->contact_sub_type : $result->contact_type);
         $rows[] = $row;
     }
     return $rows;
 }
Ejemplo n.º 9
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)
 {
     if (CRM_Utils_Array::value('grant_id', $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]);
         }
     }
     // 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', $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_Grant_PseudoConstant::grantType();
     if (!CRM_Utils_Array::value('skipRecentView', $params)) {
         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 (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;
 }
Ejemplo n.º 10
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;
 }