示例#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 search(Request $request)
 {
     $input = Input::all();
     $model = \Authorization::user();
     switch ($model->userable_type) {
         case AdministratorModel::class:
             $users = UserModel::where('name', 'like', '%' . $input['query'] . '%')->get();
             $projectQuery = ProjectModel::where('name', 'like', '%' . $input['query'] . '%');
             if (ctype_digit($input['query'])) {
                 $projects = $projectQuery->orWhere('id', intval($input['query']))->get();
             } else {
                 $projects = $projectQuery->get();
             }
             return $this->returnMultiModels([$users->all(), $projects->all()], [new UserTransformer(), new ProjectTransformer()]);
             break;
         case BuyerModel::class:
             $buyer = BuyerModel::where('id', $model->userable_id)->first();
             $retailerId = $buyer->retailer_id;
             $projectIds = \DB::table('retailer_map')->where('retailer_id', '=', $retailerId)->lists('project_id');
             $projects = ProjectModel::whereIn('id', $projectIds)->where(function ($query) use($input) {
                 if (ctype_digit($input['query'])) {
                     $query->where('name', 'like', '%' . $input['query'] . '%')->orWhere('id', intval($input['query']));
                 } else {
                     $query->where('name', 'like', '%' . $input['query'] . '%');
                 }
             })->get();
             return $this->returnProjectModel($projects);
             break;
         case DesignerModel::class:
             $projects = ProjectModel::where('user_id', $model->id)->where(function ($query) use($input) {
                 if (ctype_digit($input['query'])) {
                     $query->where('name', 'like', '%' . $input['query'] . '%')->orWhere('id', $input['query']);
                 } else {
                     $query->where('name', 'like', '%' . $input['query'] . '%');
                 }
             })->get();
             return $this->returnProjectModel($projects);
             break;
         default:
             return Response();
     }
 }