<?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 $acdQI) { $acdQI->fill($this->item); }); } public function pushField(AbstractField $acdQI) { $this->fields()->push($acdQI); return $this; } public function removeField($VDtGk) { $this->fields = $this->fields()->filter(function (AbstractField $acdQI) use($VDtGk) { return $acdQI->column() != $VDtGk; }); return $this; } public function prependField(AbstractField $acdQI) { $this->fields()->prepend($acdQI); return $this; } public function fieldDefaultRenderMode($Gttsd = null) { if (null === $Gttsd) { return $this->fieldDefaultRenderMode; } return $this->fieldDefaultRenderMode = $Gttsd; } public function fields() { return $this->fields; } public function listableFields() { return $this->fields->filter(function (AbstractField $Xvngd) { return $Xvngd->listable(); }); } public function addableFields($G8SIW = false) { return $this->fields->filter(function (AbstractField $Xvngd) use($G8SIW) { return $Xvngd->addable() || $G8SIW && $Xvngd->formShowOnly(); }); } protected function editableFields($G8SIW = false) { return $this->fields->filter(function (AbstractField $Xvngd) use($G8SIW) { return $Xvngd->editable() || $G8SIW && $Xvngd->formShowOnly(); }); } protected function showableFields() { return $this->fields->filter(function (AbstractField $Xvngd) { return $Xvngd->showable(); }); } public function sortableFields() { return $this->fields->filter(function (AbstractField $Xvngd) { return $Xvngd->sortable(); }); } public function getFieldByName($sQIr6) { return $this->fields->first(function ($RTHJ6, AbstractField $Xvngd) use($sQIr6) { return $Xvngd->name() == $sQIr6; }); } public function getFieldByColumn($VDtGk) { return $this->fields->first(function ($RTHJ6, AbstractField $Xvngd) use($VDtGk) { return $Xvngd->column() == $VDtGk; }); } }