Source of file ProductQuestionImageSelectorField.php
Size: 3,394 Bytes - Last Modified: 2021-12-23T10:41:01+00:00
/var/www/docs.ssmods.com/process/src/code/form/ProductQuestionImageSelectorField.php
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110 | <?php /** * form field to select answer for question. * * */ class ProductQuestionImageSelectorField extends OptionsetField { protected $folderID = 0; protected $options = array(); protected $objects = null; protected $width = 50; protected $height = 50; public function __construct($name, $title = '', $options = array(), $value = '', $folderID) { $this->setOptions($options); $this->setFolderID($folderID); $this->createObjects(); parent::__construct($name, $title, $options, $value); } public function setOptions($options) { $this->options = $options; } public function setFolderID($folderID) { $this->folderID = $folderID; } public function setWidth($width) { $this->width = $width; } public function setHeight($height) { $this->height = $height; } public function Field($properties = array()) { $options = ''; $source = $this->getSource(); $count = 0; if ($this->objects && $this->objects->count()) { foreach ($this->objects as $image) { $key = $image->Key; $itemID = $this->id() . "_" . $image->ID; $value = $image->Value; $labelHTML = $value; $resizedImageObject = $image->getFormattedImage("CroppedImage", $this->width, $this->height); if ($resizedImageObject) { $labelHTML = '<img src="'.$resizedImageObject->Link().'" alt="'.$value.'" />'; } if ($key == $this->value/* || $useValue */) { $useValue = false; $checked = " checked=\"checked\""; } else { $checked=""; } $odd = ($count + 1) % 2; $oddEven = $odd ? "odd" : "even"; $extraClass = " val" . preg_replace('/[^a-zA-Z0-9\-\_]/', '_', $key); $position = " pos".$count; $disabled = $this->disabled ? 'disabled="disabled"' : ''; $options .= "<li class=\"".$oddEven.$extraClass.$position."\"><input id=\"$itemID\" name=\"$this->name\" type=\"radio\" value=\"$key\"$checked $disabled class=\"radio\" /> <label for=\"$itemID\">$labelHTML</label></li>\n"; $count++; } $id = $this->id(); } if (empty($id)) { $id = 0; } return " <ul id=\"$id\" class=\"optionset {$this->extraClass()}\"> \n$options </ul>\n"; } protected function createObjects() { $this->objects = new ArrayList(); if ($this->options && is_array($this->options) && count($this->options)) { foreach ($this->options as $option) { $imageOptions = ProductQuestion::create_file_array_from_option($option); $image = DataObject::get_one( 'Image', array("ParentID" => $this->folderID, "Name" => $imageOptions), $cacheDataObjectGetOne = false ); if ($image) { $image->Key = $option; $image->Value = $option; $this->objects->push($image); } } } } } |