<?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 $E8QRJ) { $E8QRJ->fill($this->item); }); } public function pushField(AbstractField $E8QRJ) { $this->fields()->push($E8QRJ); return $this; } public function removeField($BlfaU) { $this->fields = $this->fields()->filter(function (AbstractField $E8QRJ) use($BlfaU) { return $E8QRJ->column() != $BlfaU; }); return $this; } public function prependField(AbstractField $E8QRJ) { $this->fields()->prepend($E8QRJ); return $this; } public function fieldDefaultRenderMode($HDpl6 = null) { if (null === $HDpl6) { return $this->fieldDefaultRenderMode; } return $this->fieldDefaultRenderMode = $HDpl6; } public function fields() { return $this->fields; } public function listableFields() { return $this->fields->filter(function (AbstractField $OV1o4) { return $OV1o4->listable(); }); } public function addableFields($tKZrw = false) { return $this->fields->filter(function (AbstractField $OV1o4) use($tKZrw) { return $OV1o4->addable() || $tKZrw && $OV1o4->formShowOnly(); }); } protected function editableFields($tKZrw = false) { return $this->fields->filter(function (AbstractField $OV1o4) use($tKZrw) { return $OV1o4->editable() || $tKZrw && $OV1o4->formShowOnly(); }); } protected function showableFields() { return $this->fields->filter(function (AbstractField $OV1o4) { return $OV1o4->showable(); }); } public function sortableFields() { return $this->fields->filter(function (AbstractField $OV1o4) { return $OV1o4->sortable(); }); } public function getFieldByName($f0dxO) { return $this->fields->first(function ($pztz4, AbstractField $OV1o4) use($f0dxO) { return $OV1o4->name() == $f0dxO; }); } public function getFieldByColumn($BlfaU) { return $this->fields->first(function ($pztz4, AbstractField $OV1o4) use($BlfaU) { return $OV1o4->column() == $BlfaU; }); } }