aec82c9bbaf608acce3186acf3d639b01d1fe169
5 +--------------------------------------------------------------------+
6 | CiviCRM version 4.3 |
7 +--------------------------------------------------------------------+
8 | Copyright CiviCRM LLC (c) 2004-2013 |
9 +--------------------------------------------------------------------+
10 | This file is a part of CiviCRM. |
12 | CiviCRM is free software; you can copy, modify, and distribute it |
13 | under the terms of the GNU Affero General Public License |
14 | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
16 | CiviCRM is distributed in the hope that it will be useful, but |
17 | WITHOUT ANY WARRANTY; without even the implied warranty of |
18 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
19 | See the GNU Affero General Public License for more details. |
21 | You should have received a copy of the GNU Affero General Public |
22 | License and the CiviCRM Licensing Exception along |
23 | with this program; if not, contact CiviCRM LLC |
24 | at info[AT]civicrm[DOT]org. If you have questions about the |
25 | GNU Affero General Public License or the licensing of CiviCRM, |
26 | see the CiviCRM license FAQ at http://civicrm.org/licensing |
27 +--------------------------------------------------------------------+
32 * Definition of the Tag of the CRM API.
33 * More detailed documentation can be found
34 * {@link http://objectledge.org/confluence/display/CRM/CRM+v1.0+Public+APIs
37 * @package CiviCRM_APIv3
38 * @subpackage API_File
39 * @copyright CiviCRM LLC (c) 2004-2013
47 * This API is used for creating a file
49 * @param array $params 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 an associative array of name/value property values of civicrm_file
87 * @return Array of all found file object property values.
90 function civicrm_api3_file_get($params) {
91 civicrm_api3_verify_one_mandatory($params);
92 return _civicrm_api3_basic_get(_civicrm_api3_get_BAO(__FUNCTION__
), $params);
96 * Update an existing file
98 * This api is used for updating an existing file.
99 * Required parrmeters : id of a file
101 * @param Array $params an associative array of name/value property values of civicrm_file
103 * @return array of updated file object property values
106 function &civicrm_api3_file_update($params) {
108 if (!isset($params['id'])) {
109 return civicrm_api3_create_error('Required parameter missing');
112 $fileDAO = new CRM_Core_DAO_File();
113 $fileDAO->id
= $params['id'];
114 if ($fileDAO->find(TRUE)) {
115 $fileDAO->copyValues($params);
116 if (!$params['upload_date'] && !$fileDAO->upload_date
) {
117 $fileDAO->upload_date
= date("Ymd");
122 _civicrm_api3_object_to_array(clone($fileDAO), $file);
127 * Deletes an existing file
129 * This API is used for deleting a file
130 * Required parameters : id of a file
132 * @param Int $fileId Id of the file to be deleted
134 * @return null if successfull, object of CRM_Core_Error otherwise
138 function civicrm_api3_file_delete($params) {
140 civicrm_api3_verify_mandatory($params, NULL, array('id'));
144 $entityFileDAO = new CRM_Core_DAO_EntityFile();
145 $entityFileDAO->file_id
= $params['id'];
146 if ($entityFileDAO->find()) {
147 $check = $entityFileDAO->delete();
150 $fileDAO = new CRM_Core_DAO_File();
151 $fileDAO->id
= $params['id'];
152 if ($fileDAO->find(TRUE)) {
153 $check = $fileDAO->delete();
156 return $check ?
NULL : civicrm_api3_create_error('Error while deleting a file.');