Пример #1
0
 public function transform($transformable)
 {
     $projectTransformer = \App::make(ProjectTransformer::class);
     $project = $projectTransformer->transform(ProjectModel::where('id', '=', $transformable->project_id)->first());
     $event = ActivityModel::where('id', '=', $transformable->activity_id)->first();
     $userTransformer = \App::make(UserTransformer::class);
     $owner = $userTransformer->transform(UserModel::where('id', $event->user_id)->first());
     return ['id' => $transformable->id, 'hash' => $transformable->hash, 'project' => $project, 'event' => ['user' => $owner, 'activity' => $event->body, 'corpus' => $transformable->corpus], 'read' => $transformable->read, 'type' => $transformable->notification_type, 'timestamp' => $transformable->created_at];
 }
Пример #2
0
 public function transform($transformable)
 {
     $userTransformer = \App::make(UserTransformer::class);
     $activityTransformer = \App::make(ActivityTransformer::class);
     $owner = $userTransformer->transform($transformable->fetchOwner());
     $optional = [];
     $user = \Authorization::getUser();
     if ($user->userable_type == AdministratorModel::class) {
         $optional['reviewed_by'] = $transformable->reviewed_by;
     }
     switch ($user->userable_type) {
         case DesignerModel::class:
             $activity = ActivityModel::where('project_id', '=', $transformable->id)->where(function ($query) {
                 $query->where('visibility', '=', 2)->orWhere('visibility', '=', 3);
             })->orderBy('created_at', 'desc')->first();
             break;
         case AdministratorModel::class:
             $activity = ActivityModel::where('project_id', '=', $transformable->id)->orderBy('created_at', 'desc')->first();
             break;
         case BuyerModel::class:
             $activity = ActivityModel::where('project_id', '=', $transformable->id)->where(function ($query) {
                 $query->where('visibility', '=', 1)->orWhere('visibility', '=', 3);
             })->orderBy('created_at', 'desc')->first();
             $optional['wishlisted'] = $transformable->wishlisted;
             break;
         default:
             throw new UnsupportedUserException();
     }
     if ($activity) {
         $activity = $activityTransformer->transform($activity);
     } else {
         $activity = "";
     }
     $uploadTransformer = \App::make(UploadTransformer::class);
     $photos = \DB::table('upload_map')->where('owner_hash', $transformable->hash)->get();
     $transformedPhotos = array();
     foreach ($photos as $photo) {
         $picture = UploadModel::where('hash', $photo->upload_hash)->first();
         array_push($transformedPhotos, $uploadTransformer->transform($picture));
     }
     return array_merge(['id' => $transformable->id, 'hash' => $transformable->hash, 'owner' => $owner, "name" => $transformable->name, "tier" => $transformable->tier, "status" => intval($transformable->status), "category" => $transformable->category, "product" => $transformable->product, "product_category" => $transformable->product_category, "season" => $transformable->season, "description" => $transformable->description, "link" => $this->buildUrl($transformable->hash), "updated" => $transformable->updated_at, "submitted_at" => $transformable->submitted_at, "recent_activity" => $activity, "colors" => $transformable->fetchColors(), "fabrics" => $transformable->fetchFabrics(), "details" => $transformable->fetchDetails(), "reviewed_on" => $transformable->reviewed_on, 'moq' => $transformable->moq, 'whsl' => $transformable->whsl, 'images' => $transformedPhotos], $optional);
 }