Advertisement
Guest User

Untitled

a guest
Oct 23rd, 2018
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.09 KB | None | 0 0
  1. <?php
  2.  
  3. use CRM_Otheramount_ExtensionUtil as E;
  4.  
  5. /**
  6.  * Form controller class
  7.  *
  8.  * @see https://wiki.civicrm.org/confluence/display/CRMDOC/QuickForm+Reference
  9.  */
  10. class CRM_Otheramount_Form_OtherAmountSettings extends CRM_Core_Form {
  11.  
  12.   protected $_otherAmountPriceSets;
  13.  
  14.   /**
  15.    * Set variables up before form is built.
  16.    */
  17.   public function preProcess() {
  18.     if (!CRM_Core_Permission::check('administer CiviCRM')) {
  19.       CRM_Core_Error::fatal(ts('You do not permission to access this page, please contact your system administrator.'));
  20.     }
  21.     $this->_otherAmountPriceSets = Civi::settings()->get('otherAmountPriceSets');
  22.   }
  23.  
  24.   /**
  25.    * Set default values.
  26.    *
  27.    * @return array
  28.    */
  29.   public function setDefaultValues() {
  30.     return $this->_otherAmountPriceSets;
  31.   }
  32.  
  33.   public function buildQuickForm() {
  34.     //We want active price fields with HTML type radio in active price sets that aren't quick config
  35.     $results = civicrm_api3('PriceSet', 'get', [
  36.       'sequential' => 1,
  37.       'return' => ["id"],
  38.       'is_quick_config' => 0,
  39.       'is_active' => 1,
  40.       'api.PriceField.get' => ['price_set_id' => "\$value.id", 'html_type' => "radio", 'return' => "id"],
  41.     ]);
  42.     $priceFieldIDs = array();
  43.     foreach ($results['values'] as $result) {
  44.       foreach ($result['api.PriceField.get']['values'] as $priceID) {
  45.         array_push($priceFieldIDs, $priceID['id']);
  46.       }
  47.     }
  48.     $this->addEntityRef('other_amount_price_fields', ts('Other Amount Price Fields'), array(
  49.       'entity' => 'PriceField',
  50.       'api' => array(
  51.         'params' => array(
  52.           'id' => ['IN' => $priceFieldIDs],
  53.         ),
  54.       ),
  55.       'select' => array('minimumInputLength' => 0),
  56.       'multiple' => TRUE,
  57.     ));
  58.     var_dump($this->_elements);
  59.     $this->addButtons(array(
  60.       array(
  61.         'type' => 'submit',
  62.         'name' => ts('Submit', array('domain' => 'com.domain.extension')),
  63.         'isDefault' => TRUE,
  64.       ),
  65.       array(
  66.         'type' => 'cancel',
  67.         'name' => ts('Cancel', array('domain' => 'com.domain.extension')),
  68.       ),
  69.     ));
  70.   }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement