<?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 $VWt5t) { $VWt5t->fill($this->item); }); } public function pushField(AbstractField $VWt5t) { $this->fields()->push($VWt5t); return $this; } public function removeField($XrXh2) { $this->fields = $this->fields()->filter(function (AbstractField $VWt5t) use($XrXh2) { return $VWt5t->column() != $XrXh2; }); return $this; } public function prependField(AbstractField $VWt5t) { $this->fields()->prepend($VWt5t); return $this; } public function fieldDefaultRenderMode($gwXrh = null) { if (null === $gwXrh) { return $this->fieldDefaultRenderMode; } return $this->fieldDefaultRenderMode = $gwXrh; } public function fields() { return $this->fields; } public function listableFields() { return $this->fields->filter(function (AbstractField $nsWl0) { return $nsWl0->listable(); }); } public function addableFields($iPt6X = false) { return $this->fields->filter(function (AbstractField $nsWl0) use($iPt6X) { return $nsWl0->addable() || $iPt6X && $nsWl0->formShowOnly(); }); } protected function editableFields($iPt6X = false) { return $this->fields->filter(function (AbstractField $nsWl0) use($iPt6X) { return $nsWl0->editable() || $iPt6X && $nsWl0->formShowOnly(); }); } protected function showableFields() { return $this->fields->filter(function (AbstractField $nsWl0) { return $nsWl0->showable(); }); } public function sortableFields() { return $this->fields->filter(function (AbstractField $nsWl0) { return $nsWl0->sortable(); }); } public function getFieldByName($L1g9F) { return $this->fields->first(function ($GBNIv, AbstractField $nsWl0) use($L1g9F) { return $nsWl0->name() == $L1g9F; }); } public function getFieldByColumn($XrXh2) { return $this->fields->first(function ($GBNIv, AbstractField $nsWl0) use($XrXh2) { return $nsWl0->column() == $XrXh2; }); } }