/**
  * Run the database seeds.
  *
  * @return void
  */
 public function run()
 {
     // Increase memory for this bit
     ini_set('memory_limit', '256M');
     // Set input file
     $input = storage_path('seeds/content_dump.json');
     // Retrieve the raw response from JSON file
     $raw = file_get_contents($input);
     // Encode the JSON response into a PHP object
     $entries = json_decode($raw);
     foreach ($entries as $entry) {
         // Get the right letter object for relationship
         $letter = Letter::get()->where('letter', $entry->header->letter)->first();
         // Array to hold new App\Definitnion for saveMany
         $new_definitions = [];
         // Build the Lemma object, save as $lemma
         print_r("- LEMMA -\n- ");
         $lemma = $this->makeLemma($entry, $letter);
         // Build the Definition objects
         foreach ($entry->definitions as $definition) {
             // Make the new App\Definition; Returns new App\Definitnion
             print_r(">");
             $def = $this->makeDefinition($definition, $lemma);
             // Add new $def to the $new_definitions Array
             $new_definitions[] = $def;
         }
         // Save the new App\Lemma to the associated App\Letter
         $letter->lemmas()->save($lemma);
         print_r("\n- LEMMA SAVED -\n");
         // Bulk-assign the App\Definition Array to the associated App\Lemma
         print_r("- BATCH SAVING DEFINITIONS ... ");
         $lemma->definitions()->saveMany($new_definitions);
         print_r("DONE\n");
     }
 }
 /**
  * Run the database seeds.
  *
  * @return void
  */
 public function run()
 {
     $input = storage_path('seeds/roots.json');
     $raw = file_get_contents($input);
     $roots = json_decode($raw);
     foreach ($roots->roots as $letter_key => $root_array) {
         // Get the proper App\Letter for this relationship
         $letter = Letter::get()->where("name", $letter_key)->first();
         // Create a new array to store newly created roots
         $new_roots = [];
         // Create a new App\Root for each object in the Array
         foreach ($root_array as $root) {
             // Instantiate a new Root
             $new = new Root();
             // Assign properties
             $new->display = $root;
             // Add the new App\Root to the $new_root Array
             $new_roots[] = $new;
         }
         // Save the new roots to the App\Letter
         print_r("Batch Saving {$letter->name} ... ");
         $letter->roots()->saveMany($new_roots);
         print_r("completed\n");
     }
 }
 public function mail(Request $request, $folder = 'inbox')
 {
     $letterId = $request->input('letter');
     if (isset($letterId)) {
         $letter = \App\Letter::find($letterId);
         if ($letter) {
             if ($letter->reciever == 1) {
                 $letter->status = 'read';
                 $letter->save();
                 return view($this->localeDir . 'administration.singleLetter', compact('letter'));
             } elseif ($letter->sender == 1) {
                 return view($this->localeDir . 'administration.singleLetter', compact('letter'));
             }
             return redirect('/administration/mail');
         } else {
             return redirect('/administration/mail');
         }
     } else {
         $navigation = \App\Myclasses\Arrays::mailNav($folder);
         switch ($folder) {
             case 'inbox':
                 $letters = \App\User::find(1)->hasInbox()->where('show_reciever', 'true')->orderBy('id', 'desc')->get();
                 return view($this->localeDir . 'administration.inbox', compact('letters', 'navigation'));
             case 'sent':
                 $letters = \App\User::find(1)->hasSent()->where('show_sender', 'true')->orderBy('id', 'desc')->get();
                 return view($this->localeDir . 'administration.sent', compact('letters', 'navigation'));
             case 'new':
                 $users = \App\User::all();
                 return view($this->localeDir . 'administration.newmail', compact('users', 'navigation'));
         }
         return view($this->localeDir . 'administration.adminmail');
     }
 }
Exemplo n.º 4
0
 public function mail(Request $request, $folder = 'inbox')
 {
     $letterId = $request->input('letter');
     if (isset($letterId)) {
         $letter = \App\Letter::find($letterId);
         if ($letter) {
             $id = Auth::user()->id;
             if ($letter->reciever == $id) {
                 $letter->status = 'read';
                 $letter->save();
                 return view($this->localeDir . 'cabinet.singleLetter', compact('letter'));
             } elseif ($letter->sender == $id) {
                 return view($this->localeDir . 'cabinet.singleLetter', compact('letter'));
             }
             return redirect('/cabinet/mail');
             //the letter does not belong to user
         } else {
             return redirect('/cabinet/mail');
         }
         //the letter does not exist
     } else {
         $navigation = Arrays::mailNav($folder);
         switch ($folder) {
             case 'inbox':
                 $letters = Auth::user()->hasInbox()->where('show_reciever', 'true')->orderBy('id', 'desc')->get();
                 return view($this->localeDir . 'cabinet.inbox', compact('letters', 'navigation'));
             case 'sent':
                 $letters = Auth::user()->hasSent()->where('show_sender', 'true')->orderBy('id', 'desc')->get();
                 return view($this->localeDir . 'cabinet.sent', compact('letters', 'navigation'));
             case 'new':
                 $users = \App\User::all();
                 return view($this->localeDir . 'cabinet.newmail', compact('users', 'navigation'));
         }
     }
 }
Exemplo n.º 5
0
 public function __construct($id, $user = null)
 {
     $this->letter = \App\Letter::find($id);
     if (isset($user)) {
         $this->userId = $user;
     } else {
         $this->userId = \Auth::user()->id;
     }
     $this->markDelete();
     $this->checkMarks();
 }
Exemplo n.º 6
0
 /**
  * Update the specified resource in storage.
  *
  * @param  Request  $request
  * @param  int  $id
  * @return Response
  */
 public function update(Request $request, $id)
 {
     // Setup
     $attrs = Input::get('data.attributes');
     // UPDATE
     if (is_numeric($id)) {
         $letter = Letter::findOrFail($id);
     } else {
         $letter = Letter::where('transliteration', $id)->firstOrFail();
     }
     $letter->fill($attrs);
     $letter->save();
     return $this->res->item($letter)->send();
 }
 /**
  * Seeds the 'Letters' table with the current API data from Heroku
  *
  * @return void
  */
 public function run()
 {
     // Sets input file
     $input = storage_path('seeds/letters.json');
     // Retrieves the raw response from JSON file
     $raw = file_get_contents($input);
     // encodes the JSON response into a PHP object
     $letters = json_decode($raw);
     // Creates a record in teh Letters table for each
     // letter retrieved; typecast as an array for Eloquent
     print_r("Writing ");
     foreach ($letters->letters as $letter) {
         print_r(" . ");
         Letter::create((array) $letter);
     }
     print_r("done\n");
 }