* @copyright PayPal * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ namespace PaypalAddons\classes\Shortcut\Form\Field; use Context; class Select implements FieldInteface { /** @var string*/ protected $name; /** @var array*/ protected $options; /** @var string*/ protected $label; /** @var mixed*/ protected $value; /** @var string*/ protected $type; /** @var string*/ protected $afterSelectContent; /** @var string*/ protected $css; /** @var string*/ protected $hint; public function __construct($name, $options, $label = null, $value = null, $type = null, $hint = null, $css = null) { $this->setName($name); $this->setOptions($options); $this->setLabel($label); $this->setValue($value); $this->setType($type); $this->setHint($hint); } public function render() { if (false === empty($this->options)) { foreach ($this->options as $key => $option) { if ($this->getValue() == $option->getValue()) { $option->setIsSelected(true); } } } return Context::getContext()->smarty ->assign('name', $this->getName()) ->assign('options', $this->getOptions()) ->assign('label', $this->getLabel()) ->assign('configType', $this->getType()) ->assign('afterSelectContent', $this->getAfterSelectContent()) ->assign('css', $this->getCss()) ->fetch(_PS_MODULE_DIR_ . 'paypal/views/templates/admin/_partials/form/fields/select.tpl'); } /** * @return string */ public function getName() { return (string) $this->name; } /** * @param string $name * @return Select */ public function setName($name) { $this->name = $name; return $this; } /** * @return SelectOption[] */ public function getOptions() { return $this->options; } /** * @param array $options * @return Select */ public function setOptions($options) { $this->options = []; if (empty($options)) { return $this; } foreach ($options as $option) { $this->addOption($option); } return $this; } /** * @param SelectOption $option * @return Select */ public function addOption(SelectOption $option) { $this->options[] = $option; return $this; } /** * @return string */ public function getLabel() { return (string) $this->label; } /** * @param string $label * @return Select */ public function setLabel($label) { $this->label = $label; return $this; } /** * @return mixed */ public function getValue() { return $this->value; } /** * @param mixed $value * @return Select */ public function setValue($value) { $this->value = $value; return $this; } /** * @return string */ public function getType() { return (string) $this->type; } /** * @param string $type * @return Select */ public function setType($type) { $this->type = $type; return $this; } /** * @return string */ public function getAfterSelectContent() { return (string) $this->afterSelectContent; } /** * @param string $afterSelectContent * @return Select */ public function setAfterSelectContent($afterSelectContent) { $this->afterSelectContent = (string) $afterSelectContent; return $this; } /** * @return string */ public function getCss() { return (string) $this->css; } /** * @param string $css * @return Select */ public function setCss($css) { $this->css = $css; return $this; } /** * @return string */ public function getHint() { return (string) $this->hint; } /** * @param string $hint * @return Select */ public function setHint($hint) { $this->hint = $hint; return $this; } }