<?php
namespace Moto\Application\Fonts; use Moto\Application\Model; use Moto\Application\Model\AbstractModel; class FontModel extends AbstractModel { protected $_fields = array( 'id' => array( 'type' => 'int', ), 'name' => array( 'default' => '' ), 'family' => array( 'default' => '' ), 'category' => array( 'default' => '' ), 'variants' => array( 'default' => '[]', 'type' => 'array', ), 'subsets' => array( 'default' => '[]', 'type' => 'array', ), 'version' => array( 'default' => '' ), 'last_modified' => array( 'default' => '' ), 'active' => array( 'default' => 1, 'type' => 'int', ), 'is_protected' => array( 'default' => 0, 'type' => 'int', ), 'active_variants' => array( 'default' => '[]', 'type' => 'array', ), 'active_subsets' => array( 'default' => '[]', 'type' => 'array', ), 'provider' => array( 'default' => '' ), 'created' => array(), 'modified' => array(), 'del' => array( 'default' => false, ), ); public function __construct() { parent::__construct(); $this->created = date('Y-m-d H:i:s'); $this->modified = $this->created; } public function toInsert() { $data = parent::toInsert(); $data = $this->_prepareDataToSave($data); return $data; } public function toUpdate() { $this->modified = date('Y-m-d H:i:s'); $data = parent::toUpdate(); $data = $this->_prepareDataToSave($data); return $data; } protected function _prepareDataToSave($data) { if (!is_string($data['variants'])) { $data['variants'] = json_encode($data['variants']); } if (!is_string($data['subsets'])) { $data['subsets'] = json_encode($data['subsets']); } if (!is_string($data['active_variants'])) { $data['active_variants'] = json_encode($data['active_variants']); } if (!is_string($data['active_subsets'])) { $data['active_subsets'] = json_encode($data['active_subsets']); } return $data; } public function __clone() { $this->id = null; $this->created = date('Y-m-d H:i:s'); $this->modified = $this->created; } }