/** * This function returns supporting data for various JavaScript-driven interfaces. * * The purpose of this API is to provide limited access to general-use APIs to * facilitate building user interfaces without having to grant users access to * APIs they otherwise shouldn't be able to access. * * @param array $params * @see _civicrm_api3_volunteer_util_getsupportingdata_spec() * @return array */ function civicrm_api3_volunteer_util_getsupportingdata($params) { $results = array(); $controller = CRM_Utils_Array::value('controller', $params); if ($controller === 'VolunteerProject') { $relTypes = civicrm_api3('OptionValue', 'get', array('option_group_id' => CRM_Volunteer_BAO_ProjectContact::RELATIONSHIP_OPTION_GROUP)); $results['relationship_types'] = $relTypes['values']; $results['phone_types'] = CRM_Core_OptionGroup::values("phone_type", FALSE, FALSE, TRUE); $results['default_profile'] = civicrm_api3('UFGroup', 'getvalue', array("name" => "volunteer_sign_up", "return" => "id")); } if ($controller === 'VolOppsCtrl') { $results['roles'] = CRM_Core_OptionGroup::values('volunteer_role', FALSE, FALSE, TRUE); } $results['use_profile_editor'] = CRM_Volunteer_Permission::check(array("access CiviCRM", "profile listings and forms")); if (!$results['use_profile_editor']) { $profiles = civicrm_api3('UFGroup', 'get', array("return" => "title", "sequential" => 1, 'options' => array('limit' => 0))); $results['profile_list'] = $profiles['values']; } return civicrm_api3_create_success($results, "VolunteerUtil", "getsupportingdata", $params); }
/** * Callback for event info page * * Inserts "Volunteer Now" button via {crmRegion} if a project is associated * with the event. */ function _volunteer_civicrm_pageRun_CRM_Event_Page_EventInfo(&$page) { $params = array('entity_id' => $page->_id, 'entity_table' => 'civicrm_event', 'is_active' => 1); $projects = CRM_Volunteer_BAO_Project::retrieve($params); // show volunteer button only if user has CiviVolunteer: register to volunteer AND this event has an active project if (CRM_Volunteer_Permission::check('register to volunteer') && count($projects)) { $project = current($projects); $url = CRM_Utils_System::url('civicrm/vol/', NULL, FALSE, "/volunteer/opportunities?project={$project->id}&dest=event", TRUE, TRUE); $button_text = ts('Volunteer Now', array('domain' => 'org.civicrm.volunteer')); $snippet = array('template' => 'CRM/Event/Page/volunteer-button.tpl', 'button_text' => $button_text, 'position' => 'top', 'url' => $url, 'weight' => -10); CRM_Core_Region::instance('event-page-eventinfo-actionlinks-top')->add($snippet); $snippet['position'] = 'bottom'; $snippet['weight'] = 10; CRM_Core_Region::instance('event-page-eventinfo-actionlinks-bottom')->add($snippet); CRM_Core_Resources::singleton()->addStyleFile('org.civicrm.volunteer', 'templates/CRM/Event/Page/EventInfo.css'); } }
/** * set variables up before form is built * * @access public */ function preProcess() { // VOL-71: permissions check is moved from XML to preProcess function to support // permissions-challenged Joomla instances if (CRM_Core_Config::singleton()->userPermissionClass->isModulePermissionSupported() && !CRM_Volunteer_Permission::check('register to volunteer')) { CRM_Utils_System::permissionDenied(); } $validNeedIds = array(); $needs = CRM_Utils_Request::retrieve('needs', 'String', $this, TRUE); if (!is_array($needs)) { $needs = explode(',', $needs); } foreach ($needs as $need) { if (CRM_Utils_Type::validate($need, 'Positive', FALSE)) { $validNeedIds[] = $need; } } $api = civicrm_api3('VolunteerNeed', 'get', array('id' => array('IN' => $validNeedIds))); $this->_needs = $api['values']; foreach ($this->_needs as $need) { $this->_projects[$need['project_id']] = array(); } $this->fetchProjectDetails(); $this->setDestination(); $this->_action = CRM_Utils_Request::retrieve('action', 'String', $this, FALSE); // current mode $this->_mode = $this->_action == CRM_Core_Action::PREVIEW ? 'test' : 'live'; }
/** * Function to set variables up before form is built * * @access public */ function preProcess() { // VOL-71: permissions check is moved from XML to preProcess function to support // permissions-challenged Joomla instances if (CRM_Core_Config::singleton()->userPermissionClass->isModulePermissionSupported() && !CRM_Volunteer_Permission::check('register to volunteer')) { CRM_Utils_System::permissionDenied(); } $vid = CRM_Utils_Request::retrieve('vid', 'Positive', $this, TRUE); $this->_project = CRM_Volunteer_BAO_Project::retrieveByID($vid); $this->setDestination(); $this->assign('vid', $this->_project->id); if (empty($this->_project->needs)) { CRM_Core_Error::fatal('Project has no public volunteer needs enabled'); } $this->_action = CRM_Utils_Request::retrieve('action', 'String', $this, FALSE); // current mode $this->_mode = $this->_action == CRM_Core_Action::PREVIEW ? 'test' : 'live'; // get profile id try { $this->_ufgroup_id = civicrm_api3('UFGroup', 'getvalue', array('name' => 'volunteer_sign_up', 'return' => 'id')); } catch (Exception $e) { CRM_Core_Error::fatal('CiviVolunteer custom profile could not be found'); } }
/** * Returns array of projects matching a set of one or more project properties * * @param array $params Array of one or more valid * property_name=>value pairs. If $params is set * as null, all projects will be returned * * @return array Array of matching projects * {@getfields volunteer_project_get} * @access public */ function civicrm_api3_volunteer_project_get($params) { //If we are in an editing context only show projects they can edit. $context = CRM_Utils_Array::value('context', $params); if ($context === 'edit' && !CRM_Volunteer_Permission::check('edit all volunteer projects')) { if (!isset($params['project_contacts'])) { $params['project_contacts'] = array(); } $params['project_contacts']['volunteer_owner'] = array(CRM_Core_Session::getLoggedInContactID()); unset($params['context']); } $result = CRM_Volunteer_BAO_Project::retrieve($params); foreach ($result as $k => $bao) { $result[$k] = $bao->toArray(); $result[$k]['entity_attributes'] = $bao->getEntityAttributes(); $profiles = civicrm_api3("UFJoin", "get", array("entity_id" => $bao->id, "entity_table" => "civicrm_volunteer_project", "options" => array("limit" => 0), "sequential" => 1)); $result[$k]['profiles'] = $profiles['values']; } return civicrm_api3_create_success($result, $params, 'VolunteerProject', 'get'); }
/** * Callback for event info page * * Inserts "Volunteer Now" button via {crmRegion} if a project is associated * with the event. */ function _volunteer_civicrm_pageRun_CRM_Event_Page_EventInfo(&$page) { $params = array('entity_id' => $page->_id, 'entity_table' => 'civicrm_event', 'is_active' => 1); $projects = CRM_Volunteer_BAO_Project::retrieve($params); // show volunteer button only if user has CiviVolunteer: register to volunteer AND this event has an active project if (CRM_Volunteer_Permission::check('register to volunteer') && count($projects)) { $project = current($projects); //VOL-189: Do not show the volunteer now button if there are not open needs. $openNeeds = civicrm_api3('VolunteerNeed', 'getsearchresult', array('project' => $project->id, 'sequential' => 1)); if ($openNeeds['count'] > 0) { //VOL-191: Skip "shopping cart" if only one need if ($openNeeds['count'] == 1) { $need = $openNeeds['values'][0]; $url = CRM_Utils_System::url('civicrm/volunteer/signup', "reset=1&needs[]={$need['id']}&dest=event"); } else { //VOL-190: Hide search pane in "shopping cart" for low role count projects $hideSearch = $openNeeds['count'] < 10 ? "hideSearch=always" : ($openNeeds['count'] < 25 ? "hideSearch=1" : "hideSearch=0"); $url = CRM_Utils_System::url('civicrm/vol/', NULL, FALSE, "/volunteer/opportunities?project={$project->id}&dest=event&{$hideSearch}", TRUE, TRUE); } $button_text = ts('Volunteer Now', array('domain' => 'org.civicrm.volunteer')); $snippet = array('template' => 'CRM/Event/Page/volunteer-button.tpl', 'button_text' => $button_text, 'position' => 'top', 'url' => $url, 'weight' => -10); CRM_Core_Region::instance('event-page-eventinfo-actionlinks-top')->add($snippet); $snippet['position'] = 'bottom'; $snippet['weight'] = 10; CRM_Core_Region::instance('event-page-eventinfo-actionlinks-bottom')->add($snippet); CRM_Core_Resources::singleton()->addStyleFile('org.civicrm.volunteer', 'templates/CRM/Event/Page/EventInfo.css'); } } }
/** * This function returns supporting data for various JavaScript-driven interfaces. * * The purpose of this API is to provide limited access to general-use APIs to * facilitate building user interfaces without having to grant users access to * APIs they otherwise shouldn't be able to access. * * @param array $params * @see _civicrm_api3_volunteer_util_getsupportingdata_spec() * @return array */ function civicrm_api3_volunteer_util_getsupportingdata($params) { $results = array(); $controller = CRM_Utils_Array::value('controller', $params); if ($controller === 'VolunteerProject') { $relTypes = civicrm_api3('OptionValue', 'get', array('option_group_id' => CRM_Volunteer_BAO_ProjectContact::RELATIONSHIP_OPTION_GROUP, 'options' => array('limit' => 0))); $results['relationship_types'] = $relTypes['values']; $results['phone_types'] = CRM_Core_OptionGroup::values("phone_type", FALSE, FALSE, TRUE); //Fetch the Defaults from saved settings. $defaults = CRM_Volunteer_BAO_Project::composeDefaultSettingsArray(); //StopGap because the interface for contacts didn't fit into scope if (!array_key_exists("relationships", $defaults)) { $defaults['relationships'] = _volunteerGetProjectRelationshipDefaults(); } //Allow other extensions to modify the defaults CRM_Volunteer_Hook::projectDefaultSettings($defaults); $results['defaults'] = $defaults; } if ($controller === 'VolOppsCtrl') { $results['roles'] = CRM_Core_OptionGroup::values('volunteer_role', FALSE, FALSE, TRUE); } $results['use_profile_editor'] = CRM_Volunteer_Permission::check(array("access CiviCRM", "profile listings and forms")); $results['profile_audience_types'] = CRM_Volunteer_BAO_Project::getProjectProfileAudienceTypes(); if (!$results['use_profile_editor']) { $profiles = civicrm_api3('UFGroup', 'get', array("return" => "title", "sequential" => 1, 'options' => array('limit' => 0))); $results['profile_list'] = $profiles['values']; } return civicrm_api3_create_success($results, "VolunteerUtil", "getsupportingdata", $params); }
/** * set variables up before form is built * * @access public */ function preProcess() { // VOL-71: permissions check is moved from XML to preProcess function to support // permissions-challenged Joomla instances if (CRM_Core_Config::singleton()->userPermissionClass->isModulePermissionSupported() && !CRM_Volunteer_Permission::check('register to volunteer')) { CRM_Utils_System::permissionDenied(); } $vid = CRM_Utils_Request::retrieve('vid', 'Positive', $this, TRUE); $this->_project = CRM_Volunteer_BAO_Project::retrieveByID($vid); $this->setDestination(); $this->assign('vid', $this->_project->id); if (empty($this->_project->needs)) { CRM_Core_Error::fatal('Project has no public volunteer needs enabled'); } $this->_action = CRM_Utils_Request::retrieve('action', 'String', $this, FALSE); // current mode $this->_mode = $this->_action == CRM_Core_Action::PREVIEW ? 'test' : 'live'; }