INFRA-132 - CRM/Contribute - phpcbf
[civicrm-core.git] / CRM / Contribute / Form / ManagePremiums.php
index 4c9c34bbdf75361b42d20322bf8eed2dc7d56393..fcd0c60eae038b3139874568638fecdbb9126a80 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,10 +85,9 @@ 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( );
@@ -125,7 +122,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');
 
@@ -155,9 +151,9 @@ class CRM_Contribute_Form_ManagePremiums extends CRM_Contribute_Form {
     CRM_Core_PseudoConstant::populate(
       $premiumFinancialType,
       'CRM_Financial_DAO_EntityFinancialAccount',
-      $all = True,
+      $all = TRUE,
       $retrieve = 'entity_id',
-      $filter = null,
+      $filter = NULL,
       'account_relationship = 8'
     );
 
@@ -165,15 +161,16 @@ 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))
+      if(!in_array( $key, $productFinancialType)) {
         unset( $financialType[$key] );
+      }
     }
     if( count( $financialType ) ){
       $this->assign( 'financialType', $financialType );
@@ -182,25 +179,37 @@ class CRM_Contribute_Form_ManagePremiums extends CRM_Contribute_Form {
       'select',
       'financial_type_id',
       ts( 'Financial Type' ),
-      array(''=>ts('- select -')) + $financialType
+      array('' => ts('- select -')) + $financialType
     );
 
     $this->add('checkbox', 'is_active', ts('Enabled?'));
 
     $this->addFormRule(array('CRM_Contribute_Form_ManagePremiums', 'formRule'));
 
+    $this->addButtons(array(
+        array(
+          'type' => 'upload',
+          'name' => ts('Save'),
+          'isDefault' => TRUE,
+        ),
+        array(
+          'type' => 'cancel',
+          'name' => ts('Cancel'),
+        ),
+      )
+    );
     $this->assign('productId', $this->_id);
   }
 
   /**
    * 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
    */
   public static function formRule($params, $files) {
@@ -255,14 +264,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
    */
@@ -296,12 +303,12 @@ class CRM_Contribute_Form_ManagePremiums extends CRM_Contribute_Form {
           $gdSupport = CRM_Utils_System::getModuleSetting('gd', 'GD Support');
           if($gdSupport) {
             if($imageFile) {
-              $error = false;
+              $error = FALSE;
               $params['image'] = $this->_resizeImage($imageFile, "_full", 200, 200);
               $params['thumbnail'] = $this->_resizeImage($imageFile, "_thumb", 50, 50);
             }
           } else {
-            $error = true;
+            $error = TRUE;
             $params['image'] = $config->resourceBase . 'i/contribute/default_premium.jpg';
             $params['thumbnail'] = $config->resourceBase . 'i/contribute/default_premium_thumb.jpg';
           }
@@ -341,10 +348,9 @@ 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
    *
@@ -374,10 +380,10 @@ 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);
@@ -388,4 +394,3 @@ class CRM_Contribute_Form_ManagePremiums extends CRM_Contribute_Form {
   }
 
 }
-