static function groupContact($groupID, $contactIDs, $op) { require_once 'CRM/Bridge/OG/Utils.php'; $ogID = CRM_Bridge_OG_Utils::ogID($groupID, false); if (!$ogID) { return; } require_once 'api/UFGroup.php'; foreach ($contactIDs as $contactID) { $drupalID = crm_uf_get_uf_id($contactID); if ($drupalID) { if ($op == 'add') { og_save_subscription($ogID, $drupalID, array('is_active' => 1)); } else { og_delete_subscription($ogID, $drupalID); } } } }
/** * returns all the rows in the given offset and rowCount * * @param enum $action the action being performed * @param int $offset the row number to start from * @param int $rowCount the number of rows to return * @param string $sort the sql string that describes the sort order * @param enum $output what should the result set include (web/email/csv) * * @return int the total number of rows for this action */ function &getRows($action, $offset, $rowCount, $sort, $output = null) { //$sort object processing for location fields if ($sort) { $vars = $sort->_vars; $varArray = array(); foreach ($vars as $key => $field) { $field = $vars[$key]; $fieldArray = explode('-', $field['name']); if (is_numeric(CRM_Utils_Array::value('1', $fieldArray))) { $locationType =& new CRM_Core_DAO_LocationType(); $locationType->id = $fieldArray[1]; $locationType->find(true); if ($fieldArray[0] == 'email' || $fieldArray[0] == 'im' || $fieldArray[0] == 'phone') { $field['name'] = "`" . $locationType->name . "-" . $fieldArray[0] . "-1`"; } else { $field['name'] = "`" . $locationType->name . "-" . $fieldArray[0] . "`"; } } $varArray[$key] = $field; } } $sort->_vars = $varArray; $result = $this->_query->searchQuery($offset, $rowCount, $sort, null, null, null, null, null); // process the result of the query $rows = array(); // check if edit is configured in profile settings if ($this->_gid) { $editLink = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_UFGroup', $this->_gid, 'is_edit_link'); } //FIXME : make sure to handle delete separately. CRM-4418 $mask = CRM_Core_Action::mask(array(CRM_Core_Permission::getPermission())); if ($editLink && $mask & CRM_Core_Permission::EDIT) { // do not allow edit for anon users in joomla frontend, CRM-4668 $config =& CRM_Core_Config::singleton(); if (!$config->userFrameworkFrontend) { $this->_editLink = true; } } $links =& self::links($this->_map, $this->_editLink, $this->_linkToUF, $this->_gid); require_once 'CRM/Core/PseudoConstant.php'; $locationTypes = CRM_Core_PseudoConstant::locationType(); $names = array(); static $skipFields = array('group', 'tag'); foreach ($this->_fields as $key => $field) { if (CRM_Utils_Array::value('in_selector', $field) && !in_array($key, $skipFields)) { if (strpos($key, '-') !== false) { $value = explode('-', $key); $fieldName = CRM_Utils_Array::value(0, $value); $id = CRM_Utils_Array::value(1, $value); $type = CRM_Utils_Array::value(2, $value); $locationTypeName = null; if (is_numeric($id)) { $locationTypeName = CRM_Utils_Array::value($id, $locationTypes); } else { if ($id == 'Primary') { $locationTypeName = 1; } } if (!$locationTypeName) { continue; } $locationTypeName = str_replace(' ', '_', $locationTypeName); if (in_array($fieldName, array('phone', 'im', 'email'))) { if ($type) { $names[] = "{$locationTypeName}-{$fieldName}-{$type}"; } else { $names[] = "{$locationTypeName}-{$fieldName}"; } } else { $names[] = "{$locationTypeName}-{$fieldName}"; } } else { if ($field['name'] == 'id') { $names[] = 'contact_id'; } else { $names[] = $field['name']; } } } } require_once "CRM/Core/OptionGroup.php"; $multipleSelectFields = array('preferred_communication_method' => 1); if (CRM_Core_Permission::access('Quest')) { require_once 'CRM/Quest/BAO/Student.php'; $multipleSelectFields = CRM_Quest_BAO_Student::$multipleSelectFields; } if ($this->_linkToUF) { require_once 'api/UFGroup.php'; } require_once 'CRM/Contact/BAO/Contact/Utils.php'; while ($result->fetch()) { if (isset($result->country)) { // the query returns the untranslated country name $i18n =& CRM_Core_I18n::singleton(); $result->country = $i18n->translate($result->country); } $row = array(); $empty = true; $row[] = CRM_Contact_BAO_Contact_Utils::getImage($result->contact_sub_type ? $result->contact_sub_type : $result->contact_type); if ($result->sort_name) { $row['sort_name'] = $result->sort_name; $empty = false; } else { continue; } foreach ($names as $name) { if ($cfID = CRM_Core_BAO_CustomField::getKeyID($name)) { $row[] = CRM_Core_BAO_CustomField::getDisplayValue($result->{$name}, $cfID, $this->_options, $result->contact_id); } else { if ($name == 'home_URL' && !empty($result->{$name})) { $url = CRM_Utils_System::fixURL($result->{$name}); $row[] = "<a href=\"{$url}\">{$result->{$name}}</a>"; } else { if ($multipleSelectFields && array_key_exists($name, $multipleSelectFields)) { //fix to display student checkboxes $key = $name; $paramsNew = array($key => $result->{$name}); if ($key == 'test_tutoring') { $name = array($key => array('newName' => $key, 'groupName' => 'test')); } else { if (substr($key, 0, 4) == 'cmr_') { //for readers group $name = array($key => array('newName' => $key, 'groupName' => substr($key, 0, -3))); } else { $name = array($key => array('newName' => $key, 'groupName' => $key)); } } CRM_Core_OptionGroup::lookupValues($paramsNew, $name, false); $row[] = $paramsNew[$key]; } else { if (strpos($name, '-im')) { if (!empty($result->{$name})) { $imProviders = CRM_Core_PseudoConstant::IMProvider(); $providerId = $name . "-provider_id"; $providerName = $imProviders[$result->{$providerId}]; $row[] = $result->{$name} . " ({$providerName})"; } else { $row[] = ''; } } elseif (in_array($name, array('addressee', 'email_greeting', 'postal_greeting'))) { $dname = $name . '_display'; $row[] = $result->{$dname}; } elseif (in_array($name, array('birth_date', 'deceased_date'))) { $row[] = CRM_Utils_Date::customFormat($result->{$name}); } elseif (isset($result->{$name})) { $row[] = $result->{$name}; } else { $row[] = ''; } } } } if (!empty($result->{$name})) { $empty = false; } } $newLinks = $links; $params = array('id' => $result->contact_id, 'gid' => $this->_gid); if ($this->_linkToUF) { $ufID = crm_uf_get_uf_id($result->contact_id); if (!$ufID) { unset($newLinks[CRM_Core_Action::PROFILE]); } else { $params['ufID'] = $ufID; } } $row[] = CRM_Core_Action::formLink($newLinks, $mask, $params); if (!$empty) { $rows[] = $row; } } return $rows; }