Event.php 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. <?php
  2. namespace App;
  3. use Illuminate\Database\Eloquent\Model;
  4. class Event extends Model
  5. {
  6. protected $fillable = [
  7. 'title',
  8. 'text_short',
  9. 'text',
  10. 'image',
  11. 'slug',
  12. 'online',
  13. 'big',
  14. 'small1',
  15. 'small2',
  16. 'small3',
  17. 'small4'
  18. ];
  19. function loadLayout()
  20. {
  21. $this->data = $this;
  22. if ($this->big != '')
  23. {
  24. $n = News::find($this->big);
  25. if ($n != null)
  26. {
  27. if (!$n->online)
  28. $n = null;
  29. $this->big = $n;
  30. }
  31. }
  32. if ($this->small1 != '')
  33. {
  34. $n = News::find($this->small1);
  35. if($n != null)
  36. {
  37. if (!$n->online)
  38. $n = null;
  39. $this->small1 = $n;
  40. }
  41. }
  42. if ($this->small2 != '')
  43. {
  44. $n = News::find($this->small2);
  45. if($n != null)
  46. {
  47. if (!$n->online)
  48. $n = null;
  49. $this->small2 = $n;
  50. }
  51. }
  52. if ($this->small3 != '')
  53. {
  54. $n = News::find($this->small3);
  55. if($n != null)
  56. {
  57. if (!$n->online)
  58. $n = null;
  59. $this->small3 = $n;
  60. }
  61. }
  62. if ($this->small4 != '')
  63. {
  64. $n = News::find($this->small4);
  65. if($n != null)
  66. {
  67. if (!$n->online)
  68. $n = null;
  69. $this->small4 = $n;
  70. }
  71. }
  72. if ($this->small5 != '')
  73. {
  74. $n = News::find($this->small5);
  75. if($n != null)
  76. {
  77. if (!$n->online)
  78. $n = null;
  79. $this->small5 = $n;
  80. }
  81. }
  82. if ($this->small6 != '')
  83. {
  84. $n = News::find($this->small6);
  85. if($n != null)
  86. {
  87. if (!$n->online)
  88. $n = null;
  89. $this->small6 = $n;
  90. }
  91. }
  92. }
  93. public function advs()
  94. {
  95. return $this->hasMany('App\EventAdv');
  96. }
  97. public function getAdvs()
  98. {
  99. $advs['Sopra 234x60 1'] = array();
  100. $advs['Sopra 234x60 2'] = array();
  101. $advs['Sopra 234x60 3'] = array();
  102. $advs['Sopra 234x60 4'] = array();
  103. $advs['Sotto 234x60 1'] = array();
  104. $advs['Sotto 234x60 2'] = array();
  105. $advs['Sotto 234x60 3'] = array();
  106. $advs['Sotto 234x60 4'] = array();
  107. $advs['728x90'] = array();
  108. $event_advs = $this->advs()->where('online', '=', true)->get();
  109. foreach($event_advs as $a)
  110. {
  111. $advs[$a->position][] = $a;
  112. }
  113. return $advs;
  114. }
  115. }