%PDF- %PDF-
Direktori : /var/www/html/diaspora/api/app/Models/ |
Current File : /var/www/html/diaspora/api/app/Models/KkdSection.php |
<?php namespace App\Models; use Dimsav\Translatable\Translatable; use Illuminate\Support\Facades\DB; /** * @property integer id * @property string order * @property string title * @property string description * @property boolean is_visible */ class KkdSection extends BaseModel { use Translatable; public $translatedAttributes = [ 'title', 'description', ]; /** * The attributes that are mass assignable. * * @var array */ protected $fillable = [ 'order', 'is_visible', ]; protected $casts = [ 'id' => 'integer', 'order' => 'integer', 'is_visible' => 'boolean', ]; /** * @return $this */ public function show() { $this->is_visible = true; $this->save(); return $this; } /** * @return $this */ public function hide() { $this->is_visible = false; $this->save(); return $this; } public function moveUp() { DB::beginTransaction(); try { $oldOrder = (int)$this->order; $newOrder = $oldOrder - 1; /** @var Section $section */ $section = self::query() ->where('order', $newOrder) ->first(); if ($section) { $section->order = 999; $section->save(); $this->order = $newOrder; $this->save(); $section->order = $oldOrder; $section->save(); DB::commit(); } return $this; } catch (\Exception $e) { DB::rollBack(); return $this; } } public function moveDown() { DB::beginTransaction(); try { $oldOrder = (int)$this->order; $newOrder = $oldOrder + 1; /** @var KkdSection $section */ $section = self::query() ->where('order', $newOrder) ->first(); if ($section) { $section->order = 999; $section->save(); $this->order = $newOrder; $this->save(); $section->order = $oldOrder; $section->save(); DB::commit(); } return $this; } catch (\Exception $e) { DB::rollBack(); return $this; } } public function canBeEnabled() { return $this->translations() ->count() === 2; } }