/** * Delete a need, reassign its activities to the project's default flexible need * @param $id * @return bool */ static function del($id) { $need = civicrm_api3('volunteer_need', 'getsingle', array('id' => $id)); // TODO: What do we do with associated activities when deleting a flexible need? if (empty($need['is_flexible'])) { // Lookup the flexible need $flexibleNeedId = CRM_Volunteer_BAO_Project::getFlexibleNeedID($need['project_id']); // Reassign any activities back to the flexible need $acts = civicrm_api3('volunteer_assignment', 'get', array('volunteer_need_id' => $id)); $status = CRM_Core_PseudoConstant::getKey('CRM_Activity_BAO_Activity', 'status_id', 'Available'); foreach ($acts['values'] as $act) { civicrm_api3('volunteer_assignment', 'create', array('id' => $act['id'], 'volunteer_need_id' => $flexibleNeedId, 'status_id' => $status, 'time_scheduled_minutes' => 0)); } } $dao = new CRM_Volunteer_DAO_Need(); $dao->id = $id; if ($dao->find()) { while ($dao->fetch()) { $dao->delete(); } } else { return FALSE; } return TRUE; }
/** * 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'); }