/** * Create or update a project * * @param array $params Associative array of property * name/value pairs to insert in new 'project' * @example * * @return array api result array * {@getfields volunteer_project_create} * @access public */ function civicrm_api3_volunteer_project_create($params) { //Create a locBlock if we need to if (array_key_exists("loc_block_id", $params) && $params['loc_block_id'] == 0) { $locBlock = civicrm_api3("LocBlock", "create"); $params['loc_block_id'] = $locBlock['id']; } $project = CRM_Volunteer_BAO_Project::create($params); $profiles = civicrm_api3("UFJoin", "get", array("entity_id" => $project->id, "entity_table" => "civicrm_volunteer_project", "options" => array("limit" => 0))); foreach ($profiles['values'] as $profile) { if (!in_array($profile['id'], $project->profileIds)) { // CRM-17222 //$result = civicrm_api3("UFJoin", "delete", array("id" => $profile['id'])); civicrm_api3("VolunteerProject", "removeprofile", array("id" => $profile['id'])); } } //Cleanup Project Contacts if (array_key_exists("project_contacts", $params)) { $allProjectContacts = civicrm_api3("VolunteerProjectContact", "get", array('options' => array('limit' => 0), 'project_id' => $project->id, 'sequential' => 1)); foreach ($allProjectContacts['values'] as $contact) { $relType = $contact['relationship_type_id']; if (!array_key_exists($relType, $project->contacts) || !in_array($contact['contact_id'], $project->contacts[$relType])) { civicrm_api3("VolunteerProjectContact", "delete", array("id" => $contact['id'])); } } } return civicrm_api3_create_success($project->toArray(), $params, 'VolunteerProject', 'create'); }
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; }
/** * Create or update a project * * @param array $params Associative array of property * name/value pairs to insert in new 'project' * @example * * @return array api result array * {@getfields volunteer_project_create} * @access public */ function civicrm_api3_volunteer_project_create($params) { //Create a locBlock if we need to if (array_key_exists("loc_block_id", $params) && $params['loc_block_id'] == 0) { $locBlock = civicrm_api3("LocBlock", "create"); $params['loc_block_id'] = $locBlock['id']; } $project = CRM_Volunteer_BAO_Project::create($params); $profiles = civicrm_api3("UFJoin", "get", array("entity_id" => $project->id, "entity_table" => "civicrm_volunteer_project")); foreach ($profiles['values'] as $profile) { if (!in_array($profile['id'], $project->profileIds)) { // CRM-17222 //$result = civicrm_api3("UFJoin", "delete", array("id" => $profile['id'])); $result = civicrm_api3("VolunteerProject", "removeprofile", array("id" => $profile['id'])); } } return civicrm_api3_create_success($project->toArray(), $params, 'VolunteerProject', 'create'); }
function testProjectCreate() { $params = array('entity_id' => 1, 'entity_table' => 'civicrm_event'); $project = CRM_Volunteer_BAO_Project::create($params); $this->assertObjectHasAttribute('id', $project); }
/** * 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(); }
/** * 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'); }