示例#1
0
/**
 * Returns array of groups matching a set of one or more Group properties.
 *
 * @param array $params
 *   Array of properties. If empty, all records will be returned.
 *
 * @return array
 *   Array of matching groups
 */
function civicrm_api3_group_get($params)
{
    $options = _civicrm_api3_get_options_from_params($params, TRUE, 'Group', 'get');
    if (empty($options['return']) || !in_array('member_count', $options['return'])) {
        return _civicrm_api3_basic_get(_civicrm_api3_get_BAO(__FUNCTION__), $params, TRUE, 'Group');
    }
    $groups = _civicrm_api3_basic_get(_civicrm_api3_get_BAO(__FUNCTION__), $params, FALSE, 'Group');
    foreach ($groups as $id => $group) {
        $groups[$id]['member_count'] = CRM_Contact_BAO_Group::memberCount($id);
    }
    return civicrm_api3_create_success($groups, $params, 'Group', 'get');
}
示例#2
0
文件: Edit.php 项目: agloa/tournament
 /**
  * Set up variables to build the form.
  *
  * @return void
  * @acess protected
  */
 public function preProcess()
 {
     // TODO: quit if user can't access any registration groups (remove from nav menu?)
     // CRM_Core_Error::statusBounce(ts("You do not have sufficient permission to change settings for this reserved group."));
     $this->_id = $this->get('id');
     if ($this->_id) {
         $breadCrumb = array(array('title' => ts('Manage Teams'), 'url' => CRM_Utils_System::url('civicrm/tournament/team', 'reset=1')));
         CRM_Utils_System::appendBreadCrumb($breadCrumb);
         $this->_groupValues = array();
         $params = array('id' => $this->_id);
         $this->_group = CRM_Contact_BAO_Group::retrieve($params, $this->_groupValues);
         $this->_title = $this->_groupValues['title'];
     }
     $this->assign('action', $this->_action);
     $this->assign('showBlockJS', TRUE);
     if ($this->_action == CRM_Core_Action::DELETE) {
         if (isset($this->_id)) {
             $this->assign('title', $this->_title);
             $this->assign('count', CRM_Contact_BAO_Group::memberCount($this->_id));
             CRM_Utils_System::setTitle(ts('Confirm Group Delete'));
         }
         if ($this->_groupValues['is_reserved'] == 1 && !CRM_Core_Permission::check('administer reserved groups')) {
             CRM_Core_Error::statusBounce(ts("You do not have sufficient permission to delete this reserved group."));
         }
     } else {
         if ($this->_groupValues['is_reserved'] == 1 && !CRM_Core_Permission::check('administer reserved groups')) {
             CRM_Core_Error::statusBounce(ts("You do not have sufficient permission to change settings for this reserved group."));
         }
         if (isset($this->_id)) {
             $groupValues = array('id' => $this->_id, 'title' => $this->_title, 'saved_search_id' => isset($this->_groupValues['saved_search_id']) ? $this->_groupValues['saved_search_id'] : '');
             if (isset($this->_groupValues['saved_search_id'])) {
                 $groupValues['mapping_id'] = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_SavedSearch', $this->_groupValues['saved_search_id'], 'mapping_id');
                 $groupValues['search_custom_id'] = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_SavedSearch', $this->_groupValues['saved_search_id'], 'search_custom_id');
             }
             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('Team Settings: %1', array(1 => $this->_title)));
         }
         $session = CRM_Core_Session::singleton();
         $session->pushUserContext(CRM_Utils_System::url('civicrm/tournament/team', 'reset=1'));
     }
     //build custom data
     CRM_Custom_Form_CustomData::preProcess($this, NULL, NULL, 1, 'Group', $this->_id);
 }
示例#3
0
文件: Group.php 项目: kidaa30/yes
/**
 * Returns array of groups matching a set of one or more Group properties.
 *
 * @param array $params
 *   Array of properties. If empty, all records will be returned.
 *
 * @return array
 *   Array of matching groups
 */
function civicrm_api3_group_get($params)
{
    $options = _civicrm_api3_get_options_from_params($params, TRUE, 'Group', 'get');
    if ((empty($options['return']) || !in_array('member_count', $options['return'])) && empty($params['check_permissions'])) {
        return _civicrm_api3_basic_get(_civicrm_api3_get_BAO(__FUNCTION__), $params, TRUE, 'Group');
    }
    $groups = _civicrm_api3_basic_get(_civicrm_api3_get_BAO(__FUNCTION__), $params, FALSE, 'Group');
    foreach ($groups as $id => $group) {
        if (!empty($params['check_permissions']) && !CRM_Contact_BAO_Group::checkPermission($group['id'])) {
            unset($groups[$id]);
        } elseif (!empty($options['return']) && in_array('member_count', $options['return'])) {
            $groups[$id]['member_count'] = CRM_Contact_BAO_Group::memberCount($id);
        }
    }
    return civicrm_api3_create_success($groups, $params, 'Group', 'get');
}
示例#4
0
 /**
  * set up variables to build the form
  *
  * @return void
  * @acess protected
  */
 function preProcess()
 {
     $this->_id = $this->get('id');
     if ($this->_action == CRM_CORE_ACTION_DELETE) {
         if (isset($this->_id)) {
             $params = array('id' => $this->_id);
             CRM_Contact_BAO_Group::retrieve($params, $defaults);
             $this->_title = $defaults['title'];
             $this->assign('name', $this->_title);
             $this->assign('count', CRM_Contact_BAO_Group::memberCount($this->_id));
             CRM_Utils_System::setTitle(ts('Confirm Group Delete'));
         }
     } else {
         if (isset($this->_id)) {
             $params = array('id' => $this->_id);
             CRM_Contact_BAO_Group::retrieve($params, $defaults);
             $groupValues = array('id' => $this->_id, 'title' => $defaults['title'], 'saved_search_id' => $defaults['saved_search_id']);
             $this->assign_by_ref('group', $groupValues);
             CRM_Utils_System::setTitle(ts('Group Settings: %1', array(1 => $defaults['title'])));
         }
     }
 }
示例#5
0
文件: Group.php 项目: ksecor/civicrm
 /**
  * Returns array of group object(s) matching a set of one or Group properties.
  *
  *
  * @param array       $param                 Array of one or more valid property_name=>value pairs. Limits the set of groups returned.
  * @param array       $returnProperties      Which properties should be included in the returned group objects. (member_count should be last element.)
  *  
  * @return  An array of group objects.
  *
  * @access public
  */
 static function getGroups($params = null, $returnProperties = null)
 {
     $dao =& new CRM_Contact_DAO_Group();
     $dao->is_active = 1;
     if ($params) {
         foreach ($params as $k => $v) {
             if ($k == 'name' || $k == 'title') {
                 $dao->whereAdd($k . ' LIKE "' . CRM_Core_DAO::escapeString($v) . '"');
             } else {
                 if (is_array($v)) {
                     $dao->whereAdd($k . ' IN (' . implode(',', $v) . ')');
                 } else {
                     $dao->{$k} = $v;
                 }
             }
         }
     }
     // return only specific fields if returnproperties are sent
     if (!empty($returnProperties)) {
         $dao->selectAdd();
         $dao->selectAdd(implode(',', $returnProperties));
     }
     $dao->find();
     $flag = $returnProperties && in_array('member_count', $returnProperties) ? 1 : 0;
     $groups = array();
     while ($dao->fetch()) {
         $group =& new CRM_Contact_DAO_Group();
         if ($flag) {
             $dao->member_count = CRM_Contact_BAO_Group::memberCount($dao->id);
         }
         $groups[] = clone $dao;
     }
     return $groups;
 }
示例#6
0
 /**
  * Returns array of group object(s) matching a set of one or Group properties.
  *
  * @param array $params
  *   Limits the set of groups returned.
  * @param array $returnProperties
  *   Which properties should be included in the returned group objects.
  *   (member_count should be last element.)
  * @param string $sort
  * @param int $offset
  * @param int $rowCount
  *
  * @return array
  *   Array of group objects.
  *
  *
  * @todo other BAO functions that use returnProperties (e.g. Query Objects) receive the array flipped & filled with 1s and
  * add in essential fields (e.g. id). This should follow a regular pattern like the others
  */
 public static function getGroups($params = NULL, $returnProperties = NULL, $sort = NULL, $offset = NULL, $rowCount = NULL)
 {
     $dao = new CRM_Contact_DAO_Group();
     if (!isset($params['is_active'])) {
         $dao->is_active = 1;
     }
     if ($params) {
         foreach ($params as $k => $v) {
             if ($k == 'name' || $k == 'title') {
                 $dao->whereAdd($k . ' LIKE "' . CRM_Core_DAO::escapeString($v) . '"');
             } elseif ($k == 'group_type') {
                 foreach ((array) $v as $type) {
                     $dao->whereAdd($k . " LIKE '%" . CRM_Core_DAO::VALUE_SEPARATOR . (int) $type . CRM_Core_DAO::VALUE_SEPARATOR . "%'");
                 }
             } elseif (is_array($v)) {
                 foreach ($v as &$num) {
                     $num = (int) $num;
                 }
                 $dao->whereAdd($k . ' IN (' . implode(',', $v) . ')');
             } else {
                 $dao->{$k} = $v;
             }
         }
     }
     if ($offset || $rowCount) {
         $offset = $offset > 0 ? $offset : 0;
         $rowCount = $rowCount > 0 ? $rowCount : 25;
         $dao->limit($offset, $rowCount);
     }
     if ($sort) {
         $dao->orderBy($sort);
     }
     // return only specific fields if returnproperties are sent
     if (!empty($returnProperties)) {
         $dao->selectAdd();
         $dao->selectAdd(implode(',', $returnProperties));
     }
     $dao->find();
     $flag = $returnProperties && in_array('member_count', $returnProperties) ? 1 : 0;
     $groups = array();
     while ($dao->fetch()) {
         $group = new CRM_Contact_DAO_Group();
         if ($flag) {
             $dao->member_count = CRM_Contact_BAO_Group::memberCount($dao->id);
         }
         $groups[] = clone $dao;
     }
     return $groups;
 }
 /**
  * set up variables to build the form
  *
  * @return void
  * @acess protected
  */
 function preProcess()
 {
     $this->_id = $this->get('id');
     if ($this->_id) {
         $breadCrumb = array(array('title' => ts('Manage Groups'), 'url' => CRM_Utils_System::url('civicrm/group', 'reset=1')));
         CRM_Utils_System::appendBreadCrumb($breadCrumb);
         $this->_groupValues = array();
         $params = array('id' => $this->_id);
         $this->_group =& CRM_Contact_BAO_Group::retrieve($params, $this->_groupValues);
         $this->_title = $this->_groupValues['title'];
     }
     $this->assign('action', $this->_action);
     $this->assign('showBlockJS', TRUE);
     if ($this->_action == CRM_Core_Action::DELETE) {
         if (isset($this->_id)) {
             $this->assign('title', $this->_title);
             $this->assign('count', CRM_Contact_BAO_Group::memberCount($this->_id));
             CRM_Utils_System::setTitle(ts('Confirm Group Delete'));
         }
     } else {
         if (isset($this->_id)) {
             $groupValues = array('id' => $this->_id, 'title' => $this->_title, 'saved_search_id' => isset($this->_groupValues['saved_search_id']) ? $this->_groupValues['saved_search_id'] : '');
             if (isset($this->_groupValues['saved_search_id'])) {
                 $groupValues['mapping_id'] = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_SavedSearch', $this->_groupValues['saved_search_id'], 'mapping_id');
                 $groupValues['search_custom_id'] = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_SavedSearch', $this->_groupValues['saved_search_id'], 'search_custom_id');
             }
             $this->assign_by_ref('group', $groupValues);
             CRM_Utils_System::setTitle(ts('Group Settings: %1', array(1 => $this->_title)));
         }
         $session = CRM_Core_Session::singleton();
         $session->pushUserContext(CRM_Utils_System::url('civicrm/group', 'reset=1'));
     }
     //build custom data
     CRM_Custom_Form_CustomData::preProcess($this, NULL, NULL, 1, 'Group', $this->_id);
 }
示例#8
0
 /**
  * Returns array of group object(s) matching a set of one or Group properties.
  *
  *
  * @param array       $param                 Array of one or more valid property_name=>value pairs. Limits the set of groups returned.
  * @param array       $returnProperties      Which properties should be included in the returned group objects. (member_count should be last element.)
  *  
  * @return  An array of group objects.
  *
  * @access public
  */
 function getGroups($params = null, $returnProperties = null)
 {
     $dao =& new CRM_Contact_DAO_Group();
     $dao->is_active = 1;
     if ($params) {
         foreach ($params as $k => $v) {
             if ($k == 'name' || $k == 'title') {
                 $dao->whereAdd($k . ' LIKE "' . addslashes($v) . '"');
             } else {
                 $dao->{$k} = $v;
             }
         }
     }
     $dao->find();
     $flag = $returnProperties && in_array('member_count', $returnProperties) ? 1 : 0;
     $groups = array();
     while ($dao->fetch()) {
         $group =& new CRM_Contact_DAO_Group();
         if ($flag) {
             $dao->member_count = CRM_Contact_BAO_Group::memberCount($dao->id);
         }
         $groups[] = clone $dao;
     }
     return $groups;
 }