<?php
/**
 * ------------------------ 
 *  版权所有  www.tecmz.com
 *  商业版本请购买正版授权使用
 * ------------------------
*/ namespace ModStart\Support\Concern; use Illuminate\Support\Collection; use ModStart\Field\AbstractField; use ModStart\Field\Type\FieldRenderMode; trait HasFields { private $fields; private $fieldDefaultRenderMode = 'add'; private function setupFields() { $this->fields = new Collection(); } public function fillFields() { $this->fields()->each(function (AbstractField $rZfgs) { $rZfgs->fill($this->item); }); } public function pushField(AbstractField $rZfgs) { $this->fields()->push($rZfgs); return $this; } public function removeField($t_tdX) { $this->fields = $this->fields()->filter(function (AbstractField $rZfgs) use($t_tdX) { return $rZfgs->column() != $t_tdX; }); return $this; } public function prependField(AbstractField $rZfgs) { $this->fields()->prepend($rZfgs); return $this; } public function fieldDefaultRenderMode($Mczr_ = null) { if (null === $Mczr_) { return $this->fieldDefaultRenderMode; } return $this->fieldDefaultRenderMode = $Mczr_; } public function fields() { return $this->fields; } public function listableFields() { return $this->fields->filter(function (AbstractField $Esk0p) { return $Esk0p->listable(); }); } public function addableFields($YLYPq = false) { return $this->fields->filter(function (AbstractField $Esk0p) use($YLYPq) { return $Esk0p->addable() || $YLYPq && $Esk0p->formShowOnly(); }); } protected function editableFields($YLYPq = false) { return $this->fields->filter(function (AbstractField $Esk0p) use($YLYPq) { return $Esk0p->editable() || $YLYPq && $Esk0p->formShowOnly(); }); } protected function showableFields() { return $this->fields->filter(function (AbstractField $Esk0p) { return $Esk0p->showable(); }); } public function sortableFields() { return $this->fields->filter(function (AbstractField $Esk0p) { return $Esk0p->sortable(); }); } public function getFieldByName($ZZMEd) { return $this->fields->first(function ($B34tD, AbstractField $Esk0p) use($ZZMEd) { return $Esk0p->name() == $ZZMEd; }); } public function getFieldByColumn($t_tdX) { return $this->fields->first(function ($B34tD, AbstractField $Esk0p) use($t_tdX) { return $Esk0p->column() == $t_tdX; }); } }