<?php
namespace Moto\Application\MediaLibrary\Validator; use Moto; class UpdateItem extends Moto\Validator\AbstractValidator { const ERROR_BAD_STRUCTURE = 'badStructure'; const ERROR_NO_FIELD_FOUND = 'noFieldFound'; protected $messageTemplates = array( self::ERROR_BAD_STRUCTURE => 'Tree is not array', ); protected $_errors = array(); public function isValid($fields) { if (!is_array($fields)) { $this->error(self::ERROR_BAD_STRUCTURE); return false; } $model = new Moto\Application\MediaLibrary\MediaItemModel(); $model->isModified(); foreach($fields as $field => $value) { if (!$model->isExistsField($field)) { if (!array_key_exists(self::ERROR_NO_FIELD_FOUND, $this->_errors)) { $this->_errors[self::ERROR_NO_FIELD_FOUND] = array(); } $this->_errors[self::ERROR_NO_FIELD_FOUND][$field] = 'Not exists'; } } $isValid = empty($this->_errors); return $isValid; } public function getMessages() { return $this->_errors; } } 