Example #1
0
 public function showUserProjects($hash)
 {
     $user = UserModel::where('hash', '=', $hash)->first();
     $projects = $this->service->getProjects($user);
     $models = $this->returnprojectmodels($projects);
     return $models;
 }
Example #2
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];
 }
Example #3
0
 /**
  *
  * @param array $attributes
  */
 public function createUser(array $attributes)
 {
     $existingUser = UserModel::where('email', $attributes['email'])->get();
     if (count($existingUser) > 0) {
         return false;
     }
     $this->userCreationValidator->validate($attributes);
     $attributes['password'] = Hash::make($attributes['password']);
     $attributes['hash'] = Str::random(40);
     $attributes['city'] = 'New York';
     $attributes['state'] = 'New York';
     $attributes['language'] = 'English';
     $user = $this->switchUserableFunction("createUserable", "userable_type", $attributes, $attributes);
     if (!$user) {
         throw new InvalidCreationException();
     }
     \Log::info("New user registered: {$user->name} ({$user->email})", array_merge($user->toArray(), $user->userable->toArray()));
     return $user;
 }
Example #4
0
 /**
  * Creates a new activity for a given user, associated with an input project and a specified activity type.
  * @param $user
  * @param $in
  * @param $flag 0 if a new project 1 if project activity
  * @param $type 0 if status update, 1 if comment
  * @return array|\stdClass
  */
 public function createActivity($user, $in, $flag, $files = [], $type)
 {
     $project = $this->projectRepository->getByHash($in['project_hash']);
     $content = ['hash' => Str::random(36), 'user_id' => $user->id, 'project_id' => $project->id, 'body' => $in['body'], 'html_body' => $in['html_body'], 'visibility' => 0];
     switch ($user->userable_type) {
         case DesignerModel::class:
             //designers and admins only
             $content['visibility'] = 2;
             $users = [UserModel::where('userable_type', AdministratorModel::class)->get()];
             break;
         case AdministratorModel::class:
             //if the administrator has a chosen invisibility that will be set by the admin when the admin wants to
             //switch in between visibility settings.
             if (array_key_exists('visibility', $in)) {
                 $content['visibility'] = $in['visibility'];
                 switch ($content['visibility']) {
                     case 1:
                         $retailerIds = \DB::table('retailer_map')->where('project_id', '=', $project->id)->lists('retailer_id');
                         $userIds = BuyerModel::whereIn('retailer_id', $retailerIds)->lists('id');
                         $arrayBuyers = UserModel::whereIn('userable_id', $userIds)->where('userable_type', BuyerModel::class)->get();
                         $arrayAdmins = UserModel::where('userable_type', AdministratorModel::class)->where('id', '!=', $user->id)->get();
                         $users = [$arrayBuyers->all(), $arrayAdmins->all()];
                         break;
                     case 2:
                         $users = [UserModel::where('userable_type', AdministratorModel::class)->where('id', '!=', $user->id)->orWhere('id', $project->user_id)->get()];
                         break;
                     case 3:
                         $retailerIds = \DB::table('retailer_map')->where('project_id', '=', $project->id)->lists('retailer_id');
                         $userIds = BuyerModel::whereIn('retailer_id', $retailerIds)->lists('id');
                         $arrayBuyers = UserModel::whereIn('userable_id', $userIds)->where('userable_type', BuyerModel::class)->get();
                         $arrayAll = UserModel::where('userable_type', AdministratorModel::class)->where('id', '!=', $user->id)->orWhere('id', $project->user_id)->get();
                         $users = [$arrayBuyers->all(), $arrayAll->all()];
                         break;
                     default:
                         $users = [UserModel::where('userable_type', AdministratorModel::class)->get()];
                         break;
                 }
             } else {
                 $content['visibility'] = 0;
                 $users = [UserModel::where('userable_type', AdministratorModel::class)->get()];
             }
             break;
         case BuyerModel::class:
             //buyers and admins only
             $content['visibility'] = 1;
             $users = [UserModel::where('userable_type', AdministratorModel::class)->get()];
             break;
         default:
             \App::abort(403, 'Unauthorized action.');
             break;
     }
     $project->touch();
     if (array_key_exists('status', $in)) {
         $this->projectRepository->update($in['project_hash'], ['status' => $in['status']]);
     }
     if (array_key_exists('parent_hash', $in)) {
         $parent = $this->activityRepository->getByHash($in['parent_hash']);
         $content['parent_id'] = $parent->id;
         $newActivity = $this->activityRepository->create($content);
         $activity = ['activity' => [], 'parent' => []];
         $activity['activity'] = $newActivity;
         $activity['parent'] = $parent;
     } else {
         $content['parent_id'] = 0;
         $newActivity = $this->activityRepository->create($content);
         $activity = $newActivity;
     }
     if (count($files) > 0) {
         foreach ($files as $file) {
             $this->uploadService->createUpload($user, $file, $newActivity, ['unique' => false, 'type' => 'activity-upload']);
         }
     }
     if ($flag == 0) {
         foreach ($users as $userArray) {
             foreach ($userArray as $userModel) {
                 $this->notificationService->issue('New Projects Submitted', $userModel, $project, $newActivity, ' has submitted a project.');
             }
         }
     } else {
         if ($flag == 1) {
             if ($type == 0) {
                 $corpus = ' has updated the status.';
             } else {
                 if ($type == 1) {
                     $corpus = ' has left a comment.';
                 } else {
                     $corpus = ' has submitted a project.';
                 }
             }
             foreach ($users as $userArray) {
                 foreach ($userArray as $userModel) {
                     $this->notificationService->issue('Project Activity', $userModel, $project, $newActivity, $corpus);
                 }
             }
         }
     }
     return $activity;
 }
Example #5
0
 public function searchUsers(Request $request)
 {
     $input = Input::all();
     $users = UserModel::where('name', 'like', $input['query'] . '%')->get();
     return $this->withCollection($users);
 }