Esempio n. 1
0
 /**
  * Creates a new project using the input from the form
  *
  * @param CreateProjectRequest $request The validated request
  * @return mixed
  */
 public function create(CreateProjectRequest $request)
 {
     $newEntry = Project::create(['author' => Auth::user()->username, 'user_id' => Auth::user()->id, 'title' => $request->getTitle(), 'description' => $request->getDescription(), 'body' => $request->getBody(), 'statement_title' => 'Mission Statement', 'statement_body' => 'This is where you write about your mission statement or make it whatever you want.', 'tab_title' => 'Welcome', 'tab_body' => 'Here you can write a message or maybe the status of your project for all your members to see.']);
     $thumbnail = $request->file('thumbnail');
     $thumbnail->move(base_path() . '/public/images/projects', 'product' . $newEntry->id . '.jpg');
     //Sets banner image to a random pre-made banner
     $images = glob(base_path() . "/public/images/banners/*");
     $imagePath = base_path() . '/public/images/projects/' . 'banner' . $newEntry->id . '.jpg';
     $rand = random_int(0, count($images) - 1);
     \File::copy($images[$rand], $imagePath);
     //Add creator as a member and make admin of the project
     $newEntry->addMember(true);
     //Add creator as a follower of the project
     $newEntry->addFollower();
     return redirect('/project/' . $newEntry->title);
 }
 public function store(CreateProjectRequest $request)
 {
     if ($request->hasFile('thumb_img')) {
         $sol = '../';
         $file = $request->file('thumb_img');
         $filename = uniqid() . $file->getClientOriginalName();
         $file_path = $file->move('img/upload', $filename);
         $url_path = array();
         $url_path['link_file'] = $sol . $file_path;
         $img_linker = ImageSrc::create($url_path);
         $publish_home = $request->has('publish_home') ? true : false;
         $data['public_home'] = $publish_home;
         $data = $request->all();
         $project = Project::create($data);
         $project->img_link()->save($img_linker);
     } else {
         Project::create($request->all());
     }
     return redirect('admin/projects');
 }
 /**
  * Submit a completed, previously saved project.
  *
  * @param CreateProjectRequest $request
  * @param Project $project
  * @throws ProjectNameAlreadyTakenException
  * @return string
  */
 public function update(CreateProjectRequest $request, Project $project)
 {
     $existingProject = Project::where('project_name', '=', $request->get('project_name'))->first();
     if (!is_null($existingProject) && $existingProject->user_id != Auth::user()->id) {
         throw new ProjectNameAlreadyTakenException();
     }
     $projectDetails = ['project_name' => $request->get('project_name'), 'short_desc' => $request->get('short_desc'), 'full_desc' => $request->get('full_desc'), 'target_amount' => $request->get('target_amount'), 'child_name' => $request->get('child_name'), 'slug' => strtolower(preg_replace('/[\\s-]+/', '-', $request->get('project_name'))), 'application_status' => '1', 'user_id' => Auth::user()->id];
     $userDetails = ['first_name' => $request->get('first_name'), 'last_name' => $request->get('last_name'), 'email' => $request->get('email'), 'tel_number' => $request->get('tel_number'), 'street' => $request->get('street'), 'postcode' => $request->get('postcode'), 'city' => $request->get('city'), 'country' => $request->get('country')];
     $userDocuments = [$request->file('doc_1_mand') ? $request->file('doc_1_mand') : $request->get('doc1Mand'), $request->file('doc_2_mand') ? $request->file('doc_2_mand') : $request->get('doc2Mand'), $request->file('doc_3') ? $request->file('doc_3') : $request->get('doc3'), $request->file('doc_4') ? $request->file('doc_4') : $request->get('doc4'), $request->file('doc_5') ? $request->file('doc_5') : $request->get('doc5'), $request->file('doc_6') ? $request->file('doc_6') : $request->get('doc6')];
     $userImages = ['main_img' => $request->file('main_img') ? $request->file('main_img') : $request->get('mainImage'), 'img_2' => $request->file('img_2') ? $request->file('img_2') : $request->get('img2'), 'img_3' => $request->file('img_3') ? $request->file('img_3') : $request->get('img3'), 'img_4' => $request->file('img_4') ? $request->file('img_4') : $request->get('img4')];
     // Store the original project slug,
     // for the saved images, in case of user edit.
     $originalProjectSlug = $project->slug;
     // Update or fill the Project attributes.
     foreach ($projectDetails as $attribute => $value) {
         $project->{$attribute} = $value;
     }
     // Save the changes to the Project.
     $project->save();
     // Update user model.
     $user = Auth::user();
     foreach ($userDetails as $attribute => $value) {
         $user->{$attribute} = $value;
     }
     $user->save();
     // Make the image and document directories.
     $imageFolderPath = public_path("img/{$project->slug}");
     $documentFolderPath = public_path("documents/{$project->slug}");
     $this->makeImageDirectories($imageFolderPath);
     $this->makeDocumentDirectory($documentFolderPath);
     // Create new Document instances in the database.
     // Move the documents to their directory.
     $this->moveDocumentsAndSaveToDB($userDocuments, $documentFolderPath, $project->id, $originalProjectSlug);
     // Resize the images to our needs, and save them in their directories.
     $this->resizeImagesAndSaveToFolders($userImages, $project->child_name, $imageFolderPath, $originalProjectSlug);
     // Create new Image instances in the database.
     $this->saveImageInstancesToDB($userImages, $project->child_name, $project->id);
     // Mail the administrator, of a newly submitted project.
     $project = Auth::user()->project;
     Mail::queue('emails.project-submit', ['project' => $project], function ($message) {
         $message->to('*****@*****.**', 'Administrator')->subject(trans('create-project-form.email-subject'));
     });
     // Mail the user, of a successful project submission.
     Mail::queue('emails.project-submit-user', ['project' => $project, 'user' => $user], function ($message) use($user) {
         $message->to($user->email, $user->first_name . ' ' . $user->last_name)->subject(trans('project-submit-email.user-title'));
     });
     return json_encode(['status' => 'success']);
 }