<?php
namespace App\Form\Input; class Select_DocumentType extends \Engine\Form\Input\Select { protected $pivot = null; protected $docCategory = null; protected $serviceCode = null; public function __construct($label=null, $name=null, $value=null, $possibleValues=null) { parent::__construct($label, $name, $value); $this->showDefaultOption(true); } public function setPivot($pivot) { $this->pivot = $pivot; } public function setDocCategory($docCategory) { $this->docCategory = $docCategory; } public function setServiceCode($serviceCode) { if ($this->pivot!='service') { throw new \Exception('You cannot set the service code unless the pivot is set as `service`.'); } $this->serviceCode = $serviceCode; } protected function determinePossibleValues() { $_LANG = \App\Loader_Lang::getInstance()->getGlobal(); $docCfgObj = \App\Config\IssueDocuments::getInstance();; $filterByServiceCode = []; if ($this->serviceCode) { $filterByServiceCode = $docCfgObj->getServiceDocsList($this->serviceCode); } $assocDocTypes = []; foreach($docCfgObj->getAll() as $docType=>$docDetails) { if (!$docDetails['active']) { continue; } if ($this->pivot and $docDetails['pivot']!=$this->pivot) { continue; } if ($this->docCategory and $docDetails['docCategory']!=$this->docCategory) { continue; } if ($filterByServiceCode and !$filterByServiceCode[$docType]) { continue; } if ($this->pivot) { $assocDocTypes [$docType] = $docDetails['name']; } else { $assocDocTypes [$_LANG['documentPivotName'][$docDetails['pivot']]] [$docType] = $docDetails['name']; } } return $assocDocTypes; } }