INFRA-132 - Drupal.Classes.ClassDeclaration
[civicrm-core.git] / CRM / Contribute / Form / ManagePremiums.php
index e324ccd2aebd68aa4fbdd832b425ebec10e0f4a8..4b32e02743c20a4d2ad27bc1f2119697959aac50 100644 (file)
@@ -1,7 +1,7 @@
 <?php
 /*
  +--------------------------------------------------------------------+
- | CiviCRM version 4.5                                                |
+ | CiviCRM version 4.6                                                |
  +--------------------------------------------------------------------+
  | Copyright CiviCRM LLC (c) 2004-2014                                |
  +--------------------------------------------------------------------+
@@ -40,9 +40,8 @@
 class CRM_Contribute_Form_ManagePremiums extends CRM_Contribute_Form {
 
   /**
-   * Function to pre  process the form
+   * Pre  process the form
    *
-   * @access public
    *
    * @return void
    */
@@ -51,14 +50,13 @@ class CRM_Contribute_Form_ManagePremiums extends CRM_Contribute_Form {
   }
 
   /**
-   * This function sets the default values for the form. Manage Premiums that in edit/view mode
+   * Set default values for the form. Manage Premiums that in edit/view mode
    * the default values are retrieved from the database
    *
-   * @access public
    *
    * @return void
    */
-  function setDefaultValues() {
+  public function setDefaultValues() {
     $defaults = parent::setDefaultValues();
     if ($this->_id) {
       $params = array('id' => $this->_id);
@@ -87,13 +85,12 @@ class CRM_Contribute_Form_ManagePremiums extends CRM_Contribute_Form {
   }
 
   /**
-   * Function to build the form
+   * Build the form object
    *
    * @return void
-   * @access public
    */
   public function buildQuickForm() {
-    parent::buildQuickForm( );
+    parent::buildQuickForm();
     $this->setPageTitle(ts('Premium Product'));
 
     if ($this->_action & CRM_Core_Action::PREVIEW) {
@@ -107,7 +104,10 @@ class CRM_Contribute_Form_ManagePremiums extends CRM_Contribute_Form {
 
     $this->applyFilter('__ALL__', 'trim');
     $this->add('text', 'name', ts('Name'), CRM_Core_DAO::getAttribute('CRM_Contribute_DAO_Product', 'name'), TRUE);
-    $this->addRule('name', ts('A product with this name already exists. Please select another name.'), 'objectExists', array('CRM_Contribute_DAO_Product', $this->_id));
+    $this->addRule('name', ts('A product with this name already exists. Please select another name.'), 'objectExists', array(
+        'CRM_Contribute_DAO_Product',
+        $this->_id,
+      ));
     $this->add('text', 'sku', ts('SKU'), CRM_Core_DAO::getAttribute('CRM_Contribute_DAO_Product', 'sku'));
 
     $this->add('textarea', 'description', ts('Description'), 'rows=3, cols=60');
@@ -125,7 +125,6 @@ class CRM_Contribute_Form_ManagePremiums extends CRM_Contribute_Form {
 
     $this->add('file', 'uploadFile', ts('Image File Name'), 'onChange="select_option();"');
 
-
     $this->add('text', 'price', ts('Market Value'), CRM_Core_DAO::getAttribute('CRM_Contribute_DAO_Product', 'price'), TRUE);
     $this->addRule('price', ts('Please enter the Market Value for this product.'), 'money');
 
@@ -137,7 +136,11 @@ class CRM_Contribute_Form_ManagePremiums extends CRM_Contribute_Form {
 
     $this->add('textarea', 'options', ts('Options'), 'rows=3, cols=60');
 
-    $this->add('select', 'period_type', ts('Period Type'), array('' => '- select -', 'rolling' => 'Rolling', 'fixed' => 'Fixed'));
+    $this->add('select', 'period_type', ts('Period Type'), array(
+        '' => '- select -',
+        'rolling' => 'Rolling',
+        'fixed' => 'Fixed',
+      ));
 
     $this->add('text', 'fixed_period_start_day', ts('Fixed Period Start Day'), CRM_Core_DAO::getAttribute('CRM_Contribute_DAO_Product', 'fixed_period_start_day'));
 
@@ -150,14 +153,14 @@ class CRM_Contribute_Form_ManagePremiums extends CRM_Contribute_Form {
     $this->add('text', 'frequency_interval', ts('Frequency'), CRM_Core_DAO::getAttribute('CRM_Contribute_DAO_Product', 'frequency_interval'));
 
     //Financial Type CRM-11106
-    $financialType = CRM_Contribute_PseudoConstant::financialType( );
+    $financialType = CRM_Contribute_PseudoConstant::financialType();
     $premiumFinancialType = array();
     CRM_Core_PseudoConstant::populate(
       $premiumFinancialType,
       'CRM_Financial_DAO_EntityFinancialAccount',
-      $all = True,
+      $all = TRUE,
       $retrieve = 'entity_id',
-      $filter = null,
+      $filter = NULL,
       'account_relationship = 8'
     );
 
@@ -165,24 +168,25 @@ class CRM_Contribute_Form_ManagePremiums extends CRM_Contribute_Form {
     CRM_Core_PseudoConstant::populate(
       $costFinancialType,
       'CRM_Financial_DAO_EntityFinancialAccount',
-      $all = True,
+      $all = TRUE,
       $retrieve = 'entity_id',
-      $filter = null,
+      $filter = NULL,
       'account_relationship = 7'
     );
     $productFinancialType = array_intersect($costFinancialType, $premiumFinancialType);
-    foreach( $financialType as $key => $financialTypeName ){
-      if(!in_array( $key, $productFinancialType))
-        unset( $financialType[$key] );
+    foreach ($financialType as $key => $financialTypeName) {
+      if (!in_array($key, $productFinancialType)) {
+        unset($financialType[$key]);
+      }
     }
-    if( count( $financialType ) ){
-      $this->assign( 'financialType', $financialType );
+    if (count($financialType)) {
+      $this->assign('financialType', $financialType);
     }
     $this->add(
       'select',
       'financial_type_id',
-      ts( 'Financial Type' ),
-      array(''=>ts('- select -')) + $financialType
+      ts('Financial Type'),
+      array('' => ts('- select -')) + $financialType
     );
 
     $this->add('checkbox', 'is_active', ts('Enabled?'));
@@ -207,13 +211,13 @@ class CRM_Contribute_Form_ManagePremiums extends CRM_Contribute_Form {
   /**
    * Function for validation
    *
-   * @param array $params (ref.) an assoc array of name/value pairs
+   * @param array $params
+   *   (ref.) an assoc array of name/value pairs.
    *
    * @param $files
    *
-   * @return mixed true or array of errors
-   * @access public
-   * @static
+   * @return bool|array
+   *   mixed true or array of errors
    */
   public static function formRule($params, $files) {
     if (isset($params['imageOption'])) {
@@ -267,14 +271,12 @@ class CRM_Contribute_Form_ManagePremiums extends CRM_Contribute_Form {
       $errors['frequency_interval'] = ts('Please enter the Frequency Interval for this subscription or service.');
     }
 
-
     return empty($errors) ? TRUE : $errors;
   }
 
   /**
-   * Function to process the form
+   * Process the form submission
    *
-   * @access public
    *
    * @return void
    */
@@ -289,7 +291,7 @@ class CRM_Contribute_Form_ManagePremiums extends CRM_Contribute_Form {
       CRM_Core_Session::setStatus(ts('Selected Premium Product type has been deleted.'), ts('Deleted'), 'info');
     }
     else {
-      $params    = $this->controller->exportValues($this->_name);
+      $params = $this->controller->exportValues($this->_name);
       $imageFile = CRM_Utils_Array::value('uploadFile', $params);
       $imageFile = $imageFile['name'];
 
@@ -306,25 +308,29 @@ class CRM_Contribute_Form_ManagePremiums extends CRM_Contribute_Form {
 
           // to check wether GD is installed or not
           $gdSupport = CRM_Utils_System::getModuleSetting('gd', 'GD Support');
-          if($gdSupport) {
-            if($imageFile) {
-              $error = false;
+          if ($gdSupport) {
+            if ($imageFile) {
+              $error = FALSE;
               $params['image'] = $this->_resizeImage($imageFile, "_full", 200, 200);
               $params['thumbnail'] = $this->_resizeImage($imageFile, "_thumb", 50, 50);
             }
-          } else {
-            $error = true;
+          }
+          else {
+            $error = TRUE;
             $params['image'] = $config->resourceBase . 'i/contribute/default_premium.jpg';
             $params['thumbnail'] = $config->resourceBase . 'i/contribute/default_premium_thumb.jpg';
           }
-        } elseif ($value == 'thumbnail') {
+        }
+        elseif ($value == 'thumbnail') {
           $params['image'] = $params['imageUrl'];
           $params['thumbnail'] = $params['thumbnailUrl'];
-        } elseif ($value == 'default_image') {
+        }
+        elseif ($value == 'default_image') {
           $url = parse_url($config->userFrameworkBaseURL);
           $params['image'] = $config->resourceBase . 'i/contribute/default_premium.jpg';
           $params['thumbnail'] = $config->resourceBase . 'i/contribute/default_premium_thumb.jpg';
-        } else {
+        }
+        else {
           $params['image'] = "";
           $params['thumbnail'] = "";
         }
@@ -336,7 +342,10 @@ class CRM_Contribute_Form_ManagePremiums extends CRM_Contribute_Form {
 
       // fix the money fields
       foreach (array(
-        'cost', 'price', 'min_contribution') as $f) {
+                 'cost',
+                 'price',
+                 'min_contribution',
+               ) as $f) {
         $params[$f] = CRM_Utils_Rule::cleanMoney($params[$f]);
       }
 
@@ -353,30 +362,32 @@ class CRM_Contribute_Form_ManagePremiums extends CRM_Contribute_Form {
   /**
    * Resize a premium image to a different size
    *
-   * @access private
    *
-   * @param $filename
-   * @param $resizedName
+   * @param string $filename
+   * @param string $resizedName
    * @param $width
    * @param $height
    *
-   * @return Path to image
+   * @return string
+   *   Path to image
    */
   private function _resizeImage($filename, $resizedName, $width, $height) {
     // figure out the new filename
     $pathParts = pathinfo($filename);
-    $newFilename = $pathParts['dirname']."/".$pathParts['filename'].$resizedName.".".$pathParts['extension'];
+    $newFilename = $pathParts['dirname'] . "/" . $pathParts['filename'] . $resizedName . "." . $pathParts['extension'];
 
     // get image about original image
     $imageInfo = getimagesize($filename);
     $widthOrig = $imageInfo[0];
     $heightOrig = $imageInfo[1];
     $image = imagecreatetruecolor($width, $height);
-    if($imageInfo['mime'] == 'image/gif') {
+    if ($imageInfo['mime'] == 'image/gif') {
       $source = imagecreatefromgif($filename);
-    } elseif($imageInfo['mime'] == 'image/png') {
+    }
+    elseif ($imageInfo['mime'] == 'image/png') {
       $source = imagecreatefrompng($filename);
-    } else {
+    }
+    else {
       $source = imagecreatefromjpeg($filename);
     }
 
@@ -386,18 +397,17 @@ class CRM_Contribute_Form_ManagePremiums extends CRM_Contribute_Form {
     // save the resized image
     $fp = fopen($newFilename, 'w+');
     ob_start();
-    ImageJPEG($image);
+    imagejpeg($image);
     $image_buffer = ob_get_contents();
     ob_end_clean();
-    ImageDestroy($image);
+    imagedestroy($image);
     fwrite($fp, $image_buffer);
     rewind($fp);
     fclose($fp);
 
     // return the URL to link to
     $config = CRM_Core_Config::singleton();
-    return $config->imageUploadURL.basename($newFilename);
+    return $config->imageUploadURL . basename($newFilename);
   }
 
 }
-