/** * Determine if user can edit the questionaire. * * @return bool */ public function QuestionaireEdit(User $user, Questionaire $questionaire) { // if own questionaire if ($questionaire->owner_id === $user->id) { return true; } if ($this->isGroupAdmin($user, $questionaire->owner()->get()->first())) { return true; } return false; }
/** * save the create form from a video * * @return Redirect */ protected function postCreateVideo(Request $request, $questionaire_id, $type) { $questionaire = Questionaire::where('id', $questionaire_id)->firstOrFail(); $this->authorize('video-create', $questionaire); if (!array_key_exists($type, $this->getVideoTypes())) { abort(403, 'Video type not defined'); } // @TODO : don't create new video for every step. Works for now with Mediamosa $video = new Video(); $video->type = $type; $video->questionaire_id = $questionaire_id; $video->creator_id = Auth::user()->id; $video->analysis = "no"; $videoTypes = $this->getVideoTypes(); $class = $videoTypes[$type]; $validator = $class::validatorCreateForm($request); if ($validator->fails()) { return Redirect::action('Observation\\VideoController@getCreateVideo', array($questionaire->id, $type))->withInput()->withErrors($validator); } $video->name = $request->name; $class::processCreateForm($request, $video); $video->save(); return Redirect::action('Observation\\VideoController@getVideo', $video->id); }
/** * save the create form from a block * * @return Redirect */ protected function postCreateBlock(Request $request, $questionaire_id, $type, $parent_id = NULL) { $questionaire = Questionaire::where('id', $questionaire_id)->firstOrFail(); $this->authorize('questionaire-block-edit', $questionaire); if (!array_key_exists($type, $this->getBlockTypes())) { abort(403, 'Block type not defined'); } $block = new Block(); $block->questionaire_id = $questionaire_id; $block->type = $type; $block->parent_id = $parent_id; $blockTypes = $this->getBlockTypes(); $class = $blockTypes[$type]; $validator = $class::validatorCreateForm($request); if ($validator->fails()) { return Redirect::action('Observation\\QuestionaireController@getCreateBlock', array($questionaire->id, $type, $parent_id))->withInput()->withErrors($validator); } $class::processCreateForm($request, $block); $block->save(); return Redirect::action('Observation\\QuestionaireController@getBlocks', $questionaire->id)->with('status', 'Block saved'); }