/** * @see \wcf\data\DatabaseObjectList::readObjects() */ public function readObjects() { parent::readObjects(); // get user ids $userIDs = array(); foreach ($this->objects as &$response) { if (!$this->minResponseTime || $response->time < $this->minResponseTime) { $this->minResponseTime = $response->time; } $userIDs[] = $response->userID; $response = new StructuredCommentResponse($response); $response->setIsDeletable($this->commentManager->canDeleteResponse($response->getDecoratedObject())); $response->setIsEditable($this->commentManager->canEditResponse($response->getDecoratedObject())); } unset($response); // fetch user data and avatars if (!empty($userIDs)) { $userIDs = array_unique($userIDs); $users = UserProfile::getUserProfiles($userIDs); foreach ($this->objects as $response) { if (isset($users[$response->userID])) { $response->setUserProfile($users[$response->userID]); } } } }
/** * get user objs * * @param Mixed $var * @param Array $mbqOpt * $mbqOpt['case'] = 'byUserIds' means get data by user ids.$var is the ids. * @mbqOpt['case'] = 'online' means get online user. * @return Array */ public function getObjsMbqEtUser($var, $mbqOpt) { if ($mbqOpt['case'] == 'byUserIds') { $objsUserProfile = UserProfile::getUserProfiles($var); $objsMbqEtUser = array(); foreach ($objsUserProfile as $oUserProfile) { $objsMbqEtUser[] = $this->initOMbqEtUser($oUserProfile, array('case' => 'oUserProfile')); } return $objsMbqEtUser; } elseif ($mbqOpt['case'] == 'online') { //ref wbb\page\BoardListPage::readData(),wcf\data\user\online\UsersOnlineList,MbqRdEtSysStatistics::initOMbqEtSysStatistics() if (MODULE_USERS_ONLINE && WBB_INDEX_ENABLE_ONLINE_LIST) { $usersOnlineList = new UsersOnlineList(); $usersOnlineList->readStats(); $usersOnlineList->getConditionBuilder()->add('session.userID IS NOT NULL'); $usersOnlineList->readObjects(); // check users online record $usersOnlineTotal = WBB_USERS_ONLINE_RECORD_NO_GUESTS ? $usersOnlineList->stats['members'] : $usersOnlineList->stats['total']; if ($usersOnlineTotal > WBB_USERS_ONLINE_RECORD) { // save new record $optionAction = new OptionAction(array(), 'import', array('data' => array('wbb_users_online_record' => $usersOnlineTotal, 'wbb_users_online_record_time' => TIME_NOW))); $optionAction->executeAction(); } $ids = array(); foreach ($usersOnlineList->getObjects() as $oUserOnline) { $ids[] = $oUserOnline->getDecoratedObject()->userID; } return $this->getObjsMbqEtUser($ids, array('case' => 'byUserIds')); } else { return array(); } } MbqError::alert('', __METHOD__ . ',line:' . __LINE__ . '.' . MBQ_ERR_INFO_UNKNOWN_CASE); }
/** * @see \wcf\data\DatabaseObjectList::readObjects() */ public function readObjects() { parent::readObjects(); $userIDs = array(); $eventGroups = array(); foreach ($this->objects as &$event) { $userIDs[] = $event->userID; $event = new ViewableUserActivityEvent($event); if (!isset($eventGroups[$event->objectTypeID])) { $objectType = UserActivityEventHandler::getInstance()->getObjectType($event->objectTypeID); $eventGroups[$event->objectTypeID] = array('className' => $objectType->className, 'objects' => array()); } $eventGroups[$event->objectTypeID]['objects'][] = $event; } unset($event); // set user profiles if (!empty($userIDs)) { $userIDs = array_unique($userIDs); $users = UserProfile::getUserProfiles($userIDs); foreach ($this->objects as $event) { $event->setUserProfile($users[$event->userID]); } } // parse events foreach ($eventGroups as $eventData) { $eventClass = call_user_func(array($eventData['className'], 'getInstance')); $eventClass->prepare($eventData['objects']); } }
/** * @see \wcf\data\DatabaseObjectList::readObjects() */ public function readObjects() { parent::readObjects(); EventHandler::getInstance()->fireAction($this, 'afterReadObjects'); // cache userids $userIDs = array(); foreach ($this->objects as $object) { $userIDs[] = $object->userID; $userIDs[] = $object->executedUserID; } array_unique($userIDs); UserProfile::getUserProfiles($userIDs); }
/** * @see \wcf\data\DatabaseObjectList::readObjects() */ public function readObjects() { parent::readObjects(); if (!empty($this->objects)) { $objects = array(); foreach ($this->objects as &$object) { $object = new ViewableModerationQueue($object); if (!isset($objects[$object->objectTypeID])) { $objects[$object->objectTypeID] = array(); } $objects[$object->objectTypeID][] = $object; } unset($object); foreach ($objects as $objectTypeID => $queueItems) { ModerationQueueManager::getInstance()->populate($objectTypeID, $queueItems); } // check for non-existant items $queueIDs = array(); foreach ($this->objects as $index => $object) { if ($object->isOrphaned()) { $queueIDs[] = $object->queueID; unset($this->objects[$index]); } } // remove orphaned queues if (!empty($queueIDs)) { $this->indexToObject = array_keys($this->objects); ModerationQueueManager::getInstance()->removeOrphans($queueIDs); } if ($this->loadUserProfiles) { $userIDs = array(); foreach ($this->objects as $object) { $userIDs[] = $object->getAffectedObject()->getUserID(); } $userProfiles = UserProfile::getUserProfiles($userIDs); foreach ($this->objects as $object) { if (isset($userProfiles[$object->getAffectedObject()->getUserID()])) { $object->setUserProfile($userProfiles[$object->getAffectedObject()->getUserID()]); } } } } }
/** * @see \wcf\data\DatabaseObjectList::readObjects() */ public function readObjects() { parent::readObjects(); $userIDs = array(); $likeGroups = array(); foreach ($this->objects as &$like) { $userIDs[] = $like->userID; $like = new ViewableLike($like); if (!isset($likeGroups[$like->objectTypeID])) { $objectType = ObjectTypeCache::getInstance()->getObjectType($like->objectTypeID); $likeGroups[$like->objectTypeID] = array('provider' => $objectType->getProcessor(), 'objects' => array()); } $likeGroups[$like->objectTypeID]['objects'][] = $like; } unset($like); // set user profiles if (!empty($userIDs)) { $userIDs = array_unique($userIDs); $users = UserProfile::getUserProfiles($userIDs); foreach ($this->objects as $like) { $like->setUserProfile($users[$like->userID]); } } // parse like foreach ($likeGroups as $likeData) { if ($likeData['provider'] instanceof IViewableLikeProvider) { $likeData['provider']->prepare($likeData['objects']); } } // validate permissions foreach ($this->objects as $index => $like) { if (!$like->isAccessible()) { unset($this->objects[$index]); } } $this->indexToObject = array_keys($this->objects); }
/** * Returns a user profile by id, fetches user profiles on first call. * * @param integer $userID * @return \wcf\data\user\UserProfile */ public function getUser($userID) { if (!empty($this->userIDs)) { UserProfile::getUserProfiles($this->userIDs); $this->userIDs = array(); } return UserProfile::getUserProfile($userID); }
/** * @see \wcf\page\IPage::readData() */ public function readData() { MessageForm::readData(); if (empty($_POST)) { $this->text = $this->message->message; if ($this->isFirstMessage) { $this->participantCanInvite = $this->conversation->participantCanInvite; $this->subject = $this->conversation->subject; if ($this->conversation->isDraft && $this->conversation->draftData) { $draftData = @unserialize($this->conversation->draftData); if (!empty($draftData['participants'])) { foreach (UserProfile::getUserProfiles($draftData['participants']) as $user) { if (!empty($this->participants)) { $this->participants .= ', '; } $this->participants .= $user->username; } } if (!empty($draftData['invisibleParticipants'])) { foreach (UserProfile::getUserProfiles($draftData['invisibleParticipants']) as $user) { if (!empty($this->invisibleParticipants)) { $this->invisibleParticipants .= ', '; } $this->invisibleParticipants .= $user->username; } } } } } // add breadcrumbs WCF::getBreadcrumbs()->add(new Breadcrumb(WCF::getLanguage()->get('wcf.conversation.conversations'), LinkHandler::getInstance()->getLink('ConversationList'))); WCF::getBreadcrumbs()->add($this->conversation->getBreadcrumb()); // get message list $this->messageList = new ViewableConversationMessageList(); $this->messageList->setConversation($this->conversation); $this->messageList->sqlLimit = CONVERSATION_REPLY_SHOW_MESSAGES_MAX; $this->messageList->sqlOrderBy = 'conversation_message.time DESC'; $this->messageList->getConditionBuilder()->add('conversation_message.conversationID = ?', array($this->message->conversationID)); $this->messageList->getConditionBuilder()->add("conversation_message.messageID <> ?", array($this->message->messageID)); $this->messageList->readObjects(); }
/** * Loads user profiles for outstanding user ids. */ public static function loadUsers() { $userIDs = array(); foreach (self::$users as $userID => $user) { if ($user === null) { $userIDs[] = $userID; } } // load user profiles if (!empty($userIDs)) { $userProfiles = UserProfile::getUserProfiles($userIDs); foreach ($userProfiles as $userID => $userProfile) { self::$users[$userID] = $userProfile; } } }
/** * Processes a list of notification objects. * * @param array<\wcf\data\user\notification\UserNotification> $notificationObjects * @return array */ public function processNotifications(array $notificationObjects) { // return an empty set if no notifications exist if (empty($notificationObjects)) { return array('count' => 0, 'notifications' => array()); } $authorIDs = $eventIDs = $notificationIDs = $objectTypes = array(); foreach ($notificationObjects as $notification) { // cache object types if (!isset($objectTypes[$notification->objectType])) { $objectTypes[$notification->objectType] = array('objectType' => $this->availableObjectTypes[$notification->objectType], 'objectIDs' => array(), 'objects' => array()); } $objectTypes[$notification->objectType]['objectIDs'][] = $notification->objectID; $eventIDs[] = $notification->eventID; $notificationIDs[] = $notification->notificationID; } // load authors $conditions = new PreparedStatementConditionBuilder(); $conditions->add("notificationID IN (?)", array($notificationIDs)); $sql = "SELECT\t\tnotificationID, authorID\n\t\t\tFROM\t\twcf" . WCF_N . "_user_notification_author\n\t\t\t" . $conditions . "\n\t\t\tORDER BY\ttime ASC"; $statement = WCF::getDB()->prepareStatement($sql); $statement->execute($conditions->getParameters()); $authorIDs = $authorToNotification = array(); while ($row = $statement->fetchArray()) { if ($row['authorID']) { $authorIDs[] = $row['authorID']; } if (!isset($authorToNotification[$row['notificationID']])) { $authorToNotification[$row['notificationID']] = array(); } $authorToNotification[$row['notificationID']][] = $row['authorID']; } // load authors $authors = UserProfile::getUserProfiles($authorIDs); $unknownAuthor = new UserProfile(new User(null, array('userID' => null, 'username' => WCF::getLanguage()->get('wcf.user.guest')))); // load objects associated with each object type foreach ($objectTypes as $objectType => $objectData) { $objectTypes[$objectType]['objects'] = $objectData['objectType']->getObjectsByIDs($objectData['objectIDs']); } // load required events $eventList = new UserNotificationEventList(); $eventList->getConditionBuilder()->add("user_notification_event.eventID IN (?)", array($eventIDs)); $eventList->readObjects(); $eventObjects = $eventList->getObjects(); // build notification data $notifications = array(); $deleteNotifications = array(); foreach ($notificationObjects as $notification) { $object = $objectTypes[$notification->objectType]['objects'][$notification->objectID]; if ($object->__unknownNotificationObject) { $deleteNotifications[] = $notification; continue; } $className = $eventObjects[$notification->eventID]->className; $class = new $className($eventObjects[$notification->eventID]); $class->setObject($notification, $object, isset($authors[$notification->authorID]) ? $authors[$notification->authorID] : $unknownAuthor, $notification->additionalData); if (isset($authorToNotification[$notification->notificationID])) { $eventAuthors = array(); foreach ($authorToNotification[$notification->notificationID] as $userID) { if (!$userID) { $eventAuthors[0] = $unknownAuthor; } else { if (isset($authors[$userID])) { $eventAuthors[$userID] = $authors[$userID]; } } } if (!empty($eventAuthors)) { $class->setAuthors($eventAuthors); } } $data = array('authors' => count($class->getAuthors()), 'event' => $class, 'notificationID' => $notification->notificationID, 'time' => $notification->time); $data['confirmed'] = $notification->confirmTime > 0; $notifications[] = $data; } // check access foreach ($notifications as $index => $notificationData) { if (!$notificationData['event']->checkAccess()) { if ($notificationData['event']->deleteNoAccessNotification()) { $deleteNotifications[] = $notificationData['event']->getNotification(); } unset($notifications[$index]); } } if (!empty($deleteNotifications)) { $notificationAction = new UserNotificationAction($deleteNotifications, 'delete'); $notificationAction->executeAction(); // reset notification counter UserStorageHandler::getInstance()->reset(array(WCF::getUser()->userID), 'userNotificationCount'); } return array('count' => count($notifications), 'notifications' => $notifications); }
/** * @see \wcf\system\message\embedded\object\IMessageEmbeddedObjectHandler::loadObjects() */ public function loadObjects(array $objectIDs) { return UserProfile::getUserProfiles($objectIDs); }
/** * get users by user ids * * @param Array $userIds * @return Array */ protected function getUsersByUserIds($userIds) { $objsUserProfile = UserProfile::getUserProfiles($userIds); $objsUser = array(); foreach ($objsUserProfile as $oUserProfile) { if (empty($oUserProfile)) { continue; } $oUser = $oUserProfile->getDecoratedObject(); if ($oUser->userID) { $objsUser[] = $oUser; } } return $objsUser; }
/** * @see \wcf\system\like\IViewableLikeProvider::prepare() */ public function prepare(array $likes) { if (!WCF::getSession()->getPermission('user.news.canReadEntry')) { return; } $commentLikeObjectType = ObjectTypeCache::getInstance()->getObjectTypeByName('com.woltlab.wcf.like.likeableObject', 'com.woltlab.wcf.comment'); $commentIDs = $responseIDs = array(); foreach ($likes as $like) { if ($like->objectTypeID == $commentLikeObjectType->objectTypeID) { $commentIDs[] = $like->objectID; } else { $responseIDs[] = $like->objectID; } } // fetch response $userIDs = $responses = array(); if (!empty($responseIDs)) { $responseList = new CommentResponseList(); $responseList->getConditionBuilder()->add("comment_response.responseID IN (?)", array($responseIDs)); $responseList->readObjects(); $responses = $responseList->getObjects(); foreach ($responses as $response) { $commentIDs[] = $response->commentID; if ($response->userID) { $userIDs[] = $response->userID; } } } // fetch comments $commentList = new CommentList(); $commentList->getConditionBuilder()->add("comment.commentID IN (?)", array($commentIDs)); $commentList->readObjects(); $comments = $commentList->getObjects(); // fetch users $users = array(); $entryIDs = array(); foreach ($comments as $comment) { $entryIDs[] = $comment->objectID; if ($comment->userID) { $userIDs[] = $comment->userID; } } if (!empty($userIDs)) { $users = UserProfile::getUserProfiles(array_unique($userIDs)); } $entries = array(); if (!empty($entryIDs)) { $entryList = new EntryList(); $entryList->setObjectIDs($entryIDs); $entryList->readObjects(); $entries = $entryList->getObjects(); } // set message foreach ($likes as $like) { if ($like->objectTypeID == $commentLikeObjectType->objectTypeID) { // comment like if (isset($comments[$like->objectID])) { $comment = $comments[$like->objectID]; if (isset($entries[$comment->objectID]) && $entries[$comment->objectID]->canRead()) { $like->setIsAccessible(); // short output $text = WCF::getLanguage()->getDynamicVariable('wcf.like.title.de.incendium.cms.news.comment', array('commentAuthor' => $comment->userID ? $users[$comment->userID] : null, 'entry' => $entries[$comment->objectID], 'like' => $like)); $like->setTitle($text); // output $like->setDescription($comment->getExcerpt()); } } } else { // response like if (isset($responses[$like->objectID])) { $response = $responses[$like->objectID]; $comment = $comments[$response->commentID]; if (isset($entries[$comment->objectID]) && $entries[$comment->objectID]->canRead()) { $like->setIsAccessible(); // short output $text = WCF::getLanguage()->getDynamicVariable('wcf.like.title.de.incendium.cms.news.comment.response', array('responseAuthor' => $comment->userID ? $users[$response->userID] : null, 'commentAuthor' => $comment->userID ? $users[$comment->userID] : null, 'entry' => $entries[$comment->objectID], 'like' => $like)); $like->setTitle($text); // output $like->setDescription($response->getExcerpt()); } } } } }
/** * @see \wcf\system\cronjob\ICronjob::execute() */ public function execute(Cronjob $cronjob) { parent::execute($cronjob); // get user ids $userIDs = array(); $sql = "SELECT\tDISTINCT userID\n\t\t\tFROM\twcf" . WCF_N . "_user_notification\n\t\t\tWHERE\tmailNotified = ?\n\t\t\t\tAND time < ?\n\t\t\t\tAND confirmTime = ?"; $statement = WCF::getDB()->prepareStatement($sql); $statement->execute(array(0, TIME_NOW - 3600 * 23, 0)); while ($row = $statement->fetchArray()) { $userIDs[] = $row['userID']; } if (empty($userIDs)) { return; } // get users $userList = new UserList(); $userList->setObjectIDs($userIDs); $userList->readObjects(); $users = $userList->getObjects(); // get notifications $conditions = new PreparedStatementConditionBuilder(); $conditions->add("notification.userID IN (?)", array($userIDs)); $conditions->add("notification.mailNotified = ?", array(0)); $conditions->add("notification.confirmTime = ?", array(0)); $sql = "SELECT\t\tnotification.*, notification_event.eventID, object_type.objectType\n\t\t\tFROM\t\twcf" . WCF_N . "_user_notification notification\n\t\t\tLEFT JOIN\twcf" . WCF_N . "_user_notification_event notification_event\n\t\t\tON\t\t(notification_event.eventID = notification.eventID)\n\t\t\tLEFT JOIN\twcf" . WCF_N . "_object_type object_type\n\t\t\tON\t\t(object_type.objectTypeID = notification_event.objectTypeID)\n\t\t\t" . $conditions . "\n\t\t\tORDER BY\tnotification.time"; $statement = WCF::getDB()->prepareStatement($sql); $statement->execute($conditions->getParameters()); // mark notifications as done $conditions = new PreparedStatementConditionBuilder(); $conditions->add("userID IN (?)", array($userIDs)); $conditions->add("mailNotified = ?", array(0)); $sql = "UPDATE\twcf" . WCF_N . "_user_notification\n\t\t\tSET\tmailNotified = 1\n\t\t\t" . $conditions; $statement2 = WCF::getDB()->prepareStatement($sql); $statement2->execute($conditions->getParameters()); // collect data $eventsToUser = $objectTypes = $eventIDs = $notificationObjects = array(); $availableObjectTypes = UserNotificationHandler::getInstance()->getAvailableObjectTypes(); while ($row = $statement->fetchArray()) { if (!isset($eventsToUser[$row['userID']])) { $eventsToUser[$row['userID']] = array(); } $eventsToUser[$row['userID']][] = $row['notificationID']; // cache object types if (!isset($objectTypes[$row['objectType']])) { $objectTypes[$row['objectType']] = array('objectType' => $availableObjectTypes[$row['objectType']], 'objectIDs' => array(), 'objects' => array()); } $objectTypes[$row['objectType']]['objectIDs'][] = $row['objectID']; $eventIDs[] = $row['eventID']; $notificationObjects[$row['notificationID']] = new UserNotification(null, $row); } // load authors $conditions = new PreparedStatementConditionBuilder(); $conditions->add("notificationID IN (?)", array(array_keys($notificationObjects))); $sql = "SELECT\t\tnotificationID, authorID\n\t\t\tFROM\t\twcf" . WCF_N . "_user_notification_author\n\t\t\t" . $conditions . "\n\t\t\tORDER BY\ttime ASC"; $statement = WCF::getDB()->prepareStatement($sql); $statement->execute($conditions->getParameters()); $authorIDs = $authorToNotification = array(); while ($row = $statement->fetchArray()) { if ($row['authorID']) { $authorIDs[] = $row['authorID']; } if (!isset($authorToNotification[$row['notificationID']])) { $authorToNotification[$row['notificationID']] = array(); } $authorToNotification[$row['notificationID']][] = $row['authorID']; } // load authors $authors = UserProfile::getUserProfiles($authorIDs); $unknownAuthor = new UserProfile(new User(null, array('userID' => null, 'username' => WCF::getLanguage()->get('wcf.user.guest')))); // load objects associated with each object type foreach ($objectTypes as $objectType => $objectData) { $objectTypes[$objectType]['objects'] = $objectData['objectType']->getObjectsByIDs($objectData['objectIDs']); } // load required events $eventList = new UserNotificationEventList(); $eventList->getConditionBuilder()->add("user_notification_event.eventID IN (?)", array($eventIDs)); $eventList->readObjects(); $eventObjects = $eventList->getObjects(); foreach ($eventsToUser as $userID => $events) { if (!isset($users[$userID])) { continue; } $user = $users[$userID]; // no notifications for disabled or banned users if ($user->activationCode) { continue; } if ($user->banned) { continue; } // add mail header $message = $user->getLanguage()->getDynamicVariable('wcf.user.notification.mail.header', array('user' => $user)); foreach ($events as $notificationID) { $notification = $notificationObjects[$notificationID]; $className = $eventObjects[$notification->eventID]->className; $class = new $className($eventObjects[$notification->eventID]); $class->setObject($notification, $objectTypes[$notification->objectType]['objects'][$notification->objectID], isset($authors[$notification->authorID]) ? $authors[$notification->authorID] : $unknownAuthor, $notification->additionalData); $class->setLanguage($user->getLanguage()); if (isset($authorToNotification[$notification->notificationID])) { $eventAuthors = array(); foreach ($authorToNotification[$notification->notificationID] as $userID) { if (!$userID) { $eventAuthors[0] = $unknownAuthor; } else { if (isset($authors[$userID])) { $eventAuthors[$userID] = $authors[$userID]; } } } if (!empty($eventAuthors)) { $class->setAuthors($eventAuthors); } } $message .= "\n\n"; $message .= $class->getEmailMessage('daily'); } // append notification mail footer $token = $user->notificationMailToken; if (!$token) { // generate token if not present $token = mb_substr(StringUtil::getHash(serialize(array($user->userID, StringUtil::getRandomID()))), 0, 20); $editor = new UserEditor($user); $editor->update(array('notificationMailToken' => $token)); } $message .= "\n\n"; $message .= $user->getLanguage()->getDynamicVariable('wcf.user.notification.mail.daily.footer', array('user' => $user, 'token' => $token)); // build mail $mail = new Mail(array($user->username => $user->email), $user->getLanguage()->getDynamicVariable('wcf.user.notification.mail.daily.subject', array('count' => count($events))), $message); $mail->setLanguage($user->getLanguage()); $mail->send(); } }
/** * @see \wcf\data\DatabaseObjectList::readObjects() */ public function readObjects() { parent::readObjects(); // fetch response ids $responseIDs = $userIDs = array(); foreach ($this->objects as &$comment) { if (!$this->minCommentTime || $comment->time < $this->minCommentTime) { $this->minCommentTime = $comment->time; } $commentResponseIDs = $comment->getResponseIDs(); foreach ($commentResponseIDs as $responseID) { $this->responseIDs[] = $responseID; $responseIDs[$responseID] = $comment->commentID; } if ($comment->userID) { $userIDs[] = $comment->userID; } $comment = new StructuredComment($comment); $comment->setIsDeletable($this->commentManager->canDeleteComment($comment->getDecoratedObject())); $comment->setIsEditable($this->commentManager->canEditComment($comment->getDecoratedObject())); } unset($comment); // fetch last responses if (!empty($responseIDs)) { $responseList = new CommentResponseList(); $responseList->getConditionBuilder()->add("comment_response.responseID IN (?)", array(array_keys($responseIDs))); $responseList->readObjects(); foreach ($responseList as $response) { $response = new StructuredCommentResponse($response); $response->setIsDeletable($this->commentManager->canDeleteResponse($response->getDecoratedObject())); $response->setIsEditable($this->commentManager->canEditResponse($response->getDecoratedObject())); $commentID = $responseIDs[$response->responseID]; $this->objects[$commentID]->addResponse($response); if ($response->userID) { $userIDs[] = $response->userID; } } } // fetch user data and avatars if (!empty($userIDs)) { $userIDs = array_unique($userIDs); $users = UserProfile::getUserProfiles($userIDs); foreach ($this->objects as $comment) { if ($comment->userID && isset($users[$comment->userID])) { $comment->setUserProfile($users[$comment->userID]); } foreach ($comment as $response) { if ($response->userID && isset($users[$response->userID])) { $response->setUserProfile($users[$response->userID]); } } } } }