/** * Build the form object. * * @return void */ public function buildQuickForm() { //get the context $context = $this->get('context'); if ($this->_searchBasedMailing) { $context = 'search'; } $this->assign('context', $context); $this->add('text', 'name', ts('Name Your Mailing'), CRM_Core_DAO::getAttribute('CRM_Mailing_DAO_Mailing', 'name'), TRUE); $hiddenMailingGroup = NULL; $campaignId = NULL; //CRM-7362 --add campaigns. if ($this->_mailingID) { $campaignId = CRM_Core_DAO::getFieldValue('CRM_Mailing_DAO_Mailing', $this->_mailingID, 'campaign_id'); $hiddenMailingGroup = CRM_Mailing_BAO_Mailing::hiddenMailingGroup($this->_mailingID); } CRM_Campaign_BAO_Campaign::addCampaign($this, $campaignId); //dedupe on email option $this->addElement('checkbox', 'dedupe_email', ts('Remove duplicate emails?')); // location types $locationTypes = CRM_Core_PseudoConstant::get('CRM_Core_DAO_Address', 'location_type_id', array('id' => 'display_name')); $this->addElement('select', 'location_type_id', ts("Location Type"), array('' => ts('Automatic')) + $locationTypes); $methods = CRM_Core_SelectValues::emailSelectMethods(); $this->addElement('select', 'email_selection_method', ts("Email Selection Method"), $methods); //get the mailing groups. $groups = CRM_Core_PseudoConstant::nestedGroup('Mailing'); if ($hiddenMailingGroup) { $groups[$hiddenMailingGroup] = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Group', $hiddenMailingGroup, 'title'); } $mailings = CRM_Mailing_PseudoConstant::completed(); if (!$mailings) { $mailings = array(); } // run the groups through a hook so users can trim it if needed CRM_Utils_Hook::mailingGroups($this, $groups, $mailings); //when the context is search add base group's. if ($this->_searchBasedMailing) { //get the static groups $staticGroups = CRM_Core_PseudoConstant::staticGroup(FALSE, 'Mailing'); $this->add('select', 'baseGroup', ts('Unsubscription Group'), array('' => ts('- select -')) + CRM_Contact_BAO_Group::getGroupsHierarchy($staticGroups, NULL, ' ', TRUE), TRUE, array('class' => 'crm-select2 huge')); } $select2style = array('multiple' => TRUE, 'style' => 'width: 100%; max-width: 60em;', 'class' => 'crm-select2', 'placeholder' => ts('- select -')); $this->add('select', 'includeGroups', ts('Include Group(s)'), $groups, !$this->_searchBasedMailing, $select2style); $this->add('select', 'excludeGroups', ts('Exclude Group(s)'), $groups, FALSE, $select2style); $this->add('select', 'includeMailings', ts('INCLUDE Recipients of These Mailing(s)') . ' ', $mailings, FALSE, $select2style); $this->add('select', 'excludeMailings', ts('EXCLUDE Recipients of These Mailing(s)') . ' ', $mailings, FALSE, $select2style); $this->addFormRule(array('CRM_Mailing_Form_Group', 'formRule')); $buttons = array(array('type' => 'next', 'name' => ts('Next'), 'spacing' => ' ', 'isDefault' => TRUE), array('type' => 'submit', 'name' => ts('Save & Continue Later')), array('type' => 'cancel', 'name' => ts('Cancel'))); $this->addButtons($buttons); $this->assign('groupCount', count($groups)); $this->assign('mailingCount', count($mailings)); if (count($groups) == 0 && count($mailings) == 0 && !$this->_searchBasedMailing) { CRM_Core_Error::statusBounce("To send a mailing, you must have a valid group of recipients - either at least one group that's a Mailing List or at least one previous mailing or start from a search"); } }