4 +--------------------------------------------------------------------+
5 | CiviCRM version 4.6 |
6 +--------------------------------------------------------------------+
7 | Copyright CiviCRM LLC (c) 2004-2014 |
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-2014
46 * This API is used for creating a file
48 * @param array $params
49 * An associative array of name/value property values of civicrm_file.
51 * @return array of newly created file property values.
54 function civicrm_api3_file_create($params) {
56 civicrm_api3_verify_mandatory($params, 'CRM_Core_DAO_File', array('uri'));
58 if (!isset($params['upload_date'])) {
59 $params['upload_date'] = date("Ymd");
62 $fileDAO = new CRM_Core_DAO_File();
63 $properties = array('id', 'file_type_id', 'mime_type', 'uri', 'document', 'description', 'upload_date');
65 foreach ($properties as $name) {
66 if (array_key_exists($name, $params)) {
67 $fileDAO->$name = $params[$name];
74 _civicrm_api3_object_to_array($fileDAO, $file);
76 return civicrm_api3_create_success($file, $params, 'file', 'create', $fileDAO);
82 * This api is used for finding an existing file.
83 * Required parameters : id OR file_type_id of a file
85 * @param array $params
86 * An associative array of name/value property values of civicrm_file.
88 * @return Array of all found file object property values.
91 function civicrm_api3_file_get($params) {
92 civicrm_api3_verify_one_mandatory($params);
93 return _civicrm_api3_basic_get(_civicrm_api3_get_BAO(__FUNCTION__
), $params);
97 * Update an existing file
99 * This api is used for updating an existing file.
100 * Required parameters : id of a file
102 * @param array $paramsAn array of name/value property values of civicrm_file.
103 * An array of name/value property values of civicrm_file.
105 * @return array of updated file object property values
108 function civicrm_api3_file_update($params) {
110 if (!isset($params['id'])) {
111 return civicrm_api3_create_error('Required parameter missing');
114 $fileDAO = new CRM_Core_DAO_File();
115 $fileDAO->id
= $params['id'];
116 if ($fileDAO->find(TRUE)) {
117 $fileDAO->copyValues($params);
118 if (!$params['upload_date'] && !$fileDAO->upload_date
) {
119 $fileDAO->upload_date
= date("Ymd");
124 _civicrm_api3_object_to_array(clone($fileDAO), $file);
129 * Deletes an existing file
131 * This API is used for deleting a file
132 * Required parameters : id of a file
134 * @param array $params
136 * @return array API result array
139 function civicrm_api3_file_delete($params) {
141 civicrm_api3_verify_mandatory($params, NULL, array('id'));
145 $entityFileDAO = new CRM_Core_DAO_EntityFile();
146 $entityFileDAO->file_id
= $params['id'];
147 if ($entityFileDAO->find()) {
148 $check = $entityFileDAO->delete();
151 $fileDAO = new CRM_Core_DAO_File();
152 $fileDAO->id
= $params['id'];
153 if ($fileDAO->find(TRUE)) {
154 $check = $fileDAO->delete();
157 return $check ?
NULL : civicrm_api3_create_error('Error while deleting a file.');