Exemplo n.º 1
0
 /**
  * Function to actually build the form
  *
  * @return None
  * @access public
  */
 public function buildQuickForm()
 {
     if ($this->_action == CRM_Core_Action::DELETE) {
         $this->addButtons(array(array('type' => 'next', 'name' => ts('Delete Group'), 'isDefault' => TRUE), array('type' => 'cancel', 'name' => ts('Cancel'))));
         return;
     }
     $this->applyFilter('__ALL__', 'trim');
     $this->add('text', 'title', ts('Name') . ' ', CRM_Core_DAO::getAttribute('CRM_Contact_DAO_Group', 'title'), TRUE);
     $this->add('textarea', 'description', ts('Description') . ' ', CRM_Core_DAO::getAttribute('CRM_Contact_DAO_Group', 'description'));
     $groupTypes = CRM_Core_OptionGroup::values('group_type', TRUE);
     $config = CRM_Core_Config::singleton();
     if (isset($this->_id) && CRM_Utils_Array::value('saved_search_id', $this->_groupValues)) {
         unset($groupTypes['Access Control']);
     }
     if (!empty($groupTypes)) {
         $this->addCheckBox('group_type', ts('Group Type'), $groupTypes, NULL, NULL, NULL, NULL, '   ');
     }
     $this->add('select', 'visibility', ts('Visibility'), CRM_Core_SelectValues::ufVisibility(TRUE), TRUE);
     $groupNames = CRM_Core_PseudoConstant::group();
     $parentGroups = $parentGroupElements = array();
     if (isset($this->_id) && CRM_Utils_Array::value('parents', $this->_groupValues)) {
         $parentGroupIds = explode(',', $this->_groupValues['parents']);
         foreach ($parentGroupIds as $parentGroupId) {
             $parentGroups[$parentGroupId] = $groupNames[$parentGroupId];
             if (array_key_exists($parentGroupId, $groupNames)) {
                 $parentGroupElements[$parentGroupId] = $groupNames[$parentGroupId];
                 $this->addElement('checkbox', "remove_parent_group_{$parentGroupId}", $groupNames[$parentGroupId]);
             }
         }
     }
     $this->assign_by_ref('parent_groups', $parentGroupElements);
     if (isset($this->_id)) {
         $potentialParentGroupIds = CRM_Contact_BAO_GroupNestingCache::getPotentialCandidates($this->_id, $groupNames);
     } else {
         $potentialParentGroupIds = array_keys($groupNames);
     }
     $parentGroupSelectValues = array('' => '- ' . ts('select') . ' -');
     foreach ($potentialParentGroupIds as $potentialParentGroupId) {
         if (array_key_exists($potentialParentGroupId, $groupNames)) {
             $parentGroupSelectValues[$potentialParentGroupId] = $groupNames[$potentialParentGroupId];
         }
     }
     if (count($parentGroupSelectValues) > 1) {
         if (CRM_Core_Permission::isMultisiteEnabled()) {
             $required = empty($parentGroups) ? TRUE : FALSE;
             $required = $this->_id && CRM_Core_BAO_Domain::isDomainGroup($this->_id) || !isset($this->_id) ? FALSE : $required;
         } else {
             $required = FALSE;
         }
         $this->add('select', 'parents', ts('Add Parent'), $parentGroupSelectValues, $required);
     }
     if (CRM_Core_Permission::check('administer Multiple Organizations') && CRM_Core_Permission::isMultisiteEnabled()) {
         //group organization Element
         $groupOrgDataURL = CRM_Utils_System::url('civicrm/ajax/search', 'org=1', FALSE, NULL, FALSE);
         $this->assign('groupOrgDataURL', $groupOrgDataURL);
         $this->addElement('text', 'organization', ts('Organization'), '');
         $this->addElement('hidden', 'organization_id', '', array('id' => 'organization_id'));
     }
     // is_reserved property CRM-9936
     $this->addElement('checkbox', 'is_reserved', ts('Reserved Group?'));
     if (!CRM_Core_Permission::check('administer reserved groups')) {
         $this->freeze('is_reserved');
     }
     //build custom data
     CRM_Custom_Form_CustomData::buildQuickForm($this);
     $this->addButtons(array(array('type' => 'upload', 'name' => $this->_action == CRM_Core_Action::ADD ? ts('Continue') : ts('Save'), 'isDefault' => TRUE), array('type' => 'cancel', 'name' => ts('Cancel'))));
     $doParentCheck = FALSE;
     if (CRM_Core_Permission::isMultisiteEnabled()) {
         $doParentCheck = $this->_id && CRM_Core_BAO_Domain::isDomainGroup($this->_id) ? FALSE : TRUE;
     }
     $options = array('selfObj' => $this, 'parentGroups' => $parentGroups, 'doParentCheck' => $doParentCheck);
     $this->addFormRule(array('CRM_Group_Form_Edit', 'formRule'), $options);
 }
Exemplo n.º 2
0
 /**
  * Build parent groups form elements.
  *
  * @param CRM_Core_Form $form
  *
  * @return array
  *   parent groups
  */
 public static function buildParentGroups(&$form)
 {
     $groupNames = CRM_Core_PseudoConstant::group();
     $parentGroups = $parentGroupElements = array();
     if (isset($form->_id) && !empty($form->_groupValues['parents'])) {
         $parentGroupIds = explode(',', $form->_groupValues['parents']);
         foreach ($parentGroupIds as $parentGroupId) {
             $parentGroups[$parentGroupId] = $groupNames[$parentGroupId];
             if (array_key_exists($parentGroupId, $groupNames)) {
                 $parentGroupElements[$parentGroupId] = $groupNames[$parentGroupId];
                 $form->addElement('checkbox', "remove_parent_group_{$parentGroupId}", $groupNames[$parentGroupId]);
             }
         }
     }
     $form->assign_by_ref('parent_groups', $parentGroupElements);
     if (isset($form->_id)) {
         $potentialParentGroupIds = CRM_Contact_BAO_GroupNestingCache::getPotentialCandidates($form->_id, $groupNames);
     } else {
         $potentialParentGroupIds = array_keys($groupNames);
     }
     $parentGroupSelectValues = array('' => '- ' . ts('select group') . ' -');
     foreach ($potentialParentGroupIds as $potentialParentGroupId) {
         if (array_key_exists($potentialParentGroupId, $groupNames)) {
             $parentGroupSelectValues[$potentialParentGroupId] = $groupNames[$potentialParentGroupId];
         }
     }
     if (count($parentGroupSelectValues) > 1) {
         if (CRM_Core_Permission::isMultisiteEnabled()) {
             $required = !isset($form->_id) || $form->_id && CRM_Core_BAO_Domain::isDomainGroup($form->_id) ? FALSE : empty($parentGroups);
         } else {
             $required = FALSE;
         }
         $form->add('select', 'parents', ts('Add Parent'), $parentGroupSelectValues, $required, array('class' => 'crm-select2'));
     }
     return $parentGroups;
 }
Exemplo n.º 3
0
 /**
  * Function to actually build the form
  *
  * @return None
  * @access public
  */
 public function buildQuickForm()
 {
     if ($this->_action == CRM_Core_Action::DELETE) {
         $this->addButtons(array(array('type' => 'next', 'name' => ts('Delete Group'), 'isDefault' => true), array('type' => 'cancel', 'name' => ts('Cancel'))));
         return;
     }
     $this->applyFilter('__ALL__', 'trim');
     $this->add('text', 'title', ts('Name') . ' ', CRM_Core_DAO::getAttribute('CRM_Contact_DAO_Group', 'title'), true);
     $this->addRule('title', ts('Name already exists in Database.'), 'objectExists', array('CRM_Contact_DAO_Group', $this->_id, 'title'));
     $this->add('textarea', 'description', ts('Description') . ' ', CRM_Core_DAO::getAttribute('CRM_Contact_DAO_Group', 'description'));
     require_once 'CRM/Core/OptionGroup.php';
     $groupTypes = CRM_Core_OptionGroup::values('group_type', true);
     $config =& CRM_Core_Config::singleton();
     if (isset($this->_id) && CRM_Utils_Array::value('saved_search_id', $this->_groupValues) || $config->userFramework == 'Joomla') {
         unset($groupTypes['Access Control']);
     }
     if (!CRM_Core_Permission::access('CiviMail')) {
         unset($groupTypes['Mailing List']);
     }
     if (!empty($groupTypes)) {
         $this->addCheckBox('group_type', ts('Group Type'), $groupTypes, null, null, null, null, '   ');
     }
     $this->add('select', 'visibility', ts('Visibility'), CRM_Core_SelectValues::ufVisibility(true), true);
     $groupNames =& CRM_Core_PseudoConstant::group();
     $parentGroups = array();
     if (isset($this->_id) && CRM_Utils_Array::value('parents', $this->_groupValues)) {
         $parentGroupIds = explode(',', $this->_groupValues['parents']);
         foreach ($parentGroupIds as $parentGroupId) {
             $parentGroups[$parentGroupId] = $groupNames[$parentGroupId];
             $this->addElement('checkbox', "remove_parent_group_{$parentGroupId}", $groupNames[$parentGroupId]);
         }
     }
     $this->assign_by_ref('parent_groups', $parentGroups);
     if (isset($this->_id)) {
         require_once 'CRM/Contact/BAO/GroupNestingCache.php';
         $potentialParentGroupIds = CRM_Contact_BAO_GroupNestingCache::getPotentialCandidates($this->_id, $groupNames);
     } else {
         $potentialParentGroupIds = array_keys($groupNames);
     }
     $parentGroupSelectValues = array('' => '- ' . ts('select') . ' -');
     foreach ($potentialParentGroupIds as $potentialParentGroupId) {
         if (array_key_exists($potentialParentGroupId, $groupNames)) {
             $parentGroupSelectValues[$potentialParentGroupId] = $groupNames[$potentialParentGroupId];
         }
     }
     if (count($parentGroupSelectValues) > 1) {
         if (defined('CIVICRM_MULTISITE') && CIVICRM_MULTISITE) {
             $required = empty($parentGroups) ? true : false;
             $required = $this->_id && CRM_Core_BAO_Domain::isDomainGroup($this->_id) ? false : $required;
         } else {
             $required = false;
         }
         $this->add('select', 'parents', ts('Add Parent'), $parentGroupSelectValues, $required);
     }
     if (defined('CIVICRM_MULTISITE') && CIVICRM_MULTISITE && CRM_Core_Permission::check('administer Multiple Organizations')) {
         //group organization Element
         $groupOrgDataURL = CRM_Utils_System::url('civicrm/ajax/search', 'org=1', false, null, false);
         $this->assign('groupOrgDataURL', $groupOrgDataURL);
         $this->addElement('text', 'organization', ts('Organization'), '');
         $this->addElement('hidden', 'organization_id', '', array('id' => 'organization_id'));
     }
     //build custom data
     CRM_Custom_Form_Customdata::buildQuickForm($this);
     $this->addButtons(array(array('type' => 'upload', 'name' => $this->_action == CRM_Core_Action::ADD ? ts('Continue') : ts('Save'), 'isDefault' => true), array('type' => 'cancel', 'name' => ts('Cancel'))));
     if (defined('CIVICRM_MULTISITE') && CIVICRM_MULTISITE) {
         $doParentCheck = $this->_id && CRM_Core_BAO_Domain::isDomainGroup($this->_id) ? false : true;
     } else {
         $doParentCheck = false;
     }
     if ($doParentCheck) {
         $this->addFormRule(array('CRM_Group_Form_Edit', 'formRule'), $parentGroups);
     }
 }