Skip to content
This repository has been archived by the owner on Jul 19, 2022. It is now read-only.

Overrides for 5.24.6 #152

Merged
merged 11 commits into from
Jul 20, 2020
1,167 changes: 0 additions & 1,167 deletions CRM/Core/BAO/UFField.php

This file was deleted.

3,649 changes: 0 additions & 3,649 deletions CRM/Core/BAO/UFGroup.php

This file was deleted.

2 changes: 1 addition & 1 deletion CRM/Core/Controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -442,7 +442,7 @@ public function addPages(&$stateMachine, $action = CRM_Core_Action::NONE) {
$$stateName->setOptions($options);
}
if (property_exists($$stateName, 'urlPath')) {
$$stateName->urlPath = explode('/', (string) CRM_Utils_System::getUrlPath());
$$stateName->urlPath = explode('/', (string) CRM_Utils_System::currentPath());
}
$this->addPage($$stateName);
$this->addAction($stateName, new HTML_QuickForm_Action_Direct());
Expand Down
2 changes: 2 additions & 0 deletions CRM/Core/Page/AJAX/Location.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ class CRM_Core_Page_AJAX_Location {
* obtain the location of given contact-id.
* This method is used by on-behalf-of form to dynamically generate poulate the
* location field values for selected permissioned contact.
*
* @throws \CRM_Core_Exception
*/
public static function getPermissionedLocation() {
$cid = CRM_Utils_Request::retrieve('cid', 'Integer', CRM_Core_DAO::$_nullObject, TRUE);
Expand Down
7 changes: 7 additions & 0 deletions CRM/Grant/BAO/Query.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,13 @@ public static function select(&$query) {
$query->_tables['grant_note'] = 1;
}

if (!empty($query->_returnProperties['amount_requested'])) {
$query->_select['amount_requested'] = 'civicrm_grant.amount_requested as amount_requested';
$query->_element['amount_requested'] = 1;
$query->_tables['amount_requested'] = $query->_whereTables['amount_requested'] = 1;
$query->_tables['civicrm_grant'] = $query->_whereTables['civicrm_grant'] = 1;
}

if ($query->_mode & CRM_Contact_BAO_Query::MODE_GRANT) {
$query->_select['grant_amount_requested'] = 'civicrm_grant.amount_requested as grant_amount_requested';
$query->_select['grant_amount_granted'] = 'civicrm_grant.amount_granted as grant_amount_granted';
Expand Down
8 changes: 8 additions & 0 deletions CRM/Grant/Form/Grant/Confirm.php
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,14 @@ public function preProcess() {
}
}
}
$numericFields = $this->get('numericFields');
if (!empty($numericFields)) {
foreach ($numericFields as $numericField => $type) {
if (!empty($this->_params[$numericField])) {
$this->_params[$numericField] = CRM_Utils_Money::format($this->_params[$numericField]);
}
}
}
$this->set('params', $this->_params);
}

Expand Down
10 changes: 6 additions & 4 deletions CRM/Grant/Form/Grant/Main.php
Original file line number Diff line number Diff line change
Expand Up @@ -186,9 +186,6 @@ public function buildQuickForm() {
$this->assign('showMainEmail', TRUE);
$this->addRule("email-Primary", ts('Email is not valid.'), 'email');
}
else {
$this->addElement('hidden', "email-{$this->_bltID}", 1);
}

if (!CRM_Utils_Array::value('amount_requested', $this->_fields)) {
$defaultAmount = isset($this->_values['default_amount']) ? $this->_values['default_amount'] : '0.00';
Expand All @@ -207,7 +204,11 @@ public function buildQuickForm() {

if ( !empty( $this->_fields ) ) {
$profileAddressFields = array();
$numericFields['amount_total'] = 'Float';
$numericFields = [
'amount_total' => 'Float',
'amount_requested' => 'Float',
'amount_granted' => 'Float',
];
foreach( $this->_fields as $key => $value ) {
CRM_Core_BAO_UFField::assignAddressField($key, $profileAddressFields, array('uf_group_id' => $this->_values['custom_pre_id']));
$dataType = CRM_Utils_Array::value('data_type', $value);
Expand All @@ -220,6 +221,7 @@ public function buildQuickForm() {
}
$this->assign('numericFields', json_encode($numericFields));
$this->set('profileAddressFields', $profileAddressFields);
$this->set('numericFields', $numericFields);
}

//to create an cms user
Expand Down
5 changes: 5 additions & 0 deletions CRM/Grant/Form/Grant/ThankYou.php
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,11 @@ public function buildQuickForm() {
}

$this->_submitValues = array_merge($this->_submitValues, $defaults);
foreach ($defaults as $key => $field) {
if (substr($key, 0, strlen('email-')) === 'email-') {
$this->assign('email', $defaults[$key]);
}
}

$this->setDefaults($defaults);
$this->freeze();
Expand Down
4 changes: 4 additions & 0 deletions CRM/Grant/Form/GrantBase.php
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,10 @@ class CRM_Grant_Form_GrantBase extends CRM_Core_Form {
* @access public
*/
public function preProcess() {
CRM_Core_Resources::singleton()->addStyle('#crm-container.crm-public .calc-value, #crm-container.crm-public .content {
padding-top: 6px !important;
font-size: 15px !important;
}');

// current grant application page id
$this->_id = CRM_Utils_Request::retrieve('id', 'Positive', $this);
Expand Down
170 changes: 165 additions & 5 deletions CRM/Grantapplications/BAO/GrantApplicationProfile.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,10 @@

/**
* This class contains function for Grant Applications
*
*/
class CRM_Grantapplications_BAO_GrantApplicationProfile extends CRM_Core_DAO {
static function getGrantFields() {

public static function getGrantFields() {
$exportableFields = self::exportableFields('Grant');

$skipFields = array('grant_id', 'grant_contact_id');
Expand All @@ -50,7 +50,7 @@ static function getGrantFields() {
return $exportableFields;
}

static function exportableFields() {
public static function exportableFields() {
$grantFields = array(
'grant_status_id' => array(
'title' => ts('Grant Status'),
Expand Down Expand Up @@ -87,10 +87,170 @@ static function exportableFields() {
*
* return array of enabled extensions
*/
static function checkRelatedExtensions($name = 'biz.jmaconsulting.bugp') {
public static function checkRelatedExtensions($name = 'biz.jmaconsulting.bugp') {
$enableDisable = NULL;
$sql = "SELECT is_active FROM civicrm_extension WHERE full_name = '{name}'";
$enableDisable = CRM_Core_DAO::singleValueQuery($sql);
return $enableDisable;
}
}

/**
* Calculate the profile type 'group_type' as per profile fields.
*
* @param int $gId
* Profile id.
* @param bool $includeTypeValues
* @param int $ignoreFieldId
* Ignore particular profile field.
*
* @return array
* list of calculated group type
*/
public static function calculateGroupType($gId, $includeTypeValues = FALSE, $ignoreFieldId = NULL) {
//get the profile fields.
$ufFields = CRM_Core_BAO_UFGroup::getFields($gId, FALSE, NULL, NULL, NULL, TRUE, NULL, TRUE);
return self::_calculateGroupType($ufFields, $includeTypeValues, $ignoreFieldId);
}

/**
* Calculate the profile type 'group_type' as per profile fields.
*
* @param $ufFields
* @param bool $includeTypeValues
* @param int $ignoreFieldId
* Ignore perticular profile field.
*
* @return array
* list of calculated group type
*/
public static function _calculateGroupType($ufFields, $includeTypeValues = FALSE, $ignoreFieldId = NULL) {
$groupType = $groupTypeValues = $customFieldIds = [];
if (!empty($ufFields)) {
foreach ($ufFields as $fieldName => $fieldValue) {
//ignore field from group type when provided.
//in case of update profile field.
if ($ignoreFieldId && ($ignoreFieldId == $fieldValue['field_id'])) {
continue;
}
if (!in_array($fieldValue['field_type'], $groupType)) {
$groupType[$fieldValue['field_type']] = $fieldValue['field_type'];
}

if ($includeTypeValues && ($fldId = CRM_Core_BAO_CustomField::getKeyID($fieldName))) {
$customFieldIds[$fldId] = $fldId;
}
}
}

if (!empty($customFieldIds)) {
$query = 'SELECT DISTINCT(cg.id), cg.extends, cg.extends_entity_column_id, cg.extends_entity_column_value FROM civicrm_custom_group cg LEFT JOIN civicrm_custom_field cf ON cf.custom_group_id = cg.id WHERE cg.extends_entity_column_value IS NOT NULL AND cf.id IN (' . implode(',', $customFieldIds) . ')';

$customGroups = CRM_Core_DAO::executeQuery($query);
while ($customGroups->fetch()) {
if (!$customGroups->extends_entity_column_value) {
continue;
}

$groupTypeName = "{$customGroups->extends}Type";
if ($customGroups->extends == 'Participant' && $customGroups->extends_entity_column_id) {
$groupTypeName = CRM_Core_PseudoConstant::getName('CRM_Core_DAO_CustomGroup', 'extends_entity_column_id', $customGroups->extends_entity_column_id);
}

foreach (explode(CRM_Core_DAO::VALUE_SEPARATOR, $customGroups->extends_entity_column_value) as $val) {
if ($val) {
$groupTypeValues[$groupTypeName][$val] = $val;
}
}
}

if (!empty($groupTypeValues)) {
$groupType = array_merge($groupType, $groupTypeValues);
}
}

return $groupType;
}

/**
* Update the profile type 'group_type' as per profile fields including group types and group subtype values.
* Build and store string like: group_type1,group_type2[VALUE_SEPERATOR]group_type1Type:1:2:3,group_type2Type:1:2
*
* FIELDS GROUP_TYPE
* BirthDate + Email Individual,Contact
* BirthDate + Subject Individual,Activity
* BirthDate + Subject + SurveyOnlyField Individual,Activity\0ActivityType:28
* BirthDate + Subject + SurveyOnlyField + PhoneOnlyField (Not allowed)
* BirthDate + SurveyOnlyField Individual,Activity\0ActivityType:28
* BirthDate + Subject + SurveyOrPhoneField Individual,Activity\0ActivityType:2:28
* BirthDate + SurveyOrPhoneField Individual,Activity\0ActivityType:2:28
* BirthDate + SurveyOrPhoneField + SurveyOnlyField Individual,Activity\0ActivityType:2:28
* BirthDate + StudentField + Subject + SurveyOnlyField Individual,Activity,Student\0ActivityType:28
*
* @param int $gId
* @param array $groupTypes
* With key having group type names.
*
* @return bool
*/
public static function updateGroupTypes($gId, $groupTypes = []) {
if (!is_array($groupTypes) || !$gId) {
return FALSE;
}

// If empty group types set group_type as 'null'
if (empty($groupTypes)) {
return CRM_Core_DAO::setFieldValue('CRM_Core_DAO_UFGroup', $gId, 'group_type', 'null');
}

$componentGroupTypes = ['Contribution', 'Participant', 'Membership', 'Activity', 'Case', 'Grant'];
$validGroupTypes = array_merge([
'Contact',
'Individual',
'Organization',
'Household',
], $componentGroupTypes, CRM_Contact_BAO_ContactType::subTypes());

$gTypes = $gTypeValues = [];

$participantExtends = ['ParticipantRole', 'ParticipantEventName', 'ParticipantEventType'];
// Get valid group type and group subtypes
foreach ($groupTypes as $groupType => $value) {
if (in_array($groupType, $validGroupTypes) && !in_array($groupType, $gTypes)) {
$gTypes[] = $groupType;
}

$subTypesOf = NULL;

if (in_array($groupType, $participantExtends)) {
$subTypesOf = $groupType;
}
elseif (strpos($groupType, 'Type') > 0) {
$subTypesOf = substr($groupType, 0, strpos($groupType, 'Type'));
}
else {
continue;
}

if (!empty($value) &&
(in_array($subTypesOf, $componentGroupTypes) ||
in_array($subTypesOf, $participantExtends)
)
) {
$gTypeValues[$subTypesOf] = $groupType . ":" . implode(':', $value);
}
}

if (empty($gTypes)) {
return FALSE;
}

// Build String to store group types and group subtypes
$groupTypeString = implode(',', $gTypes);
if (!empty($gTypeValues)) {
$groupTypeString .= CRM_Core_DAO::VALUE_SEPARATOR . implode(',', $gTypeValues);
}

return CRM_Core_DAO::setFieldValue('CRM_Core_DAO_UFGroup', $gId, 'group_type', $groupTypeString);
}

}
21 changes: 21 additions & 0 deletions CRM/Grantapplications/Upgrader.php
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,27 @@ public static function migrateOnBehalfOfInfo() {
return TRUE;
}

/**
* Upgrade to add workflow name
*
* @return TRUE on success
* @throws Exception
*/
public function upgrade_4800() {
$this->ctx->log->info('Applying update 4800 | Add workflow name to message template');
// Get workflow name and id.
$sql = "SELECT ov.id, ov.name
FROM civicrm_option_value ov
INNER JOIN civicrm_option_group og ON og.id = ov.option_group_id
WHERE og.name = 'msg_tpl_workflow_grant'";
$workflowDetails = CRM_Core_DAO::executeQuery($sql)->fetchAll()[0];
$sql = "UPDATE civicrm_msg_template
SET workflow_name = %1
WHERE workflow_id = %2";
CRM_Core_DAO::executeQuery($sql, [1 => [$workflowDetails['name'], 'String'], 2 => [$workflowDetails['id'], 'Integer']]);
return TRUE;
}


/**
* Example: Run a slow upgrade process by breaking it up into smaller chunk
Expand Down
28 changes: 14 additions & 14 deletions CRM/UF/Page/ProfileEditor.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,17 +54,17 @@ public static function registerProfileScripts() {
'profilePreviewKey' => CRM_Core_Key::get('CRM_UF_Form_Inline_Preview', TRUE),
];
})
->addScriptFile('civicrm', 'packages/backbone/json2.js', 100, 'html-header', FALSE)
->addScriptFile('civicrm', 'packages/backbone/backbone.js', 120, 'html-header')
->addScriptFile('civicrm', 'packages/backbone/backbone.marionette.js', 125, 'html-header', FALSE)
->addScriptFile('civicrm', 'packages/backbone/backbone.collectionsubset.js', 125, 'html-header', FALSE)
->addScriptFile('civicrm', 'packages/backbone-forms/distribution/backbone-forms.js', 130, 'html-header', FALSE)
->addScriptFile('civicrm', 'packages/backbone-forms/distribution/adapters/backbone.bootstrap-modal.min.js', 140, 'html-header', FALSE)
->addScriptFile('civicrm', 'packages/backbone-forms/distribution/editors/list.min.js', 140, 'html-header', FALSE)
->addStyleFile('civicrm', 'packages/backbone-forms/distribution/templates/default.css', 140, 'html-header')
->addScriptFile('civicrm.packages', 'backbone/json2.js', 100, 'html-header', FALSE)
->addScriptFile('civicrm.packages', 'backbone/backbone.js', 120, 'html-header')
->addScriptFile('civicrm.packages', 'backbone/backbone.marionette.js', 125, 'html-header', FALSE)
->addScriptFile('civicrm.packages', 'backbone/backbone.collectionsubset.js', 125, 'html-header', FALSE)
->addScriptFile('civicrm.packages', 'backbone-forms/distribution/backbone-forms.js', 130, 'html-header', FALSE)
->addScriptFile('civicrm.packages', 'backbone-forms/distribution/adapters/backbone.bootstrap-modal.min.js', 140, 'html-header', FALSE)
->addScriptFile('civicrm.packages', 'backbone-forms/distribution/editors/list.min.js', 140, 'html-header', FALSE)
->addStyleFile('civicrm.packages', 'backbone-forms/distribution/templates/default.css', 140, 'html-header')
->addScript('CRM.BB = Backbone.noConflict();', 300, 'html-header')
->addScriptFile('civicrm', 'packages/jquery/plugins/jstree/jquery.jstree.js', 0, 'html-header', FALSE)
->addStyleFile('civicrm', 'packages/jquery/plugins/jstree/themes/default/style.css', 0, 'html-header')
->addScriptFile('civicrm.packages', 'jquery/plugins/jstree/jquery.jstree.js', 0, 'html-header', FALSE)
->addStyleFile('civicrm.packages', 'jquery/plugins/jstree/themes/default/style.css', 0, 'html-header')
->addStyleFile('civicrm', 'css/crm.designer.css', 140, 'html-header')
->addScriptFile('civicrm', 'js/crm.backbone.js', 150)
->addScriptFile('civicrm', 'js/model/crm.schema-mapped.js', 200)
Expand Down Expand Up @@ -247,10 +247,10 @@ public static function convertCiviModelToBackboneModel($extends, $title, $availa

// schema in format array($fieldName => $fieldSchema)
// sections in format array($sectionName => $section)
$result = array(
'schema' => array(),
'sections' => array(),
);
$result = [
'schema' => [],
'sections' => [],
];

// build field list
foreach ($availableFields as $fieldName => $field) {
Expand Down
16 changes: 16 additions & 0 deletions grantapplications.php
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,11 @@ function grantapplications_civicrm_buildForm($formName, &$form) {
$form->setDefaults($defaults);
}
}
if ($formName == "CRM_Grant_Form_GrantView") {
CRM_Core_Resources::singleton()->addStyle('.crm-info-panel td {
width: 50% !important;
}');
}
}

function grantapplications_civicrm_pageRun(&$page) {
Expand Down Expand Up @@ -588,6 +593,17 @@ function grantapplications_enableDisableNavigationMenu($action) {
grantapplications_addRemoveMenu($action);
}

function grantapplications_civicrm_alterUFFields(&$fields) {
$fields['Grant'] = CRM_Grant_BAO_Grant::exportableFields();
}

function grantapplications_civicrm_post($entity, $op, $id, $object) {
if ($entity === 'UFField' && in_array($op, ['edit', 'create'])) {
$fieldsType = CRM_Grantapplications_BAO_GrantApplicationProfile::calculateGroupType($object->uf_group_id, TRUE);
CRM_Grantapplications_BAO_GrantApplicationProfile::updateGroupTypes($object->uf_group_id, $fieldsType);
}
}

function grantapplications_dashboardActionLinks() {
return array(
CRM_Core_Action::UPDATE => array(
Expand Down