芝麻web文件管理V1.00
编辑当前文件:/home/mgatv524/cms.mgaplay.com.br/lib/Entity/MenuBoardProductOption.php
. */ namespace Xibo\Entity; use Respect\Validation\Validator as v; use Xibo\Service\LogServiceInterface; use Xibo\Storage\StorageServiceInterface; use Xibo\Support\Exception\InvalidArgumentException; /** * @SWG\Definition() */ class MenuBoardProductOption implements \JsonSerializable { use EntityTrait; /** * @SWG\Property(description="The Menu Product ID that this Option belongs to") * @var int */ public $menuProductId; /** * @SWG\Property(description="The option name") * @var string */ public $option; /** * @SWG\Property(description="The option value") * @var string */ public $value; /** * Entity constructor. * @param StorageServiceInterface $store * @param LogServiceInterface $log */ public function __construct($store, $log, $dispatcher) { $this->setCommonDependencies($store, $log, $dispatcher); } public function __clone() { $this->menuProductId = null; } public function __toString() { return sprintf('ProductOption %s with value %s', $this->option, $this->value); } /** * @throws InvalidArgumentException */ public function validate() { if (!v::stringType()->notEmpty()->validate($this->option) && v::stringType()->notEmpty()->validate($this->value)) { throw new InvalidArgumentException(__('Each value needs a corresponding option'), 'option'); } if (!v::stringType()->notEmpty()->validate($this->value) && v::stringType()->notEmpty()->validate($this->option)) { throw new InvalidArgumentException(__('Each option needs a corresponding value'), 'value'); } } /** * @param array $options * @throws InvalidArgumentException */ public function save($options = []) { $options = array_merge([ 'validate' => true, ], $options); $this->getLog()->debug('Saving ' . $this); if ($options['validate']) { $this->validate(); } $this->getStore()->insert( 'INSERT INTO `menu_product_options` (`menuProductId`, `option`, `value`) VALUES (:menuProductId, :option, :value) ON DUPLICATE KEY UPDATE `value` = :value2', [ 'menuProductId' => $this->menuProductId, 'option' => $this->option, 'value' => $this->value, 'value2' => $this->value ] ); } public function delete() { $this->getStore()->update( 'DELETE FROM `menu_product_options` WHERE `menuProductId` = :menuProductId AND `option` = :option', [ 'menuProductId' => $this->menuProductId, 'option' => $this->option ] ); } }