X-Git-Url: https://vcs.fsf.org/?a=blobdiff_plain;f=CRM%2FContribute%2FBAO%2FManagePremiums.php;h=8373b2971364c96a349ad285f38d4931125dd39c;hb=2ddf4544e42a25a923cb3183dcd4f865eaf02958;hp=9ddf411b79f35eada744b64cfb047f763e635f6c;hpb=c4f10bdde8763c3b8a2861d71dab6cfe29580932;p=civicrm-core.git diff --git a/CRM/Contribute/BAO/ManagePremiums.php b/CRM/Contribute/BAO/ManagePremiums.php index 9ddf411b79..8373b29713 100644 --- a/CRM/Contribute/BAO/ManagePremiums.php +++ b/CRM/Contribute/BAO/ManagePremiums.php @@ -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; }