Ejemplo n.º 1
0
 public function findByUser($userId, User $viewer, $limit = null, $offset = 0, $type = null)
 {
     $query = Activity::where('user_id', $userId)->whereIn('type', array_keys(Activity::getTypes()))->orderBy('time', 'desc')->skip($offset)->take($limit);
     if ($type !== null) {
         $query->where('type', $type);
     }
     return $query->get();
 }
Ejemplo n.º 2
0
 /**
  * Sync a piece of activity so that it is present for the specified users,
  * and not present for anyone else.
  *
  * @param \Flarum\Core\Activity\ActivityInterface $activity
  * @param \Flarum\Core\Models\User[] $users
  * @return void
  */
 public function sync(ActivityInterface $activity, array $users)
 {
     Activity::unguard();
     $attributes = ['type' => $activity::getType(), 'subject_id' => $activity->getSubject()->id, 'time' => $activity->getTime()];
     $toDelete = Activity::where($attributes)->get();
     $toInsert = [];
     foreach ($users as $user) {
         $existing = $toDelete->where('user_id', $user->id)->first();
         if ($k = $toDelete->search($existing)) {
             $toDelete->pull($k);
         } else {
             $toInsert[] = $attributes + ['user_id' => $user->id];
         }
     }
     if (count($toDelete)) {
         Activity::whereIn('id', $toDelete->lists('id'))->delete();
     }
     if (count($toInsert)) {
         Activity::insert($toInsert);
     }
 }
Ejemplo n.º 3
0
 public function extend(Application $app)
 {
     $class = $this->class;
     Activity::registerType($class);
     ActivitySerializer::$subjects[$class::getType()] = $this->serializer;
 }