<?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 $Mk6lP) { $Mk6lP->fill($this->item); }); } public function pushField(AbstractField $Mk6lP) { $this->fields()->push($Mk6lP); return $this; } public function removeField($mSZnY) { $this->fields = $this->fields()->filter(function (AbstractField $Mk6lP) use($mSZnY) { return $Mk6lP->column() != $mSZnY; }); return $this; } public function prependField(AbstractField $Mk6lP) { $this->fields()->prepend($Mk6lP); return $this; } public function fieldDefaultRenderMode($mdHu1 = null) { if (null === $mdHu1) { return $this->fieldDefaultRenderMode; } return $this->fieldDefaultRenderMode = $mdHu1; } public function fields() { return $this->fields; } public function listableFields() { return $this->fields->filter(function (AbstractField $yFnpO) { return $yFnpO->listable(); }); } public function addableFields($DOixg = false) { return $this->fields->filter(function (AbstractField $yFnpO) use($DOixg) { return $yFnpO->addable() || $DOixg && $yFnpO->formShowOnly(); }); } protected function editableFields($DOixg = false) { return $this->fields->filter(function (AbstractField $yFnpO) use($DOixg) { return $yFnpO->editable() || $DOixg && $yFnpO->formShowOnly(); }); } protected function showableFields() { return $this->fields->filter(function (AbstractField $yFnpO) { return $yFnpO->showable(); }); } public function sortableFields() { return $this->fields->filter(function (AbstractField $yFnpO) { return $yFnpO->sortable(); }); } public function getFieldByName($c6VKG) { return $this->fields->first(function ($Fkd1C, AbstractField $yFnpO) use($c6VKG) { return $yFnpO->name() == $c6VKG; }); } public function getFieldByColumn($mSZnY) { return $this->fields->first(function ($Fkd1C, AbstractField $yFnpO) use($mSZnY) { return $yFnpO->column() == $mSZnY; }); } }