Exemple #1
0
 /**
  * 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;
 }