Merge pull request #12158 from agileware/Accessibility-Issue-4
[civicrm-core.git] / CRM / Core / BAO / File.php
index 7b0ade3794b2615473d30fd0b653075dfbb7e59c..e0f4b2fa279922a576dfdff4cd721647a381830d 100644 (file)
@@ -1,9 +1,9 @@
 <?php
 /*
  +--------------------------------------------------------------------+
- | CiviCRM version 4.7                                                |
+ | CiviCRM version 5                                                  |
  +--------------------------------------------------------------------+
- | Copyright CiviCRM LLC (c) 2004-2017                                |
+ | Copyright CiviCRM LLC (c) 2004-2018                                |
  +--------------------------------------------------------------------+
  | This file is a part of CiviCRM.                                    |
  |                                                                    |
@@ -28,7 +28,7 @@
 /**
  *
  * @package CRM
- * @copyright CiviCRM LLC (c) 2004-2017
+ * @copyright CiviCRM LLC (c) 2004-2018
  * $Id$
  *
  */
@@ -40,6 +40,34 @@ class CRM_Core_BAO_File extends CRM_Core_DAO_File {
 
   static $_signableFields = array('entityTable', 'entityID', 'fileID');
 
+  /**
+   * Takes an associative array and creates a File object.
+   *
+   * @param array $params
+   *   (reference ) an assoc array of name/value pairs.
+   *
+   * @return CRM_Core_BAO_File
+   */
+  public static function create($params) {
+    $fileDAO = new CRM_Core_DAO_File();
+
+    $op = empty($params['id']) ? 'create' : 'edit';
+
+    CRM_Utils_Hook::pre($op, 'File', CRM_Utils_Array::value('id', $params), $params);
+
+    $fileDAO->copyValues($params);
+
+    if (empty($params['id']) && empty($params['created_id'])) {
+      $fileDAO->created_id = CRM_Core_Session::getLoggedInContactID();
+    }
+
+    $fileDAO->save();
+
+    CRM_Utils_Hook::post($op, 'File', $fileDAO->id, $fileDAO);
+
+    return $fileDAO;
+  }
+
   /**
    * @param int $fileID
    * @param int $entityID