Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add project type to civivolunteer #586

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions CRM/Volunteer/BAO/NeedSearch.php
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,16 @@ private function setSearchParams($userSearchParams) {
$this->searchParams['project']['proximity'] = $proximity;
}

$type = CRM_Utils_Array::value('type_id', $userSearchParams);
if ($type) {
$this->searchParams['project']['type_id'] = is_array($type) ? $type : explode(',', $type);
}

$locBlock = CRM_Utils_Array::value('loc_block_id', $userSearchParams);
if ($locBlock) {
$this->searchParams['project']['loc_block_id'] = is_array($locBlock) ? $locBlock : explode(',', $locBlock);
}

$beneficiary = CRM_Utils_Array::value('beneficiary', $userSearchParams);
if ($beneficiary) {
if (!array_key_exists('project_contacts', $this->searchParams['project'])) {
Expand Down
8 changes: 7 additions & 1 deletion CRM/Volunteer/BAO/Project.php
Original file line number Diff line number Diff line change
Expand Up @@ -470,7 +470,13 @@ public static function retrieve(array $params) {
foreach ($project->fields() as $field) {
$fieldName = $field['name'];
if (!empty($project->$fieldName)) {
$query->where('!column = @value', array(
if (!is_array($project->$fieldName)) {
$exprs = '!column = @value';
} else {
$exprs = '!column IN (@value)';
}

$query->where($exprs, array(
'column' => $fieldName,
'value' => $project->$fieldName,
));
Expand Down
21 changes: 20 additions & 1 deletion CRM/Volunteer/DAO/Project.php
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,12 @@ class CRM_Volunteer_DAO_Project extends CRM_Core_DAO {
* @var int
*/
public $campaign_id;

/**
* The type associated with this Volunteer Project. Implicit FK to option_value row in volunteer_project_type option_group.
*
* @var int unsigned
*/
public $type_id;
/**
* Class constructor.
*/
Expand Down Expand Up @@ -255,6 +260,20 @@ public static function &fields() {
],
'add' => '4.5',
],
'type_id' => [
'name' => 'type_id',
'type' => CRM_Utils_Type::T_INT,
'title' => ts('Type', array('domain' => 'org.civicrm.volunteer')) ,
'description' => 'Implicit FK to option_value row in volunteer_project_type option_group.',
'default' => 'NULL',
'table_name' => 'civicrm_volunteer_project',
'entity' => 'Project',
'bao' => 'CRM_Volunteer_DAO_Project',
'pseudoconstant' => array(
'optionGroupName' => 'volunteer_project_type',
'optionEditPath' => 'civicrm/admin/options/volunteer_project_type',
)
],
];
CRM_Core_DAO_AllCoreTables::invoke(__CLASS__, 'fields_callback', Civi::$statics[__CLASS__]['fields']);
}
Expand Down
30 changes: 30 additions & 0 deletions CRM/Volunteer/Upgrader.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ class CRM_Volunteer_Upgrader extends CRM_Volunteer_Upgrader_Base {
const customContactGroupName = 'Volunteer_Information';
const customContactTypeName = 'Volunteer';
const skillLevelOptionGroupName = 'skill_level';
const volProjectTypeOptionGroupName = 'volunteer_project_type';

public function install() {
$volActivityTypeId = $this->createActivityType(CRM_Volunteer_BAO_Assignment::CUSTOM_ACTIVITY_TYPE);
Expand All @@ -59,6 +60,9 @@ public function install() {
$this->schemaUpgrade20();
$this->addNeedEndDate();
$this->installNeedMetaDateFields();

$this->installTypeIdField();
$this->createVolProjectTypeOptionGroup();

// uncomment the next line to insert sample data
// $this->executeSqlFile('sql/volunteer_sample.mysql');
Expand Down Expand Up @@ -453,6 +457,32 @@ public function upgrade_2301() {
return TRUE;
}

public function installTypeIdField() {
$query = CRM_Core_DAO::executeQuery('
ALTER TABLE `civicrm_volunteer_project`
ADD `type_id` int(11) DEFAULT NULL COMMENT \'Implicit FK to option_value row in volunteer_project_type option_group.\';');
return !is_a($query, 'DB_Error');
}

public function upgrade_2400() {
$this->ctx->log->info('Applying update 2400 - Adding type id data field to volunteer project');
return $this->installTypeIdField();
}

public function createVolProjectTypeOptionGroup() {
$this->createPossibleDuplicateRecord('OptionGroup', array(
'is_active' => 1,
'name' => self::volProjectTypeOptionGroupName,
'title' => ts('Volunteer Project Type', array('domain' => 'org.civicrm.volunteer')),
));
}

public function upgrade_2401() {
$this->ctx->log->info('Applying update 2400 - Creating volunteer_project_type Option Group');
$this->createVolProjectTypeOptionGroup();
return TRUE;
}

public function uninstall() {
$customgroups = civicrm_api3('CustomGroup', 'get', [
'name' => ['IN' => [
Expand Down
9 changes: 9 additions & 0 deletions ang/volunteer/Project.html
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
<h1 crm-page-title>{{ts('CiviVolunteer')}}</h1>

<div class="crm-vol-project" crm-vol-perm-to-class>
<div id="backboneIncludes"></div>

Expand All @@ -11,6 +13,13 @@
<input class="big crm-form-text" crm-ui-id="projectForm.title" ng-model="project.title" ng-required="true" />
</div>

<div class="crm-vol-project-type" crm-ui-field='{name: "projectForm.type_id", title: ts("Project Type")}'>
<select class="big crm-form-select crm-vol-type" crm-ui-select="{placeholder: '', allowClear:true}"
ng-options="key as value for (key , value) in project_types track by key" ng-model="project.type_id">
<option />
</select>
</div>

<div class="crm-vol-description" crm-ui-field="{name: 'projectForm.description', title: ts('Project Description')}">
<p>
<span class="crm-button crm-icon-button crm-vol-button crm-vol-preview-description crm-vol-project-preview-description" ng-click="previewDescription()">
Expand Down
9 changes: 7 additions & 2 deletions ang/volunteer/Project.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,11 @@
controller: 'VolunteerProject'
});
},
project_types: function(crmApi) {
return crmApi('VolunteerUtil', 'getprojecttypeoptions', {}).then(function(result) {
return result.values;
});
},
relationship_data: function(crmApi, $route) {
var params = {
"sequential": 1,
Expand Down Expand Up @@ -64,8 +69,7 @@
}
);


angular.module('volunteer').controller('VolunteerProject', function($scope, $sce, $location, $q, $route, crmApi, crmUiAlert, crmUiHelp, countries, project, profile_status, relationship_data, supporting_data, location_blocks, volBackbone) {
angular.module('volunteer').controller('VolunteerProject', function($scope, $sce, $location, $q, $route, crmApi, crmUiAlert, crmUiHelp, countries, project, profile_status, project_types, campaigns, relationship_data, supporting_data, location_blocks, volBackbone) {

/**
* We use custom "dirty" logic rather than rely on Angular's native
Expand Down Expand Up @@ -167,6 +171,7 @@
}

$scope.campaignFilter = CRM.volunteer.campaignFilter;
$scope.project_types = project_types;
$scope.relationship_types = supporting_data.values.relationship_types;
$scope.phone_types = supporting_data.values.phone_types;
$scope.supporting_data = supporting_data.values;
Expand Down
8 changes: 8 additions & 0 deletions ang/volunteer/Projects.html
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
<h1 crm-page-title>{{ts('CiviVolunteer')}}</h1>

<div class="crm-container">

<div class="help" ng-show="!canAccessAllProjects">
Expand Down Expand Up @@ -30,6 +32,12 @@
<div class="crm-vol-field crm-vol-field-projects-search-title" crm-ui-field="{name: 'volProjectSearchForm.title', title: ts('Title')}">
<input crm-ui-id="volProjectSearchForm.title" ng-model="searchParams.title" />
</div>
<div class="crm-vol-field crm-vol-field-projects-search-type" crm-ui-field="{name: 'volProjectSearchForm.type_id', title: ts('Type')}">
<select class="big crm-form-select crm-vol-type" crm-ui-select="{placeholder: ts('Filter by Type'), allowClear:true}"
ng-options="key as value for (key , value) in project_types track by key" ng-model="searchParams.type_id">
<option />
</select>
</div>
<div class="crm-vol-field crm-vol-field-projects-search-beneficiaries" crm-ui-field="{name: 'volProjectSearchForm.beneficiary', title: ts('Beneficiary')}">
<!-- TODO for VOL-267: Replace this with an entityRef widget. -->
<select class="big crm-form-select crm-vol-beneficiary" crm-ui-select="{placeholder: ts('Filter by Beneficiary'), allowClear:true}"
Expand Down
8 changes: 7 additions & 1 deletion ang/volunteer/Projects.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,11 @@
});
});
},
project_types: function(crmApi) {
return crmApi('VolunteerUtil', 'getprojecttypeoptions', {}).then(function(result) {
return result.values;
});
},
volunteerBackbone: function(volBackbone) {
return volBackbone.load();
}
Expand All @@ -54,7 +59,7 @@
);

// TODO for VOL-276: Remove reference to beneficiaries object, based on deprecated API.
angular.module('volunteer').controller('VolunteerProjects', function ($scope, $filter, crmApi, crmStatus, crmUiHelp, projectData, $location, volunteerBackbone, beneficiaries, $window) {
angular.module('volunteer').controller('VolunteerProjects', function ($scope, $filter, crmApi, crmStatus, crmUiHelp, projectData, $location, volunteerBackbone, beneficiaries, project_types, campaigns, $window) {
// The ts() and hs() functions help load strings for this module.
var ts = $scope.ts = CRM.ts('org.civicrm.volunteer');
var hs = $scope.hs = crmUiHelp({file: 'CRM/volunteer/Projects'}); // See: templates/CRM/volunteer/Projects.hlp
Expand All @@ -68,6 +73,7 @@
// TODO for VOL-276: Remove reference to beneficiaries object, based on deprecated API.
$scope.beneficiaries = beneficiaries;
$scope.campaignFilter = CRM.volunteer.campaignFilter;
$scope.project_types = project_types;
$scope.needBase = CRM.url("civicrm/volunteer/need");
$scope.assignBase = CRM.url("civicrm/volunteer/assign");
$scope.urlPublicVolOppSearch = CRM.url('civicrm/vol/', '', 'front') + '#/volunteer/opportunities';
Expand Down
28 changes: 28 additions & 0 deletions ang/volunteer/VolOppsCtrl.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
Required vars: volOppData(), searchParams
-->

<h1 crm-page-title>{{ts('Available Opportunities')}}</h1>

<div class="crm-container">
<div class="help">
<p>
Expand All @@ -27,6 +29,32 @@ <h2>{{:: ts('Find Volunteer Opportunities') }}</h2>
<input crm-ui-id="volOppSearchForm.date_end" crm-ui-datepicker="{time: false}" ng-model="searchParams.date_end" />
</div>

<div crm-ui-field="{name: 'volOppSearchForm.type_id', title: ts('Type')}" class="crm-vol-opp-type">
<select
crm-ui-id="volOppSearchForm.type_id"
crm-ui-select="{minimumInputLength: 0, placeholder: ts('Select Volunteer Type(s)')}"
type="text"
multiple="multiple"
name="type_id"
ng-model="searchParams.type_id"
ng-options="key as value for (key , value) in project_types track by key"
class="big crm-form-text">
</select>
</div>

<div crm-ui-field="{name: 'volOppSearchForm.loc_block_id', title: ts('Location')}" class="crm-vol-opp-location">
<select
crm-ui-id="volOppSearchForm.loc_block_id"
crm-ui-select="{minimumInputLength: 0, placeholder: ts('Select Location')}"
type="text"
multiple="multiple"
name="loc_block_id"
ng-model="searchParams.loc_block_id"
ng-options="key as value for (key , value) in location_blocks track by key"
class="big crm-form-text">
</select>
</div>

<div crm-ui-field="{name: 'volOppSearchForm.role_id', title: ts('Role')}" class="crm-vol-opp-role">
<select
crm-ui-id="volOppSearchForm.role_id"
Expand Down
14 changes: 12 additions & 2 deletions ang/volunteer/VolOppsCtrl.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,20 @@
return crmApi('VolunteerUtil', 'getsupportingdata', {
controller: 'VolOppsCtrl'
});
}
},
project_types: function(crmApi) {
return crmApi('VolunteerUtil', 'getprojecttypeoptions', {}).then(function(result) {
return result.values;
});
},
location_blocks: function(crmApi) {
return crmApi('VolunteerProject', 'locations', {});
},
}
});
});

angular.module('volunteer').controller('VolOppsCtrl', function ($route, $scope, $window, $timeout, crmStatus, crmUiHelp, volOppSearch, countries, settings, supporting_data) {
angular.module('volunteer').controller('VolOppsCtrl', function ($route, $scope, $window, $timeout, crmApi, crmStatus, crmUiHelp, volOppSearch, countries, settings, supporting_data, project_types, location_blocks) {
// The ts() and hs() functions help load strings for this module.
var ts = $scope.ts = CRM.ts('org.civicrm.volunteer');
var hs = $scope.hs = crmUiHelp({file: 'ang/VolOppsCtrl'}); // See: templates/ang/VolOppsCtrl.hlp
Expand Down Expand Up @@ -59,6 +67,8 @@

$scope.countries = countries;
$scope.roles = supporting_data.values.roles;
$scope.project_types = project_types;
$scope.location_blocks = location_blocks.values;
$scope.searchParams = volOppSearch.params;
$scope.volOppData = volOppSearch.results;

Expand Down
13 changes: 13 additions & 0 deletions api/v3/VolunteerUtil.php
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,19 @@ function civicrm_api3_volunteer_util_getsupportingdata($params) {
return civicrm_api3_create_success($results, "VolunteerUtil", "getsupportingdata", $params);
}

/**
* This method returns a list of project type options
*
* @param array $params
* Not presently used.
* @return array
*/
function civicrm_api3_volunteer_util_getprojecttypeoptions($params) {
$result = CRM_Core_OptionGroup::values(CRM_Volunteer_Upgrader::volProjectTypeOptionGroupName, FALSE, FALSE, TRUE);

return civicrm_api3_create_success($result, "VolunteerUtil", "getprojecttypeoptions", $params);
}

/**
* This method returns a list of beneficiaries
*
Expand Down
9 changes: 9 additions & 0 deletions volunteer.php
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,15 @@ function volunteer_civicrm_navigationMenu(&$menu) {
'separator' => 0,
));

_volunteer_civix_insert_navigation_menu($menu, 'volunteer_volunteers', array(
'label' => E::ts('Configure Project Types'),
'name' => 'volunteer_config_project_types',
'url' => 'civicrm/admin/options/volunteer_project_type?reset=1',
'permission' => NULL,
'operator' => NULL,
'separator' => 0,
));

_volunteer_civix_insert_navigation_menu($menu, 'volunteer_volunteers', array(
'label' => E::ts('Configure Volunteer Settings'),
'name' => 'volunteer_config_settings',
Expand Down
2 changes: 1 addition & 1 deletion xml/Menu/Volunteer.xml
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@
<item>
<path>civicrm/vol</path>
<page_callback>CRM_Volunteer_Page_Angular</page_callback>
<title>CiviVolunteer</title>
<title>CiviCRM</title>
<access_callback>1</access_callback>
<is_public>true</is_public>
</item>
Expand Down