<?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 $Lgjfa) { $Lgjfa->fill($this->item); }); } public function pushField(AbstractField $Lgjfa) { $this->fields()->push($Lgjfa); return $this; } public function removeField($JJepM) { $this->fields = $this->fields()->filter(function (AbstractField $Lgjfa) use($JJepM) { return $Lgjfa->column() != $JJepM; }); return $this; } public function prependField(AbstractField $Lgjfa) { $this->fields()->prepend($Lgjfa); return $this; } public function fieldDefaultRenderMode($wvO30 = null) { if (null === $wvO30) { return $this->fieldDefaultRenderMode; } return $this->fieldDefaultRenderMode = $wvO30; } public function fields() { return $this->fields; } public function listableFields() { return $this->fields->filter(function (AbstractField $ZpLX1) { return $ZpLX1->listable(); }); } public function addableFields($VbJQK = false) { return $this->fields->filter(function (AbstractField $ZpLX1) use($VbJQK) { return $ZpLX1->addable() || $VbJQK && $ZpLX1->formShowOnly(); }); } protected function editableFields($VbJQK = false) { return $this->fields->filter(function (AbstractField $ZpLX1) use($VbJQK) { return $ZpLX1->editable() || $VbJQK && $ZpLX1->formShowOnly(); }); } protected function showableFields() { return $this->fields->filter(function (AbstractField $ZpLX1) { return $ZpLX1->showable(); }); } public function sortableFields() { return $this->fields->filter(function (AbstractField $ZpLX1) { return $ZpLX1->sortable(); }); } public function getFieldByName($L4owo) { return $this->fields->first(function ($plrwN, AbstractField $ZpLX1) use($L4owo) { return $ZpLX1->name() == $L4owo; }); } public function getFieldByColumn($JJepM) { return $this->fields->first(function ($plrwN, AbstractField $ZpLX1) use($JJepM) { return $ZpLX1->column() == $JJepM; }); } }