Exemplo n.º 1
0
 /**
  * Add word
  *
  * @param  Request  $request
  * @return Response
  */
 public function add(Request $request)
 {
     $this->validate($request, ['room_id' => 'required', 'english' => 'required', 'spanish' => 'required', 'vietnamese' => 'required']);
     $word = new Word();
     $word->room_id = $request->room_id;
     $word->english = $request->english;
     $word->spanish = $request->spanish;
     $word->vietnamese = $request->vietnamese;
     $word->save();
     return redirect('/home');
 }
 /**
  * Generating array structure for game
  * @return $words[]
  */
 public function getRandom25Words()
 {
     $words = Word::orderBy(DB::raw('RAND()'))->limit(25);
     $words->increment('used');
     $words = $words->get(['word'])->toArray();
     $ids = $this->uniqueRandomIds(0, 24, 16);
     $deathId = $this->uniqueRandomIds(0, 15, 1)[0];
     $deathNumber = $ids[$deathId];
     array_splice($ids, $deathId, 1);
     sort($ids);
     $team = $this->uniqueRandomIds(0, 1, 1)[0];
     for ($i = 0; $i < count($words); $i++) {
         $words[$i]['team'] = 2;
         $words[$i]['discovered'] = False;
         if (!empty($ids) && $i == $ids[0]) {
             $words[$i]['team'] = $team;
             $team = $team == 1 ? 0 : 1;
             array_splice($ids, 0, 1);
         } else {
             if ($i == $deathNumber) {
                 $words[$i]['team'] = 3;
             }
         }
     }
     return $words;
 }
 public function run()
 {
     $fake = Faker::create();
     foreach (range(1, 30) as $index) {
         Word::create(['lexical_form' => $fake->word, 'definition' => $fake->paragraph(4), 'part_of_speech' => $fake->word, 'mounce_chapter' => $fake->numberBetween(1, 300), 'nt_word_count' => $fake->numberBetween(1, 50000)]);
     }
 }
 /**
  * Store a newly created resource in storage.
  *
  * @param  \Illuminate\Http\Request  $request
  *
  * @return \Illuminate\Http\Response
  */
 public function store(Request $request)
 {
     $validator = \Validator::make($request->all(), ['word_id' => 'required|exists:words,id', 'translation_id' => 'required|exists:translations,id']);
     if ($validator->passes()) {
         $user = \Auth::user();
         $word = Word::find($request->input('word_id'));
         if (!$user->exercises()->where('word_id', $word->id)->first()) {
             if ($translation = $word->translations()->find($request->input('translation_id'))) {
                 $exercise = new Exercise();
                 $exercise->setNewStatus($user);
                 $exercise->user()->associate($user);
                 $exercise->word()->associate($word);
                 $exercise->save();
                 $exercise->translations()->attach($translation);
                 $response = response()->json(['id' => $exercise->getId()], 201);
             } else {
                 $response = response()->json(['errors' => ['This translation hasn\'t found in the exercise word.']], 404);
             }
         } else {
             $response = response()->json(['errors' => ['You already have this word in your exercises.']], 400);
         }
     } else {
         $response = response()->json(['errors' => $validator->messages()->all()], 400);
     }
     return $response;
 }
 /**
  * Display the specified word.
  *
  * @param int $id
  * @return Response
  */
 public function show($id)
 {
     $word = Word::find($id);
     if (!$word) {
         return $this->respondNotFound('Word does not exist.');
     }
     return $this->respond(['data' => $this->wordTransformer->transform($word)]);
 }
Exemplo n.º 6
0
 private function getRandomWord()
 {
     if (self::USE_DATABASE == 0) {
         $request = Requests::get('http://randomword.setgetgo.com/get.php');
         return strtolower($request->body);
     }
     return \App\Word::orderBy(\DB::raw('RAND()'))->first()->word;
 }
Exemplo n.º 7
0
 /**
  * Store a newly created resource in storage.
  *
  * @param  Request  $request
  * @return Response
  */
 public function store(Request $request)
 {
     $word = Word::where('name', $request->name)->first();
     $book = new Book(['title' => $request->title, 'text' => $request->text]);
     if ($word) {
         $book = $word->books()->save($book);
     }
 }
 public function run()
 {
     $faker = Faker::create();
     $wordIds = Word::lists('id');
     $tagIds = Tag::lists('id');
     foreach (range(1, 30) as $index) {
         DB::table('tag_word')->insert(['word_id' => $faker->randomElement($wordIds->all()), 'tag_id' => $faker->randomElement($tagIds->all())]);
     }
 }
 /**
  * Store a newly created resource in storage.
  *
  * @param \Illuminate\Http\Request  $request
  * @param \App\Word $word
  *
  * @return \Illuminate\Http\Response
  */
 public function store(Request $request, Word $word)
 {
     $validator = \Validator::make($request->all(), ['translation_id' => 'required|exists:translations,id']);
     if ($validator->passes()) {
         if (is_null($word->position)) {
             $translationId = $request->input('translation_id');
             if (!$word->translations()->find($translationId)) {
                 $word->translations()->attach($translationId);
                 $response = response('This translation has added to the word.', 201);
             } else {
                 $response = response()->json(['errors' => ['This translation already belongs the word.']], 400);
             }
         } else {
             $response = response()->json(['errors' => ['You have attempted to bind a translation with a non-custom word']], 400);
         }
     } else {
         $response = response()->json(['errors' => $validator->messages()->all()], 400);
     }
     return $response;
 }
Exemplo n.º 10
0
 public function index(Request $request)
 {
     $validator = Validator::make($request->all(), ['word' => 'required', 'source_language' => 'required', 'target_language' => 'required']);
     if ($validator->fails()) {
         $errors = $validator->errors();
     } elseif ($data = Word::translate($request->all())) {
         $status = 200;
     } else {
         $errors = 'Not found';
     }
     return response(['data' => isset($data) ? $data : '', 'error' => isset($errors) ? $errors : ''], isset($status) ? $status : 404);
 }
 public function createExercise()
 {
     $users = User::all();
     $words = Word::all();
     foreach (range(1, 5) as $i) {
         $user = $users->random();
         $word = $words->random();
         $translation = $word->translations->random();
         $exercise = new Exercise();
         $exercise->status = 'new';
         $exercise->reading = 10;
         $exercise->memory = 10;
         $exercise->user()->associate($user);
         $exercise->word()->associate($word);
         $exercise->translation()->associate($translation);
         $exercise->save();
         echo 'Exercise id: ' . $exercise->id . '<br>';
     }
 }
Exemplo n.º 12
0
 /**
  * Display a single tag.
  *
  * @param $wordId
  * @return \Illuminate\Database\Eloquent\Collection|static[]
  */
 private function getTags($wordId)
 {
     //TODO: add exception handling for 'modelnotfound' exception
     return $wordId ? Word::findOrFail($wordId)->tags : Tag::all();
 }
Exemplo n.º 13
0
 /**
  * Show the logged in dashboard, if authenticated
  *
  * @return Response
  */
 public function index(Request $request)
 {
     $words = Word::processableWords($request->input('offset'));
     return view('dashboard.index', ['words' => $words]);
 }
Exemplo n.º 14
0
 public function time(Request $request)
 {
     $starttime = Carbon::createFromTimestamp(intval($request->starttime / 1000));
     $endtime = Carbon::createFromTimestamp(intval($request->endtime / 1000));
     if ($endtime == $starttime) {
         $starttime = $starttime->subDays(1);
     }
     $words = Word::whereBetween('created_at', [$starttime->toDateTimeString(), $endtime->toDateTimeString()])->lists('name', 'info');
     $respon = [];
     foreach ($words as $info => $name) {
         $respon[] = array('name' => $name, 'info' => $info);
     }
     if ($respon) {
         return Response::json($respon, 200, []);
     }
     return Response::json([], 404, []);
 }
 /**
  * Store a newly created resource in storage.
  *
  * @param  \Illuminate\Http\Request  $request
  *
  * @return \Illuminate\Http\Response
  */
 public function store(Request $request)
 {
     $validator = \Validator::make($request->all(), ['body' => 'required', 'translation_id' => 'sometimes|exists:translations,id', 'via_dictionary' => 'sometimes|boolean']);
     if ($validator->passes()) {
         if ($request->input('via_dictionary')) {
             $definitions = \YaDictionary::lookup($request->input('body'));
             if ($definitions) {
                 foreach ($definitions as $definition) {
                     $partOfSpeech = $definition->getPartOfSpeech();
                     if (!($position = Position::where('body', $partOfSpeech)->first())) {
                         $position = Position::create(['body' => $partOfSpeech]);
                     }
                     if (!Word::where('body', $definition->getText())->where('position_id', $position->id)->first()) {
                         $word = new Word();
                         $word->body = $definition->getText();
                         $word->ts = $definition->getTranscription();
                         $word->position()->associate($position);
                         $word->save();
                         $translationIds = [];
                         foreach ($definition->getTranslations() as $yaTranslation) {
                             if (!($translation = Translation::where('body', $yaTranslation->getText())->first())) {
                                 $translation = Translation::create(['body' => $yaTranslation->getText()]);
                             }
                             $translationIds[] = $translation->id;
                         }
                         $word->translations()->attach($translationIds);
                     }
                 }
                 $response = response('This word has created from the dictionary', 201);
             } else {
                 $response = response()->json(['errors' => ['This word has not found in the dictionary.']], 404);
             }
         } else {
             if ($translationId = $request->input('translation_id')) {
                 $word = Word::create(['body' => $request->input('body')]);
                 $word->translations()->attach($translationId);
                 $response = response()->json(['id' => $word->getId()], 201);
             } else {
                 $response = response()->json(['errors' => ['It needs a translation.']], 400);
             }
         }
     } else {
         $response = response()->json(['errors' => $validator->messages()->all()], 400);
     }
     return $response;
 }
Exemplo n.º 16
0
 /**
  * Get all of the words for a given user.
  *
  * @param  User  $user
  * @return Collection
  */
 public function forUser(User $user)
 {
     return Word::where('user_id', $user->id)->orderBy('created_at', 'asc')->get();
 }
Exemplo n.º 17
0
 /**
  * Get words for room.
  *
  * @param id Room id
  * @return Collection
  */
 public function getWordsForRoom($room_id)
 {
     return Word::where('room_id', $room_id)->orderBy('english', 'asc')->get();
 }
Exemplo n.º 18
0
 public static function getWordList($end)
 {
     $word = Word::all()->where('word', 'like', '%' . $end);
     return $word;
 }
Exemplo n.º 19
0
 private function selectRandomWord()
 {
     $word = Word::orderByRaw("RAND()")->first();
     return $word->word;
 }