<?php
namespace Moto\Application\Presets; use Moto\Application\Model; use Moto\Application\Model\AbstractModel; class PresetModel extends AbstractModel { protected $_fields = array( 'id' => array(), 'name' => array( 'default' => '' ), 'widget_name' => array( 'default' => '' ), 'class_name' => array( 'default' => '' ), 'is_system' => array( 'default' => 0 ), 'is_responsive' => array( 'default' => 0 ), 'properties' => array( 'default' => '{}' ), 'template' => array( 'default' => 'default' ), 'created' => array(), 'modified' => array(), ); public $is_system = 0; public $is_responsive = 0; public $properties; public function __construct() { parent::__construct(); $this->created = date('Y-m-d H:i:s'); $this->modified = $this->created; } public function toInsert() { $data = parent::toInsert(); if (empty($data['properties'])) { $data['properties'] = '{}'; } if (!is_string($data['properties'])) { $data['properties'] = json_encode($data['properties']); } return $data; } public function toUpdate() { $this->modified = date('Y-m-d H:i:s'); $data = parent::toUpdate(); if (empty($data['properties'])) { $data['properties'] = '{}'; } if (!is_string($data['properties'])) { $data['properties'] = json_encode($data['properties']); } return $data; } public function __clone() { $this->created = date('Y-m-d H:i:s'); $this->modified = $this->created; } protected function _preSetFromArray($data) { if ($this->is_system) { unset($data['name']); unset($data['widget_name']); unset($data['class_name']); unset($data['is_system']); } return $data; } public function getTemplatePath() { if (!empty($this->template) && $this->template[0] === '@') { return $this->template; } return '@websiteWidgets/' . $this->widget_name .'/templates/' . $this->template . '.twig.css'; } } 