2014-12-08 13:43:04 +00:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* Implementation of EditFolder controller
|
|
|
|
*
|
|
|
|
* @category DMS
|
|
|
|
* @package SeedDMS
|
|
|
|
* @license GPL 2
|
|
|
|
* @version @version@
|
|
|
|
* @author Uwe Steinmann <uwe@steinmann.cx>
|
|
|
|
* @copyright Copyright (C) 2010-2013 Uwe Steinmann
|
|
|
|
* @version Release: @package_version@
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Class which does the busines logic for editing a folder
|
|
|
|
*
|
|
|
|
* @category DMS
|
|
|
|
* @package SeedDMS
|
|
|
|
* @author Uwe Steinmann <uwe@steinmann.cx>
|
|
|
|
* @copyright Copyright (C) 2010-2013 Uwe Steinmann
|
|
|
|
* @version Release: @package_version@
|
|
|
|
*/
|
|
|
|
class SeedDMS_Controller_EditFolder extends SeedDMS_Controller_Common {
|
|
|
|
|
|
|
|
public function run() {
|
|
|
|
$dms = $this->params['dms'];
|
|
|
|
$user = $this->params['user'];
|
|
|
|
$settings = $this->params['settings'];
|
|
|
|
$folder = $this->params['folder'];
|
|
|
|
|
2017-10-12 13:40:38 +00:00
|
|
|
if(false === $this->callHook('preEditFolder')) {
|
|
|
|
if(empty($this->errormsg))
|
|
|
|
$this->errormsg = 'hook_preEditFolder_failed';
|
|
|
|
return null;
|
2014-12-08 13:43:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
$result = $this->callHook('editFolder', $folder);
|
|
|
|
if($result === null) {
|
2017-10-12 13:40:38 +00:00
|
|
|
$name = $this->params['name'];
|
2014-12-08 13:43:04 +00:00
|
|
|
if(($oldname = $folder->getName()) != $name)
|
|
|
|
if(!$folder->setName($name))
|
|
|
|
return false;
|
|
|
|
|
2017-10-12 13:40:38 +00:00
|
|
|
$comment = $this->params['comment'];
|
2014-12-08 13:43:04 +00:00
|
|
|
if(($oldcomment = $folder->getComment()) != $comment)
|
|
|
|
if(!$folder->setComment($comment))
|
|
|
|
return false;
|
|
|
|
|
2017-10-12 13:40:38 +00:00
|
|
|
$attributes = $this->params['attributes'];
|
2014-12-08 13:43:04 +00:00
|
|
|
$oldattributes = $folder->getAttributes();
|
|
|
|
if($attributes) {
|
|
|
|
foreach($attributes as $attrdefid=>$attribute) {
|
|
|
|
$attrdef = $dms->getAttributeDefinition($attrdefid);
|
2019-12-13 14:00:04 +00:00
|
|
|
if(null === ($ret = $this->callHook('validateAttribute', $attrdef, $attribute))) {
|
2014-12-08 13:43:04 +00:00
|
|
|
if($attribute) {
|
2015-04-15 14:12:11 +00:00
|
|
|
if(!$attrdef->validate($attribute)) {
|
2016-10-27 07:19:35 +00:00
|
|
|
$this->errormsg = getAttributeValidationText($attrdef->getValidationError(), $attrdef->getName(), $attribute);
|
2015-04-15 14:12:11 +00:00
|
|
|
return false;
|
|
|
|
}
|
2016-10-27 07:19:35 +00:00
|
|
|
|
2014-12-08 13:43:04 +00:00
|
|
|
if(!isset($oldattributes[$attrdefid]) || $attribute != $oldattributes[$attrdefid]->getValue()) {
|
|
|
|
if(!$folder->setAttributeValue($dms->getAttributeDefinition($attrdefid), $attribute))
|
|
|
|
return false;
|
|
|
|
}
|
2016-10-27 08:55:33 +00:00
|
|
|
} elseif($attrdef->getMinValues() > 0) {
|
|
|
|
$this->errormsg = getMLText("attr_min_values", array("attrname"=>$attrdef->getName()));
|
2014-12-08 13:43:04 +00:00
|
|
|
} elseif(isset($oldattributes[$attrdefid])) {
|
|
|
|
if(!$folder->removeAttribute($dms->getAttributeDefinition($attrdefid)))
|
|
|
|
return false;
|
|
|
|
}
|
2019-12-13 14:00:04 +00:00
|
|
|
} else {
|
|
|
|
if($ret === false)
|
|
|
|
return false;
|
|
|
|
}
|
2014-12-08 13:43:04 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
foreach($oldattributes as $attrdefid=>$oldattribute) {
|
|
|
|
if(!isset($attributes[$attrdefid])) {
|
|
|
|
if(!$folder->removeAttribute($dms->getAttributeDefinition($attrdefid)))
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-10-12 13:40:38 +00:00
|
|
|
$sequence = $this->params['sequence'];
|
2014-12-08 13:43:04 +00:00
|
|
|
if(strcasecmp($sequence, "keep")) {
|
|
|
|
if($folder->setSequence($sequence)) {
|
|
|
|
} else {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-01-17 17:25:39 +00:00
|
|
|
} elseif($result === false) {
|
|
|
|
if(empty($this->errormsg))
|
|
|
|
$this->errormsg = 'hook_editFolder_failed';
|
|
|
|
return false;
|
|
|
|
}
|
2014-12-08 13:43:04 +00:00
|
|
|
|
2019-01-17 17:25:39 +00:00
|
|
|
if(!$this->callHook('postEditFolder')) {
|
|
|
|
}
|
2014-12-08 13:43:04 +00:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|