Example #1
0
 protected function saveProject($params)
 {
     $this->minimumProjectParams($params);
     $this->_project = CRM_Volunteer_BAO_Project::create($params);
     // if we created a project:
     if (!key_exists('id', $params)) {
         $form = $this->getSubmitValues();
         if (CRM_Utils_Array::value('is_active', $form, 0) === '1') {
             // create the flexible need
             $need = array('project_id' => $this->_project->id, 'is_flexible' => '1', 'visibility_id' => CRM_Core_OptionGroup::getValue('visibility', 'public', 'name'));
             CRM_Volunteer_BAO_Need::create($need);
         }
     }
     return $this->_project;
 }
Example #2
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();
 }