Ejemplo n.º 1
0
 function createAuthor($fio, $link)
 {
     $author = new Author();
     $author->fio = $fio;
     $author->link = $link;
     $author->save();
     return $author;
 }
Ejemplo n.º 2
0
 public function run()
 {
     $authors = Author::all();
     $this->iterate(self::GROUPS_TO_SEED / 2, self::GROUPS_TO_SEED, function ($i) use($authors) {
         $this->createGroup($authors->random(1));
     });
 }
Ejemplo n.º 3
0
 public function input($key = NULL, $default = NULL)
 {
     $input = parent::input();
     if ($link = Author::matchLink($input['link'])) {
         $input['link'] = $link;
     }
     if (!@$input['fio']) {
         $input['fio'] = $input['link'];
     }
     return $input;
 }
Ejemplo n.º 4
0
 public function checkAuthor(Author $author, array $data)
 {
     $stats = null;
     $author->fio = array_pull($data, 'fio');
     $author->title = array_pull($data, 'title');
     $author->rating = array_pull($data, 'rating');
     $author->visitors = array_pull($data, 'visitors');
     $groups = array_pull($data, 'groups');
     $authorData = $author->diffAttributes();
     $authorData = $author->filterImportantUpdatedAttributes($authorData);
     $groups = $this->synkGroups($author, $groups);
     if ($groups) {
         $authorData['groups'] = $groups;
         $authorData['id'] = $author->id;
     }
     if ($authorData) {
         $author->touch();
     }
     $author->save();
     if ($authorData) {
         $stats['author'] = $authorData;
     }
     return $stats;
 }
Ejemplo n.º 5
0
 /**
  * Run the database seeds.
  *
  * @return void
  */
 public function run()
 {
     $authors = Author::all();
     $this->iterate(self::PAGES_TO_SEED / 2, self::PAGES_TO_SEED, function ($i) use($authors) {
         $author = $authors->random();
         do {
             $author = $authors->random();
         } while ($author->groups->isEmpty());
         $faker = $this->faker();
         $page = new Page();
         $page->title = $faker->sentence(5);
         $page->annotation = Str::limit(join(' ', $faker->sentences(5)), 250);
         $page->link = $faker->slug(3);
         $page->size = $faker->numberBetween(0, 9999);
         $page->author()->associate($author);
         $page->group()->associate($author->groups->random());
         $page->save();
     });
 }
Ejemplo n.º 6
0
 public function getCheck(Request $request)
 {
     $selected = 0;
     foreach ($request->query() as $key => $value) {
         if ($value == '' && (string) intval($key) == "{$key}") {
             $selected = intval($key);
             break;
         }
     }
     $id = $selected;
     if (!$id) {
         $queue = $this->pickAuthor();
         $id = intval(array_shift($queue));
     }
     $stats = [];
     if (!$selected) {
         $stats['pending'] = $queue;
     }
     if ($id) {
         $author = Author::find($id);
         if ($author) {
             $stats = array_merge_recursive($stats, $this->checkAuthor($author));
         } else {
             throw new \Exception("Author with ID {$id} not found");
         }
     }
     if ($id && !$selected) {
         header("Refresh: 2");
     }
     return response()->json($stats);
 }