public function createEdit()
 {
     $quizId = Input::get('quizId', null);
     $quizData = Input::get('quiz', array());
     try {
         if ($quizId || !empty($quizData['id'])) {
             //die(var_dump($quizId));
             $quiz = Quiz::findOrFail($quizId ? $quizId : $quizData['id']);
         } else {
             $quiz = new Quiz();
         }
     } catch (ModelNotFoundException $e) {
         return Response::json(array('error' => 1, 'message' => $e->getMessage()));
     }
     if (Request::ajax() && Request::isMethod('post')) {
         //Form submitted- Create the quiz
         //$keys = ['topic', 'description', 'pageContent', 'image', 'questions', 'results', 'ogImages'];
         foreach ($quizData as $key => $val) {
             $quiz->{$key} = is_array($quizData[$key]) ? json_encode($quizData[$key]) : $quizData[$key];
         }
         $quiz->active = !empty($quizData['active']) && ($quizData['active'] === "true" || $quizData['active'] === true) ? true : false;
         try {
             self::saveThumbnails($quiz);
         } catch (InvalidArgumentException $e) {
             return Response::error("Error! Quiz not saved! " . $e->getMessage());
         }
         $quiz->save();
         return Response::json(array('success' => 1, 'quiz' => $quiz));
     } else {
         //Form submitted- Create the quiz or parse and show forms if basic quizData is passed
         $populateQuizData = Input::get('quizData', '{}');
         $populateQuizData = json_decode($populateQuizData);
         $quizSchema = new \Schemas\QuizSchema();
         $questionSchema = new \Schemas\QuestionSchema();
         $choiceSchema = new \Schemas\ChoiceSchema();
         $resultSchema = new \Schemas\ResultSchema();
         /*if(!empty(Input::get('test')))
         		die(var_dump($quiz));*/
         return View::make('admin/quizes/create')->with(array('quizSchema' => $quizSchema->getSchema(), 'questionSchema' => $questionSchema->getSchema(), 'choiceSchema' => $choiceSchema->getSchema(), 'resultSchema' => $resultSchema->getSchema(), 'quizData' => $quiz->id ? json_encode($quiz) : json_encode($populateQuizData), 'quiz' => $quiz, 'editingMode' => $quizId ? true : false, 'creationMode' => $quizId ? false : true));
     }
 }
 public function createEdit()
 {
     $listId = Input::get('listId', null);
     $listData = json_decode(Input::get('list', '{}'), true);
     $duplicateList = Input::get('duplicate-list', array());
     $duplicateListData = null;
     try {
         if ($duplicateList) {
             $duplicateListObject = ViralList::findOrFail($duplicateList);
             $duplicateListData = $duplicateListObject->toArray();
             unset($duplicateListData['id']);
             View::share(array('duplicateList' => $duplicateListObject));
         }
         if ($listId || !empty($listData['id'])) {
             //die(var_dump($listId));
             $list = ViralList::findOrFail($listId ? $listId : $listData['id']);
         } else {
             $list = new ViralList();
         }
     } catch (ModelNotFoundException $e) {
         return Response::json(array('error' => 1, 'message' => $e->getMessage()));
     }
     if (Request::ajax() && Request::isMethod('post')) {
         //Form submitted- Create the list
         //$keys = ['topic', 'description', 'pageContent', 'image', 'questions', 'results', 'ogImages'];
         foreach ($listData as $key => $val) {
             $list->{$key} = is_array($listData[$key]) ? json_encode($listData[$key]) : $listData[$key];
         }
         $list->active = !empty($listData['active']) && ($listData['active'] === "true" || $listData['active'] === true) ? true : false;
         try {
             self::saveThumbnails($list);
         } catch (InvalidArgumentException $e) {
             return Response::error("Error! List not saved! " . $e->getMessage());
         }
         $list->save();
         return Response::json(array('success' => 1, 'list' => $list));
     } else {
         //Form submitted- Create the list or parse and show forms if basic listData is passed
         $populateListData = Input::get('listData', '{}');
         $populateListData = json_decode($populateListData);
         if (!empty($duplicateListData)) {
             $populateListData = $duplicateListData;
         }
         $listSchema = new \Schemas\ListSchema();
         $questionSchema = new \Schemas\QuestionSchema();
         $choiceSchema = new \Schemas\ChoiceSchema();
         $resultSchema = new \Schemas\ResultSchema();
         /*if(!empty(Input::get('test')))
           die(var_dump($list));*/
         return View::make('admin/lists/create')->with(array('listSchema' => $listSchema->getSchema(), 'questionSchema' => $questionSchema->getSchema(), 'choiceSchema' => $choiceSchema->getSchema(), 'resultSchema' => $resultSchema->getSchema(), 'listData' => $list->id ? json_encode($list) : json_encode($populateListData), 'list' => $list, 'editingMode' => $listId ? true : false, 'creationMode' => $listId ? false : true));
     }
 }