$name = $params[$name]; } } $fileDAO->save(); $file = array(); _civicrm_api3_object_to_array($fileDAO, $file); return civicrm_api3_create_success($file, $params, 'file', 'create', $fileDAO); } /** * Get a file. * * This api is used for finding an existing file. * Required parameters : id OR file_type_id of a file * * @param array $params an associative array of name/value property values of civicrm_file * * @return Array of all found file object property values. * @access public */ function civicrm_api3_file_get($params) { civicrm_api3_verify_one_mandatory($params); return _civicrm_api3_basic_get(_civicrm_api3_get_BAO(__FUNCTION__), $params); } /** * Update an existing file * * This api is used for updating an existing file. * Required parameters : id of a file * * @param Array $params an array of name/value property values of civicrm_file * * @return array of updated file object property values * @access public */ function civicrm_api3_file_update($params) { if (!isset($params['id'])) { return civicrm_api3_create_error('Required parameter missing'); } $fileDAO = new CRM_Core_DAO_File(); $fileDAO->id = $params['id']; if ($fileDAO->find(TRUE)) { $fileDAO->copyValues($params); if (!$params['upload_date'] && !$fileDAO->upload_date) { $fileDAO->upload_date = date("Ymd"); } $fileDAO->save(); } $file = array(); _civicrm_api3_object_to_array(clone($fileDAO), $file); return $file; } /** * Deletes an existing file * * This API is used for deleting a file * Required parameters : id of a file * * @param $params * * @internal param Int $fileId Id of the file to be deleted * * @return null if successfull, object of CRM_Core_Error otherwise * @access public */ function civicrm_api3_file_delete($params) { civicrm_api3_verify_mandatory($params, NULL, array('id')); $check = FALSE; $entityFileDAO = new CRM_Core_DAO_EntityFile(); $entityFileDAO->file_id = $params['id']; if ($entityFileDAO->find()) { $check = $entityFileDAO->delete(); } $fileDAO = new CRM_Core_DAO_File(); $fileDAO->id = $params['id']; if ($fileDAO->find(TRUE)) { $check = $fileDAO->delete(); } return $check ? NULL : civicrm_api3_create_error('Error while deleting a file.'); }