<?php
namespace Moto\Application\Styles; use Moto\Application\Model; use Moto\Application\Model\AbstractModel; class StyleModel extends AbstractModel { protected $_fields = array( 'id' => array(), 'name' => array( 'default' => '' ), 'class_name' => array( 'default' => '' ), 'type' => array( 'default' => '' ), 'is_system' => array( 'default' => 0 ), 'is_responsive' => array( 'default' => 0 ), 'properties' => array( 'default' => '{}' ), 'link' => array( 'default' => '{}' ), 'modified' => array(), 'created' => 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']); } if (empty($data['link']) && $data['type'] == 'text') { $data['link'] = '{"desktop":{"base":{"color":"#1e0fbe"},"hover":{"color":"#1e0fbe","text-decoration":"underline"}}}'; } if (!is_string($data['link'])) { $data['link'] = json_encode($data['link']); } 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']); } if (empty($data['link']) && $data['type'] == 'text') { $data['link'] = '{"desktop":{"base":{"color":"#1e0fbe"},"hover":{"color":"#1e0fbe","text-decoration":"underline"}}}'; } if (!is_string($data['link'])) { $data['link'] = json_encode($data['link']); } 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['class_name']); unset($data['is_system']); } return $data; } } 