4 +--------------------------------------------------------------------+
5 | CiviCRM version 4.4 |
6 +--------------------------------------------------------------------+
7 | Copyright CiviCRM LLC (c) 2004-2013 |
8 +--------------------------------------------------------------------+
9 | This file is a part of CiviCRM. |
11 | CiviCRM is free software; you can copy, modify, and distribute it |
12 | under the terms of the GNU Affero General Public License |
13 | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
15 | CiviCRM is distributed in the hope that it will be useful, but |
16 | WITHOUT ANY WARRANTY; without even the implied warranty of |
17 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
18 | See the GNU Affero General Public License for more details. |
20 | You should have received a copy of the GNU Affero General Public |
21 | License and the CiviCRM Licensing Exception along |
22 | with this program; if not, contact CiviCRM LLC |
23 | at info[AT]civicrm[DOT]org. If you have questions about the |
24 | GNU Affero General Public License or the licensing of CiviCRM, |
25 | see the CiviCRM license FAQ at http://civicrm.org/licensing |
26 +--------------------------------------------------------------------+
31 * Definition of the Tag of the CRM API.
32 * More detailed documentation can be found
33 * {@link http://objectledge.org/confluence/display/CRM/CRM+v1.0+Public+APIs
36 * @package CiviCRM_APIv3
37 * @subpackage API_File
38 * @copyright CiviCRM LLC (c) 2004-2013
46 * This API is used for creating a file
48 * @param array $params an associative array of name/value property values of civicrm_file
50 * @return array of newly created file property values.
53 function civicrm_api3_file_create($params) {
55 civicrm_api3_verify_mandatory($params, 'CRM_Core_DAO_File', array('uri'));
57 if (!isset($params['upload_date'])) {
58 $params['upload_date'] = date("Ymd");
61 $fileDAO = new CRM_Core_DAO_File();
62 $properties = array('id', 'file_type_id', 'mime_type', 'uri', 'document', 'description', 'upload_date');
64 foreach ($properties as $name) {
65 if (array_key_exists($name, $params)) {
66 $fileDAO->$name = $params[$name];
73 _civicrm_api3_object_to_array($fileDAO, $file);
75 return civicrm_api3_create_success($file, $params, 'file', 'create', $fileDAO);
81 * This api is used for finding an existing file.
82 * Required parameters : id OR file_type_id of a file
84 * @param array $params an associative array of name/value property values of civicrm_file
86 * @return Array of all found file object property values.
89 function civicrm_api3_file_get($params) {
90 civicrm_api3_verify_one_mandatory($params);
91 return _civicrm_api3_basic_get(_civicrm_api3_get_BAO(__FUNCTION__
), $params);
95 * Update an existing file
97 * This api is used for updating an existing file.
98 * Required parrmeters : id of a file
100 * @param Array $params an associative array of name/value property values of civicrm_file
102 * @return array of updated file object property values
105 function &civicrm_api3_file_update($params) {
107 if (!isset($params['id'])) {
108 return civicrm_api3_create_error('Required parameter missing');
111 $fileDAO = new CRM_Core_DAO_File();
112 $fileDAO->id
= $params['id'];
113 if ($fileDAO->find(TRUE)) {
114 $fileDAO->copyValues($params);
115 if (!$params['upload_date'] && !$fileDAO->upload_date
) {
116 $fileDAO->upload_date
= date("Ymd");
121 _civicrm_api3_object_to_array(clone($fileDAO), $file);
126 * Deletes an existing file
128 * This API is used for deleting a file
129 * Required parameters : id of a file
131 * @param Int $fileId Id of the file to be deleted
133 * @return null if successfull, object of CRM_Core_Error otherwise
137 function civicrm_api3_file_delete($params) {
139 civicrm_api3_verify_mandatory($params, NULL, array('id'));
143 $entityFileDAO = new CRM_Core_DAO_EntityFile();
144 $entityFileDAO->file_id
= $params['id'];
145 if ($entityFileDAO->find()) {
146 $check = $entityFileDAO->delete();
149 $fileDAO = new CRM_Core_DAO_File();
150 $fileDAO->id
= $params['id'];
151 if ($fileDAO->find(TRUE)) {
152 $check = $fileDAO->delete();
155 return $check ?
NULL : civicrm_api3_create_error('Error while deleting a file.');