本文整理汇总了PHP中CRM_Contact_BAO_Group::checkPermission方法的典型用法代码示例。如果您正苦于以下问题:PHP CRM_Contact_BAO_Group::checkPermission方法的具体用法?PHP CRM_Contact_BAO_Group::checkPermission怎么用?PHP CRM_Contact_BAO_Group::checkPermission使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CRM_Contact_BAO_Group
的用法示例。
在下文中一共展示了CRM_Contact_BAO_Group::checkPermission方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: civicrm_api3_group_get
/**
* 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');
}
示例2: buildQuickForm
/**
* Build the common elements between the search/advanced form.
*/
public function buildQuickForm()
{
parent::buildQuickForm();
CRM_Core_Resources::singleton()->addScriptFile('civicrm', 'packages/jquery/plugins/jstree/jquery.jstree.js', 0, 'html-header', FALSE)->addStyleFile('civicrm', 'packages/jquery/plugins/jstree/themes/default/style.css', 0, 'html-header');
$permission = CRM_Core_Permission::getPermission();
// some tasks.. what do we want to do with the selected contacts ?
$tasks = array();
if ($this->_componentMode == 1 || $this->_componentMode == 7) {
$tasks += CRM_Contact_Task::permissionedTaskTitles($permission, CRM_Utils_Array::value('deleted_contacts', $this->_formValues));
} else {
$className = $this->_modeValue['taskClassName'];
$tasks += $className::permissionedTaskTitles($permission, FALSE);
}
if (isset($this->_ssID)) {
if ($permission == CRM_Core_Permission::EDIT) {
$tasks = $tasks + CRM_Contact_Task::optionalTaskTitle();
}
$search_custom_id = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_SavedSearch', $this->_ssID, 'search_custom_id');
$savedSearchValues = array('id' => $this->_ssID, 'name' => CRM_Contact_BAO_SavedSearch::getName($this->_ssID, 'title'), 'search_custom_id' => $search_custom_id);
$this->assign_by_ref('savedSearch', $savedSearchValues);
$this->assign('ssID', $this->_ssID);
}
if ($this->_context === 'smog') {
// CRM-11788, we might want to do this for all of search where force=1
$formQFKey = CRM_Utils_Array::value('qfKey', $this->_formValues);
$getQFKey = CRM_Utils_Array::value('qfKey', $_GET);
$postQFKey = CRM_Utils_Array::value('qfKey', $_POST);
if ($formQFKey && empty($getQFKey) && empty($postQFKey)) {
$url = CRM_Utils_System::makeURL('qfKey') . $formQFKey;
CRM_Utils_System::redirect($url);
}
$permissionForGroup = FALSE;
if (!empty($this->_groupID)) {
// check if user has permission to edit members of this group
$permission = CRM_Contact_BAO_Group::checkPermission($this->_groupID);
if ($permission && in_array(CRM_Core_Permission::EDIT, $permission)) {
$permissionForGroup = TRUE;
}
// check if _groupID exists, it might not if
// we are displaying a hidden group
if (!isset($this->_group[$this->_groupID])) {
$this->_group[$this->_groupID] = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Group', $this->_groupID, 'title');
}
// set the group title
$groupValues = array('id' => $this->_groupID, 'title' => $this->_group[$this->_groupID]);
$this->assign_by_ref('group', $groupValues);
// also set ssID if this is a saved search
$ssID = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Group', $this->_groupID, 'saved_search_id');
$this->assign('ssID', $ssID);
//get the saved search mapping id
if ($ssID) {
$this->_ssID = $ssID;
$ssMappingId = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_SavedSearch', $ssID, 'mapping_id');
$this->assign('ssMappingID', $ssMappingId);
}
// Set dynamic page title for 'Show Members of Group'
CRM_Utils_System::setTitle(ts('Contacts in Group: %1', array(1 => $this->_group[$this->_groupID])));
}
$group_contact_status = array();
foreach (CRM_Core_SelectValues::groupContactStatus() as $k => $v) {
if (!empty($k)) {
$group_contact_status[] = $this->createElement('checkbox', $k, NULL, $v);
}
}
$this->addGroup($group_contact_status, 'group_contact_status', ts('Group Status'));
$this->assign('permissionedForGroup', $permissionForGroup);
}
// add the go button for the action form, note it is of type 'next' rather than of type 'submit'
if ($this->_context === 'amtg') {
// check if _groupID exists, it might not if
// we are displaying a hidden group
if (!isset($this->_group[$this->_amtgID])) {
$this->assign('permissionedForGroup', FALSE);
$this->_group[$this->_amtgID] = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Group', $this->_amtgID, 'title');
}
// Set dynamic page title for 'Add Members Group'
CRM_Utils_System::setTitle(ts('Add to Group: %1', array(1 => $this->_group[$this->_amtgID])));
// also set the group title and freeze the action task with Add Members to Group
$groupValues = array('id' => $this->_amtgID, 'title' => $this->_group[$this->_amtgID]);
$this->assign_by_ref('group', $groupValues);
$this->add('submit', $this->_actionButtonName, ts('Add Contacts to %1', array(1 => $this->_group[$this->_amtgID])), array('class' => 'crm-form-submit'));
$this->add('hidden', 'task', CRM_Contact_Task::GROUP_CONTACTS);
$selectedRowsRadio = $this->addElement('radio', 'radio_ts', NULL, '', 'ts_sel', array('checked' => 'checked'));
$allRowsRadio = $this->addElement('radio', 'radio_ts', NULL, '', 'ts_all');
$this->assign('ts_sel_id', $selectedRowsRadio->_attributes['id']);
$this->assign('ts_all_id', $allRowsRadio->_attributes['id']);
}
$selectedContactIds = array();
$qfKeyParam = CRM_Utils_Array::value('qfKey', $this->_formValues);
// We use ajax to handle selections only if the search results component_mode is set to "contacts"
if ($qfKeyParam && ($this->get('component_mode') <= 1 || $this->get('component_mode') == 7)) {
$this->addClass('crm-ajax-selection-form');
$qfKeyParam = "civicrm search {$qfKeyParam}";
$selectedContactIdsArr = CRM_Core_BAO_PrevNextCache::getSelection($qfKeyParam);
$selectedContactIds = array_keys($selectedContactIdsArr[$qfKeyParam]);
}
$this->assign_by_ref('selectedContactIds', $selectedContactIds);
//.........这里部分代码省略.........
示例3: getGroupContacts
/**
* Returns array of contacts who are members of the specified group.
*
* @param CRM_Contact $group A valid group object (passed by reference)
* @param array $returnProperties Which properties
* should be included in the returned Contact object(s). If NULL,
* the default set of contact properties will be
* included. group_contact properties (such as 'status',
* ' in_date', etc.) are included automatically.Note:Do not inclue
* Id releted properties.
* @param text $status A valid status value ('Added', 'Pending', 'Removed').
* @param text $sort Associative array of
* one or more "property_name"=>"sort direction"
* pairs which will control order of Contact objects returned.
* @param Int $offset Starting row index.
* @param Int $row_count Maximum number of rows to returns.
*
*
* @return $contactArray Array of contacts who are members of the specified group
*
* @access public
*/
static function getGroupContacts(&$group, $returnProperties = null, $status = 'Added', $sort = null, $offset = null, $row_count = null, $includeChildGroups = false)
{
$groupDAO =& new CRM_Contact_DAO_Group();
$groupDAO->id = $group->id;
if (!$groupDAO->find(true)) {
return CRM_Core_Error::createError("Could not locate group with id: {$id}");
}
// make sure user has got permission to view this group
require_once 'CRM/Contact/BAO/Group.php';
if (!CRM_Contact_BAO_Group::checkPermission($groupDAO->id, $groupDAO->title)) {
return CRM_Core_Error::createError("You do not have permission to access group with id: {$id}");
}
$query = '';
if (empty($returnProperties)) {
$query = "SELECT contact_a.id as contact_id,\n civicrm_email.email as email";
} else {
$query = "SELECT contact_a.id as contact_id , {$grpStatus} as status,";
$query .= implode(',', $returnProperties);
}
$params = array();
if ($includeChildGroups) {
require_once 'CRM/Contact/BAO/GroupNesting.php';
$groupIds = CRM_Contact_BAO_GroupNesting::getDescendentGroupIds(array($group->id));
} else {
$groupIds = array($group->id);
}
foreach ($groupIds as $groupId) {
$params[] = array('group', 'IN', array($group->id => true), 0, 0);
}
require_once 'CRM/Core/BAO/Email.php';
require_once 'CRM/Contact/BAO/Contact.php';
$tables = array(CRM_Core_BAO_Email::getTableName() => true, CRM_Contact_BAO_Contact::getTableName() => true);
$inner = array();
$whereTables = array();
$where = CRM_Contact_BAO_Query::getWhereClause($params, null, $tables, $whereTables);
$permission = CRM_Core_Permission::whereClause(CRM_Core_Permission::VIEW, $tables, $whereTables);
$from = CRM_Contact_BAO_Query::fromClause($tables, $inner);
$query .= " {$from} WHERE {$permission} AND {$where} ";
if ($sort != null) {
$order = array();
foreach ($sort as $key => $direction) {
$order[] = " {$key} {$direction} ";
}
$query .= " ORDER BY " . implode(',', $order);
}
if (!is_null($offset) && !is_null($row_count)) {
$query .= " LIMIT {$offset}, {$row_count}";
}
$dao =& new CRM_Contact_DAO_Contact();
$dao->query($query);
// this is quite inefficient, we need to change the return
// values in docs
$contactArray = array();
while ($dao->fetch()) {
$contactArray[] = clone $dao;
}
return $contactArray;
}
示例4: getValues
/**
* Given a contact id and a field set, return the values from the db
* for this contact
*
* @param int $cid
* @param array $fields
* The profile fields of interest.
* @param array $values
* The values for the above fields.
* @param bool $searchable
* Searchable or not.
* @param array $componentWhere
* Component condition.
* @param bool $absolute
* Return urls in absolute form (useful when sending an email).
* @param null $additionalWhereClause
*/
public static function getValues($cid, &$fields, &$values, $searchable = TRUE, $componentWhere = NULL, $absolute = FALSE, $additionalWhereClause = NULL)
{
if (empty($cid) && empty($componentWhere)) {
return NULL;
}
// get the contact details (hier)
$returnProperties = CRM_Contact_BAO_Contact::makeHierReturnProperties($fields);
$params = $cid ? array(array('contact_id', '=', $cid, 0, 0)) : array();
// add conditions specified by components. eg partcipant_id etc
if (!empty($componentWhere)) {
$params = array_merge($params, $componentWhere);
}
$query = new CRM_Contact_BAO_Query($params, $returnProperties, $fields);
$options =& $query->_options;
$details = $query->searchQuery(0, 0, NULL, FALSE, FALSE, FALSE, FALSE, FALSE, $additionalWhereClause);
if (!$details->fetch()) {
return;
}
$query->convertToPseudoNames($details);
$config = CRM_Core_Config::singleton();
$locationTypes = CRM_Core_PseudoConstant::get('CRM_Core_DAO_Address', 'location_type_id');
$imProviders = CRM_Core_PseudoConstant::get('CRM_Core_DAO_IM', 'provider_id');
$websiteTypes = CRM_Core_PseudoConstant::get('CRM_Core_DAO_Website', 'website_type_id');
$multipleFields = array('url');
//start of code to set the default values
foreach ($fields as $name => $field) {
// fix for CRM-3962
if ($name == 'id') {
$name = 'contact_id';
}
// skip fields that should not be displayed separately
if (!empty($field['skipDisplay'])) {
continue;
}
// Create a unique, non-empty index for each field.
$index = $field['title'];
if ($index === '') {
$index = ' ';
}
while (array_key_exists($index, $values)) {
$index .= ' ';
}
$params[$index] = $values[$index] = '';
$customFieldName = NULL;
// hack for CRM-665
if (isset($details->{$name}) || $name == 'group' || $name == 'tag') {
// to handle gender / suffix / prefix
if (in_array(substr($name, 0, -3), array('gender', 'prefix', 'suffix'))) {
$params[$index] = $details->{$name};
$values[$index] = $details->{$name};
} elseif (in_array($name, CRM_Contact_BAO_Contact::$_greetingTypes)) {
$dname = $name . '_display';
$values[$index] = $details->{$dname};
$name = $name . '_id';
$params[$index] = $details->{$name};
} elseif (in_array($name, array('state_province', 'country', 'county'))) {
$values[$index] = $details->{$name};
$idx = $name . '_id';
$params[$index] = $details->{$idx};
} elseif ($name === 'preferred_communication_method') {
$communicationFields = CRM_Core_PseudoConstant::get('CRM_Contact_DAO_Contact', 'preferred_communication_method');
$compref = array();
$pref = explode(CRM_Core_DAO::VALUE_SEPARATOR, $details->{$name});
foreach ($pref as $k) {
if ($k) {
$compref[] = $communicationFields[$k];
}
}
$params[$index] = $details->{$name};
$values[$index] = implode(',', $compref);
} elseif ($name === 'preferred_language') {
$params[$index] = $details->{$name};
$values[$index] = CRM_Core_PseudoConstant::getLabel('CRM_Contact_DAO_Contact', 'preferred_language', $details->{$name});
} elseif ($name == 'group') {
$groups = CRM_Contact_BAO_GroupContact::getContactGroup($cid, 'Added', NULL, FALSE, TRUE);
$title = $ids = array();
foreach ($groups as $g) {
// CRM-8362: User and User Admin visibility groups should be included in display if user has
// VIEW permission on that group
$groupPerm = CRM_Contact_BAO_Group::checkPermission($g['group_id'], $g['title']);
if ($g['visibility'] != 'User and User Admin Only' || CRM_Utils_Array::key(CRM_Core_Permission::VIEW, $groupPerm)) {
$title[] = $g['title'];
if ($g['visibility'] == 'Public Pages') {
//.........这里部分代码省略.........
示例5: buildQuickForm
/**
* Build the common elements between the search/advanced form
*
* @access public
* @return void
*/
function buildQuickForm()
{
$permission = CRM_Core_Permission::getPermission();
// some tasks.. what do we want to do with the selected contacts ?
$tasks = array('' => ts('- more actions -')) + CRM_Contact_Task::permissionedTaskTitles($permission);
if (isset($this->_ssID)) {
if ($permission == CRM_Core_Permission::EDIT) {
$tasks = $tasks + CRM_Contact_Task::optionalTaskTitle();
}
$savedSearchValues = array('id' => $this->_ssID, 'name' => CRM_Contact_BAO_SavedSearch::getName($this->_ssID, 'title'));
$this->assign_by_ref('savedSearch', $savedSearchValues);
$this->assign('ssID', $this->_ssID);
}
if ($this->_context === 'smog') {
// need to figure out how to freeze a bunch of checkboxes, hack for now
if ($this->_action != CRM_Core_Action::ADVANCED) {
//Fix ME
//$this->_groupElement->freeze( );
}
// also set the group title
$groupValues = array('id' => $this->_groupID, 'title' => $this->_group[$this->_groupID]);
$this->assign_by_ref('group', $groupValues);
// also set ssID if this is a saved search
$ssID = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Group', $this->_groupID, 'saved_search_id');
$this->assign('ssID', $ssID);
//get the saved search mapping id
if ($ssID) {
$ssMappingId = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_SavedSearch', $ssID, 'mapping_id');
}
if (isset($ssMappingId)) {
$this->assign('ssMappingID', $ssMappingId);
}
$group_contact_status = array();
foreach (CRM_Core_SelectValues::groupContactStatus() as $k => $v) {
if (!empty($k)) {
$group_contact_status[] = HTML_QuickForm::createElement('checkbox', $k, null, $v);
}
}
$this->addGroup($group_contact_status, 'group_contact_status', ts('Group Status'));
/*
* commented out to fix CRM-4268
*
* $this->addGroupRule( 'group_contact_status',
* ts( 'Please select at least Group Status value.' ), 'required', null, 1 );
*/
// Set dynamic page title for 'Show Members of Group'
CRM_Utils_System::setTitle(ts('Group Members: %1', array(1 => $this->_group[$this->_groupID])));
// check if user has permission to edit members of this group
require_once 'CRM/Contact/BAO/Group.php';
$permission = CRM_Contact_BAO_Group::checkPermission($this->_groupID, $this->_group[$this->_groupID]);
if ($permission && in_array(CRM_Core_Permission::EDIT, $permission)) {
$this->assign('permissionedForGroup', true);
} else {
$this->assign('permissionedForGroup', false);
}
}
/*
* add the go button for the action form, note it is of type 'next' rather than of type 'submit'
*
*/
if ($this->_context === 'amtg') {
// Set dynamic page title for 'Add Members Group'
CRM_Utils_System::setTitle(ts('Add Members: %1', array(1 => $this->_group[$this->_amtgID])));
// also set the group title and freeze the action task with Add Members to Group
$groupValues = array('id' => $this->_amtgID, 'title' => $this->_group[$this->_amtgID]);
$this->assign_by_ref('group', $groupValues);
$this->add('submit', $this->_actionButtonName, ts('Add Contacts to %1', array(1 => $this->_group[$this->_amtgID])), array('class' => 'form-submit', 'onclick' => "return checkPerformAction('mark_x', '" . $this->getName() . "', 1);"));
$this->add('hidden', 'task', CRM_Contact_Task::GROUP_CONTACTS);
} else {
$this->add('select', 'task', ts('Actions:') . ' ', $tasks);
$this->add('submit', $this->_actionButtonName, ts('Go'), array('class' => 'form-submit', 'id' => 'Go', 'onclick' => "return checkPerformAction('mark_x', '" . $this->getName() . "', 0);"));
}
// need to perform tasks on all or selected items ? using radio_ts(task selection) for it
$this->addElement('radio', 'radio_ts', null, '', 'ts_sel', array('checked' => 'checked', 'onclick' => 'toggleTaskAction( true );'));
$this->addElement('radio', 'radio_ts', null, '', 'ts_all', array('onclick' => $this->getName() . ".toggleSelect.checked = false; toggleCheckboxVals('mark_x_', this);toggleTaskAction( true );"));
/*
* add form checkboxes for each row. This is needed out here to conform to QF protocol
* of all elements being declared in builQuickForm
*/
$rows = $this->get('rows');
if (is_array($rows)) {
$this->addElement('checkbox', 'toggleSelect', null, null, array('onclick' => "toggleTaskAction( true ); return toggleCheckboxVals('mark_x_',this);"));
foreach ($rows as $row) {
$this->addElement('checkbox', $row['checkbox'], null, null, array('onclick' => "toggleTaskAction( true ); return checkSelectedBox('" . $row['checkbox'] . "', '" . $this->getName() . "');"));
}
}
// add buttons
$this->addButtons(array(array('type' => 'refresh', 'name' => ts('Search'), 'isDefault' => true)));
$this->add('submit', $this->_printButtonName, ts('Print'), array('class' => 'form-submit', 'id' => 'Print', 'onclick' => "return checkPerformAction('mark_x', '" . $this->getName() . "', 1);"));
$this->setDefaultAction('refresh');
}
示例6: getGroupList
/**
* This function to get list of groups.
*
* @param array $params
* Associated array for params.
*
* @return array
*/
public static function getGroupList(&$params)
{
$config = CRM_Core_Config::singleton();
$whereClause = self::whereClause($params, FALSE);
//$this->pagerAToZ( $whereClause, $params );
if (!empty($params['rowCount']) && $params['rowCount'] > 0) {
$limit = " LIMIT {$params['offset']}, {$params['rowCount']} ";
}
$orderBy = ' ORDER BY groups.title asc';
if (!empty($params['sort'])) {
$orderBy = ' ORDER BY ' . CRM_Utils_Type::escape($params['sort'], 'String');
// CRM-16905 - Sort by count cannot be done with sql
if (strpos($params['sort'], 'count') === 0) {
$orderBy = $limit = '';
}
}
$select = $from = $where = "";
$groupOrg = FALSE;
if (CRM_Core_Permission::check('administer Multiple Organizations') && CRM_Core_Permission::isMultisiteEnabled()) {
$select = ", contact.display_name as org_name, contact.id as org_id";
$from = " LEFT JOIN civicrm_group_organization gOrg\n ON gOrg.group_id = groups.id\n LEFT JOIN civicrm_contact contact\n ON contact.id = gOrg.organization_id ";
//get the Organization ID
$orgID = CRM_Utils_Request::retrieve('oid', 'Positive', CRM_Core_DAO::$_nullObject);
if ($orgID) {
$where = " AND gOrg.organization_id = {$orgID}";
}
$groupOrg = TRUE;
}
$query = "\n SELECT groups.*, createdBy.sort_name as created_by {$select}\n FROM civicrm_group groups\n LEFT JOIN civicrm_contact createdBy\n ON createdBy.id = groups.created_id\n {$from}\n WHERE {$whereClause} {$where}\n GROUP BY groups.id\n {$orderBy}\n {$limit}";
$object = CRM_Core_DAO::executeQuery($query, $params, TRUE, 'CRM_Contact_DAO_Group');
//FIXME CRM-4418, now we are handling delete separately
//if we introduce 'delete for group' make sure to handle here.
$groupPermissions = array(CRM_Core_Permission::VIEW);
if (CRM_Core_Permission::check('edit groups')) {
$groupPermissions[] = CRM_Core_Permission::EDIT;
$groupPermissions[] = CRM_Core_Permission::DELETE;
}
// CRM-9936
$reservedPermission = CRM_Core_Permission::check('administer reserved groups');
$links = self::actionLinks();
$allTypes = CRM_Core_OptionGroup::values('group_type');
$values = $groupsToCount = array();
$visibility = CRM_Core_SelectValues::ufVisibility();
while ($object->fetch()) {
$permission = CRM_Contact_BAO_Group::checkPermission($object->id, $object->title);
//@todo CRM-12209 introduced an ACL check in the whereClause function
// it may be that this checking is now obsolete - or that what remains
// should be removed to the whereClause (which is also accessed by getCount)
if ($permission) {
$newLinks = $links;
$values[$object->id] = array('class' => array(), 'count' => '0');
CRM_Core_DAO::storeValues($object, $values[$object->id]);
// Wrap with crm-editable. Not an ideal solution.
if (in_array(CRM_Core_Permission::EDIT, $groupPermissions)) {
$values[$object->id]['title'] = '<span class="crm-editable crmf-title">' . $values[$object->id]['title'] . '</span>';
}
if ($object->saved_search_id) {
$values[$object->id]['title'] .= ' (' . ts('Smart Group') . ')';
// check if custom search, if so fix view link
$customSearchID = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_SavedSearch', $object->saved_search_id, 'search_custom_id');
if ($customSearchID) {
$newLinks[CRM_Core_Action::VIEW]['url'] = 'civicrm/contact/search/custom';
$newLinks[CRM_Core_Action::VIEW]['qs'] = "reset=1&force=1&ssID={$object->saved_search_id}";
}
}
$action = array_sum(array_keys($newLinks));
// CRM-9936
if (array_key_exists('is_reserved', $object)) {
//if group is reserved and I don't have reserved permission, suppress delete/edit
if ($object->is_reserved && !$reservedPermission) {
$action -= CRM_Core_Action::DELETE;
$action -= CRM_Core_Action::UPDATE;
$action -= CRM_Core_Action::DISABLE;
}
}
if (array_key_exists('is_active', $object)) {
if ($object->is_active) {
$action -= CRM_Core_Action::ENABLE;
} else {
$values[$object->id]['class'][] = 'disabled';
$action -= CRM_Core_Action::VIEW;
$action -= CRM_Core_Action::DISABLE;
}
}
$action = $action & CRM_Core_Action::mask($groupPermissions);
$values[$object->id]['visibility'] = $visibility[$values[$object->id]['visibility']];
$groupsToCount[$object->saved_search_id ? 'civicrm_group_contact_cache' : 'civicrm_group_contact'][] = $object->id;
if (isset($values[$object->id]['group_type'])) {
$groupTypes = explode(CRM_Core_DAO::VALUE_SEPARATOR, substr($values[$object->id]['group_type'], 1, -1));
$types = array();
foreach ($groupTypes as $type) {
$types[] = CRM_Utils_Array::value($type, $allTypes);
//.........这里部分代码省略.........
示例7: buildQuickForm
/**
* Build the common elements between the search/advanced form
*
* @access public
*
* @return void
*/
function buildQuickForm()
{
$permission = CRM_Core_Permission::getPermission();
// some tasks.. what do we want to do with the selected contacts ?
$tasks = array('' => ts('- actions -'));
if ($this->_componentMode == 1 || $this->_componentMode == 7) {
$tasks += CRM_Contact_Task::permissionedTaskTitles($permission, CRM_Utils_Array::value('deleted_contacts', $this->_formValues));
} else {
require_once str_replace('_', DIRECTORY_SEPARATOR, $this->_modeValue['taskClassName']) . '.php';
eval('$tasks += ' . $this->_modeValue['taskClassName'] . '::permissionedTaskTitles( $permission );');
}
if (isset($this->_ssID)) {
if ($permission == CRM_Core_Permission::EDIT) {
$tasks = $tasks + CRM_Contact_Task::optionalTaskTitle();
}
$search_custom_id = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_SavedSearch', $this->_ssID, 'search_custom_id');
$savedSearchValues = array('id' => $this->_ssID, 'name' => CRM_Contact_BAO_SavedSearch::getName($this->_ssID, 'title'), 'search_custom_id' => $search_custom_id);
$this->assign_by_ref('savedSearch', $savedSearchValues);
$this->assign('ssID', $this->_ssID);
}
if ($this->_context === 'smog') {
if (!empty($this->_groupID)) {
// set the group title
$groupValues = array('id' => $this->_groupID, 'title' => $this->_group[$this->_groupID]);
$this->assign_by_ref('group', $groupValues);
// also set ssID if this is a saved search
$ssID = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Group', $this->_groupID, 'saved_search_id');
$this->assign('ssID', $ssID);
//get the saved search mapping id
if ($ssID) {
$this->_ssID = $ssID;
$ssMappingId = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_SavedSearch', $ssID, 'mapping_id');
$this->assign('ssMappingID', $ssMappingId);
}
}
$group_contact_status = array();
foreach (CRM_Core_SelectValues::groupContactStatus() as $k => $v) {
if (!empty($k)) {
$group_contact_status[] = $this->createElement('checkbox', $k, NULL, $v);
}
}
$this->addGroup($group_contact_status, 'group_contact_status', ts('Group Status'));
$this->assign('permissionedForGroup', FALSE);
if (!empty($this->_groupID)) {
// Set dynamic page title for 'Show Members of Group'
CRM_Utils_System::setTitle(ts('Contacts in Group: %1', array(1 => $this->_group[$this->_groupID])));
// check if user has permission to edit members of this group
$permission = CRM_Contact_BAO_Group::checkPermission($this->_groupID, $this->_group[$this->_groupID]);
if ($permission && in_array(CRM_Core_Permission::EDIT, $permission)) {
$this->assign('permissionedForGroup', TRUE);
}
}
}
// add the go button for the action form, note it is of type 'next' rather than of type 'submit'
if ($this->_context === 'amtg') {
// Set dynamic page title for 'Add Members Group'
CRM_Utils_System::setTitle(ts('Add to Group: %1', array(1 => $this->_group[$this->_amtgID])));
// also set the group title and freeze the action task with Add Members to Group
$groupValues = array('id' => $this->_amtgID, 'title' => $this->_group[$this->_amtgID]);
$this->assign_by_ref('group', $groupValues);
$this->add('submit', $this->_actionButtonName, ts('Add Contacts to %1', array(1 => $this->_group[$this->_amtgID])), array('class' => 'form-submit', 'onclick' => "return checkPerformAction('mark_x', '" . $this->getName() . "', 1);"));
$this->add('hidden', 'task', CRM_Contact_Task::GROUP_CONTACTS);
} else {
$this->add('select', 'task', ts('Actions:') . ' ', $tasks);
$this->add('submit', $this->_actionButtonName, ts('Go'), array('class' => 'form-submit', 'id' => 'Go', 'onclick' => "return checkPerformAction('mark_x', '" . $this->getName() . "', 0, " . (int) empty($this->_customSearchClass) . ");"));
}
// need to perform tasks on all or selected items ? using radio_ts(task selection) for it
$selectedRowsRadio = $this->addElement('radio', 'radio_ts', NULL, '', 'ts_sel', array('checked' => 'checked', 'onclick' => 'toggleTaskAction( true );'));
$this->assign('ts_sel_id', $selectedRowsRadio->_attributes['id']);
if ($qfKeyParam = CRM_Utils_Array::value('qfKey', $this->_formValues)) {
$qfKeyParam = "civicrm search {$qfKeyParam}";
$selectedContactIdsArr = CRM_Core_BAO_PrevNextCache::getSelection($qfKeyParam);
$selectedContactIds = array_keys($selectedContactIdsArr[$qfKeyParam]);
}
$this->assign_by_ref('selectedContactIds', $selectedContactIds);
$allRowsRadio = $this->addElement('radio', 'radio_ts', NULL, '', 'ts_all', array('onclick' => $this->getName() . ".toggleSelect.checked = false; toggleCheckboxVals('mark_x_', this);toggleTaskAction( true );toggleContactSelection( 'resetSel', '{$qfKeyParam}', 'reset' );"));
$this->assign('ts_all_id', $allRowsRadio->_attributes['id']);
/*
* add form checkboxes for each row. This is needed out here to conform to QF protocol
* of all elements being declared in builQuickForm
*/
$rows = $this->get('rows');
if (is_array($rows)) {
$this->addElement('checkbox', 'toggleSelect', NULL, NULL, array('onclick' => "toggleTaskAction( true ); toggleCheckboxVals('mark_x_',this);return toggleContactSelection( 'toggleSelect', '" . $qfKeyParam . "' , 'multiple' );"));
$unselectedContactIds = array();
foreach ($rows as $row) {
$this->addElement('checkbox', $row['checkbox'], NULL, NULL, array('onclick' => "toggleContactSelection( '" . $row['checkbox'] . "', '" . $qfKeyParam . "' , 'single' );toggleTaskAction( true ); return checkSelectedBox('" . $row['checkbox'] . "');"));
if (!in_array($row['contact_id'], $selectedContactIds)) {
$unselectedContactIds[] = $row['contact_id'];
}
}
$this->assign_by_ref('unselectedContactIds', $unselectedContactIds);
}
//.........这里部分代码省略.........
示例8: getGroupContacts
/**
* Returns array of contacts who are members of the specified group.
*
* @param CRM_Contact $group A valid group object (passed by reference)
* @param array $returnProperties Which properties
* should be included in the returned Contact object(s). If NULL,
* the default set of contact properties will be
* included. group_contact properties (such as 'status',
* ' in_date', etc.) are included automatically.Note:Do not inclue
* Id releted properties.
* @param text $status A valid status value ('Added', 'Pending', 'Removed').
* @param text $sort Associative array of
* one or more "property_name"=>"sort direction"
* pairs which will control order of Contact objects returned.
* @param Int $offset Starting row index.
* @param Int $row_count Maximum number of rows to returns.
*
*
* @return $contactArray Array of contacts who are members of the specified group
*
* @access public
*/
function getGroupContacts(&$group, $returnProperties = null, $status = 'Added', $sort = null, $offset = null, $row_count = null)
{
$query = "SELECT * FROM civicrm_group WHERE id = " . CRM_Utils_Type::escape($group->id, 'Integer');
$groupDAO =& new CRM_Contact_DAO_Group();
$groupDAO->id = $group->id;
if (!$groupDAO->find(true)) {
return CRM_Core_Error::createError("Could not locate group with id: {$id}");
}
// make sure user has got permission to view this group
if (!CRM_Contact_BAO_Group::checkPermission($groupDAO->id, $groupDAO->title)) {
return CRM_Core_Error::createError("You do not have permission to access group with id: {$id}");
}
$query = '';
if (empty($returnProperties)) {
$query = "SELECT civicrm_contact.id as contact_id,\n civicrm_email.email as email";
//$query = "SELECT *,civicrm_contact.id as contact_id, (talk to lobo before re-enabling this)
//civicrm_email.email as email";
} else {
$query = "SELECT civicrm_contact.id as contact_id ,";
$query .= implode(',', $returnProperties);
}
$fv = array('group' => array($group->id => true));
if ($status) {
$fv['group_contact_status'] = array($status => true);
} else {
$fv['group_contact_status'] = array('Added' => true, 'Removed' => true, 'Pending' => true);
}
$tables = array(CRM_Contact_BAO_GroupContact::getTableName() => true, CRM_Core_BAO_Email::getTableName() => true, CRM_Contact_BAO_Contact::getTableName() => true, CRM_Contact_BAO_Group::getTableName() => true);
$inner = array();
$whereTables = array();
$where = CRM_Contact_BAO_Query::getWhereClause($fv, null, $tables, $whereTables);
$permission = CRM_Core_Permission::whereClause(CRM_CORE_PERMISSION_VIEW, $tables, $whereTables);
$from = CRM_Contact_BAO_Query::fromClause($tables, $inner);
$query .= " {$from} WHERE {$permission} AND {$where} ";
if ($sort != null) {
$order = array();
foreach ($sort as $key => $direction) {
$order[] = " {$key} {$direction} ";
}
$query .= " ORDER BY " . implode(',', $order);
}
if ($offset != null && $row_count != null) {
$query .= " LIMIT {$offset}, {$row_count}";
}
// CRM_Core_Error::debug( 'q', $query );
$dao =& new CRM_Contact_DAO_Contact();
$dao->query($query);
// this is quite inefficient, we need to change the return
// values in docs
$contactArray = array();
while ($dao->fetch()) {
$contactArray[] = clone $dao;
}
return $contactArray;
}
示例9: checkPermission
/**
* Make sure that the user has permission to access this group.
*
* @param int $id
* The id of the object.
* @param int $title
* Name or title of the object.
*
* @return string
* the permission that the user has (or null)
*/
public function checkPermission($id, $title)
{
return CRM_Contact_BAO_Group::checkPermission($id, $title);
}
示例10: crm_delete_group
/**
*
* 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;
}
示例11: getGroupList
/**
* This function to get list of groups
*
* @param array $params associated array for params
* @access public
*/
static function getGroupList(&$params)
{
$config = CRM_Core_Config::singleton();
$whereClause = self::whereClause($params, FALSE);
//$this->pagerAToZ( $whereClause, $params );
if (!empty($params['rowCount']) && $params['rowCount'] > 0) {
$limit = " LIMIT {$params['offset']}, {$params['rowCount']} ";
}
$orderBy = ' ORDER BY groups.title asc';
if (CRM_Utils_Array::value('sort', $params)) {
$orderBy = ' ORDER BY ' . CRM_Utils_Array::value('sort', $params);
}
$select = $from = $where = "";
$groupOrg = FALSE;
if (CRM_Core_Permission::check('administer Multiple Organizations') && CRM_Core_Permission::isMultisiteEnabled()) {
$select = ", contact.display_name as org_name, contact.id as org_id";
$from = " LEFT JOIN civicrm_group_organization gOrg\n ON gOrg.group_id = groups.id\n LEFT JOIN civicrm_contact contact\n ON contact.id = gOrg.organization_id ";
//get the Organization ID
$orgID = CRM_Utils_Request::retrieve('oid', 'Positive', CRM_Core_DAO::$_nullObject);
if ($orgID) {
$where = " AND gOrg.organization_id = {$orgID}";
}
$groupOrg = TRUE;
}
$query = "\n SELECT groups.* {$select}\n FROM civicrm_group groups\n {$from}\n WHERE {$whereClause} {$where}\n {$orderBy}\n {$limit}";
$object = CRM_Core_DAO::executeQuery($query, $params, TRUE, 'CRM_Contact_DAO_Group');
//FIXME CRM-4418, now we are handling delete separately
//if we introduce 'delete for group' make sure to handle here.
$groupPermissions = array(CRM_Core_Permission::VIEW);
if (CRM_Core_Permission::check('edit groups')) {
$groupPermissions[] = CRM_Core_Permission::EDIT;
$groupPermissions[] = CRM_Core_Permission::DELETE;
}
// CRM-9936
$reservedPermission = CRM_Core_Permission::check('administer reserved groups');
$links = self::actionLinks();
$allTypes = CRM_Core_OptionGroup::values('group_type');
$values = array();
while ($object->fetch()) {
$permission = CRM_Contact_BAO_Group::checkPermission($object->id, $object->title);
if ($permission) {
$newLinks = $links;
$values[$object->id] = array();
CRM_Core_DAO::storeValues($object, $values[$object->id]);
if ($object->saved_search_id) {
$values[$object->id]['title'] .= ' (' . ts('Smart Group') . ')';
// check if custom search, if so fix view link
$customSearchID = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_SavedSearch', $object->saved_search_id, 'search_custom_id');
if ($customSearchID) {
$newLinks[CRM_Core_Action::VIEW]['url'] = 'civicrm/contact/search/custom';
$newLinks[CRM_Core_Action::VIEW]['qs'] = "reset=1&force=1&ssID={$object->saved_search_id}";
}
}
$action = array_sum(array_keys($newLinks));
// CRM-9936
if (array_key_exists('is_reserved', $object)) {
//if group is reserved and I don't have reserved permission, suppress delete/edit
if ($object->is_reserved && !$reservedPermission) {
$action -= CRM_Core_Action::DELETE;
$action -= CRM_Core_Action::UPDATE;
$action -= CRM_Core_Action::DISABLE;
}
}
$values[$object->id]['class'] = '';
if (array_key_exists('is_active', $object)) {
if ($object->is_active) {
$action -= CRM_Core_Action::ENABLE;
} else {
$values[$object->id]['class'] = 'disabled';
$action -= CRM_Core_Action::VIEW;
$action -= CRM_Core_Action::DISABLE;
}
}
$action = $action & CRM_Core_Action::mask($groupPermissions);
$values[$object->id]['visibility'] = CRM_Contact_DAO_Group::tsEnum('visibility', $values[$object->id]['visibility']);
if (isset($values[$object->id]['group_type'])) {
$groupTypes = explode(CRM_Core_DAO::VALUE_SEPARATOR, substr($values[$object->id]['group_type'], 1, -1));
$types = array();
foreach ($groupTypes as $type) {
$types[] = CRM_Utils_Array::value($type, $allTypes);
}
$values[$object->id]['group_type'] = implode(', ', $types);
}
$values[$object->id]['action'] = CRM_Core_Action::formLink($newLinks, $action, array('id' => $object->id, 'ssid' => $object->saved_search_id));
if ($groupOrg) {
if ($object->org_id) {
$contactUrl = CRM_Utils_System::url('civicrm/contact/view', "reset=1&cid={$object->org_id}");
$values[$object->id]['org_info'] = "<a href='{$contactUrl}'>{$object->org_name}</a>";
} else {
$values[$object->id]['org_info'] = '';
// Empty cell
}
} else {
$values[$object->id]['org_info'] = NULL;
//.........这里部分代码省略.........
示例12: buildQuickForm
/**
* Build the common elements between the search/advanced form
*
* @access public
*
* @return void
*/
function buildQuickForm()
{
CRM_Core_Resources::singleton()->addScriptFile('civicrm', 'js/crm.searchForm.js')->addScriptFile('civicrm', 'packages/jquery/plugins/jstree/jquery.jstree.js', 0, 'html-header', FALSE)->addStyleFile('civicrm', 'packages/jquery/plugins/jstree/themes/default/style.css', 0, 'html-header');
$permission = CRM_Core_Permission::getPermission();
// some tasks.. what do we want to do with the selected contacts ?
$tasks = array('' => ts('- actions -'));
if ($this->_componentMode == 1 || $this->_componentMode == 7) {
$tasks += CRM_Contact_Task::permissionedTaskTitles($permission, CRM_Utils_Array::value('deleted_contacts', $this->_formValues));
} else {
$className = $this->_modeValue['taskClassName'];
$tasks += $className::permissionedTaskTitles($permission, false);
}
if (isset($this->_ssID)) {
if ($permission == CRM_Core_Permission::EDIT) {
$tasks = $tasks + CRM_Contact_Task::optionalTaskTitle();
}
$search_custom_id = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_SavedSearch', $this->_ssID, 'search_custom_id');
$savedSearchValues = array('id' => $this->_ssID, 'name' => CRM_Contact_BAO_SavedSearch::getName($this->_ssID, 'title'), 'search_custom_id' => $search_custom_id);
$this->assign_by_ref('savedSearch', $savedSearchValues);
$this->assign('ssID', $this->_ssID);
}
if ($this->_context === 'smog') {
// CRM-11788, we might want to do this for all of search where force=1
$formQFKey = CRM_Utils_Array::value('qfKey', $this->_formValues);
$getQFKey = CRM_Utils_Array::value('qfKey', $_GET);
$postQFKey = CRM_Utils_Array::value('qfKey', $_POST);
if ($formQFKey && empty($getQFKey) && empty($postQFKey)) {
$url = CRM_Utils_System::makeURL('qfKey') . $formQFKey;
CRM_Utils_System::redirect($url);
}
if (!empty($this->_groupID)) {
$permissionForGroup = FALSE;
// check if user has permission to edit members of this group
$permission = CRM_Contact_BAO_Group::checkPermission($this->_groupID);
if ($permission && in_array(CRM_Core_Permission::EDIT, $permission)) {
$permissionForGroup = TRUE;
}
// check if _groupID exists, it might not if
// we are displaying a hidden group
if (!isset($this->_group[$this->_groupID])) {
$permissionForGroup = FALSE;
$this->_group[$this->_groupID] = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Group', $this->_groupID, 'title');
}
$this->assign('permissionedForGroup', $permissionForGroup);
// set the group title
$groupValues = array('id' => $this->_groupID, 'title' => $this->_group[$this->_groupID]);
$this->assign_by_ref('group', $groupValues);
// also set ssID if this is a saved search
$ssID = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Group', $this->_groupID, 'saved_search_id');
$this->assign('ssID', $ssID);
//get the saved search mapping id
if ($ssID) {
$this->_ssID = $ssID;
$ssMappingId = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_SavedSearch', $ssID, 'mapping_id');
$this->assign('ssMappingID', $ssMappingId);
}
// Set dynamic page title for 'Show Members of Group'
CRM_Utils_System::setTitle(ts('Contacts in Group: %1', array(1 => $this->_group[$this->_groupID])));
}
$group_contact_status = array();
foreach (CRM_Core_SelectValues::groupContactStatus() as $k => $v) {
if (!empty($k)) {
$group_contact_status[] = $this->createElement('checkbox', $k, NULL, $v);
}
}
$this->addGroup($group_contact_status, 'group_contact_status', ts('Group Status'));
$this->assign('permissionedForGroup', FALSE);
}
// add the go button for the action form, note it is of type 'next' rather than of type 'submit'
if ($this->_context === 'amtg') {
// check if _groupID exists, it might not if
// we are displaying a hidden group
if (!isset($this->_group[$this->_amtgID])) {
$this->assign('permissionedForGroup', FALSE);
$this->_group[$this->_amtgID] = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Group', $this->_amtgID, 'title');
}
// Set dynamic page title for 'Add Members Group'
CRM_Utils_System::setTitle(ts('Add to Group: %1', array(1 => $this->_group[$this->_amtgID])));
// also set the group title and freeze the action task with Add Members to Group
$groupValues = array('id' => $this->_amtgID, 'title' => $this->_group[$this->_amtgID]);
$this->assign_by_ref('group', $groupValues);
$this->add('submit', $this->_actionButtonName, ts('Add Contacts to %1', array(1 => $this->_group[$this->_amtgID])), array('class' => 'form-submit', 'onclick' => "return checkPerformAction('mark_x', '" . $this->getName() . "', 1);"));
$this->add('hidden', 'task', CRM_Contact_Task::GROUP_CONTACTS);
} else {
$this->add('select', 'task', ts('Actions:') . ' ', $tasks);
$this->add('submit', $this->_actionButtonName, ts('Go'), array('class' => 'form-submit', 'id' => 'Go', 'onclick' => "return checkPerformAction('mark_x', '" . $this->getName() . "', 0, 1);"));
}
// need to perform tasks on all or selected items ? using radio_ts(task selection) for it
$selectedRowsRadio = $this->addElement('radio', 'radio_ts', NULL, '', 'ts_sel', array('checked' => 'checked', 'onclick' => 'toggleTaskAction( true );'));
$this->assign('ts_sel_id', $selectedRowsRadio->_attributes['id']);
if ($qfKeyParam = CRM_Utils_Array::value('qfKey', $this->_formValues)) {
$qfKeyParam = "civicrm search {$qfKeyParam}";
$selectedContactIdsArr = CRM_Core_BAO_PrevNextCache::getSelection($qfKeyParam);
//.........这里部分代码省略.........