From aa4ad33a7ab27bfa3ab8c88b824ed0d4cff4375f Mon Sep 17 00:00:00 2001 From: Sean Madsen Date: Fri, 21 Jul 2017 10:43:49 -0600 Subject: [PATCH] CRM-20821 - Improve ManagePremiums formRule() - Improve CRM_Contribute_Form_ManagePremiums::formRule() - Require an image file, if "upload" is chosen - Remove the commented-out code for a rule which required images to be within a certain size - Minor refactoring to improve code clarity --- CRM/Contribute/Form/ManagePremiums.php | 35 +++++++++++++------------- 1 file changed, 18 insertions(+), 17 deletions(-) diff --git a/CRM/Contribute/Form/ManagePremiums.php b/CRM/Contribute/Form/ManagePremiums.php index aabda090dd..437505d834 100644 --- a/CRM/Contribute/Form/ManagePremiums.php +++ b/CRM/Contribute/Form/ManagePremiums.php @@ -201,35 +201,36 @@ class CRM_Contribute_Form_ManagePremiums extends CRM_Contribute_Form { * * @param array $params * (ref.) an assoc array of name/value pairs. - * * @param $files * * @return bool|array * mixed true or array of errors */ public static function formRule($params, $files) { - if (isset($params['imageOption'])) { - if ($params['imageOption'] == 'thumbnail') { - if (!$params['imageUrl']) { - $errors['imageUrl'] = ts('Image URL is Required'); - } - if (!$params['thumbnailUrl']) { - $errors['thumbnailUrl'] = ts('Thumbnail URL is Required'); - } + + // If choosing to upload an image, then an image must be provided + if ( + isset($params['imageOption']) && + $params['imageOption'] == 'image' && + empty($files['uploadFile']['name']) + ) { + $errors['uploadFile'] = ts('A file must be selected'); + } + + // If choosing to use image URLs, then both URLs must be present + if (isset($params['imageOption']) && $params['imageOption'] == 'thumbnail') { + if (!$params['imageUrl']) { + $errors['imageUrl'] = ts('Image URL is Required'); + } + if (!$params['thumbnailUrl']) { + $errors['thumbnailUrl'] = ts('Thumbnail URL is Required'); } } + // CRM-13231 financial type required if product has cost if (!empty($params['cost']) && empty($params['financial_type_id'])) { $errors['financial_type_id'] = ts('Financial Type is required for product having cost.'); } - $fileLocation = $files['uploadFile']['tmp_name']; - if ($fileLocation != "") { - list($width, $height) = getimagesize($fileLocation); - - if (($width < 80 || $width > 500) || ($height < 80 || $height > 500)) { - //$errors ['uploadFile'] = "Please Enter files with dimensions between 80 x 80 and 500 x 500," . " Dimensions of this file is ".$width."X".$height; - } - } if (!$params['period_type']) { if ($params['fixed_period_start_day'] || $params['duration_unit'] || $params['duration_interval'] || -- 2.25.1