Commit c5943e54 authored by Monish Deb's avatar Monish Deb

cleanup and remove overriden core files

parent d96f1357
<?php
/*
+--------------------------------------------------------------------+
| CiviCRM version 4.4 |
+--------------------------------------------------------------------+
| Copyright CiviCRM LLC (c) 2004-2013 |
+--------------------------------------------------------------------+
| This file is a part of CiviCRM. |
| |
| CiviCRM is free software; you can copy, modify, and distribute it |
| under the terms of the GNU Affero General Public License |
| Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
| |
| CiviCRM is distributed in the hope that it will be useful, but |
| WITHOUT ANY WARRANTY; without even the implied warranty of |
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
| See the GNU Affero General Public License for more details. |
| |
| You should have received a copy of the GNU Affero General Public |
| License and the CiviCRM Licensing Exception along |
| with this program; if not, contact CiviCRM LLC |
| at info[AT]civicrm[DOT]org. If you have questions about the |
| GNU Affero General Public License or the licensing of CiviCRM, |
| see the CiviCRM license FAQ at http://civicrm.org/licensing |
+--------------------------------------------------------------------+
*/
/**
*
* @package CRM
* @copyright CiviCRM LLC (c) 2004-2013
* $Id$
*
*/
class CRM_Grant_BAO_Grant extends CRM_Grant_DAO_Grant {
/**
* static field for all the grant information that we can potentially export
* @var array
* @static
*/
static $_exportableFields = NULL;
/**
* class constructor
*/
function __construct() {
parent::__construct();
}
/**
* Function to get events Summary
*
* @static
*
* @return array Array of event summary values
*/
static function getGrantSummary($admin = FALSE) {
$query = "SELECT
p.id,
p.label,
g.status_id,
count(g.id) AS status_total,
sum(g.amount_total) AS amount_requested,
sum(g.amount_granted) AS amount_granted,
sum(cp.amount) AS total_paid,
sum(g.amount_granted)/count(g.id) AS average_amount
FROM civicrm_grant_program p
LEFT JOIN civicrm_grant g ON g.grant_program_id = p.id
LEFT JOIN civicrm_entity_payment ep ON ep.entity_id = g.id AND ep.entity_table = 'civicrm_grant'
LEFT JOIN civicrm_payment cp ON cp.id = ep.payment_id
WHERE g.status_id IS NOT NULL
GROUP BY g.grant_program_id, g.status_id WITH ROLLUP";
$dao = CRM_Core_DAO::executeQuery($query, CRM_Core_DAO::$_nullArray);
$status = array( );
$summary = array( );
$summary['total_grants'] = $programs = NULL;
$summary['no_of_grants'] = NULL;
$querys = "SELECT
v.label as label,
v.weight as value,
v.value as info
FROM civicrm_option_value v, civicrm_option_group g
WHERE v.option_group_id = g.id
AND g.name = 'grant_status'
AND g.is_active = 1
ORDER BY v.weight";
$daos = CRM_Core_DAO::executeQuery($querys, CRM_Core_DAO::$_nullArray);
while ($daos->fetch()) {
$status[$daos->value] = array(
'weight' => $daos->value,
'value' => $daos->info,
'label' => $daos->label,
'total' => 0,
);
}
foreach ($status as $id => $name) {
$stats[$status[$id]['value']] = array(
'label' => $name['label'],
'value' => $name['value'],
'weight' => $name['weight'],
'total' => 0
);
}
$count = 1;
while ($dao->fetch()) {
if ($dao->N == $count) {
$summary['total_grants']['total_requested'] = $dao->amount_requested ? CRM_Utils_Money::format($dao->amount_requested) : CRM_Utils_Money::format(0);
$summary['total_grants']['total_granted'] = $dao->amount_granted ? CRM_Utils_Money::format($dao->amount_granted) : CRM_Utils_Money::format(0);
$summary['total_grants']['total_paid'] = $dao->total_paid ? CRM_Utils_Money::format($dao->total_paid) : CRM_Utils_Money::format(0);
$summary['total_grants']['total_average'] = $dao->average_amount ? CRM_Utils_Money::format($dao->average_amount) : CRM_Utils_Money::format(0);
continue;
}
if (!empty($dao->status_id)) {
$programs[$dao->label][$stats[$dao->status_id]['weight']] = array(
'label' => $stats[$dao->status_id]['label'],
'total' => $dao->status_total,
'value' => $stats[$dao->status_id]['value'],
'amount_requested' => $dao->amount_requested ? CRM_Utils_Money::format($dao->amount_requested) : CRM_Utils_Money::format(0),
'amount_granted' => $dao->amount_granted ? CRM_Utils_Money::format($dao->amount_granted) : CRM_Utils_Money::format(0),
'total_paid' => $dao->total_paid ? CRM_Utils_Money::format($dao->total_paid) : CRM_Utils_Money::format(0),
'average_amount' => $dao->average_amount ? CRM_Utils_Money::format($dao->average_amount) : CRM_Utils_Money::format(0),
'pid' => $dao->id,
);
$programs[$dao->label] = $programs[$dao->label] + array_diff_key($status, $programs[$dao->label]); //add the two arrays
ksort($programs[$dao->label]);
$summary['total_grants']['all'] = 'All';
$summary['no_of_grants'] += $dao->status_total;
}
else {
$programs["<b>Subtotal $dao->label </b>"]['subtotal'] = array(
'label' => '',
'total' => $dao->status_total,
'amount_requested' => $dao->amount_requested ? CRM_Utils_Money::format($dao->amount_requested) : CRM_Utils_Money::format(0),
'amount_granted' => $dao->amount_granted ? CRM_Utils_Money::format($dao->amount_granted) : CRM_Utils_Money::format(0),
'total_paid' => $dao->total_paid ? CRM_Utils_Money::format($dao->total_paid) : CRM_Utils_Money::format(0),
'average_amount' => $dao->average_amount ? CRM_Utils_Money::format($dao->average_amount) : CRM_Utils_Money::format(0),
);
}
$count++;
}
$summary['per_status'] = $programs;
return $summary;
}
/**
* Function to get events Summary
*
* @static
*
* @return array Array of event summary values
*/
static function getGrantStatusOptGroup() {
$params = array();
$params['name'] = CRM_Grant_BAO_Grant::$statusGroupName;
$defaults = array();
$og = CRM_Core_BAO_OptionGroup::retrieve($params, $defaults);
if (!$og) {
CRM_Core_Error::fatal('No option group for grant statuses - database discrepancy! Make sure you loaded civicrm_data.mysql');
}
return $og;
}
/**
* Function to retrieve statistics for grants.
*
* @static
*
* @return array Array of grant summary statistics
*/
static function getGrantStatistics($admin = FALSE) {
$grantStatuses = array();
}
/**
* 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;
}
/**
* 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_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 (!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_id', $ids)) {
CRM_Utils_Hook::post('edit', 'Grant', $grant->id, $grant);
}
else {
CRM_Utils_Hook::post('create', 'Grant', $grant->id, $grant);
}
return $result;
}
/**
* function to create the event
*
* @param array $params reference array contains the values submitted by the form
* @param array $ids reference array contains the id
*
* @access public
* @static
*
*/
public static function create(&$params, &$ids) {
$transaction = new CRM_Core_Transaction();
$grant = self::add($params, $ids);
if (is_a($grant, 'CRM_Core_Error')) {
$transaction->rollback();
return $grant;
}
$session = CRM_Core_Session::singleton();
$id = $session->get('userID');
if (!$id) {
$id = CRM_Utils_Array::value('contact_id', $params);
}
if (CRM_Utils_Array::value('note', $params) || CRM_Utils_Array::value('id', CRM_Utils_Array::value('note',$ids))) {
$noteParams = array(
'entity_table' => 'civicrm_grant',
'note' => $params['note'] = $params['note'] ? $params['note'] : "null",
'entity_id' => $grant->id,
'contact_id' => $id,
'modified_date' => date('Ymd'),
);
CRM_Core_BAO_Note::add($noteParams, $ids['note']);
}
// Log the information on successful add/edit of Grant
$logParams = array(
'entity_table' => 'civicrm_grant',
'entity_id' => $grant->id,
'modified_id' => $id,
'modified_date' => date('Ymd'),
);
CRM_Core_BAO_Log::add($logParams);
// add custom field values
if (CRM_Utils_Array::value('custom', $params) && is_array($params['custom'])) {
CRM_Core_BAO_CustomValueTable::store($params['custom'], 'civicrm_grant', $grant->id);
}
// check and attach and files as needed
CRM_Core_BAO_File::processAttachment($params,
'civicrm_grant',
$grant->id
);
$transaction->commit();
return $grant;
}
/**
* Function to delete the Contact
*
* @param int $cid contact id
*
* @access public
* @static
*
*/
static function deleteContact($id) {
$grant = new CRM_Grant_DAO_Grant();
$grant->contact_id = $id;
$grant->delete();
return FALSE;
}
/**
* Function to delete the grant
*
* @param int $id grant id
*
* @access public
* @static
*
*/
static function del($id) {
CRM_Utils_Hook::pre('delete', 'Grant', $id, CRM_Core_DAO::$_nullArray);
$grant = new CRM_Grant_DAO_Grant();
$grant->id = $id;
$grant->find();
// delete the recently created Grant
$grantRecent = array(
'id' => $id,
'type' => 'Grant',
);
CRM_Utils_Recent::del($grantRecent);
if ($grant->fetch()) {
$results = $grant->delete();
CRM_Utils_Hook::post('delete', 'Grant', $grant->id, $grant);
return $results;
}
return FALSE;
}
/**
* combine all the exportable fields from the lower levels object
*
* @return array array of exportable Fields
* @access public
* @static
*/
static function &exportableFields() {
if (!self::$_exportableFields) {
if (!self::$_exportableFields) {
self::$_exportableFields = array();
}
$grantFields = array(
'grant_status' => array(
'title' => 'Grant Status',
'name' => 'grant_status',
'data_type' => CRM_Utils_Type::T_STRING,
),
'grant_type' => array(
'title' => 'Grant Type',
'name' => 'grant_type',
'data_type' => CRM_Utils_Type::T_STRING,
),
'grant_money_transfer_date' => array(
'title' => 'Grant Money Transfer Date',
'name' => 'grant_money_transfer_date',
'data_type' => CRM_Utils_Type::T_DATE,
),
'grant_amount_requested' => array(
'title' => 'Grant Amount Requested',
'name' => 'grant_amount_requested',
'data_type' => CRM_Utils_Type::T_FLOAT,
),
'grant_application_received_date' => array(
'title' => 'Grant Application Recieved Date',
'name' => 'grant_application_received_date',
'data_type' => CRM_Utils_Type::T_DATE,
),
);
$fields = CRM_Grant_DAO_Grant::export();
$grantNote = array('grant_note' => array('title' => ts('Grant Note'),
'name' => 'grant_note',
'data_type' => CRM_Utils_Type::T_TEXT,
));
$fields = array_merge($fields, $grantFields, $grantNote,
CRM_Core_BAO_CustomField::getFieldsForImport('Grant')
);
self::$_exportableFields = $fields;
}
return self::$_exportableFields;
}
/**
* Function to get grant record count for a Contact
*
* @param int $contactId Contact ID
*
* @return int count of grant records
* @access public
* @static
*/
static function getContactGrantCount($contactID) {
$query = "SELECT count(*) FROM civicrm_grant WHERE civicrm_grant.contact_id = {$contactID} ";
return CRM_Core_DAO::singleValueQuery($query);
}
}
......@@ -74,53 +74,53 @@ class CRM_Grant_BAO_GrantPayment extends CRM_Grant_DAO_GrantPayment {
}
return NULL;
}
function &exportableFields() {
if (!self::$_exportableFields) {
if (!self::$_exportableFields) {
self::$_exportableFields = array();
}
$grantFields = array(
'id' => array(
$grantFields = array(
'id' => array(
'title' => 'Payment ID',
'name' => 'id',
'data_type' => CRM_Utils_Type::T_INT
'data_type' => CRM_Utils_Type::T_INT
),
'payment_batch_number' => array(
'payment_batch_number' => array(
'title' => 'Payment Batch Nnumber',
'name' => 'payment_batch_number',
'data_type' => CRM_Utils_Type::T_INT
'data_type' => CRM_Utils_Type::T_INT
),
'payment_number' => array(
'payment_number' => array(
'title' => 'Payment Number',
'name' => 'payment_number',
'data_type' => CRM_Utils_Type::T_INT
'data_type' => CRM_Utils_Type::T_INT
),
'financial_type_id' => array(
'financial_type_id' => array(
'title' => 'Financial Type ID',
'name' => 'financial_type_id',
'data_type' => CRM_Utils_Type::T_INT
'data_type' => CRM_Utils_Type::T_INT
),
'contact_id' => array(
'contact_id' => array(
'title' => 'Contact ID',
'name' => 'contact_id',
'data_type' => CRM_Utils_Type::T_INT
'data_type' => CRM_Utils_Type::T_INT
),
'payment_created_date' => array(
'payment_created_date' => array(
'title' => 'Payment Created Date',
'name' => 'payment_created_date',
'data_type' => CRM_Utils_Type::T_DATE
'data_type' => CRM_Utils_Type::T_DATE
),
'payment_date' => array(
'payment_date' => array(
'title' => 'Payment Date',
'name' => 'payment_date',
'data_type' => CRM_Utils_Type::T_DATE
'data_type' => CRM_Utils_Type::T_DATE
),
'payable_to_name' => array(
'title' => 'Payable To Name',
'name' => 'payable_to_name',
'data_type' => CRM_Utils_Type::T_STRING
'data_type' => CRM_Utils_Type::T_STRING
),
'payable_to_address' => array(
'title' => 'Payable To Address',
......@@ -153,7 +153,7 @@ class CRM_Grant_BAO_GrantPayment extends CRM_Grant_DAO_GrantPayment {
'data_type' => CRM_Utils_Type::T_STRING
)
);
$fields = CRM_Grant_DAO_GrantPayment::export();
self::$_exportableFields = $fields;
}
......@@ -165,44 +165,44 @@ class CRM_Grant_BAO_GrantPayment extends CRM_Grant_DAO_GrantPayment {
*
* @param array $params reference array contains the values submitted by the form
* @param array $ids reference array contains the id
*
*
* @access public
* @static
* @static
* @return object
*/
*/
static function add(&$params, &$ids) {
if (empty($params)) {
return;
}
if (isset( $params['total_amount'])) {
$params[$field] = CRM_Utils_Rule::cleanMoney($params['total_amount']);
}
// convert dates to mysql format
$dates = array(
$dates = array(
'payment_date',
'payment_created_date'
'payment_created_date'
);
foreach ($dates as $date) {
if (isset($params[$date])) {
$params[$date] = CRM_Utils_Date::processDate($params[$date], NULL, TRUE);
}
}
}
$grantPayment = new CRM_Grant_DAO_GrantPayment();
$grantPayment->id = CRM_Utils_Array::value('id', $ids);
$grantPayment->copyValues($params);
return $grantPayment->save();
}
static function del($id) {
static function del($id) {
CRM_Utils_Hook::pre('delete', 'GrantPayment', $id, CRM_Core_DAO::$_nullArray);
$grantPayment = new CRM_Grant_DAO_GrantPayment();
$grantPayment->id = $id;
$grantPayment->id = $id;
$grantPayment->find();