/** * Get all selected recipients for the field * @return array of usersIds which are recipients of the notification * @access public */ private function _getRecipients($objectID) { $params = $this->getParamsValues(); $recipients = array(); if (isset($params['usersGroupsField']) && $params['usersGroupsField']) { //instanciate related item $item = CMS_poly_object_catalog::getObjectByID($objectID, false, true); if (!is_object($item) || $item->hasError()) { return $recipients; } //does selected field represent users or groups ? $field = new CMS_poly_object_field($params['usersGroupsField']); $isGroup = $field->getParameter('isGroup'); //get item field value $ids = $item->objectValues($params['usersGroupsField'])->getValue('ids'); if (!$ids) { return array(); } //get users ids if ($isGroup) { foreach ($ids as $groupId) { $usersIds = CMS_profile_usersGroupsCatalog::getGroupUsers($groupId, false); foreach ($usersIds as $userId) { $recipients[$userId] = $userId; } } } else { $recipients = $ids; } } else { //get all active users ids $allUsers = CMS_profile_usersCatalog::getAll(true, false, false); //check if user is in included or excluded parameters lists $selectedGroups = $params['disableGroups'] ? explode(';', $params['disableGroups']) : array(); $selectedUsers = $params['disableUsers'] ? explode(';', $params['disableUsers']) : array(); //check all users to see if it match selection parameters foreach ($allUsers as $userId) { if ($params['includeExclude']) { //user must be in selected groups or users to get email $userSelected = false; if (is_array($selectedGroups) && $selectedGroups) { foreach ($selectedGroups as $groupId) { if (CMS_profile_usersGroupsCatalog::userBelongsToGroup($userId, $groupId)) { $userSelected = true; } } } if (is_array($selectedUsers) && $selectedUsers && in_array($userId, $selectedUsers)) { $userSelected = true; } } else { //user must NOT be in selected groups or users to get email $userSelected = true; if (is_array($selectedGroups) && $selectedGroups) { foreach ($selectedGroups as $groupId) { if (CMS_profile_usersGroupsCatalog::userBelongsToGroup($userId, $groupId)) { $userSelected = false; } } } if (is_array($selectedUsers) && $selectedUsers && in_array($userId, $selectedUsers)) { $userSelected = false; } } if ($userSelected) { $recipients[] = $userId; } } } return $recipients; }
/** * Return a list of all objects names of given type * * @param boolean $public are the needed datas public ? /!\ Does not apply for this type of object * @param array $searchConditions, search conditions to add. /!\ only keywords apply for this type of object * @return array(integer objectID => string objectName) * @access public * @static */ function getListOfNamesForObject($public = false, $searchConditions = array()) { $params = $this->getParamsValues(); //load user/group $userGroupSorted = $params['isGroup'] ? CMS_profile_usersGroupsCatalog::getGroupsLabels() : CMS_profile_usersCatalog::getUsersLabels(true, true); //filter by keyword if any if (isset($searchConditions['keywords']) && $searchConditions['keywords']) { $keywords = trim($searchConditions['keywords']); foreach ($userGroupSorted as $id => $label) { if (stripos($label, $keywords) === false) { unset($userGroupSorted[$id]); } } } // Clean users/groups with enable/disable parameters if ($params['isGroup']) { $disableGroups = $params['disableGroups'] ? explode(';', $params['disableGroups']) : array(); if (is_array($disableGroups) && $disableGroups) { if ($params['includeExclude']) { // Include foreach ($userGroupSorted as $groupId => $label) { if (!in_array($groupId, $disableGroups)) { unset($userGroupSorted[$groupId]); } } } else { // Exclude foreach ($userGroupSorted as $groupId => $label) { if (in_array($groupId, $disableGroups)) { unset($userGroupSorted[$groupId]); } } } } } else { $disableGroups = $params['disableGroups'] ? explode(';', $params['disableGroups']) : array(); $disableUsers = $params['disableUsers'] ? explode(';', $params['disableUsers']) : array(); if (is_array($disableGroups) && $disableGroups) { if ($params['includeExclude']) { // Include foreach ($userGroupSorted as $userId => $label) { foreach ($disableGroups as $groupId) { if (!CMS_profile_usersGroupsCatalog::userBelongsToGroup($userId, $groupId)) { unset($userGroupSorted[$userId]); } } } } else { // Exclude foreach ($userGroupSorted as $userId => $label) { foreach ($disableGroups as $groupId) { if (CMS_profile_usersGroupsCatalog::userBelongsToGroup($userId, $groupId)) { unset($userGroupSorted[$userId]); } } } } } if (is_array($disableUsers) && $disableUsers) { if ($params['includeExclude']) { // Include foreach ($userGroupSorted as $groupId => $label) { if (!in_array($groupId, $disableUsers)) { unset($userGroupSorted[$groupId]); } } } else { // Exclude foreach ($userGroupSorted as $groupId => $label) { if (in_array($groupId, $disableUsers)) { unset($userGroupSorted[$groupId]); } } } } } //sort objects by name case insensitive natcasesort($userGroupSorted); return $userGroupSorted; }