Esempio n. 1
0
 /**
  * Process the form when submitted.
  */
 public function postProcess()
 {
     CRM_Utils_System::flushCache('CRM_Core_DAO_Group');
     $updateNestingCache = FALSE;
     if ($this->_action & CRM_Core_Action::DELETE) {
         CRM_Contact_BAO_Group::discard($this->_id);
         CRM_Core_Session::setStatus(ts("The Group '%1' has been deleted.", array(1 => $this->_title)), ts('Group Deleted'), 'success');
         $updateNestingCache = TRUE;
     } else {
         // store the submitted values in an array
         $params = $this->controller->exportValues($this->_name);
         $params['is_active'] = CRM_Utils_Array::value('is_active', $this->_groupValues, 1);
         if ($this->_action & CRM_Core_Action::UPDATE) {
             $params['id'] = $this->_id;
         }
         if ($this->_action & CRM_Core_Action::UPDATE && isset($this->_groupOrganizationID)) {
             $params['group_organization'] = $this->_groupOrganizationID;
         }
         $params['is_reserved'] = CRM_Utils_Array::value('is_reserved', $params, FALSE);
         $groupTypeIds = array();
         $groupType = CRM_Utils_Array::value('group_type', $params);
         if (is_array($groupType)) {
             foreach ($groupType as $type => $selected) {
                 if ($selected) {
                     $groupTypeIds[] = $type;
                 }
             }
         }
         $params['group_type'] = $groupTypeIds;
         $params['custom'] = CRM_Core_BAO_CustomField::postProcess($params, $this->_id, 'Group');
         $group = CRM_Contact_BAO_Group::create($params);
         //Remove any parent groups requested to be removed
         if (!empty($this->_groupValues['parents'])) {
             $parentGroupIds = explode(',', $this->_groupValues['parents']);
             foreach ($parentGroupIds as $parentGroupId) {
                 if (isset($params["remove_parent_group_{$parentGroupId}"])) {
                     CRM_Contact_BAO_GroupNesting::remove($parentGroupId, $group->id);
                     $updateNestingCache = TRUE;
                 }
             }
         }
         CRM_Core_Session::setStatus(ts('The Group \'%1\' has been saved.', array(1 => $group->title)), ts('Group Saved'), 'success');
         // Add context to the session, in case we are adding members to the group
         if ($this->_action & CRM_Core_Action::ADD) {
             $this->set('context', 'amtg');
             $this->set('amtgID', $group->id);
             $session = CRM_Core_Session::singleton();
             $session->pushUserContext(CRM_Utils_System::url('civicrm/group/search', 'reset=1&force=1&context=smog&gid=' . $group->id));
         }
     }
     // update the nesting cache
     if ($updateNestingCache) {
         CRM_Contact_BAO_GroupNestingCache::update();
     }
 }
Esempio n. 2
0
 /**
  * Process the form when submitted
  *
  * @return void
  * @access public
  */
 public function postProcess()
 {
     $updateNestingCache = false;
     if ($this->_action & CRM_Core_Action::DELETE) {
         CRM_Contact_BAO_Group::discard($this->_id);
         CRM_Core_Session::setStatus(ts("The Group '%1' has been deleted.", array(1 => $this->_title)));
         $updateNestingCache = true;
     } else {
         // store the submitted values in an array
         $params = $this->controller->exportValues($this->_name);
         $params['is_active'] = 1;
         if ($this->_action & CRM_Core_Action::UPDATE) {
             $params['id'] = $this->_id;
         }
         if ($this->_action & CRM_Core_Action::UPDATE && isset($this->_groupOrganizationID)) {
             $params['group_organization'] = $this->_groupOrganizationID;
         }
         $customFields = CRM_Core_BAO_CustomField::getFields('Group');
         $params['custom'] = CRM_Core_BAO_CustomField::postProcess($params, $customFields, $this->_id, 'Group');
         require_once 'CRM/Contact/BAO/Group.php';
         $group =& CRM_Contact_BAO_Group::create($params);
         /*
          * Remove any parent groups requested to be removed
          */
         if (CRM_Utils_Array::value('parents', $this->_groupValues)) {
             $parentGroupIds = explode(',', $this->_groupValues['parents']);
             foreach ($parentGroupIds as $parentGroupId) {
                 if (isset($params["remove_parent_group_{$parentGroupId}"])) {
                     CRM_Contact_BAO_GroupNesting::remove($parentGroupId, $group->id);
                     $updateNestingCache = true;
                 }
             }
         }
         CRM_Core_Session::setStatus(ts('The Group \'%1\' has been saved.', array(1 => $group->title)));
         /*
          * Add context to the session, in case we are adding members to the group
          */
         if ($this->_action & CRM_Core_Action::ADD) {
             $this->set('context', 'amtg');
             $this->set('amtgID', $group->id);
             $session =& CRM_Core_Session::singleton();
             $session->pushUserContext(CRM_Utils_System::url('civicrm/group/search', 'reset=1&force=1&context=smog&gid=' . $group->id));
         }
     }
     // update the nesting cache
     if ($updateNestingCache) {
         require_once 'CRM/Contact/BAO/GroupNestingCache.php';
         CRM_Contact_BAO_GroupNestingCache::update();
     }
     require_once 'CRM/Utils/Recent.php';
     // add the recently added group
     CRM_Utils_Recent::add($group->title, CRM_Utils_System::url('civicrm/group/search', 'reset=1&force=1&context=smog&gid=' . $group->id), $group->id, 'Group', null, null);
 }