示例#1
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);
 }
示例#2
0
 public function transform($transformable)
 {
     $userTransformer = \App::make(UserTransformer::class);
     $owner = $userTransformer->transform($transformable->fetchOwner());
     $children = [];
     if (count($transformable->children) > 0) {
         foreach ($transformable->children as $child) {
             $children[] = $this->transform($child);
         }
     }
     $uploadTransformer = \App::make(UploadTransformer::class);
     $files = \DB::table('upload_map')->where('owner_hash', $transformable->hash)->get();
     $transformedFiles = array();
     foreach ($files as $file) {
         $upload = UploadModel::where('hash', $file->upload_hash)->first();
         array_push($transformedFiles, $uploadTransformer->transform($upload));
     }
     $transformed = ['hash' => $transformable->hash, 'author' => $owner, 'children' => $children, 'body' => $transformable->body, 'html_body' => $transformable->body, 'updated_at' => $transformable->updated_at, 'files' => $transformedFiles];
     return $transformed;
 }