<?php
/*
+--------------------------------------------------------------------+
- | CiviCRM version 4.3 |
+ | CiviCRM version 4.4 |
+--------------------------------------------------------------------+
| Copyright CiviCRM LLC (c) 2004-2013 |
+--------------------------------------------------------------------+
*/
function preProcess() {
$this->_id = $this->get('id');
-
if ($this->_id) {
$breadCrumb = array(array('title' => ts('Manage Groups'),
'url' => CRM_Utils_System::url('civicrm/group',
'search_custom_id'
);
}
- if (CRM_Utils_Array::value('created_id', $this->_groupValues))
+ if (!empty($this->_groupValues['created_id']))
$groupValues['created_by'] =
CRM_Core_DAO::getFieldValue("CRM_Contact_DAO_Contact", $this->_groupValues['created_id'] , 'sort_name', 'id');
+ if (!empty($this->_groupValues['modified_id'])) {
+ $groupValues['modified_by'] =
+ CRM_Core_DAO::getFieldValue("CRM_Contact_DAO_Contact", $this->_groupValues['modified_id'] , 'sort_name', 'id');
+ }
+
$this->assign_by_ref('group', $groupValues);
CRM_Utils_System::setTitle(ts('Group Settings: %1', array(1 => $this->_title)));
* the default values are retrieved from the database
*
* @access public
- * @return None
+ * @return void
*/
function setDefaultValues() {
$defaults = array();
if (isset($this->_id)) {
$defaults = $this->_groupValues;
- if (CRM_Utils_Array::value('group_type', $defaults)) {
+ if (!empty($defaults['group_type'])) {
$types = explode(CRM_Core_DAO::VALUE_SEPARATOR,
substr($defaults['group_type'], 1, -1)
);
}
}
- if (CRM_Core_Permission::check('administer Multiple Organizations') &&
- CRM_Core_Permission::isMultisiteEnabled()
- ) {
+ if (CRM_Core_Permission::check('administer Multiple Organizations') && CRM_Core_Permission::isMultisiteEnabled()) {
CRM_Contact_BAO_GroupOrganization::retrieve($this->_id, $defaults);
-
- if (CRM_Utils_Array::value('group_organization', $defaults)) {
- //used in edit mode
- $this->_groupOrganizationID = $defaults['group_organization'];
- }
-
- $this->assign('organizationID', CRM_Utils_Array::value('organization_id',$defaults));
}
}
}
}
- if (!CRM_Utils_Array::value('parents', $defaults)) {
+ if (empty($defaults['parents'])) {
$defaults['parents'] = CRM_Core_BAO_Domain::getGroupId();
}
/**
* Function to actually build the form
*
- * @return None
+ * @return void
* @access public
*/
public function buildQuickForm() {
return;
}
+ // We want the "new group" form to redirect the user
+ if ($this->_action == CRM_Core_Action::ADD) {
+ $this->preventAjaxSubmit();
+ }
+
$this->applyFilter('__ALL__', 'trim');
$this->add('text', 'title', ts('Name') . ' ',
CRM_Core_DAO::getAttribute('CRM_Contact_DAO_Group', 'title'), TRUE
$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)
- ) {
+ if (isset($this->_id) && !empty($this->_groupValues['saved_search_id'])) {
unset($groupTypes['Access Control']);
}
);
}
- $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);
- }
+ $this->add('select', 'visibility', ts('Visibility'), CRM_Core_SelectValues::groupVisibility(), TRUE);
- $parentGroupSelectValues = array('' => '- ' . ts('select') . ' -');
- foreach ($potentialParentGroupIds as $potentialParentGroupId) {
- if (array_key_exists($potentialParentGroupId, $groupNames)) {
- $parentGroupSelectValues[$potentialParentGroupId] = $groupNames[$potentialParentGroupId];
- }
- }
+ //CRM-14190
+ $parentGroups = self::buildParentGroups($this);
- 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()
- ) {
+ 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'));
+ $props = array('api' => array('params' => array('contact_type' => 'Organization')));
+ $this->addEntityRef('organization_id', ts('Organization'), $props);
}
// is_reserved property CRM-9936
}
$grpAdd = 0;
- if (CRM_Utils_Array::value('parents', $fields)) {
+ if (!empty($fields['parents'])) {
$grpAdd++;
}
}
// do check for both name and title uniqueness
- if (CRM_Utils_Array::value('title', $fields)) {
+ if (!empty($fields['title'])) {
$title = trim($fields['title']);
$query = "
SELECT count(*)
$group = CRM_Contact_BAO_Group::create($params);
/*
- * Remove any parent groups requested to be removed
- */
+ * Remove any parent groups requested to be removed
+ */
- if (CRM_Utils_Array::value('parents', $this->_groupValues)) {
+ if (!empty($this->_groupValues['parents'])) {
$parentGroupIds = explode(',', $this->_groupValues['parents']);
foreach ($parentGroupIds as $parentGroupId) {
if (isset($params["remove_parent_group_$parentGroupId"])) {
CRM_Contact_BAO_GroupNestingCache::update();
}
}
+
+ /*
+ * Build parent groups form elements
+ *
+ * @obj form object passed by reference
+ *
+ * @return parent groups array
+ * @static
+ * @access public
+ */
+ static function buildParentGroups( &$obj ) {
+ $groupNames = CRM_Core_PseudoConstant::group();
+ $parentGroups = $parentGroupElements = array();
+ if (isset($obj->_id) &&
+ CRM_Utils_Array::value('parents', $obj->_groupValues)
+ ) {
+ $parentGroupIds = explode(',', $obj->_groupValues['parents']);
+ foreach ($parentGroupIds as $parentGroupId) {
+ $parentGroups[$parentGroupId] = $groupNames[$parentGroupId];
+ if (array_key_exists($parentGroupId, $groupNames)) {
+ $parentGroupElements[$parentGroupId] = $groupNames[$parentGroupId];
+ $obj->addElement('checkbox', "remove_parent_group_$parentGroupId",
+ $groupNames[$parentGroupId]
+ );
+ }
+ }
+ }
+ $obj->assign_by_ref('parent_groups', $parentGroupElements);
+
+ if (isset($obj->_id)) {
+ $potentialParentGroupIds = CRM_Contact_BAO_GroupNestingCache::getPotentialCandidates($obj->_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 = empty($parentGroups) ? TRUE : FALSE;
+ $required = (($obj->_id && CRM_Core_BAO_Domain::isDomainGroup($obj->_id)) ||
+ !isset($obj->_id)
+ ) ? FALSE : $required;
+ }
+ else {
+ $required = FALSE;
+ }
+ $obj->add('select', 'parents', ts('Add Parent'), $parentGroupSelectValues, $required, array('class' => 'crm-select2'));
+ }
+
+ return $parentGroups;
+ }
}