| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032 |
- <?php
- namespace App;
- use App\News;
- use Illuminate\Database\Eloquent\Model;
- use App\Notifications\FacebookPost;
- use App\Notifications\TwitterPost;
- class Section extends Model
- {
- protected $fillable = [
- 'name',
- 'type',
- 'position',
- 'layout',
- 'big',
- 'medium1',
- 'medium2',
- 'medium3',
- 'small1',
- 'small2',
- 'small3',
- 'small4',
- 'small5',
- 'small6',
- 'slug',
- 'before',
- 'after',
- 'show_social',
- 'show_social_twitter'
- ];
- function loadLayout()
- {
- $id = $this->id;
- $this->data = $this;
- if ($this->big != '')
- {
- $n = News::find($this->big);
- if ($n != null)
- {
- if (!$n->online)
- $n = null;
- $this->big = $n;
- }
- }
-
- if ($this->small1 != '')
- {
- $n = News::find($this->small1);
- if($n != null)
- {
- if (!$n->online)
- $n = null;
- $this->small1 = $n;
- }
- }
- if ($this->small2 != '')
- {
- $n = News::find($this->small2);
- if($n != null)
- {
- if (!$n->online)
- $n = null;
- $this->small2 = $n;
- }
- }
- if ($this->small3 != '')
- {
- $n = News::find($this->small3);
- if($n != null)
- {
- if (!$n->online)
- $n = null;
- $this->small3 = $n;
- }
- }
- if ($this->small4 != '')
- {
- $n = News::find($this->small4);
- if($n != null)
- {
- if (!$n->online)
- $n = null;
- $this->small4 = $n;
- }
- }
- if ($this->small5 != '')
- {
- $n = News::find($this->small5);
- if($n != null)
- {
- if (!$n->online)
- $n = null;
- $this->small5 = $n;
- }
- }
- if ($this->small6 != '')
- {
- $n = News::find($this->small6);
- if($n != null)
- {
- if (!$n->online)
- $n = null;
- $this->small6 = $n;
- }
- }
- }
- /*
- function generateLayout()
- {
- $id = $this->id;
- $aExist = array();
- if ($this->big != '')
- {
- $n = News::find($this->big);
- if ($n != null)
- {
- if ($n->section_id == $id && $n->section_position != '')
- {
- $n->section_position = '';
- $n->save();
- }
- if ($n->region_1_id == $id && $n->region_1_position != '')
- {
- $n->region_1_position = '';
- $n->save();
- }
- if ($n->region_2_id == $id && $n->region_2_position != '')
- {
- $n->region_2_position = '';
- $n->save();
- }
- }
- $aExist[] = $this->big;
- }
- if ($this->small1 != '')
- {
- $n = News::find($this->small1);
- if ($n != null)
- {
- if ($n->section_id == $id && $n->section_position != '')
- {
- $n->section_position = '';
- $n->save();
- }
- if ($n->region_1_id == $id && $n->region_1_position != '')
- {
- $n->region_1_position = '';
- $n->save();
- }
- if ($n->region_2_id == $id && $n->region_2_position != '')
- {
- $n->region_2_position = '';
- $n->save();
- }
- }
- $aExist[] = $this->small1;
- }
- if ($this->small2 != '')
- {
- $n = News::find($this->small2);
- if ($n != null)
- {
- if ($n->section_id == $id && $n->section_position != '')
- {
- $n->section_position = '';
- $n->save();
- }
- if ($n->region_1_id == $id && $n->region_1_position != '')
- {
- $n->region_1_position = '';
- $n->save();
- }
- if ($n->region_2_id == $id && $n->region_2_position != '')
- {
- $n->region_2_position = '';
- $n->save();
- }
- }
- $aExist[] = $this->small2;
- }
- if ($this->small3 != '')
- {
- $n = News::find($this->small3);
- if ($n != null)
- {
- if ($n->section_id == $id && $n->section_position != '')
- {
- $n->section_position = '';
- $n->save();
- }
- if ($n->region_1_id == $id && $n->region_1_position != '')
- {
- $n->region_1_position = '';
- $n->save();
- }
- if ($n->region_2_id == $id && $n->region_2_position != '')
- {
- $n->region_2_position = '';
- $n->save();
- }
- }
- $aExist[] = $this->small3;
- }
- if ($this->small4 != '')
- {
- $n = News::find($this->small4);
- if ($n != null)
- {
- if ($n->section_id == $id && $n->section_position != '')
- {
- $n->section_position = '';
- $n->save();
- }
- if ($n->region_1_id == $id && $n->region_1_position != '')
- {
- $n->region_1_position = '';
- $n->save();
- }
- if ($n->region_2_id == $id && $n->region_2_position != '')
- {
- $n->region_2_position = '';
- $n->save();
- }
- }
- $aExist[] = $this->small4;
- }
- if ($this->small5 != '')
- {
- $n = News::find($this->small5);
- if ($n != null)
- {
- if ($n->section_id == $id && $n->section_position != '')
- {
- $n->section_position = '';
- $n->save();
- }
- if ($n->region_1_id == $id && $n->region_1_position != '')
- {
- $n->region_1_position = '';
- $n->save();
- }
- if ($n->region_2_id == $id && $n->region_2_position != '')
- {
- $n->region_2_position = '';
- $n->save();
- }
- }
- $aExist[] = $this->small5;
- }
- if ($this->small6 != '')
- {
- $n = News::find($this->small6);
- if ($n != null)
- {
- if ($n->section_id == $id && $n->section_position != '')
- {
- $n->section_position = '';
- $n->save();
- }
- if ($n->region_1_id == $id && $n->region_1_position != '')
- {
- $n->region_1_position = '';
- $n->save();
- }
- if ($n->region_2_id == $id && $n->region_2_position != '')
- {
- $n->region_2_position = '';
- $n->save();
- }
- }
- $aExist[] = $this->small6;
- }
-
- $this->data = $this;
- if ($this->big != '')
- {
- $n = News::find($this->big);
- if ($n != null)
- {
- if (!$n->online)
- $n = null;
- $position = 'big';
- // Controllo se c'è una news dopo questa da pubblicare che va in questa sezione/posizione, se si faccio il replace
- $checks = News::whereNotIn('id', $aExist)->where('date', '<=', date('Y-m-d H:i:s'))->where('online', '=', true)->where(function ($q) use ($id) {
- $q->where('region_1_id', '=', $id)->orWhere('region_2_id', '=', $id)->orWhere('section_id', '=', $id);
- })->where(function ($q) use ($position) {
- $q->where('region_1_position', '=', $position)->orWhere('region_2_position', '=', $position)->orWhere('section_position', '=', $position);
- })->get();
- foreach($checks as $c)
- {
-
- if ($c->section_id == $id && $c->section_position == $position)
- {
- $s = Section::findOrFail($this->id);
- $s->big = $c->id;
- $s->save();
- $c->section_position = '';
- if (!$c->published)
- {
- $c->notify(new FacebookPost());
- $c->notify(new TwitterPost());
- $c->published = true;
- }
- $c->save();
- $n = $c;
- break;
- }
- if ($c->region_1_id == $id && $c->region_1_position == $position)
- {
- $s = Section::findOrFail($this->id);
- $s->big = $c->id;
- $s->save();
- $c->region_1_position = '';
- if (!$c->published)
- {
- $c->notify(new FacebookPost());
- $c->notify(new TwitterPost());
- $c->published = true;
- }
- $c->save();
- $n = $c;
- break;
- }
- if ($c->region_2_id == $id && $c->region_2_position == $position)
- {
- $s = Section::findOrFail($this->id);
- $s->big = $c->id;
- $s->save();
- $c->region_2_position = '';
- if (!$c->published)
- {
- $c->notify(new FacebookPost());
- $c->notify(new TwitterPost());
- $c->published = true;
- }
- $c->save();
- $n = $c;
- break;
- }
- }
- $this->big = $n;
- }
- }
-
- if ($this->small1 != '')
- {
- $n = News::find($this->small1);
- if($n != null)
- {
- if (!$n->online)
- $n = null;
- $position = 'small1';
- // Controllo se c'è una news dopo questa da pubblicare che va in questa sezione/posizione, se si faccio il replace
- $checks = News::whereNotIn('id', $aExist)->where('date', '<=', date('Y-m-d H:i:s'))->where('online', '=', true)->where(function ($q) use ($id) {
- $q->where('region_1_id', '=', $id)->orWhere('region_2_id', '=', $id)->orWhere('section_id', '=', $id);
- })->where(function ($q) use ($position) {
- $q->where('region_1_position', '=', $position)->orWhere('region_2_position', '=', $position)->orWhere('section_position', '=', $position);
- })->get();
- foreach($checks as $c)
- {
- if ($c->section_id == $id && $c->section_position == $position)
- {
- $s = Section::findOrFail($this->id);
- $s->small1 = $c->id;
- $s->save();
- $c->section_position = '';
- if (!$c->published)
- {
- $c->notify(new FacebookPost());
- $c->notify(new TwitterPost());
- $c->published = true;
- }
- $c->save();
- $n = $c;
- break;
- }
- if ($c->region_1_id == $id && $c->region_1_position == $position)
- {
- $s = Section::findOrFail($this->id);
- $s->small1 = $c->id;
- $s->save();
- $c->region_1_position = '';
- if (!$c->published)
- {
- $c->notify(new FacebookPost());
- $c->notify(new TwitterPost());
- $c->published = true;
- }
- $c->save();
- $n = $c;
- break;
- }
- if ($c->region_2_id == $id && $c->region_2_position == $position)
- {
- $s = Section::findOrFail($this->id);
- $s->small1 = $c->id;
- $s->save();
- $c->region_2_position = '';
- if (!$c->published)
- {
- $c->notify(new FacebookPost());
- $c->notify(new TwitterPost());
- $c->published = true;
- }
- $c->save();
- $n = $c;
- break;
- }
- }
- $this->small1 = $n;
- }
- }
- if ($this->small2 != '')
- {
- $n = News::find($this->small2);
- if($n != null)
- {
- if (!$n->online)
- $n = null;
- $position = 'small2';
- // Controllo se c'è una news dopo questa da pubblicare che va in questa sezione/posizione, se si faccio il replace
- $checks = News::whereNotIn('id', $aExist)->where('date', '<=', date('Y-m-d H:i:s'))->where('online', '=', true)->where(function ($q) use ($id) {
- $q->where('region_1_id', '=', $id)->orWhere('region_2_id', '=', $id)->orWhere('section_id', '=', $id);
- })->where(function ($q) use ($position) {
- $q->where('region_1_position', '=', $position)->orWhere('region_2_position', '=', $position)->orWhere('section_position', '=', $position);
- })->get();
- foreach($checks as $c)
- {
- if ($c->section_id == $id && $c->section_position == $position)
- {
- $s = Section::findOrFail($this->id);
- $s->small2 = $c->id;
- $s->save();
- $c->section_position = '';
- if (!$c->published)
- {
- $c->notify(new FacebookPost());
- $c->notify(new TwitterPost());
- $c->published = true;
- }
- $c->save();
- $n = $c;
- break;
- }
- if ($c->region_1_id == $id && $c->region_1_position == $position)
- {
- $s = Section::findOrFail($this->id);
- $s->small2 = $c->id;
- $s->save();
- $c->region_1_position = '';
- if (!$c->published)
- {
- $c->notify(new FacebookPost());
- $c->notify(new TwitterPost());
- $c->published = true;
- }
- $c->save();
- $n = $c;
- break;
- }
- if ($c->region_2_id == $id && $c->region_2_position == $position)
- {
- $s = Section::findOrFail($this->id);
- $s->small2 = $c->id;
- $s->save();
- $c->region_2_position = '';
- if (!$c->published)
- {
- $c->notify(new FacebookPost());
- $c->notify(new TwitterPost());
- $c->published = true;
- }
- $c->save();
- $n = $c;
- break;
- }
- }
- $this->small2 = $n;
- }
- }
- if ($this->small3 != '')
- {
- $n = News::find($this->small3);
- if($n != null)
- {
- if (!$n->online)
- $n = null;
- $position = 'small3';
- // Controllo se c'è una news dopo questa da pubblicare che va in questa sezione/posizione, se si faccio il replace
- $checks = News::whereNotIn('id', $aExist)->where('date', '<=', date('Y-m-d H:i:s'))->where('online', '=', true)->where(function ($q) use ($id) {
- $q->where('region_1_id', '=', $id)->orWhere('region_2_id', '=', $id)->orWhere('section_id', '=', $id);
- })->where(function ($q) use ($position) {
- $q->where('region_1_position', '=', $position)->orWhere('region_2_position', '=', $position)->orWhere('section_position', '=', $position);
- })->get();
- foreach($checks as $c)
- {
- if ($c->section_id == $id && $c->section_position == $position)
- {
- $s = Section::findOrFail($this->id);
- $s->small3 = $c->id;
- $s->save();
- $c->section_position = '';
- if (!$c->published)
- {
- $c->notify(new FacebookPost());
- $c->notify(new TwitterPost());
- $c->published = true;
- }
- $c->save();
- $n = $c;
- break;
- }
- if ($c->region_1_id == $id && $c->region_1_position == $position)
- {
- $s = Section::findOrFail($this->id);
- $s->small3 = $c->id;
- $s->save();
- $c->region_1_position = '';
- if (!$c->published)
- {
- $c->notify(new FacebookPost());
- $c->notify(new TwitterPost());
- $c->published = true;
- }
- $c->save();
- $n = $c;
- break;
- }
- if ($c->region_2_id == $id && $c->region_2_position == $position)
- {
- $s = Section::findOrFail($this->id);
- $s->small3 = $c->id;
- $s->save();
- $c->region_2_position = '';
- if (!$c->published)
- {
- $c->notify(new FacebookPost());
- $c->notify(new TwitterPost());
- $c->published = true;
- }
- $c->save();
- $n = $c;
- break;
- }
- }
- $this->small3 = $n;
- }
- }
- if ($this->small4 != '')
- {
- $n = News::find($this->small4);
- if($n != null)
- {
- if (!$n->online)
- $n = null;
-
- $position = 'small4';
- // Controllo se c'è una news dopo questa da pubblicare che va in questa sezione/posizione, se si faccio il replace
- $checks = News::whereNotIn('id', $aExist)->where('date', '<=', date('Y-m-d H:i:s'))->where('online', '=', true)->where(function ($q) use ($id) {
- $q->where('region_1_id', '=', $id)->orWhere('region_2_id', '=', $id)->orWhere('section_id', '=', $id);
- })->where(function ($q) use ($position) {
- $q->where('region_1_position', '=', $position)->orWhere('region_2_position', '=', $position)->orWhere('section_position', '=', $position);
- })->get();
- foreach($checks as $c)
- {
- if ($c->section_id == $id && $c->section_position == $position)
- {
- $s = Section::findOrFail($this->id);
- $s->small4 = $c->id;
- $s->save();
- $c->section_position = '';
- if (!$c->published)
- {
- $c->notify(new FacebookPost());
- $c->notify(new TwitterPost());
- $c->published = true;
- }
- $c->save();
- $n = $c;
- break;
- }
- if ($c->region_1_id == $id && $c->region_1_position == $position)
- {
- $s = Section::findOrFail($this->id);
- $s->small4 = $c->id;
- $s->save();
- $c->region_1_position = '';
- if (!$c->published)
- {
- $c->notify(new FacebookPost());
- $c->notify(new TwitterPost());
- $c->published = true;
- }
- $c->save();
- $n = $c;
- break;
- }
- if ($c->region_2_id == $id && $c->region_2_position == $position)
- {
- $s = Section::findOrFail($this->id);
- $s->small4 = $c->id;
- $s->save();
- $c->region_2_position = '';
- if (!$c->published)
- {
- $c->notify(new FacebookPost());
- $c->notify(new TwitterPost());
- $c->published = true;
- }
- $c->save();
- $n = $c;
- break;
- }
- }
- $this->small4 = $n;
- }
- }
- if ($this->small5 != '')
- {
- $n = News::find($this->small5);
- if($n != null)
- {
- if (!$n->online)
- $n = null;
- $position = 'small5';
- // Controllo se c'è una news dopo questa da pubblicare che va in questa sezione/posizione, se si faccio il replace
- $checks = News::whereNotIn('id', $aExist)->where('date', '<=', date('Y-m-d H:i:s'))->where('online', '=', true)->where(function ($q) use ($id) {
- $q->where('region_1_id', '=', $id)->orWhere('region_2_id', '=', $id)->orWhere('section_id', '=', $id);
- })->where(function ($q) use ($position) {
- $q->where('region_1_position', '=', $position)->orWhere('region_2_position', '=', $position)->orWhere('section_position', '=', $position);
- })->get();
- foreach($checks as $c)
- {
- if ($c->section_id == $id && $c->section_position == $position)
- {
- $s = Section::findOrFail($this->id);
- $s->small5 = $c->id;
- $s->save();
- $c->section_position = '';
- if (!$c->published)
- {
- $c->notify(new FacebookPost());
- $c->notify(new TwitterPost());
- $c->published = true;
- }
- $c->save();
- $n = $c;
- break;
- }
- if ($c->region_1_id == $id && $c->region_1_position == $position)
- {
- $s = Section::findOrFail($this->id);
- $s->small5 = $c->id;
- $s->save();
- $c->region_1_position = '';
- if (!$c->published)
- {
- $c->notify(new FacebookPost());
- $c->notify(new TwitterPost());
- $c->published = true;
- }
- $c->save();
- $n = $c;
- break;
- }
- if ($c->region_2_id == $id && $c->region_2_position == $position)
- {
- $s = Section::findOrFail($this->id);
- $s->small5 = $c->id;
- $s->save();
- $c->region_2_position = '';
- if (!$c->published)
- {
- $c->notify(new FacebookPost());
- $c->notify(new TwitterPost());
- $c->published = true;
- }
- $c->save();
- $n = $c;
- break;
- }
- }
- $this->small5 = $n;
- }
- }
- if ($this->small6 != '')
- {
- $n = News::find($this->small6);
- if($n != null)
- {
- if (!$n->online)
- $n = null;
- $position = 'small6';
- // Controllo se c'è una news dopo questa da pubblicare che va in questa sezione/posizione, se si faccio il replace
- $checks = News::whereNotIn('id', $aExist)->where('date', '<=', date('Y-m-d H:i:s'))->where('online', '=', true)->where(function ($q) use ($id) {
- $q->where('region_1_id', '=', $id)->orWhere('region_2_id', '=', $id)->orWhere('section_id', '=', $id);
- })->where(function ($q) use ($position) {
- $q->where('region_1_position', '=', $position)->orWhere('region_2_position', '=', $position)->orWhere('section_position', '=', $position);
- })->get();
- foreach($checks as $c)
- {
- if ($c->section_id == $id && $c->section_position == $position)
- {
- $s = Section::findOrFail($this->id);
- $s->small6 = $c->id;
- $s->save();
- $c->section_position = '';
- if (!$c->published)
- {
- $c->notify(new FacebookPost());
- $c->notify(new TwitterPost());
- $c->published = true;
- }
- $c->save();
- $n = $c;
- break;
- }
- if ($c->region_1_id == $id && $c->region_1_position == $position)
- {
- $s = Section::findOrFail($this->id);
- $s->small6 = $c->id;
- $s->save();
- $c->region_1_position = '';
- if (!$c->published)
- {
- $c->notify(new FacebookPost());
- $c->notify(new TwitterPost());
- $c->published = true;
- }
- $c->save();
- $n = $c;
- break;
- }
- if ($c->region_2_id == $id && $c->region_2_position == $position)
- {
- $s = Section::findOrFail($this->id);
- $s->small6 = $c->id;
- $s->save();
- $c->region_2_position = '';
- if (!$c->published)
- {
- $c->notify(new FacebookPost());
- $c->notify(new TwitterPost());
- $c->published = true;
- }
- $c->save();
- $n = $c;
- break;
- }
- }
- $this->small6 = $n;
- }
- }
- }*/
- function news_online($type)
- {
- if ($type == 'section')
- return News::where('section_id', '=', $this->id)->where('online', '=', true)->count();
- else
- {
- $id = $this->id;
- return News::where('online', '=', true)->where(function ($q) use ($id) {
- $q->where('region_1_id', '=', $id)->orWhere('region_2_id', '=', $id);
- })->count();
- }
- }
- function news($type)
- {
- if ($type == 'section')
- return News::where('section_id', '=', $this->id)->count();
- else
- return News::where('region_1_id', '=', $this->id)->orWhere('region_2_id', '=', $this->id)->count();
- }
-
- public function advs()
- {
- return $this->hasMany('App\SectionAdv');
- }
- public function getAdvs()
- {
- $advs = array();
- $sections_advs = $this->advs()->where('online', '=', true)->get(); //SectionAdv::where('section_id', '=', $section->id)->orderBy('position')->get();
- foreach($sections_advs as $a)
- {
- $advs[$a->position][] = $a;
- }
-
- return $advs;
- }
- public function position($news_id)
- {
- $img = '';
- if ($this->layout != '')
- {
- if($this->big == $news_id)
- $img = $this->layout . '_big';
- /*if($this->medium1 == $news_id)
- $img = $this->layout . '_medium1';
- if($this->medium2 == $news_id)
- $img = $this->layout . '_medium2';
- if($this->medium3 == $news_id)
- $img = $this->layout . '_medium3';*/
- if($this->small1 == $news_id)
- $img = $this->layout . '_small1';
- if($this->small2 == $news_id)
- $img = $this->layout . '_small2';
- if($this->small3 == $news_id)
- $img = $this->layout . '_small3';
- if($this->small4 == $news_id)
- $img = $this->layout . '_small4';
- if($this->small5 == $news_id)
- $img = $this->layout . '_small5';
- if($this->small6 == $news_id)
- $img = $this->layout . '_small6';
-
-
- }
-
- $ret = '';
- if ($img != '')
- $ret = '<img src="/images/layout/' . $img . '.jpg" style="max-width:100px;">';
-
- return $ret;
- }
- /*
- public function clearLayout()
- {
- $id = $this->id;
- $aSel = array();
- if ($this->big)
- $aSel[] = $this->big;
- if ($this->small1)
- $aSel[] = $this->small1;
- if ($this->small2)
- $aSel[] = $this->small2;
- if ($this->small3)
- $aSel[] = $this->small3;
- if ($this->small4)
- $aSel[] = $this->small4;
- if ($this->small5)
- $aSel[] = $this->small5;
- if ($this->small6)
- $aSel[] = $this->small6;
- $news = News::whereNotIn('id', $aSel)->where(function ($q) use ($id) {
- $q->where('section_id', '=', $id)->orWhere('region_1_id', '=', $id)->orWhere('region_2_id', '=', $id);
- })->where(function ($q) {
- $q->where('region_1_position', '<>', '')->orWhere('region_2_position', '<>', '')->orWhere('section_position', '<>', '');
- })->where('online', '=', true)->where('date', '<=', date("Y-m-d 23:59:59"))->where('breaking_news', '=', false)->orderBy('date', 'DESC')->get();
-
- $idx = 0;
- if ($this->big == '')
- {
- $this->big = @$news[$idx]->id;
- $idx++;
- }
- else
- {
- $n = News::where('id', '=', $this->big)->where('online', '=', true)->where('date', '<=', date("Y-m-d 23:59:59"))->where('breaking_news', '=', false)->first();
- if (!$n || !$n->online)
- {
- $this->big = @$news[$idx]->id;
- $idx++;
- }
- }
- if ($this->small1 == '')
- {
- $this->small1 = @$news[$idx]->id;
- $idx++;
- }
- else
- {
- $n = News::where('id', '=', $this->small1)->where('online', '=', true)->where('date', '<=', date("Y-m-d 23:59:59"))->where('breaking_news', '=', false)->first();
- if (!$n || !$n->online)
- {
- $this->small1 = @$news[$idx]->id;
- $idx++;
- }
- }
- if ($this->small2 == '')
- {
- $this->small2 = @$news[$idx]->id;
- $idx++;
- }
- else
- {
- $n = News::where('id', '=', $this->small2)->where('online', '=', true)->where('date', '<=', date("Y-m-d 23:59:59"))->where('breaking_news', '=', false)->first();
- if (!$n || !$n->online)
- {
- $this->small2 = @$news[$idx]->id;
- $idx++;
- }
- }
- if ($this->small3 == '')
- {
- $this->small3 = @$news[$idx]->id;
- $idx++;
- }
- else
- {
- $n = News::where('id', '=', $this->small3)->where('online', '=', true)->where('date', '<=', date("Y-m-d 23:59:59"))->where('breaking_news', '=', false)->first();
- if (!$n || !$n->online)
- {
- $this->small3 = @$news[$idx]->id;
- $idx++;
- }
- }
- if ($this->layout == 'layout_3' || $this->layout == 'layout_4' || $this->layout == 'layout_5')
- {
- if ($this->small4 == '')
- {
- $this->small4 = @$news[$idx]->id;
- $idx++;
- }
- else
- {
- $n = News::where('id', '=', $this->small4)->where('online', '=', true)->where('date', '<=', date("Y-m-d 23:59:59"))->where('breaking_news', '=', false)->first();
- if (!$n || !$n->online)
- {
- $this->small4 = @$news[$idx]->id;
- $idx++;
- }
- }
- if ($this->layout == 'layout_4')
- {
- if ($this->small5 == '')
- {
- $this->small5 = @$news[$idx]->id;
- $idx++;
- }
- else
- {
- $n = News::where('id', '=', $this->small5)->where('online', '=', true)->where('date', '<=', date("Y-m-d 23:59:59"))->where('breaking_news', '=', false)->first();
- if (!$n || !$n->online)
- {
- $this->small5 = @$news[$idx]->id;
- $idx++;
- }
- }
- if ($this->small6 == '')
- {
- $this->small6 = @$news[$idx]->id;
- $idx++;
- }
- else
- {
- $n = News::where('id', '=', $this->small6)->where('online', '=', true)->where('date', '<=', date("Y-m-d 23:59:59"))->where('breaking_news', '=', false)->first();
- if (!$n || !$n->online)
- {
- $this->small6 = @$news[$idx]->id;
- $idx++;
- }
- }
- }
- else
- {
- $this->small5 = '';
- $this->small6 = '';
- }
- }
- else
- {
- $this->small4 = '';
- $this->small5 = '';
- $this->small6 = '';
- }
- $this->save();
- $this->generateLayout();
- // $section->save();
- }
- */
- }
|