/** * Tests CRM_Volunteer_BAO_Assignment::createVolunteerActivity() to ensure * that the activity subject defaults to the project title. */ function testActivitySubject() { $need = $project = $volunteerContactId = NULL; extract($this->setUpProject(), EXTR_IF_EXISTS); $assignmentId = CRM_Volunteer_BAO_Assignment::createVolunteerActivity(array('assignee_contact_id' => $volunteerContactId, 'source_contact_id' => $volunteerContactId, 'volunteer_need_id' => $need->id)); $activitySubject = civicrm_api3('Activity', 'getvalue', array('activity_id' => $assignmentId, 'return' => 'subject')); $this->assertEquals($project->title, $activitySubject); }
function __construct() { $this->customGroup = CRM_Volunteer_BAO_Assignment::getCustomGroup(); $this->customFields = CRM_Volunteer_BAO_Assignment::getCustomFields(); $this->activityTypeID = CRM_Volunteer_BAO_Assignment::getActivityTypeId(); $this->_columns = array('project' => array('fields' => array('project' => array('name' => 'title', 'title' => ts('Project', array('domain' => 'org.civicrm.volunteer')), 'no_repeat' => TRUE, 'default' => TRUE)), 'alias' => 'project', 'order_bys' => array('title' => array('title' => ts('Project', array('domain' => 'org.civicrm.volunteer')), 'default' => 1)), 'grouping' => 'project-fields'), 'civicrm_contact' => array('dao' => 'CRM_Contact_DAO_Contact', 'fields' => array('contact_assignee' => array('name' => 'sort_name', 'title' => ts('Volunteer Name', array('domain' => 'org.civicrm.volunteer')), 'alias' => 'civicrm_contact_assignee_civireport', 'default' => TRUE, 'required' => TRUE), 'contact_source' => array('name' => 'sort_name', 'title' => ts('Source Contact Name', array('domain' => 'org.civicrm.volunteer')), 'alias' => 'civicrm_contact_source', 'no_repeat' => TRUE), 'contact_target' => array('name' => 'sort_name', 'title' => ts('Target Contact Name', array('domain' => 'org.civicrm.volunteer')), 'alias' => 'contact_civireport')), 'filters' => array('contact_assignee' => array('name' => 'sort_name', 'alias' => 'civicrm_contact_assignee_civireport', 'title' => ts('Volunteer Name', array('domain' => 'org.civicrm.volunteer')), 'operator' => 'like', 'type' => CRM_Report_Form::OP_STRING), 'contact_source' => array('name' => 'sort_name', 'alias' => 'civicrm_contact_source', 'title' => ts('Source Contact Name', array('domain' => 'org.civicrm.volunteer')), 'operator' => 'like', 'type' => CRM_Report_Form::OP_STRING), 'contact_target' => array('name' => 'sort_name', 'alias' => 'contact_civireport', 'title' => ts('Target Contact Name', array('domain' => 'org.civicrm.volunteer')), 'operator' => 'like', 'type' => CRM_Report_Form::OP_STRING), 'current_user' => array('name' => 'current_user', 'title' => ts('Limit To Current User', array('domain' => 'org.civicrm.volunteer')), 'type' => CRM_Utils_Type::T_INT, 'operatorType' => CRM_Report_Form::OP_SELECT, 'options' => array('0' => ts('No', array('domain' => 'org.civicrm.volunteer')), '1' => ts('Yes', array('domain' => 'org.civicrm.volunteer'))))), 'grouping' => 'contact-fields', 'order_bys' => array('sort_name' => array('title' => ts('Last Name, First Name', array('domain' => 'org.civicrm.volunteer')), 'default' => '1')), 'alias' => 'civicrm_contact_assignee'), 'civicrm_email' => array('dao' => 'CRM_Core_DAO_Email', 'fields' => array('contact_assignee_email' => array('name' => 'email', 'title' => ts('Volunteer Email', array('domain' => 'org.civicrm.volunteer')), 'alias' => 'civicrm_email_assignee'), 'contact_source_email' => array('name' => 'email', 'title' => ts('Source Contact Email', array('domain' => 'org.civicrm.volunteer')), 'alias' => 'civicrm_email_source'), 'contact_target_email' => array('name' => 'email', 'title' => ts('Target Contact Email', array('domain' => 'org.civicrm.volunteer')), 'alias' => 'civicrm_email_target'))), 'civicrm_phone' => array('dao' => 'CRM_Core_DAO_Phone', 'fields' => array('contact_assignee_phone' => array('name' => 'phone', 'title' => ts('Volunteer Phone', array('domain' => 'org.civicrm.volunteer')), 'alias' => 'civicrm_phone_assignee'), 'contact_source_phone' => array('name' => 'phone', 'title' => ts('Source Contact Phone', array('domain' => 'org.civicrm.volunteer')), 'alias' => 'civicrm_phone_source'), 'contact_target_phone' => array('name' => 'phone', 'title' => ts('Target Contact Phone', array('domain' => 'org.civicrm.volunteer')), 'alias' => 'civicrm_phone_target'))), 'civicrm_activity' => array('dao' => 'CRM_Activity_DAO_Activity', 'fields' => array('id' => array('no_display' => TRUE, 'required' => TRUE), 'source_record_id' => array('no_display' => TRUE, 'required' => TRUE), 'activity_type_id' => array('no_display' => TRUE, 'required' => TRUE), 'activity_subject' => array('title' => ts('Subject', array('domain' => 'org.civicrm.volunteer')), 'default' => TRUE), 'activity_date_time' => array('title' => ts('Scheduled Date/Time', array('domain' => 'org.civicrm.volunteer')), 'default' => TRUE, 'type' => CRM_Utils_Type::T_STRING), 'status_id' => array('title' => ts('Activity Status', array('domain' => 'org.civicrm.volunteer')), 'default' => TRUE, 'type' => CRM_Utils_Type::T_STRING)), 'filters' => array('activity_date_time' => array('default' => 'this.month', 'operatorType' => CRM_Report_Form::OP_DATE), 'activity_subject' => array('title' => ts('Activity Subject', array('domain' => 'org.civicrm.volunteer'))), 'id' => array('title' => ts('Project', array('domain' => 'org.civicrm.volunteer')), 'operatorType' => CRM_Report_Form::OP_ENTITYREF, 'type' => CRM_Utils_Type::T_INT, 'attributes' => array('entity' => 'VolunteerProject', 'select' => array('minimumInputLength' => 0)), 'alias' => 'project_civireport'), 'status_id' => array('title' => ts('Activity Status', array('domain' => 'org.civicrm.volunteer')), 'operatorType' => CRM_Report_Form::OP_MULTISELECT, 'options' => CRM_Core_PseudoConstant::activityStatus()))), 'civicrm_activity_assignment' => array('dao' => 'CRM_Activity_DAO_ActivityContact', 'fields' => array('contact_id' => array('no_display' => TRUE, 'required' => TRUE)), 'alias' => 'activity_assignment'), 'civicrm_activity_target' => array('dao' => 'CRM_Activity_DAO_ActivityContact', 'fields' => array('contact_id' => array('no_display' => TRUE, 'required' => TRUE)), 'alias' => 'activity_target'), 'civicrm_activity_source' => array('dao' => 'CRM_Activity_DAO_ActivityContact', 'fields' => array('contact_id' => array('no_display' => TRUE, 'required' => TRUE)), 'alias' => 'activity_source'), 'role' => array('fields' => array('role' => array('name' => $this->customFields['volunteer_role_id']['column_name'], 'title' => ts('Volunteer Role', array('domain' => 'org.civicrm.volunteer')), 'alias' => 'cg', 'no_repeat' => TRUE, 'default' => TRUE)), 'order_bys' => array('name' => array('title' => ts('Volunteer Role', array('domain' => 'org.civicrm.volunteer')))), 'alias' => 'ov'), 'time_scheduled' => array('fields' => array('time_scheduled' => array('name' => $this->customFields['time_scheduled_minutes']['column_name'], 'title' => ts('Time Scheduled in Minutes', array('domain' => 'org.civicrm.volunteer')), 'alias' => 'cg', 'no_repeat' => TRUE, 'default' => TRUE))), 'time_completed' => array('fields' => array('time_completed' => array('name' => $this->customFields['time_completed_minutes']['column_name'], 'title' => ts('Time Completed in Minutes', array('domain' => 'org.civicrm.volunteer')), 'alias' => 'cg', 'no_repeat' => TRUE, 'default' => TRUE))), 'civicrm_case_activity' => array('dao' => 'CRM_Case_DAO_CaseActivity', 'fields' => array('case_id' => array('name' => 'case_id', 'no_display' => TRUE, 'required' => TRUE)), 'alias' => 'case_activity')); $this->_groupFilter = TRUE; $this->_tagFilter = TRUE; parent::__construct(); }
/** * VOL-154: Verifies that an activity created in a project is tagged with the * project's campaign. */ function testCampaignInheritance() { // begin setup $campaign = CRM_Core_DAO::createTestObject('CRM_Campaign_BAO_Campaign'); $this->assertObjectHasAttribute('id', $campaign, 'Failed to prepopulate Campaign'); $project = CRM_Core_DAO::createTestObject('CRM_Volunteer_BAO_Project', array('campaign_id' => $campaign->id)); $this->assertObjectHasAttribute('id', $project, 'Failed to prepopulate Volunteer Project'); $need = CRM_Core_DAO::createTestObject('CRM_Volunteer_BAO_Need', array('project_id' => $project->id)); $this->assertObjectHasAttribute('id', $need, 'Failed to prepopulate Volunteer Need'); // end setup $activityId = CRM_Volunteer_BAO_Assignment::createVolunteerActivity(array('assignee_contact_id' => 1, 'source_contact_id' => 1, 'volunteer_need_id' => $need->id)); $this->assertNotSame(FALSE, $activityId, 'Failed to create Volunteer Activity'); $createdActivity = CRM_Volunteer_BAO_Assignment::findById($activityId); $this->assertEquals($campaign->id, $createdActivity->campaign_id, 'Activity did not inherit campaign from volunteer project'); }
function __construct() { $config = CRM_Core_Config::singleton(); $this->customGroup = CRM_Volunteer_BAO_Assignment::getCustomGroup(); $this->customFields = CRM_Volunteer_BAO_Assignment::getCustomFields(); $this->activityTypeID = CRM_Volunteer_BAO_Assignment::volunteerActivityTypeId(); $titleQuery = "SELECT e.id, e.title FROM civicrm_event e \n INNER JOIN civicrm_volunteer_project p ON e.id = p.entity_id\n WHERE p.is_active = 1"; $titles = CRM_Core_DAO::executeQuery($titleQuery); $this->title = array(); while ($titles->fetch()) { $this->title[$titles->id] = $titles->title; } asort($this->title); $this->_columns = array('project' => array('fields' => array('project' => array('name' => 'title', 'title' => ts('Project', array('domain' => 'org.civicrm.volunteer')), 'no_repeat' => TRUE, 'default' => TRUE)), 'alias' => 'project', 'order_bys' => array('title' => array('title' => ts('Project', array('domain' => 'org.civicrm.volunteer')), 'default' => 1)), 'grouping' => 'project-fields'), 'civicrm_contact' => array('dao' => 'CRM_Contact_DAO_Contact', 'fields' => array('contact_assignee' => array('name' => 'sort_name', 'title' => ts('Volunteer Name', array('domain' => 'org.civicrm.volunteer')), 'alias' => 'civicrm_contact_assignee_civireport', 'default' => TRUE, 'required' => TRUE), 'contact_source' => array('name' => 'sort_name', 'title' => ts('Source Contact Name', array('domain' => 'org.civicrm.volunteer')), 'alias' => 'civicrm_contact_source', 'no_repeat' => TRUE), 'contact_target' => array('name' => 'sort_name', 'title' => ts('Target Contact Name', array('domain' => 'org.civicrm.volunteer')), 'alias' => 'contact_civireport')), 'filters' => array('contact_assignee' => array('name' => 'sort_name', 'alias' => 'civicrm_contact_assignee_civireport', 'title' => ts('Volunteer Name', array('domain' => 'org.civicrm.volunteer')), 'operator' => 'like', 'type' => CRM_Report_Form::OP_STRING), 'contact_source' => array('name' => 'sort_name', 'alias' => 'civicrm_contact_source', 'title' => ts('Source Contact Name', array('domain' => 'org.civicrm.volunteer')), 'operator' => 'like', 'type' => CRM_Report_Form::OP_STRING), 'contact_target' => array('name' => 'sort_name', 'alias' => 'contact_civireport', 'title' => ts('Target Contact Name', array('domain' => 'org.civicrm.volunteer')), 'operator' => 'like', 'type' => CRM_Report_Form::OP_STRING), 'current_user' => array('name' => 'current_user', 'title' => ts('Limit To Current User', array('domain' => 'org.civicrm.volunteer')), 'type' => CRM_Utils_Type::T_INT, 'operatorType' => CRM_Report_Form::OP_SELECT, 'options' => array('0' => ts('No', array('domain' => 'org.civicrm.volunteer')), '1' => ts('Yes', array('domain' => 'org.civicrm.volunteer'))))), 'grouping' => 'contact-fields', 'order_bys' => array('sort_name' => array('title' => ts('Last Name, First Name', array('domain' => 'org.civicrm.volunteer')), 'default' => '1')), 'alias' => 'civicrm_contact_assignee'), 'civicrm_email' => array('dao' => 'CRM_Core_DAO_Email', 'fields' => array('contact_assignee_email' => array('name' => 'email', 'title' => ts('Volunteer Email', array('domain' => 'org.civicrm.volunteer')), 'alias' => 'civicrm_email_assignee'), 'contact_source_email' => array('name' => 'email', 'title' => ts('Source Contact Email', array('domain' => 'org.civicrm.volunteer')), 'alias' => 'civicrm_email_source'), 'contact_target_email' => array('name' => 'email', 'title' => ts('Target Contact Email', array('domain' => 'org.civicrm.volunteer')), 'alias' => 'civicrm_email_target'))), 'civicrm_phone' => array('dao' => 'CRM_Core_DAO_Phone', 'fields' => array('contact_assignee_phone' => array('name' => 'phone', 'title' => ts('Volunteer Phone', array('domain' => 'org.civicrm.volunteer')), 'alias' => 'civicrm_phone_assignee'), 'contact_source_phone' => array('name' => 'phone', 'title' => ts('Source Contact Phone', array('domain' => 'org.civicrm.volunteer')), 'alias' => 'civicrm_phone_source'), 'contact_target_phone' => array('name' => 'phone', 'title' => ts('Target Contact Phone', array('domain' => 'org.civicrm.volunteer')), 'alias' => 'civicrm_phone_target'))), 'civicrm_activity' => array('dao' => 'CRM_Activity_DAO_Activity', 'fields' => array('id' => array('no_display' => TRUE, 'required' => TRUE), 'source_record_id' => array('no_display' => TRUE, 'required' => TRUE), 'activity_type_id' => array('no_display' => TRUE, 'required' => TRUE), 'activity_subject' => array('title' => ts('Subject', array('domain' => 'org.civicrm.volunteer')), 'default' => TRUE), 'activity_date_time' => array('title' => ts('Scheduled Date/Time', array('domain' => 'org.civicrm.volunteer')), 'default' => TRUE, 'type' => CRM_Utils_Type::T_STRING), 'status_id' => array('title' => ts('Activity Status', array('domain' => 'org.civicrm.volunteer')), 'default' => TRUE, 'type' => CRM_Utils_Type::T_STRING)), 'filters' => array('activity_date_time' => array('default' => 'this.month', 'operatorType' => CRM_Report_Form::OP_DATE), 'activity_subject' => array('title' => ts('Activity Subject', array('domain' => 'org.civicrm.volunteer'))), 'id' => array('title' => ts('Project', array('domain' => 'org.civicrm.volunteer')), 'operatorType' => CRM_Report_Form::OP_MULTISELECT, 'options' => $this->title, 'alias' => 'project_civireport', 'type' => CRM_Utils_Type::T_INT), 'status_id' => array('title' => ts('Activity Status', array('domain' => 'org.civicrm.volunteer')), 'operatorType' => CRM_Report_Form::OP_MULTISELECT, 'options' => CRM_Core_PseudoConstant::activityStatus()))), 'civicrm_activity_assignment' => array('dao' => 'CRM_Activity_DAO_ActivityContact', 'fields' => array('contact_id' => array('no_display' => TRUE, 'required' => TRUE)), 'alias' => 'activity_assignment'), 'civicrm_activity_target' => array('dao' => 'CRM_Activity_DAO_ActivityContact', 'fields' => array('contact_id' => array('no_display' => TRUE, 'required' => TRUE)), 'alias' => 'activity_target'), 'civicrm_activity_source' => array('dao' => 'CRM_Activity_DAO_ActivityContact', 'fields' => array('contact_id' => array('no_display' => TRUE, 'required' => TRUE)), 'alias' => 'activity_source'), 'role' => array('fields' => array('role' => array('name' => $this->customFields['volunteer_role_id']['column_name'], 'title' => ts('Volunteer Role', array('domain' => 'org.civicrm.volunteer')), 'alias' => 'cg', 'no_repeat' => TRUE, 'default' => TRUE)), 'order_bys' => array('name' => array('title' => ts('Volunteer Role', array('domain' => 'org.civicrm.volunteer')))), 'alias' => 'ov'), 'time_scheduled' => array('fields' => array('time_scheduled' => array('name' => $this->customFields['time_scheduled_minutes']['column_name'], 'title' => ts('Time Scheduled in Minutes', array('domain' => 'org.civicrm.volunteer')), 'alias' => 'cg', 'no_repeat' => TRUE, 'default' => TRUE))), 'time_completed' => array('fields' => array('time_completed' => array('name' => $this->customFields['time_completed_minutes']['column_name'], 'title' => ts('Time Completed in Minutes', array('domain' => 'org.civicrm.volunteer')), 'alias' => 'cg', 'no_repeat' => TRUE, 'default' => TRUE))), 'civicrm_case_activity' => array('dao' => 'CRM_Case_DAO_CaseActivity', 'fields' => array('case_id' => array('name' => 'case_id', 'no_display' => TRUE, 'required' => TRUE)), 'alias' => 'case_activity')); $this->_groupFilter = TRUE; $this->_tagFilter = TRUE; parent::__construct(); }
/** * Returns array of assignments matching a set of one or more group properties * * @param array $params Associative array of property name/value pairs * describing the assignments to be retrieved. * @example * @return array ID-indexed array of matching assignments * {@getfields assignment_get} * @access public */ function civicrm_api3_volunteer_assignment_get($params) { $result = CRM_Volunteer_BAO_Assignment::retrieve($params); return civicrm_api3_create_success($result, $params, 'Activity', 'get'); }
/** * @todo per totten's suggestion, wrap all these writes in a transaction; * see http://wiki.civicrm.org/confluence/display/CRMDOC43/Transaction+Reference */ function postProcess() { $cid = CRM_Utils_Array::value('userID', $_SESSION['CiviCRM'], NULL); $values = $this->controller->exportValues(); $profileFields = array(); foreach ($this->getProfileIDs() as $profileID) { $profileFields += CRM_Core_BAO_UFGroup::getFields($profileID); } $profileValues = array_intersect_key($values, $profileFields); $activityValues = array_diff_key($values, $profileValues); // Search for duplicate if (!$cid) { $dedupeParams = CRM_Dedupe_Finder::formatParams($profileValues, 'Individual'); $dedupeParams['check_permission'] = FALSE; $ids = CRM_Dedupe_Finder::dupesByParams($dedupeParams, 'Individual'); if ($ids) { $cid = $ids[0]; } } $cid = CRM_Contact_BAO_Contact::createProfileContact($profileValues, $profileFields, $cid); $activity_statuses = CRM_Activity_BAO_Activity::buildOptions('status_id', 'create'); $projectNeeds = array(); foreach ($this->_needs as $need) { $activityValues['volunteer_need_id'] = $need['id']; $activityValues['activity_date_time'] = CRM_Utils_Array::value('start_time', $need); $activityValues['assignee_contact_id'] = $cid; $activityValues['is_test'] = $this->_mode === 'test' ? 1 : 0; // below we assume that volunteers are always signing up only themselves; // for now this is a safe assumption, but we may need to revisit this. $activityValues['source_contact_id'] = $cid; // Set status to Available if user selected Flexible Need, else set to Scheduled. if (CRM_Utils_Array::value('is_flexible', $need)) { $activityValues['status_id'] = CRM_Utils_Array::key('Available', $activity_statuses); } else { $activityValues['status_id'] = CRM_Utils_Array::key('Scheduled', $activity_statuses); } $activityValues['time_scheduled_minutes'] = CRM_Utils_Array::value('duration', $need); CRM_Volunteer_BAO_Assignment::createVolunteerActivity($activityValues); if (!array_key_exists($need['project_id'], $projectNeeds)) { $projectNeeds[$need['project_id']] = array(); } $need['role'] = $need['role_label']; $need['description'] = $need['role_description']; $need['duration'] = CRM_Utils_Array::value('duration', $need); $projectNeeds[$need['project_id']][$need['id']] = $need; } // Send confirmation email to volunteer list($displayName, $email) = CRM_Contact_BAO_Contact_Location::getEmailDetails($cid); list($domainEmailName, $domainEmailAddress) = CRM_Core_BAO_Domain::getNameAndEmail(); if ($email) { $tplParams = $this->prepareTplParams($projectNeeds); $sendTemplateParams = array('contactId' => $cid, 'from' => "{$domainEmailName} <" . $domainEmailAddress . ">", 'groupName' => 'msg_tpl_workflow_volunteer', 'isTest' => $this->_mode === 'test', 'toName' => $displayName, 'toEmail' => $email, 'tplParams' => array("volunteer_projects" => $tplParams), 'valueName' => 'volunteer_registration'); $bcc = array(); foreach ($tplParams as $data) { foreach ($data['contacts'] as $manager) { $bcc[$manager['contact_id']] = "{$manager['display_name']} <{$manager['email']}>"; } } if (count($bcc)) { $sendTemplateParams['bcc'] = implode(', ', $bcc); } CRM_Core_BAO_MessageTemplate::sendTemplate($sendTemplateParams); } $statusMsg = ts('You are scheduled to volunteer. Thank you!', array('domain' => 'org.civicrm.volunteer')); CRM_Core_Session::setStatus($statusMsg, '', 'success'); CRM_Utils_System::redirect($this->_destination); }
/** * Callback for core Activity view and form * * Display user-friendly label for Need ID rather than an integer, or hide * the field altogether, depending on context. */ function _volunteer_civicrm_buildForm_CRM_Activity_Form_Activity($formName, &$form) { // determine name that the Volunteer Need ID field would be given in this form $custom_group = CRM_Volunteer_BAO_Assignment::getCustomGroup(); $custom_fields = CRM_Volunteer_BAO_Assignment::getCustomFields(); $group_id = $custom_group['id']; $field_id = $custom_fields['volunteer_need_id']['id']; // element name varies depending on context $possible_element_names = array('custom_' . $field_id . '_1', 'custom_' . $field_id . '_-1'); $element_name = NULL; foreach ($possible_element_names as $name) { if ($form->elementExists($name)) { $element_name = $name; break; } } // If it contains the Volunteer Need ID field, this is an edit form if (isset($element_name)) { $field = $form->getElement($element_name); $form->removeElement($element_name); // If need_id isn't set, do not re-add need_id field as a dropdown. // See http://issues.civicrm.org/jira/browse/VOL-24?focusedCommentId=53836#comment-53836 if ($need_id = $field->_attributes['value']) { $need = civicrm_api3('VolunteerNeed', 'getsingle', array('id' => $need_id, 'return' => 'project_id')); $Project = CRM_Volunteer_BAO_Project::retrieveByID($need['project_id']); $needs = array(); foreach ($Project->needs as $key => $value) { $needs[$key] = $value['role_label'] . ': ' . $value['display_time']; } asort($needs); $form->add('select', $element_name, $field->_label, $needs, TRUE); } } elseif (isset($form->_activityTypeName) && $form->_activityTypeName == 'Volunteer') { $custom = $form->get_template_vars('viewCustomData'); if (!empty($custom[$group_id])) { $index = key($custom[$group_id]); if (!empty($custom[$group_id][$index]['fields'][$field_id]['field_value'])) { $value =& $custom[$group_id][$index]['fields'][$field_id]['field_value']; $need = civicrm_api3('VolunteerNeed', 'getsingle', array('id' => $value)); $value = $need['role_label'] . ': ' . $need['display_time']; $form->assign('viewCustomData', $custom); } } } }
/** * process the form after the input has been submitted and validated * * @access public * * @return None */ public function postProcess() { $params = $this->controller->exportValues($this->_name); $validParams = self::getCompletedRows($params['field']); $count = 0; foreach ($validParams as $value) { if (!empty($value['activity_id'])) { // update the activity record $volunteer = array('status_id' => $value['volunteer_status'], 'id' => $value['activity_id'], 'time_completed_minutes' => CRM_Utils_Array::value('actual_duration', $value), 'time_scheduled_minutes' => CRM_Utils_Array::value('scheduled_duration', $value)); CRM_Volunteer_BAO_Assignment::createVolunteerActivity($volunteer); } else { $flexibleNeedId = CRM_Volunteer_BAO_Project::getFlexibleNeedID($this->_vid); // create new Volunteer activity records $volunteer = array('assignee_contact_id' => $value['contact_id'], 'status_id' => $value['volunteer_status'], 'subject' => $this->_title . ' Volunteering', 'volunteer_need_id' => $flexibleNeedId, 'volunteer_role_id' => CRM_Utils_Array::value('volunteer_role', $value), 'time_completed_minutes' => CRM_Utils_Array::value('actual_duration', $value), 'time_scheduled_minutes' => CRM_Utils_Array::value('scheduled_duration', $value)); if (!empty($value['start_date'])) { $volunteer['activity_date_time'] = CRM_Utils_Date::processDate($value['start_date'], $value['start_date_time'], TRUE); } CRM_Volunteer_BAO_Assignment::createVolunteerActivity($volunteer); } $count++; } $statusMsg = ts('Volunteer hours have been logged.', array('domain' => 'org.civicrm.volunteer')); CRM_Core_Session::setStatus($statusMsg, ts('Saved', array('domain' => 'org.civicrm.volunteer')), 'success'); }
/** * @todo per totten's suggestion, wrap all these writes in a transaction; * see http://wiki.civicrm.org/confluence/display/CRMDOC43/Transaction+Reference */ function postProcess() { $cid = CRM_Utils_Array::value('userID', $_SESSION['CiviCRM'], NULL); $values = $this->controller->exportValues(); $isFlexible = FALSE; // Role id is not present in form $values when the only public need is the flexible need. // So if role id is not set OR if it matches flexible role id constant then use the flexible need id if (!isset($values['volunteer_role_id']) || (int) CRM_Utils_Array::value('volunteer_role_id', $values) === CRM_Volunteer_BAO_Need::FLEXIBLE_ROLE_ID) { $isFlexible = TRUE; foreach ($this->_project->needs as $n) { if ($n['is_flexible'] === '1') { $values['volunteer_need_id'] = $n['id']; break; } } } unset($values['volunteer_role_id']); // we don't need this anymore $params = array('id' => CRM_Utils_Array::value('volunteer_need_id', $values), 'version' => 3); $need = civicrm_api('VolunteerNeed', 'getsingle', $params); $profile_fields = CRM_Core_BAO_UFGroup::getFields($this->_ufgroup_id); $profile_values = array_intersect_key($values, $profile_fields); $builtin_values = array_diff_key($values, $profile_values); // Search for duplicate if (!$cid) { $dedupeParams = CRM_Dedupe_Finder::formatParams($profile_values, 'Individual'); $dedupeParams['check_permission'] = FALSE; $ids = CRM_Dedupe_Finder::dupesByParams($dedupeParams, 'Individual'); if ($ids) { $cid = $ids[0]; } } $cid = CRM_Contact_BAO_Contact::createProfileContact($profile_values, $profile_fields, $cid, NULL, $this->_ufgroup_id); $activity_statuses = CRM_Activity_BAO_Activity::buildOptions('status_id', 'create'); $builtin_values['activity_date_time'] = CRM_Utils_Array::value('start_time', $need); $builtin_values['assignee_contact_id'] = $cid; $builtin_values['is_test'] = $this->_mode === 'test' ? 1 : 0; // below we assume that volunteers are always signing up only themselves; // for now this is a safe assumption, but we may need to revisit this. $builtin_values['source_contact_id'] = $cid; // Set status to Available if user selected Flexible Need, else set to Scheduled. if ($isFlexible) { $builtin_values['status_id'] = CRM_Utils_Array::key('Available', $activity_statuses); } else { $builtin_values['status_id'] = CRM_Utils_Array::key('Scheduled', $activity_statuses); } $builtin_values['subject'] = $this->_project->title; $builtin_values['time_scheduled_minutes'] = CRM_Utils_Array::value('duration', $need); CRM_Volunteer_BAO_Assignment::createVolunteerActivity($builtin_values); // Send confirmation email to volunteer list($displayName, $email) = CRM_Contact_BAO_Contact_Location::getEmailDetails($cid); list($domainEmailName, $domainEmailAddress) = CRM_Core_BAO_Domain::getNameAndEmail(); if ($email) { $date = CRM_Utils_Date::customFormat($builtin_values['activity_date_time'], "%m/%E/%Y at %l:%M %P"); $html = "You are scheduled to volunteer at the " . $builtin_values["subject"] . " on " . $date . ". Thank You!"; $mailParams["from"] = "{$domainEmailName} <" . $domainEmailAddress . ">"; $mailParams["toName"] = $displayName; $mailParams["toEmail"] = $email; $mailParams["subject"] = "Volunteer Confirmation for {$builtin_values['subject']}"; $mailParams["text"] = $html; $mailParams["html"] = $html; $mailParams["replyTo"] = $domainEmailAddress; CRM_Utils_Mail::send($mailParams); } $statusMsg = ts('You are scheduled to volunteer. Thank you!', array('domain' => 'org.civicrm.volunteer')); CRM_Core_Session::setStatus($statusMsg, '', 'success'); CRM_Utils_System::redirect($this->_destination); }
/** * VOL-154: Verifies that, when a project's campaign is updated, the campaign * for each associated activity is as well. */ function testProjectCampaignUpdate() { $testObjects = $this->_createTestObjects(); CRM_Volunteer_BAO_Project::create(array('campaign_id' => $testObjects['campaign']->id, 'id' => $testObjects['project']->id)); $updatedActivity = CRM_Volunteer_BAO_Assignment::findById($testObjects['activity']['id']); $this->assertEquals($testObjects['campaign']->id, $updatedActivity->campaign_id, 'Activity campaign was not updated with project campaign'); // Test unsetting campaign from a project. CRM_Volunteer_BAO_Project::create(array('campaign_id' => '', 'id' => $testObjects['project']->id)); $updatedActivity = CRM_Volunteer_BAO_Assignment::findById($testObjects['activity']['id']); $this->assertEquals('', $updatedActivity->campaign_id, 'Activity campaign was not updated with empty project campaign'); }
/** * Facilitates propagatation of changes in a Project to associated Activities. * * This method takes no arguments because the Assignment BAO handles * propagation internally. * * @see CRM_Volunteer_BAO_Assignment::setActivityDefaults() */ public function updateAssociatedActivities() { $activities = CRM_Volunteer_BAO_Assignment::retrieve(array('project_id' => $this->id)); foreach ($activities as $activity) { CRM_Volunteer_BAO_Assignment::createVolunteerActivity(array('id' => $activity['id'])); } }
/** * @todo per totten's suggestion, wrap all these writes in a transaction; * see http://wiki.civicrm.org/confluence/display/CRMDOC43/Transaction+Reference */ function postProcess() { $cid = CRM_Utils_Array::value('userID', $_SESSION['CiviCRM'], NULL); $values = $this->controller->exportValues(); $profileFields = array(); foreach ($this->getProfileIDs() as $profileID) { $profileFields += CRM_Core_BAO_UFGroup::getFields($profileID); } $profileValues = array_intersect_key($values, $profileFields); $activityValues = array_diff_key($values, $profileValues); // Search for duplicate if (!$cid) { $dedupeParams = CRM_Dedupe_Finder::formatParams($profileValues, 'Individual'); $dedupeParams['check_permission'] = FALSE; $ids = CRM_Dedupe_Finder::dupesByParams($dedupeParams, 'Individual'); if ($ids) { $cid = $ids[0]; } } $cid = CRM_Contact_BAO_Contact::createProfileContact($profileValues, $profileFields, $cid); $activity_statuses = CRM_Activity_BAO_Activity::buildOptions('status_id', 'create'); foreach ($this->_needs as $need) { $activityValues['volunteer_need_id'] = $need['id']; $activityValues['activity_date_time'] = CRM_Utils_Array::value('start_time', $need); $activityValues['assignee_contact_id'] = $cid; $activityValues['is_test'] = $this->_mode === 'test' ? 1 : 0; // below we assume that volunteers are always signing up only themselves; // for now this is a safe assumption, but we may need to revisit this. $activityValues['source_contact_id'] = $cid; // Set status to Available if user selected Flexible Need, else set to Scheduled. if (CRM_Utils_Array::value('is_flexible', $need)) { $activityValues['status_id'] = CRM_Utils_Array::key('Available', $activity_statuses); } else { $activityValues['status_id'] = CRM_Utils_Array::key('Scheduled', $activity_statuses); } $activityValues['time_scheduled_minutes'] = CRM_Utils_Array::value('duration', $need); CRM_Volunteer_BAO_Assignment::createVolunteerActivity($activityValues); } $statusMsg = ts('You are scheduled to volunteer. Thank you!', array('domain' => 'org.civicrm.volunteer')); CRM_Core_Session::setStatus($statusMsg, '', 'success'); CRM_Utils_System::redirect($this->_destination); }
/** * This function Loops through the needs the user is signing up for * and creates activity records for them. * * @param int $cid * The contact ID for whom this activity is to be created * @param array $activityValues * An array of values corresponding to the data the user submitted minus the profile fields * @return array * Project needs data for use in sending confirmation email. */ private function createVolunteerActivity($cid, array $activityValues) { $projectNeeds = array(); $activity_statuses = CRM_Activity_BAO_Activity::buildOptions('status_id', 'create'); foreach ($this->_needs as $need) { $activityValues['volunteer_need_id'] = $need['id']; $activityValues['activity_date_time'] = CRM_Utils_Array::value('start_time', $need); $activityValues['assignee_contact_id'] = $cid; $activityValues['is_test'] = $this->_mode === 'test' ? 1 : 0; $activityValues['source_contact_id'] = $this->_primary_volunteer_id; // Set status to Available if user selected Flexible Need, else set to Scheduled. if (CRM_Utils_Array::value('is_flexible', $need)) { $activityValues['status_id'] = CRM_Utils_Array::key('Available', $activity_statuses); } else { $activityValues['status_id'] = CRM_Utils_Array::key('Scheduled', $activity_statuses); } $activityValues['time_scheduled_minutes'] = CRM_Utils_Array::value('duration', $need); CRM_Volunteer_BAO_Assignment::createVolunteerActivity($activityValues); if (!array_key_exists($need['project_id'], $projectNeeds)) { $projectNeeds[$need['project_id']] = array(); } $need['role'] = $need['role_label']; $need['description'] = $need['role_description']; $need['duration'] = CRM_Utils_Array::value('duration', $need); $projectNeeds[$need['project_id']][$need['id']] = $need; } return $projectNeeds; }