<?php
namespace Moto\Application\MediaLibrary\InputFilter; use Moto\Application\MediaLibrary; use Moto\InputFilter\AbstractInputFilter; use Traversable; use Zend\InputFilter\InputFilterInterface; use Moto; class RenameFolder extends AbstractInputFilter { protected $_name = 'mediaLibraryFolder.rename'; public function init() { $this->add(array( 'name' => 'id', 'required' => true, 'filters' => array( array('name' => 'StripTags'), array('name' => 'StringTrim'), ), 'validators' => array( array( "name" => "Digits", 'break_chain_on_failure' => true, ), array( 'name' => 'Db\RecordExists', 'options' => array( 'table' => Moto\Config::get('database.prefix') . 'media_folders', 'field' => 'id', 'adapter' => Moto\Config::get('databaseAdapter'), ) ) ), )); $this->_addElementName(); } protected function _addElementName($currentId = 0, $parentId = 0) { $this->remove('name'); $this->add(array( 'name' => 'name', 'required' => true, 'filters' => array( array('name' => 'StripTags'), array('name' => 'StringTrim'), ), 'validators' => array( array( 'name' => 'StringLength', 'options' => array( 'encoding' => 'UTF-8', 'min' => 1, 'max' => 200, ), 'break_chain_on_failure' => true, ), array( 'name' => 'Moto\Application\MediaLibrary\Validator\UniqueTreeItem', 'options' => array( 'table' => Moto\Config::get('database.prefix') . 'media_folders', 'field' => 'name', 'adapter' => Moto\Config::get('databaseAdapter'), 'parent_id' => $parentId, 'exclude' => array( 'field' => 'id', 'value' => (int)$currentId, ) ) ) ), )); } public function setData($data) { if (!empty($data['id'])) { $table = new MediaLibrary\MediaFoldersTable(); $folder = $table->getById($data['id']); if ($folder) { $this->_addElementName($data['id'], $folder['parent_id']); } } $result = parent::setData($data); return $result; } }