Source of file SimpleListFieldDB.php
Size: 2,440 Bytes - Last Modified: 2021-12-23T10:21:10+00:00
/var/www/docs.ssmods.com/process/src/model/fieldtypes/SimpleListFieldDB.php
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134 | <?php class SimpleListFieldDB extends Text{ /** * Template */ private $template = null; /** * List object */ private static $listobj = array(); public function __construct($name = null, $options = array()) { parent::__construct($name, $options); } /** * Get the list */ public function getList(){ // define an unique key $key = $this->name.'_'.md5($this->value); if( isset(self::$listobj[$key]) ){ return self::$listobj[$key]; } if($this->value){ self::$listobj[$key] = json_decode($this->value); } else{ self::$listobj[$key] = false; } return self::$listobj[$key]; } /** * Is Enabled */ public function isEnabled(){ $list = $this->getList(); return ( isset($list->enable) && $list->enable ); } /** * Count items */ public function Count(){ $list = $this->getList(); return ( isset($list->items) && !empty($list->items) ) ? count($list->items) : false; } /** * Get list heading */ public function getHeading(){ $list = $this->getList(); if( isset($list->heading) && $list->heading ){ return Convert::html2raw($list->heading); } return null; } /** * Get list items */ public function getItems(){ $list = $this->getList(); if( isset($list->items) && !empty($list->items) ) { $arrayList = new ArrayList(); foreach($list->items as $id => $item){ $item->ID = $id; $arrayList->push( new ArrayData($item) ); } return $arrayList; } return false; } /** * Set template name (without *.ss extension). * * @param string $template */ public function setTemplate($template) { $this->template = $template; return $this; } /** * @return string */ public function getTemplate() { return $this->template; } /** * For template */ public function forTemplate() { $list = $this->getList(); if( isset($list->enable) && $list->enable ) { // Get scenario $scenario = isset($list->scenario) ? $list->scenario : ''; // Get view file to render $template = $this->template ? $this->template : ( $scenario ? 'SimpleListFieldDB_'.$scenario : 'SimpleListFieldDB' ); $template = new SSViewer($template); return $template->process($this->customise(new ArrayData(array( 'FieldName' => $this->name, 'Heading' => $this->getHeading(), 'Items' => $this->getItems() )))); } return false; } } |