Merge pull request #10766 from seamuslee001/contribute_perm_fix
[civicrm-core.git] / CRM / Contribute / BAO / ManagePremiums.php
index 4c7e3b8c45107aea408131dc82353a4dc170f8e1..8373b2971364c96a349ad285f38d4931125dd39c 100644 (file)
@@ -3,7 +3,7 @@
  +--------------------------------------------------------------------+
  | CiviCRM version 4.7                                                |
  +--------------------------------------------------------------------+
- | Copyright CiviCRM LLC (c) 2004-2016                                |
+ | Copyright CiviCRM LLC (c) 2004-2017                                |
  +--------------------------------------------------------------------+
  | This file is a part of CiviCRM.                                    |
  |                                                                    |
@@ -28,7 +28,7 @@
 /**
  *
  * @package CRM
- * @copyright CiviCRM LLC (c) 2004-2016
+ * @copyright CiviCRM LLC (c) 2004-2017
  */
 class CRM_Contribute_BAO_ManagePremiums extends CRM_Contribute_DAO_Product {
 
@@ -86,42 +86,33 @@ class CRM_Contribute_BAO_ManagePremiums extends CRM_Contribute_DAO_Product {
   }
 
   /**
-   * add the financial types.
+   * Add a premium product to the database, and return it.
    *
    * @param array $params
    *   Reference array contains the values submitted by the form.
    * @param array $ids
    *   Reference array contains the id.
    *
-   *
-   * @return object
+   * @return CRM_Contribute_DAO_Product
    */
   public static function add(&$params, &$ids) {
-    // CRM-14283 - strip protocol and domain from image URLs
-    $image_type = array('image', 'thumbnail');
-    foreach ($image_type as $key) {
-      if (isset($params[$key]) && $params[$key]) {
-        $parsedURL = explode('/', $params[$key]);
-        $pathComponents = array_slice($parsedURL, 3);
-        $params[$key] = '/' . implode('/', $pathComponents);
-      }
-    }
+    $params = array_merge(array(
+      'id' => CRM_Utils_Array::value('premium', $ids),
+      'image' => '',
+      'thumbnail' => '',
+      'is_active' => 0,
+      'is_deductible' => FALSE,
+      'currency' => CRM_Core_Config::singleton()->defaultCurrency,
+    ), $params);
 
-    $params['is_active'] = CRM_Utils_Array::value('is_active', $params, FALSE);
-    $params['is_deductible'] = CRM_Utils_Array::value('is_deductible', $params, FALSE);
+    // Modify the submitted values for 'image' and 'thumbnail' so that we use
+    // local URLs for these images when possible.
+    $params['image'] = CRM_Utils_String::simplifyURL($params['image'], TRUE);
+    $params['thumbnail'] = CRM_Utils_String::simplifyURL($params['thumbnail'], TRUE);
 
-    // action is taken depending upon the mode
+    // Save and return
     $premium = new CRM_Contribute_DAO_Product();
     $premium->copyValues($params);
-
-    $premium->id = CRM_Utils_Array::value('premium', $ids);
-
-    // set currency for CRM-1496
-    if (!isset($premium->currency)) {
-      $config = CRM_Core_Config::singleton();
-      $premium->currency = $config->defaultCurrency;
-    }
-
     $premium->save();
     return $premium;
   }