/**
  * Display a listing of the resource.
  *
  * @return Res2ponse
  */
 public function index()
 {
     $s = Setting::first();
     $word = WordCard::find($s->word_id);
     $settings = array('answer_time' => $s->answer_time, 'daily_bonus' => $s->daily_bonus, 'general_cost' => $s->general_cost, 'top_bonus' => $s->top_bonus, 'word_cost' => $s->word_cost, 'life_cost' => $s->life_cost, 'words_for_the_next_bonus' => $s->words_for_the_next_bonus, 'word' => array('id' => $s->word_id, 'word' => $word->word, 'answer' => $word->answer, 'category_id' => $word->category_id), 'quiz' => ['url' => $s->quiz, 'added_on' => $s->added_on]);
     return $this->respond($settings);
 }
Exemplo n.º 2
0
 public function fire()
 {
     $pushWords = new Collection();
     $dayWord = WordCard::find(Setting::first()->word_id);
     $pushWords->push(['word_id' => $dayWord->id, 'category_id' => $dayWord->category_id]);
     Category::all()->each(function ($category) use($pushWords) {
         $this->info("looking at category {$category->id}");
         $word = $this->getSentWord($category);
         if ($word) {
             $pushWords->push(['word_id' => $word->id, 'category_id' => $category->id]);
         } else {
             $this->error('Empty category');
         }
     });
     $this->check();
     $this->pushWords2($pushWords);
 }
Exemplo n.º 3
0
 public function pushWord($word)
 {
     $word = WordCard::find($word['word_id']);
     DB::table('users')->where('word_id', 0)->update(['word_id' => Setting::first()->word_id]);
     User::where('device', '<>', '')->groupBy('device')->chunk(200, function ($users) use($word) {
         $devices = PushNotification::DeviceCollection($users->map(function ($user) {
             $this->line($user->device);
             return PushNotification::Device($user->device, ['badge' => 1]);
         })->toArray());
         //            foreach ($users as $user) {
         //                $rawdevices[] = PushNotification::Device($user->device, ['badge' => 1]);
         //            }
         //            $devices = PushNotification::DeviceCollection($rawdevices);
         $this->line('Sending chunk of 200...');
         try {
             PushNotification::app('IOS')->to($devices)->send($word->word . " - новое слово для изучения", ["custom" => ["cdata" => [["word_id" => $word->id, "cat_id" => $word->category_id]], "type" => 0]]);
         } catch (Exception $e) {
             $this->error($e);
         }
     });
     $this->info('Dayword ' . $word->word . '(' . $word->id . ') category ' . $word->category_id . ' pushed.');
 }
 /**
  * Remove the specified resource from storage.
  *
  * @param  int  $id
  * @return Response
  */
 public function destroy($id)
 {
     $wordCard = WordCard::find($id);
     $category = Category::find($wordCard->category_id);
     if ($wordCard->delete()) {
         $category->update_amount();
         $category->save();
         return $this->respondNoContent();
     }
     return $this->respondServerError();
 }