示例#1
0
 /**
  * Store a newly created resource in storage.
  *
  * @param  \Illuminate\Http\Request  $request
  * @return \Illuminate\Http\Response
  */
 public function store(Requests\CreatePointRequest $request, $id)
 {
     $input = Request::all();
     $point = new Point();
     $point->member_id = $id;
     $point->event_id = $input['event_id'];
     $point->point = $input['point'];
     $point->save();
     $member = Member::find($id);
     $member->update(['total_points' => $point->point + $member->total_points]);
     return redirect()->action('MembersController@show', $id);
 }
 public function store(Request $request)
 {
     $point = new Point();
     $point->user_id = 0;
     // TODO: replace with actual user id
     $point->stat = $request->input('stat');
     $point->source = $request->input('source');
     $point->source_url = $request->input('source_url');
     $point->valid_until = $request->input('valid_until');
     $point->weight = 0;
     $point->save();
 }
 public function add()
 {
     $activeTab = Input::get('task_type_id') ? Input::get('task_type_id') : '1';
     $task_types = TaskType::all();
     $saleTypes = SaleType::all();
     $user = Auth::user();
     $point = intval(Input::get('point'));
     $task = Task::findOrFail(Input::get('task_id'));
     $pointAudit = new PointAudit();
     $pointAudit->point = $point * $task->value;
     $pointAudit->user_id = $user->id;
     $pointAudit->company_id = $user->company_id;
     $pointAudit->date = new \DateTime();
     $pointAudit->task_id = $task->id;
     $pointAudit->save();
     $pointID = $user->id . date("mdY");
     $pointEntity = Point::find($pointID);
     if ($pointEntity != null) {
         $pointEntity->points = $pointEntity->points + $point * $task->value;
         $pointEntity->update();
     } else {
         $pointEntity = new Point();
         $pointEntity->id = $pointID;
         $pointEntity->month = date("m");
         $pointEntity->year = date("Y");
         $pointEntity->user_id = $user->id;
         $pointEntity->company_id = $user->company_id;
         $pointEntity->points = $point * $task->value;
         $pointEntity->save();
     }
     $message = 'You have ' . ($pointAudit->point > 0 ? 'added' : 'adjusted') . ' <strong> ' . intval($point) . ' points</strong> to <strong>' . $task->name . '</strong>.';
     $today_total = $this->getTodaysStats();
     $today_target = 140;
     $isErr = false;
     return view('myStat.add', compact('user', 'today_total', 'task_types', 'tasks', 'activeTab', 'isErr', 'message', 'today_target', 'saleTypes'));
 }
 /**
  * Store a newly created resource in storage.
  *
  * @NOTE That Tags should be a comma seperated list of tag_id's.
  *
  * @param Request $request
  *
  * @return Response
  */
 public function store(Request $request)
 {
     try {
         $validator = \Validator::make($request->all(), ['name' => 'required|min:3', 'description' => 'required|min:3', 'latitude' => 'required|min:3', 'longitude' => 'required|min:3', 'tags' => 'required', 'country' => 'required', 'files' => 'required']);
         if ($validator->fails()) {
             return $this->respondWithError($validator->errors());
         }
         $point = new Point();
         $point->name = $request->get('name');
         $point->description = $request->get('description');
         $point->longitude = $request->get('longitude');
         $point->latitude = $request->get('latitude');
         $point->country = $request->get('country');
         $point->created_by = Auth::user()->id;
         $point->updated_by = Auth::user()->id;
         if (!$point->save()) {
             return $this->respondWithError();
         }
         /* @param tags !NOTE! Tags should be a comma seperated list of tag id's */
         $tags = explode(',', $request->get('tags'));
         foreach ($tags as $t) {
             $tag = new PointTag();
             $tag->point_id = $point->id;
             $tag->created_by = Auth::user()->id;
             $tag->tags_id = $t;
             if (!$tag->save()) {
                 return $this->respondWithError('Could not add tag (' . $t . ')');
             }
         }
         $this->addFiles($request->get('files'));
         return Fractal::item($point, new PointTransformer())->responseJson(200);
     } catch (Exception $e) {
         return $this->respondInternalError();
     }
 }