/** * Execute the console command. * * @return mixed */ public function fire() { $log = new Process(); $log->name = "make-history"; $log->status = "running"; $log->save(); $today = Carbon::today(); $topToday = array(); $newspapers = Newspaper::select('id')->get(); $tags = Tag::select('id')->get(); foreach ($newspapers as $key => $n) { $top = $this->getTopLink($today, $n->id, false); if ($top) { $topToday[] = $top; } } foreach ($tags as $key => $t) { $top = $this->getTopLink($today, false, $t->id); if ($top) { $topToday[] = $top; } } $topToday = array_unique($topToday); //Remove links for today History::where('date', '=', $today)->delete(); //Save history foreach ($topToday as $key => $t) { $this->info($t->title); try { $h = new History(); $h->id_ref = $t->id; unset($t->id); $h->fill($t->toArray()); $h->date = $today; $h->save(); } catch (Exception $e) { } } $log->status = "finished"; $log->save(); }
function AssertNewspaper(Newspaper $news, $id, $title, $city) { $this->assertEquals($id, $news->getId()); $this->assertEquals($title, $news->getTitle()); $this->assertEquals($city, $news->getCity()); }
/** * Observer,that who recieves news */ class Reader implements SplObserver { private $name; public function __construct($name) { $this->name = $name; } public function update(\SplSubject $subject) { echo $this->name . ' is reading breakout news <b>' . $subject->getContent() . '</b><br>'; } } $newspaper = new Newspaper('Newyork Times'); $allen = new Reader('Allen'); $jim = new Reader('Jim'); $linda = new Reader('Linda'); //add reader $newspaper->attach($allen); $newspaper->attach($jim); $newspaper->attach($linda); //remove reader $newspaper->detach($linda); var_dump('----debug----', $newspaper, '----debug----'); //set break outs $newspaper->breakOutNews('USA break down!'); //=====output====== //Allen is reading breakout news USA break down! (Newyork Times) //Jim is reading breakout news USA break down! (Newyork Times)
} /** * Observer,that who recieves news */ class Reader implements SplObserver { private $name; public function __construct($name) { $this->name = $name; } public function update(\SplSubject $subject) { echo $this->name . ' is reading breakout news <b>' . $subject->getContent() . '</b><br>'; } } $newspaper = new Newspaper('Newyork Times'); $allen = new Reader('Allen'); $jim = new Reader('Jim'); $linda = new Reader('Linda'); //add reader $newspaper->attach($allen); $newspaper->attach($jim); $newspaper->attach($linda); //remove reader $newspaper->detach($linda); //set break outs $newspaper->breakOutNews('USA break down!'); //=====output====== //Allen is reading breakout news USA break down! (Newyork Times) //Jim is reading breakout news USA break down! (Newyork Times)
public function getNewspapers() { return Response::json(Newspaper::select('id', 'name', 'logo')->orderBy('name', 'ASC')->get()); }