setStateUser() public static method

Set the user for which the state relationship should be loaded.
public static setStateUser ( User $user )
$user User
Example #1
0
 /**
  * {@inheritdoc}
  */
 protected function getDefaultAttributes($discussion)
 {
     $gate = $this->gate->forUser($this->actor);
     $attributes = parent::getDefaultAttributes($discussion) + ['commentsCount' => (int) $discussion->comments_count, 'participantsCount' => (int) $discussion->participants_count, 'startTime' => $this->formatDate($discussion->start_time), 'lastTime' => $this->formatDate($discussion->last_time), 'lastPostNumber' => (int) $discussion->last_post_number, 'canReply' => $gate->allows('reply', $discussion), 'canRename' => $gate->allows('rename', $discussion), 'canDelete' => $gate->allows('delete', $discussion), 'canHide' => $gate->allows('hide', $discussion)];
     if ($discussion->hide_time) {
         $attributes['isHidden'] = true;
         $attributes['hideTime'] = $this->formatDate($discussion->hide_time);
     }
     Discussion::setStateUser($this->actor);
     if ($state = $discussion->state) {
         $attributes += ['readTime' => $this->formatDate($state->read_time), 'readNumber' => (int) $state->read_number];
     }
     return $attributes;
 }
Example #2
0
 /**
  * @param SearchCriteria $criteria
  * @param int|null $limit
  * @param int $offset
  * @param array $load An array of relationships to load on the results.
  * @return SearchResults
  */
 public function search(SearchCriteria $criteria, $limit = null, $offset = 0, array $load = [])
 {
     $actor = $criteria->actor;
     $query = $this->discussions->query()->whereVisibleTo($actor);
     // Construct an object which represents this search for discussions.
     // Apply gambits to it, sort, and paging criteria. Also give extensions
     // an opportunity to modify it.
     $search = new DiscussionSearch($query->getQuery(), $actor);
     $this->gambits->apply($search, $criteria->query);
     $this->applySort($search, $criteria->sort);
     $this->applyOffset($search, $offset);
     $this->applyLimit($search, $limit + 1);
     // TODO: inject dispatcher
     event(new ConfigureDiscussionSearch($search, $criteria));
     // Execute the search query and retrieve the results. We get one more
     // results than the user asked for, so that we can say if there are more
     // results. If there are, we will get rid of that extra result.
     $discussions = $query->get();
     $areMoreResults = $limit > 0 && $discussions->count() > $limit;
     if ($areMoreResults) {
         $discussions->pop();
     }
     // The relevant posts relationship isn't a typical Eloquent
     // relationship; rather, we need to extract that information from our
     // search object. We will delegate that task and prevent Eloquent
     // from trying to load it.
     if (in_array('relevantPosts', $load)) {
         $this->loadRelevantPosts($discussions, $search);
         $load = array_diff($load, ['relevantPosts', 'relevantPosts.discussion', 'relevantPosts.user']);
     }
     Discussion::setStateUser($actor);
     $discussions->load($load);
     return new SearchResults($discussions, $areMoreResults);
 }