Esempio n. 1
0
 public function index()
 {
     $rewards = Reward::orderBy('position', 'ASC')->get();
     $reward = new Reward();
     if (Request::isMethod('post')) {
         $validator = Validator::make(Request::all(), $this->rules);
         if ($validator->passes()) {
             $reward->title = Request::input('title');
             $reward->year = Request::input('year');
             $reward->portfolio_id = Request::input('portfolio') == '-' ? null : Request::input('portfolio');
             $reward->group_id = Request::input('group') == '-' ? null : Request::input('group');
             $reward->position = Request::input('position');
             $reward->enabled = Request::has('enabled');
             if ($file = Request::file('photo')) {
                 $reward->photo = $this->upload($file, 'photo');
             }
             $reward->save();
             return redirect('admin/reward')->with('msg', 'Агентство было успешно создано');
         } else {
             return redirect('admin/reward')->withInput()->withErrors($validator);
         }
     }
     return view('admin.reward', ['rewards' => $rewards, 'reward' => $reward, 'portfolioOptions' => $this->portfolioOptions(), 'groupOptions' => $this->groupOptions()]);
 }
Esempio n. 2
0
 public function postUpdateproject(ProjectFormRequest $request)
 {
     $step = $request->get('step');
     $secret_key = $request->get('_secret_key_');
     if (empty($secret_key)) {
         $project = new Project();
         $project->fill($request->except('_token'));
         $project->user_id = $request->input('user_id');
         $project->slug = Str::slug($request->input('name'));
         # Attach file with project
         if ($request->hasFile('file_attachment')) {
             $response = Event::fire(new FileAttachment($request, ['input_file_tag' => 'file_attachment', 'width' => $this->width, 'height' => $this->height, 'mHeight' => $this->mHeight, 'mWidth' => $this->mWidth]));
             if (count($response) > 0) {
                 $project->file_attachment = $response[0];
             }
         }
         # Attach file with project : End
         if ($project->save()) {
             $auto_id = $project->id;
             //$secret_id = Crypt::encrypt($auto_id);
             $request->session()->flash('alert-success', 'Project has been updated successfully');
             $step = $step + 1;
             Session::put('editfstep', $step);
             Session::put('editfs_id', $auto_id);
             return \Redirect::to('/project/projectedit');
         } else {
             Session::put('editfstep', $step);
             $request->session()->flash('alert-warning', 'Error on project creation ! ');
             return redirect()->back()->withInput();
         }
     } else {
         $project_id = $secret_key;
         if ($step == 1) {
             $project = Project::find($project_id);
             $project->fill($request->except('_token'));
             $project->slug = Str::slug($request->input('name'));
             if ($request->hasFile('file_attachment')) {
                 $response = Event::fire(new FileAttachment($request, ['input_file_tag' => 'file_attachment', 'width' => $this->width, 'height' => $this->height, 'mHeight' => $this->mHeight, 'mWidth' => $this->mWidth]));
                 if (count($response) > 0) {
                     $project->file_attachment = $response[0];
                 }
             }
             if ($project->save()) {
                 $request->session()->flash('alert-success', 'Project has been updated successfully');
                 $step = $step + 1;
                 Session::put('editfstep', $step);
                 return \Redirect::to('/project/projectedit');
             }
         }
         if ($step == 2) {
             $projectData = array();
             $projectData['details_description'] = $request->get('details_description');
             $projectData['address'] = $request->get('address');
             $projectData['address_alternate'] = $request->get('address_alternate');
             $projectData['city'] = $request->get('city');
             $projectData['state'] = $request->get('state');
             $projectData['country_id'] = $request->get('country_id');
             $projectData['feed_url'] = $request->get('feed_url');
             $projectData['pincode'] = $request->get('pincode');
             $projectData['external_video_url'] = $request->get('external_video_url');
             //$projectData['media_file_attachment'] = $request->get('media_file_attachment');
             $projectData['media_file_short_note'] = $request->get('media_file_short_note');
             if ($request->hasFile('media_file_attachment')) {
                 $response = Event::fire(new FileAttachment($request, ['input_file_tag' => 'media_file_attachment', 'width' => $this->width, 'height' => $this->height, 'mHeight' => $this->mHeight, 'mWidth' => $this->mWidth]));
                 if (count($response) > 0) {
                     $projectData['media_file_attachment'] = $response[0];
                 }
             }
             if (Project::where('id', $project_id)->update($projectData)) {
                 $request->session()->flash('alert-success', 'Project has been updated successfully');
                 $step = $step + 1;
                 Session::put('editfstep', $step);
                 return \Redirect::to('/project/projectedit');
             } else {
                 Session::put('editfstep', $step);
                 $request->session()->flash('alert-warning', 'Error on project creation ! ');
                 return redirect()->back()->withInput();
             }
         }
         if ($step == 3) {
             $projectData = array();
             //dd( $request->all());
             $reward_row_count = $request->get('reward_row_count');
             $past_row_count = $request->get('past_row_count');
             $pledge_amount = $request->get('pledge_amount');
             $short_note = $request->get('short_note');
             $user_limit = $request->get('user_limit');
             $delevery_year = $request->get('delevery_year');
             $delevery_month = $request->get('delevery_month');
             $shipping_details = $request->get('shipping_details');
             $present_id = $request->get('editid');
             $file = $request->file('file_attachment');
             $startcounter = $past_row_count + 1;
             $endcounter = $reward_row_count - 1;
             if (count($pledge_amount) > 0) {
                 $rewardsData = array();
                 for ($k = 0; $k <= $past_row_count; $k++) {
                     /* $reward = new Reward(); */
                     $rewaedid = $present_id[$k];
                     $reward = Reward::find($rewaedid);
                     if (Reward::find($rewaedid)) {
                         if ($file[$k] != '') {
                             $imageName = uniqid('project-reward-', true) . '.' . $file[$k]->getClientOriginalExtension();
                             $realPath = base_path() . '/public/images/file-attached-to-project/';
                             $resizePath = base_path() . '/public/images/file-attached-to-project/resize/' . $imageName;
                             $openMakePath = $realPath . $imageName;
                             $file[$k]->move($realPath, $imageName);
                             Image::make($openMakePath)->resize(1400, 623)->save($resizePath);
                             $reward->reword_image = $imageName;
                         }
                         $reward->pledge_amount = $pledge_amount[$k];
                         $reward->short_note = $short_note[$k];
                         $reward->user_limit = $user_limit[$k];
                         $reward->delevery_year = $delevery_year[$k];
                         $reward->delevery_month = $delevery_month[$k];
                         $reward->shipping_details = $shipping_details[$k];
                         $reward->P_ID = $project_id;
                         $reward->active = 1;
                         $reward->save();
                     }
                 }
                 for ($m = $startcounter; $m <= $endcounter; $m++) {
                     $addreward = new Reward();
                     if ($file[$k] != '') {
                         $imageName = uniqid('project-reward-', true) . '.' . $file[$k]->getClientOriginalExtension();
                         $realPath = base_path() . '/public/images/file-attached-to-project/';
                         $resizePath = base_path() . '/public/images/file-attached-to-project/resize/' . $imageName;
                         $openMakePath = $realPath . $imageName;
                         $file[$k]->move($realPath, $imageName);
                         Image::make($openMakePath)->resize(1400, 623)->save($resizePath);
                         $addreward->reword_image = $imageName;
                     }
                     $addreward->pledge_amount = $pledge_amount[$m];
                     $addreward->short_note = $short_note[$m];
                     $addreward->user_limit = $user_limit[$m];
                     $addreward->delevery_year = $delevery_year[$m];
                     $addreward->delevery_month = $delevery_month[$m];
                     $addreward->shipping_details = $shipping_details[$m];
                     $addreward->P_ID = $project_id;
                     $addreward->active = 1;
                     $addreward->save();
                 }
                 $step = $step + 2;
                 Session::put('editfstep', $step);
                 return \Redirect::to('/project/projectedit');
             }
         }
     }
 }