/** * Function to actually build the form * * @param null * * @return void * @access public */ public function buildQuickForm() { // lets trim all the whitespace $this->applyFilter('__ALL__', 'trim'); // label $this->add('text', 'label', ts('Field Label'), CRM_Core_DAO::getAttribute('CRM_Price_DAO_Field', 'label'), true); // html_type $javascript = 'onchange="option_html_type(this.form)";'; require_once 'CRM/Price/BAO/Field.php'; $htmlTypes = CRM_Price_BAO_Field::htmlTypes(); $sel = $this->add('select', 'html_type', ts('Input Field Type'), $htmlTypes, true, $javascript); // price (for text inputs) $this->add('text', 'price', ts('Price')); $this->registerRule('price', 'callback', 'moneySigned', 'CRM_Utils_Rule'); $this->addRule('price', ts('must be a monetary value'), 'moneySigned'); if ($this->_action == CRM_Core_Action::UPDATE) { $this->freeze('html_type'); } // form fields of Custom Option rows $_showHide =& new CRM_Core_ShowHideBlocks('', ''); $attributes = CRM_Core_DAO::getAttribute('CRM_Core_DAO_OptionValue'); $labelAttribute = $attributes['label']; $nameAttribute = $attributes['name']; $weightAttribute = $attributes['weight']; for ($i = 1; $i <= self::NUM_OPTION; $i++) { //the show hide blocks $showBlocks = 'optionField_' . $i; if ($i > 2) { $_showHide->addHide($showBlocks); if ($i == self::NUM_OPTION) { $_showHide->addHide('additionalOption'); } } else { $_showHide->addShow($showBlocks); } // label $this->add('text', 'option_label[' . $i . ']', ts('Label'), $labelAttribute); // name $this->add('text', 'option_name[' . $i . ']', ts('Name'), $nameAttribute); // Below rule is uncommented for CRM-1313 $this->addRule('option_name[' . $i . ']', ts('Please enter a valid amount for this field.'), 'moneySigned'); // weight $this->add('text', 'option_weight[' . $i . ']', ts('Order'), $weightAttribute); // is active ? $this->add('checkbox', 'option_status[' . $i . ']', ts('Active?')); $defaultOption[$i] = $this->createElement('radio', null, null, null, $i); //for checkbox handling of default option $this->add('checkbox', "default_checkbox_option[{$i}]", null); } //default option selection $this->addGroup($defaultOption, 'default_option'); $_showHide->addToTemplate(); // is_display_amounts $this->add('checkbox', 'is_display_amounts', ts('Display Amount?')); // weight $this->add('text', 'weight', ts('Order'), CRM_Core_DAO::getAttribute('CRM_Price_DAO_Field', 'weight'), true); $this->addRule('weight', ts('is a numeric field'), 'numeric'); // checkbox / radio options per line $this->add('text', 'options_per_line', ts('Options Per Line')); $this->addRule('options_per_line', ts('must be a numeric value'), 'numeric'); // help post, mask, attributes, javascript ? $this->add('textarea', 'help_post', ts('Field Help'), CRM_Core_DAO::getAttribute('CRM_Price_DAO_Field', 'help_post')); // active_on $date_options = array('minYear' => date('Y'), 'maxYear' => date('Y') + 5, 'addEmptyOption' => true); $this->add('date', 'active_on', ts('Active On'), $date_options); // expire_on $this->add('date', 'expire_on', ts('Expire On'), $date_options); // is required ? $this->add('checkbox', 'is_required', ts('Required?')); // is active ? $this->add('checkbox', 'is_active', ts('Active?')); // add buttons $this->addButtons(array(array('type' => 'next', 'name' => ts('Save'), 'isDefault' => true), array('type' => 'next', 'name' => ts('Save and New'), 'subName' => 'new'), array('type' => 'cancel', 'name' => ts('Cancel')))); // add a form rule to check default value $this->addFormRule(array('CRM_Price_Form_Field', 'formRule'), $this); // if view mode pls freeze it with the done button. if ($this->_action & CRM_Core_Action::VIEW) { $this->freeze(); $url = CRM_Utils_System::url('civicrm/admin/price/field', 'reset=1&action=browse&sid=' . $this->_sid); $this->addElement('button', 'done', ts('Done'), array('onclick' => "location.href='{$url}'")); } }
/** * Function to actually build the form * * @param null * * @return void * @access public */ public function buildQuickForm() { // lets trim all the whitespace $this->applyFilter('__ALL__', 'trim'); // add a hidden field to remember the price set id // this get around the browser tab issue $this->add('hidden', 'sid', $this->_sid); $this->add('hidden', 'fid', $this->_fid); // label $this->add('text', 'label', ts('Field Label'), CRM_Core_DAO::getAttribute('CRM_Price_DAO_Field', 'label'), TRUE); // html_type $javascript = 'onchange="option_html_type(this.form)";'; $htmlTypes = CRM_Price_BAO_Field::htmlTypes(); // Text box for Participant Count for a field $eventComponentId = CRM_Core_Component::getComponentID('CiviEvent'); $memberComponentId = CRM_Core_Component::getComponentID('CiviMember'); $attributes = CRM_Core_DAO::getAttribute('CRM_Price_DAO_FieldValue'); $this->assign('useForMember', FALSE); if (in_array($eventComponentId, $this->_extendComponentId)) { $this->add('text', 'count', ts('Participant Count'), $attributes['count']); $this->addRule('count', ts('Participant Count should be a positive number'), 'positiveInteger'); $this->add('text', 'max_value', ts('Max Participants'), $attributes['max_value']); $this->addRule('max_value', ts('Please enter a valid Max Participants.'), 'positiveInteger'); $this->add('textArea', 'description', ts('Description'), $attributes['description']); $this->assign('useForEvent', TRUE); } else { if (in_array($memberComponentId, $this->_extendComponentId)) { $this->_useForMember = 1; $this->assign('useForMember', $this->_useForMember); } $this->assign('useForEvent', FALSE); } $sel = $this->add('select', 'html_type', ts('Input Field Type'), $htmlTypes, TRUE, $javascript); // price (for text inputs) $this->add('text', 'price', ts('Price')); $this->registerRule('price', 'callback', 'money', 'CRM_Utils_Rule'); $this->addRule('price', ts('must be a monetary value'), 'money'); if ($this->_action == CRM_Core_Action::UPDATE) { $this->freeze('html_type'); } // form fields of Custom Option rows $_showHide = new CRM_Core_ShowHideBlocks('', ''); for ($i = 1; $i <= self::NUM_OPTION; $i++) { //the show hide blocks $showBlocks = 'optionField_' . $i; if ($i > 2) { $_showHide->addHide($showBlocks); if ($i == self::NUM_OPTION) { $_showHide->addHide('additionalOption'); } } else { $_showHide->addShow($showBlocks); } // label $attributes['label']['size'] = 25; $this->add('text', 'option_label[' . $i . ']', ts('Label'), $attributes['label']); // amount $this->add('text', 'option_amount[' . $i . ']', ts('Amount'), $attributes['amount']); $this->addRule('option_amount[' . $i . ']', ts('Please enter a valid amount for this field.'), 'money'); if (in_array($eventComponentId, $this->_extendComponentId)) { // count $this->add('text', 'option_count[' . $i . ']', ts('Participant Count'), $attributes['count']); $this->addRule('option_count[' . $i . ']', ts('Please enter a valid Participants Count.'), 'positiveInteger'); // max_value $this->add('text', 'option_max_value[' . $i . ']', ts('Max Participants'), $attributes['max_value']); $this->addRule('option_max_value[' . $i . ']', ts('Please enter a valid Max Participants.'), 'positiveInteger'); // description //$this->add('textArea', 'option_description['.$i.']', ts('Description'), array('rows' => 1, 'cols' => 40 )); } elseif (in_array($memberComponentId, $this->_extendComponentId)) { $membershipTypes = CRM_Member_PseudoConstant::membershipType(); $js = array('onchange' => "calculateRowValues( {$i} );"); $this->add('select', 'membership_type_id[' . $i . ']', ts('Membership Type'), array('' => ' ') + $membershipTypes, FALSE, $js); } // weight $this->add('text', 'option_weight[' . $i . ']', ts('Order'), $attributes['weight']); // is active ? $this->add('checkbox', 'option_status[' . $i . ']', ts('Active?')); $defaultOption[$i] = $this->createElement('radio', NULL, NULL, NULL, $i); //for checkbox handling of default option $this->add('checkbox', "default_checkbox_option[{$i}]", NULL); } //default option selection $this->addGroup($defaultOption, 'default_option'); $_showHide->addToTemplate(); // is_display_amounts $this->add('checkbox', 'is_display_amounts', ts('Display Amount?')); // weight $this->add('text', 'weight', ts('Order'), CRM_Core_DAO::getAttribute('CRM_Price_DAO_Field', 'weight'), TRUE); $this->addRule('weight', ts('is a numeric field'), 'numeric'); // checkbox / radio options per line $this->add('text', 'options_per_line', ts('Options Per Line')); $this->addRule('options_per_line', ts('must be a numeric value'), 'numeric'); // help post, mask, attributes, javascript ? $this->add('textarea', 'help_post', ts('Field Help'), CRM_Core_DAO::getAttribute('CRM_Price_DAO_Field', 'help_post')); // active_on $date_options = array('format' => 'dmY His', 'minYear' => date('Y') - 1, 'maxYear' => date('Y') + 5, 'addEmptyOption' => TRUE); $this->addDateTime('active_on', ts('Active On'), FALSE, array('formatType' => 'activityDateTime')); // expire_on $this->addDateTime('expire_on', ts('Expire On'), FALSE, array('formatType' => 'activityDateTime')); // is required ? $this->add('checkbox', 'is_required', ts('Required?')); // is active ? $this->add('checkbox', 'is_active', ts('Active?')); // add buttons $this->addButtons(array(array('type' => 'next', 'name' => ts('Save'), 'isDefault' => TRUE), array('type' => 'next', 'name' => ts('Save and New'), 'subName' => 'new'), array('type' => 'cancel', 'name' => ts('Cancel')))); // is public? $this->add('select', 'visibility_id', ts('Visibility'), CRM_Core_PseudoConstant::visibility()); // add a form rule to check default value $this->addFormRule(array('CRM_Price_Form_Field', 'formRule'), $this); // if view mode pls freeze it with the done button. if ($this->_action & CRM_Core_Action::VIEW) { $this->freeze(); $url = CRM_Utils_System::url('civicrm/admin/price/field', 'reset=1&action=browse&sid=' . $this->_sid); $this->addElement('button', 'done', ts('Done'), array('onclick' => "location.href='{$url}'")); } }
/** * Browse all price set fields. * * @param null * * @return void * @access public */ function browse() { require_once 'CRM/Price/BAO/Field.php'; $priceField = array(); $priceFieldBAO =& new CRM_Price_BAO_Field(); // fkey is sid $priceFieldBAO->price_set_id = $this->_sid; $priceFieldBAO->orderBy('weight, label'); $priceFieldBAO->find(); while ($priceFieldBAO->fetch()) { $priceField[$priceFieldBAO->id] = array(); CRM_Core_DAO::storeValues($priceFieldBAO, $priceField[$priceFieldBAO->id]); // get price if it's a text field if ($priceFieldBAO->html_type == 'Text') { $optionValues = array(); $params = array('name' => "civicrm_price_field.amount.{$priceFieldBAO->id}"); require_once 'CRM/Core/OptionValue.php'; CRM_Core_OptionValue::getValues($params, $optionValues); $priceField[$priceFieldBAO->id]['price'] = CRM_Utils_Array::value('value', array_pop($optionValues)); } $action = array_sum(array_keys($this->actionLinks())); if ($priceFieldBAO->is_active) { $action -= CRM_Core_Action::ENABLE; } else { $action -= CRM_Core_Action::DISABLE; } if ($priceFieldBAO->active_on == '0000-00-00 00:00:00') { $priceField[$priceFieldBAO->id]['active_on'] = ''; } if ($priceFieldBAO->expire_on == '0000-00-00 00:00:00') { $priceField[$priceFieldBAO->id]['expire_on'] = ''; } // need to translate html types from the db require_once 'CRM/Price/BAO/Field.php'; $htmlTypes = CRM_Price_BAO_Field::htmlTypes(); $priceField[$priceFieldBAO->id]['html_type'] = $htmlTypes[$priceField[$priceFieldBAO->id]['html_type']]; $priceField[$priceFieldBAO->id]['order'] = $priceField[$priceFieldBAO->id]['weight']; $priceField[$priceFieldBAO->id]['action'] = CRM_Core_Action::formLink(self::actionLinks(), $action, array('fid' => $priceFieldBAO->id, 'sid' => $this->_sid)); } $returnURL = CRM_Utils_System::url('civicrm/admin/price/field', "reset=1&action=browse&sid={$this->_sid}"); $filter = "price_set_id = {$this->_sid}"; require_once 'CRM/Utils/Weight.php'; CRM_Utils_Weight::addOrder($priceField, 'CRM_Price_DAO_Field', 'id', $returnURL, $filter); $this->assign('priceField', $priceField); }