/**
  * Performs the search.
  *
  * Stashes the results in $this->searchResults.
  *
  * @return array $this->searchResults
  */
 public function search()
 {
     $projects = CRM_Volunteer_BAO_Project::retrieve($this->searchParams['project']);
     foreach ($projects as $project) {
         $results = array();
         $flexibleNeed = civicrm_api3('VolunteerNeed', 'getsingle', array('id' => $project->flexible_need_id));
         if ($flexibleNeed['visibility_id'] === CRM_Core_OptionGroup::getValue('visibility', 'public', 'name')) {
             $needId = $flexibleNeed['id'];
             $results[$needId] = $flexibleNeed;
         }
         $openNeeds = $project->open_needs;
         foreach ($openNeeds as $key => $need) {
             if ($this->needFitsSearchCriteria($need)) {
                 $results[$key] = $need;
             }
         }
         if (!empty($results)) {
             $this->projects[$project->id] = array();
         }
         $this->searchResults += $results;
     }
     $this->getSearchResultsProjectData();
     usort($this->searchResults, array($this, "usortDateAscending"));
     return $this->searchResults;
 }
Ejemplo n.º 2
0
 function testProjectRetrieve()
 {
     $project = CRM_Core_DAO::createTestObject('CRM_Volunteer_BAO_Project');
     $this->assertObjectHasAttribute('id', $project, 'Failed to prepopulate Volunteer Project');
     $projectRetrieved = CRM_Volunteer_BAO_Project::retrieve(array('id' => $project->id));
     $this->assertNotEmpty($projectRetrieved);
 }
Ejemplo n.º 3
0
 /**
  * build all the data structures needed to build the form
  *
  * @return void
  * @access public
  */
 function preProcess()
 {
     $this->_vid = CRM_Utils_Request::retrieve('vid', 'Positive', $this, TRUE);
     if (!CRM_Volunteer_Permission::checkProjectPerms(CRM_Core_Action::UPDATE, $this->_vid)) {
         CRM_Utils_System::permissionDenied();
     }
     $this->_batchInfo['item_count'] = 50;
     $params = array('project_id' => $this->_vid);
     $this->_volunteerData = CRM_Volunteer_BAO_Assignment::retrieve($params);
     $projects = CRM_Volunteer_BAO_Project::retrieve(array('id' => $this->_vid));
     $project = $projects[$this->_vid];
     $this->_entityID = $project->entity_id;
     $this->_entityTable = $project->entity_table;
     $this->_title = $project->title;
     $this->_title .= ' ( ' . CRM_Utils_Date::customFormat($project->start_date);
     $this->_start_date = $project->start_date;
     if ($project->end_date) {
         $this->_title .= ' - ' . CRM_Utils_Date::customFormat($project->end_date) . ' )';
     } else {
         $this->_title .= ' )';
     }
     /*
      * Because CiviCRM's asset management framework isn't mature yet (e.g., adding
      * assets to forms rendered in pop-ups using CRM_Core_Resources doesn't work),
      * we pass a URL fragment to the template and include them via HTML.
      */
     $this->assign('extResourceURL', CRM_Core_Resources::singleton()->getUrl('org.civicrm.volunteer'));
     $this->assign('vid', $this->_vid);
 }
 protected function getProject()
 {
     if ($this->_project === NULL) {
         $this->_project = current(CRM_Volunteer_BAO_Project::retrieve(array('entity_id' => $this->getEntityId(), 'entity_table' => CRM_Event_DAO_Event::$_tableName)));
     }
     return $this->_project;
 }
/**
 * 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)
{
    $result = CRM_Volunteer_BAO_Project::retrieve($params);
    foreach ($result as $k => $dao) {
        $result[$k] = $dao->toArray();
    }
    return civicrm_api3_create_success($result, $params, 'VolunteerProject', 'get');
}
Ejemplo n.º 6
0
 protected function getProject($params = NULL)
 {
     if ($this->_project === NULL) {
         $this->minimumProjectParams($params);
         return $this->_project = current(CRM_Volunteer_BAO_Project::retrieve($params));
     } else {
         return $this->_project;
     }
 }
 protected function getProject($params = NULL)
 {
     if ($this->_project === NULL) {
         $this->minimumProjectParams($params);
         $this->_project = current(CRM_Volunteer_BAO_Project::retrieve($params));
         if ($this->_project) {
             $beneficiaryIds = CRM_Volunteer_BAO_Project::getContactsByRelationship($this->_project->id, 'volunteer_beneficiary');
             $this->_project->target_contact_id = implode(',', $beneficiaryIds);
         }
     }
     return $this->_project;
 }
Ejemplo n.º 8
0
 /**
  * build all the data structures needed to build the form
  *
  * @return void
  * @access public
  */
 function preProcess()
 {
     $this->_vid = CRM_Utils_Request::retrieve('vid', 'Positive', $this, TRUE);
     $this->_batchInfo['item_count'] = 50;
     $params = array('project_id' => $this->_vid);
     $this->_volunteerData = CRM_Volunteer_BAO_Assignment::retrieve($params);
     $projects = CRM_Volunteer_BAO_Project::retrieve(array('id' => $this->_vid));
     $project = $projects[$this->_vid];
     $this->_entityID = $project->entity_id;
     $this->_entityTable = $project->entity_table;
     $this->_title = $project->title;
     $this->_title .= ' ( ' . CRM_Utils_Date::customFormat($project->start_date);
     $this->_start_date = $project->start_date;
     if ($project->end_date) {
         $this->_title .= ' - ' . CRM_Utils_Date::customFormat($project->end_date) . ' )';
     } else {
         $this->_title .= ' )';
     }
 }
Ejemplo n.º 9
0
 /**
  * Performs the search.
  *
  * Stashes the results in $this->searchResults.
  *
  * @return array $this->searchResults
  */
 public function search()
 {
     $projects = CRM_Volunteer_BAO_Project::retrieve($this->searchParams['project']);
     foreach ($projects as $project) {
         $openNeeds = $project->open_needs;
         if (empty($openNeeds)) {
             continue;
         }
         foreach ($openNeeds as $key => $need) {
             if (!$this->needFitsSearchCriteria($need)) {
                 unset($openNeeds[$key]);
             } elseif (!array_key_exists($project->id, $this->projects)) {
                 $this->projects[$project->id] = array();
             }
         }
         $this->searchResults += $openNeeds;
     }
     $this->getSearchResultsProjectData();
     return $this->searchResults;
 }
Ejemplo n.º 10
0
 /**
  * Function to process the form. Enables/disables Volunteer Project. If the
  * Project does not already exist, it is created, along with a "flexible" Need.
  *
  * @access public
  *
  * @return None
  */
 public function postProcess()
 {
     $form = $this->exportValues();
     $form['is_active'] = CRM_Utils_Array::value('is_active', $form, 0);
     $params = array('entity_id' => $this->_id, 'entity_table' => CRM_Event_DAO_Event::$_tableName);
     // see if this project already exists
     $projects = CRM_Volunteer_BAO_Project::retrieve($params);
     if (count($projects)) {
         // force an update rather than an insert
         $params['id'] = current($projects)->id;
     }
     // save the project record
     $params += array('is_active' => $form['is_active'], 'target_contact_id' => $form['target_contact_id']);
     $project = CRM_Volunteer_BAO_Project::create($params);
     // if the project doesn't already exist and the user enabled vol management,
     // create the flexible need
     if (count($projects) !== 1 && $form['is_active'] === '1') {
         $need = array('project_id' => $project->id, 'is_flexible' => '1', 'visibility_id' => CRM_Core_OptionGroup::getValue('visibility', 'public', 'name'));
         CRM_Volunteer_BAO_Need::create($need);
     }
     parent::endPostProcess();
 }
Ejemplo n.º 11
0
/**
 * 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');
    }
}
/**
 * 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');
        }
    }
}