示例#1
0
 public function editGet($id = null)
 {
     $users = User::all();
     $project = Project::findOrNew($id);
     $assignees = $project->assignees->keyBy('id')->toArray();
     return view('project.edit')->with('users', $users)->with('project', $project)->with('assignees', $assignees);
 }
 public function index($id)
 {
     $id = decrypt($id);
     $project = Project::findOrNew($id);
     $logs = $project->log;
     if (is_null($logs)) {
         $logs = Project::findOrNew($id);
         return view('content.detailProject', ['project' => $project, 'log' => $logs]);
     }
     $gp_nama = json_decode($project->developer);
     for ($i = 0; $i < count($gp_nama); $i++) {
         $nama[$i] = DB::table('users')->where('id', $gp_nama[$i])->value('name');
     }
     $res_nama = collect($nama);
     return view('content.detailProject', ['project' => $project, 'log' => $logs, 'fillname' => $res_nama]);
 }
 /**
  * Update the specified resource in storage.
  *
  * @param  \Illuminate\Http\Request  $request
  * @param  int  $id
  * @return \Illuminate\Http\Response
  */
 public function update(Request $request, $id)
 {
     if (!Sentinel::hasAccess(["project.update"])) {
         abort(401);
     }
     $this->rules["name"] = "required|unique:projects,name,{$id},id";
     $this->validate($request, $this->rules);
     $project = Project::findOrNew($id);
     $project->name = $request->get("name");
     $project->is_done = is_null($request->get("is_done")) ? 0 : $request->get("is_done");
     $project->mark = $request->get("mark");
     foreach ($project->descriptions as $description) {
         /** @var Description $description */
         $description->delete();
     }
     $dutchDesc = new Description();
     $dutchDesc->description = $request->get("dutchDesc");
     $dutchDesc->language_id = 1;
     $project->descriptions()->save($dutchDesc);
     $englishDesc = new Description();
     $englishDesc->description = $request->get("englishDesc");
     $englishDesc->language_id = 2;
     $project->descriptions()->save($englishDesc);
     $project->type = $request->get("type");
     $project->save();
     Toastr::success("The project {$project->name} has been successfully updated");
     return redirect(action("Admin\\ProjectsController@show", $id));
 }
 /**
  * Save an incomplete state of a Project.
  *
  * @param SaveProjectRequest $request
  * @return string
  * @throws ProjectNameAlreadyTakenException
  */
 public function save(SaveProjectRequest $request)
 {
     $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'))), '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')];
     // Find the Project which belongs to the user, or create a new one.
     $projectID = !is_null(Auth::user()->incompleteProject->first()) ? Auth::user()->incompleteProject->first()->id : null;
     $project = Project::findOrNew($projectID);
     // 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);
     Session::flash('flash_message', trans('create-project-form.save-success'));
     return json_encode(['url' => url(LaravelLocalization::getCurrentLocale() . '/' . trans('routes.create-project/edit') . '/' . $project->slug)]);
 }
示例#5
0
 public function dataUpdate()
 {
     $input = Request::all();
     $input['tgl_target'] = date('Y-m-d', strtotime(str_replace('-', '/', $input['tgl_target'])));
     $input['tgl_pesan'] = date('Y-m-d', strtotime(str_replace('-', '/', $input['tgl_target'])));
     $input['developer'] = json_encode($input['developer']);
     $pro = Project::findOrNew(decrypt($input['id']));
     $pro->name = $input['name'];
     $pro->klien = $input['klien'];
     $pro->tgl_pesan = $input['tgl_pesan'];
     $pro->tgl_target = $input['tgl_target'];
     $pro->developer = $input['developer'];
     $pro->desc = $input['desc'];
     $pro->save();
     Session::flash('flash_message', 'Berhasil Mengedit Data Project ' . $pro->name);
     return redirect('project');
 }