/** * Function to actually build the form * * @param null * * @return void * @access public */ public function buildQuickForm() { $subTypeId = CRM_Core_DAO::getFieldValue('CRM_Campaign_DAO_Survey', $this->_surveyId, 'activity_type_id'); if (!CRM_Core_BAO_CustomGroup::autoCreateByActivityType($subTypeId)) { $activityTypes = CRM_Core_PseudoConstant::activityType(TRUE, TRUE, FALSE, 'label', TRUE, FALSE); // everything // FIXME: Displays weird "/\ Array" message; doesn't work with tabs CRM_Core_Session::setStatus(ts('There are no custom data sets for activity type "%1". To create one, <a href="%2" target="%3">click here</a>.', array(1 => $activityTypes[$subTypeId], 2 => CRM_Utils_System::url('civicrm/admin/custom/group', 'action=add&reset=1'), 3 => '_blank'))); } $allowCoreTypes = CRM_Campaign_BAO_Survey::surveyProfileTypes(); $allowSubTypes = array('ActivityType' => array($subTypeId)); $entities = array(array('entity_name' => 'contact_1', 'entity_type' => 'IndividualModel'), array('entity_name' => 'activity_1', 'entity_type' => 'ActivityModel', 'entity_sub_type' => $subTypeId)); $this->addProfileSelector('contact_profile_id', ts('Contact Info'), $allowCoreTypes, $allowSubTypes, $entities); $this->addProfileSelector('activity_profile_id', ts('Questions'), $allowCoreTypes, $allowSubTypes, $entities); // Note: Because this is in a tab, we also preload the schema via CRM_Campaign_Form_Survey::preProcess parent::buildQuickForm(); }
/** * Function to actually build the form * * @param null * * @return void * @access public */ public function buildQuickForm() { if ($this->_action & CRM_Core_Action::DELETE) { $this->addButtons(array(array('type' => 'next', 'name' => ts('Delete'), 'isDefault' => TRUE), array('type' => 'cancel', 'name' => ts('Cancel')))); return; } if ($this->_cdType) { return CRM_Custom_Form_CustomData::buildQuickForm($this); } $this->add('text', 'title', ts('Title'), CRM_Core_DAO::getAttribute('CRM_Campaign_DAO_Survey', 'title'), TRUE); $surveyActivityTypes = CRM_Campaign_BAO_Survey::getSurveyActivityType(); // Activity Type id $this->add('select', 'activity_type_id', ts('Activity Type'), array('' => ts('- select -')) + $surveyActivityTypes, TRUE); // Campaign id $campaigns = CRM_Campaign_BAO_Campaign::getCampaigns(CRM_Utils_Array::value('campaign_id', $this->_values)); $this->add('select', 'campaign_id', ts('Campaign'), array('' => ts('- select -')) + $campaigns); $customProfiles = CRM_Core_BAO_UFGroup::getProfiles(CRM_Campaign_BAO_Survey::surveyProfileTypes()); // custom group id $this->add('select', 'profile_id', ts('Profile'), array('' => ts('- select -')) + $customProfiles); $optionGroups = CRM_Campaign_BAO_Survey::getResultSets(); if (empty($optionGroups)) { $optionTypes = array('1' => ts('Create new result set')); } else { $optionTypes = array('1' => ts('Create a new result set'), '2' => ts('Use existing result set')); $this->add('select', 'option_group_id', ts('Select Result Set'), array('' => ts('- select -')) + $optionGroups, FALSE, array('onChange' => 'loadOptionGroup( )')); } $element =& $this->addRadio('option_type', ts('Survey Responses'), $optionTypes, array('onclick' => "showOptionSelect();"), '<br/>', TRUE); if (empty($optionGroups) || !CRM_Utils_Array::value('result_id', $this->_values)) { $this->setdefaults(array('option_type' => 1)); } elseif (CRM_Utils_Array::value('result_id', $this->_values)) { $this->setdefaults(array('option_type' => 2, 'option_group_id' => $this->_values['result_id'])); } // form fields of Custom Option rows $defaultOption = array(); $_showHide = new CRM_Core_ShowHideBlocks('', ''); $optionAttributes = CRM_Core_DAO::getAttribute('CRM_Core_DAO_OptionValue'); $optionAttributes['label']['size'] = $optionAttributes['value']['size'] = 25; 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); } $this->add('text', 'option_label[' . $i . ']', ts('Label'), $optionAttributes['label']); // value $this->add('text', 'option_value[' . $i . ']', ts('Value'), $optionAttributes['value']); // weight $this->add('text', "option_weight[{$i}]", ts('Order'), $optionAttributes['weight']); $this->add('text', 'option_interval[' . $i . ']', ts('Recontact Interval'), CRM_Core_DAO::getAttribute('CRM_Campaign_DAO_Survey', 'release_frequency')); $defaultOption[$i] = $this->createElement('radio', NULL, NULL, NULL, $i); } //default option selection $this->addGroup($defaultOption, 'default_option'); $_showHide->addToTemplate(); // script / instructions $this->addWysiwyg('instructions', ts('Instructions for interviewers'), array('rows' => 5, 'cols' => 40)); // release frequency $this->add('text', 'release_frequency', ts('Release frequency'), CRM_Core_DAO::getAttribute('CRM_Campaign_DAO_Survey', 'release_frequency')); $this->addRule('release_frequency', ts('Release Frequency interval should be a positive number.'), 'positiveInteger'); // max reserved contacts at a time $this->add('text', 'default_number_of_contacts', ts('Maximum reserved at one time'), CRM_Core_DAO::getAttribute('CRM_Campaign_DAO_Survey', 'default_number_of_contacts')); $this->addRule('default_number_of_contacts', ts('Maximum reserved at one time should be a positive number'), 'positiveInteger'); // total reserved per interviewer $this->add('text', 'max_number_of_contacts', ts('Total reserved per interviewer'), CRM_Core_DAO::getAttribute('CRM_Campaign_DAO_Survey', 'max_number_of_contacts')); $this->addRule('max_number_of_contacts', ts('Total reserved contacts should be a positive number'), 'positiveInteger'); // is active ? $this->add('checkbox', 'is_active', ts('Active?')); // is default ? $this->add('checkbox', 'is_default', ts('Default?')); // 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_Campaign_Form_Survey', 'formRule'), $this); }