/** * Delete a saved search. * * @param int $id * Id of saved search. */ public function delete($id) { // first delete the group associated with this saved search $group = new CRM_Contact_DAO_Group(); $group->saved_search_id = $id; if ($group->find(TRUE)) { CRM_Contact_BAO_Group::discard($group->id); } $savedSearch = new CRM_Contact_DAO_SavedSearch(); $savedSearch->id = $id; $savedSearch->is_active = 0; $savedSearch->save(); }
static function updateCiviGroup(&$params, $op, $groupType = NULL) { $abort = false; $params['version'] = 3; $params['id'] = CRM_Bridge_OG_Utils::groupID($params['source'], $params['title'], $abort); if ($op == 'add') { if ($groupType) { $params['group_type'] = $groupType; } $group = civicrm_api('group', 'create', $params); if (!civicrm_error($group)) { $params['group_id'] = $group['id']; } } else { // do this only if we have a valid id if ($params['id']) { CRM_Contact_BAO_Group::discard($params['id']); $params['group_id'] = $params['id']; } } unset($params['id']); }
static function updateCiviGroup(&$params, $op, $groupType = null) { $abort = $op == 'delete' ? true : false; $params['id'] = CRM_Bridge_OG_Utils::groupID($params['source'], $params['title'], $abort); if ($op == 'add') { require_once 'api/v2/Group.php'; if ($groupType) { $params['group_type'] = $groupType; } $group = civicrm_group_add($params); if (!civicrm_error($group)) { $params['group_id'] = $group['result']; } } else { // do this only if we have a valid id if ($params['id']) { require_once 'CRM/Contact/BAO/Group.php'; CRM_Contact_BAO_Group::discard($params['id']); $params['group_id'] = $params['id']; } } unset($params['id']); }
/** * Delete an existing Group. * * @param array $params * [id] * * @return array * API result array */ function civicrm_api3_group_delete($params) { CRM_Contact_BAO_Group::discard($params['id']); return civicrm_api3_create_success(TRUE); }
/** * 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(); } }
/** * * Delete an existing group. * * @param $group A valid group object (passed by reference) * * @return null, if successful.or CRM error object, if permissions are insufficient, etc. * * * @access public */ function crm_delete_group(&$group) { _crm_initialize(); if (!is_a($group, 'CRM_Contact_BAO_Group') && !is_a($group, 'CRM_Contact_DAO_Group')) { return _crm_error('Invalid group object passed in'); } if ($group->id == null) { return _crm_error('Could not locate group with id: $id'); } if (!CRM_Contact_BAO_Group::checkPermission($group->id, $group->title)) { return CRM_Core_Error::fatal("You do not have permission to access group with id: {$id}"); } CRM_Contact_BAO_Group::discard($group->id); return null; }
/** * delete an existing group * * This method is used to delete any existing group. id of the group * to be deleted is required field in $params array * * @param array $params (referance) array containing id of the group * to be deleted * * @return array (referance) returns flag true if successfull, error * message otherwise * * @access public */ function civicrm_group_delete(&$params) { _civicrm_initialize(); if (is_null($params) || !is_array($params) || !CRM_Utils_Array::value('id', $params)) { return civicrm_create_error('Required parameter missing'); } CRM_Contact_BAO_Group::discard($params['id']); return civicrm_create_success(TRUE); }
/** * 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); }
/** * Delete an existing Group. * * @param array $params * [id] * * @return array * API result array */ function civicrm_api3_group_delete($params) { $group = civicrm_api3_group_get(array('id' => $params['id'])); if ($group['count'] == 0) { throw new API_Exception('Could not delete group ' . $params['id']); } CRM_Contact_BAO_Group::discard($params['id']); return civicrm_api3_create_success(TRUE); }
/** * Process the form when submitted * * @return void * @access public */ function postProcess() { 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))); } else { // store the submitted values in an array $params = $this->exportValues(); $params['domain_id'] = CRM_Core_Config::domainID(); $params['is_active'] = 1; if ($this->_action & CRM_CORE_ACTION_UPDATE) { $params['id'] = $this->_id; } $group =& CRM_Contact_BAO_Group::create($params); // do the updates/inserts CRM_Core_BAO_CustomGroup::postProcess($this->_groupTree, $params); CRM_Core_BAO_CustomGroup::updateCustomData($this->_groupTree, 'Group', $group->id); 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)); } } }