From 0e9179a9e552f071a4235641a1d39f9cdb9a62a6 Mon Sep 17 00:00:00 2001 From: Uwe Steinmann Date: Thu, 12 Oct 2017 15:38:41 +0200 Subject: [PATCH] move most of the logic into the controller --- controllers/class.DocumentAccess.php | 148 ++++++++++++++++++++++++ controllers/class.EditDocument.php | 161 +++++++++++++++++++++++++++ 2 files changed, 309 insertions(+) create mode 100644 controllers/class.DocumentAccess.php create mode 100644 controllers/class.EditDocument.php diff --git a/controllers/class.DocumentAccess.php b/controllers/class.DocumentAccess.php new file mode 100644 index 000000000..aaeb6a457 --- /dev/null +++ b/controllers/class.DocumentAccess.php @@ -0,0 +1,148 @@ + + * @copyright Copyright (C) 2010-2017 Uwe Steinmann + * @version Release: @package_version@ + */ + +/** + * Class which does the busines logic for editing a folder + * + * @category DMS + * @package SeedDMS + * @author Uwe Steinmann + * @copyright Copyright (C) 2010-2017 Uwe Steinmann + * @version Release: @package_version@ + */ +class SeedDMS_Controller_DocumentAccess extends SeedDMS_Controller_Common { + + public function run() { + $dms = $this->params['dms']; + $user = $this->params['user']; + $folder = $this->params['folder']; + $document = $this->params['document']; + $settings = $this->params['settings']; + $action = $this->params['action']; + + // Change owner ----------------------------------------------------------- + if ($action == "setowner") { + if(false === $this->callHook('preSetOwner', $document)) { + if(empty($this->errormsg)) + $this->errormsg = 'hook_preSetOwner_failed'; + return null; + } + $newowner = $this->params['newowner']; + $oldowner = $document->getOwner(); + if($document->setOwner($newowner)) { + if(false === $this->callHook('postSetOwner', $document, $oldowner)) { + if(empty($this->errormsg)) + $this->errormsg = 'hook_postSetOwner_failed'; + return null; + } + } + } elseif ($action == "notinherit") { + if(false === $this->callHook('preSetNotInherit', $document)) { + if(empty($this->errormsg)) + $this->errormsg = 'hook_preSetNotInherit_failed'; + return null; + } + + /* Get default access before access is not longer inherited. This + * will return the default access from the parent folder. + */ + $defAccess = $document->getDefaultAccess(); + if(!$document->setInheritAccess(false)) { + return false; + } + + if(!$document->setDefaultAccess($defAccess)) { + return false; + } + + //copy ACL of parent folder + $mode = $this->params['mode']; + if ($mode == "copy") { + $accessList = $folder->getAccessList(); + foreach ($accessList["users"] as $userAccess) + $document->addAccess($userAccess->getMode(), $userAccess->getUserID(), true); + foreach ($accessList["groups"] as $groupAccess) + $document->addAccess($groupAccess->getMode(), $groupAccess->getGroupID(), false); + } + + if(false === $this->callHook('postSetNotInherit', $document)) { + if(empty($this->errormsg)) + $this->errormsg = 'hook_postSetNotInherit_failed'; + return null; + } + } elseif ($action == "inherit") { + if(false === $this->callHook('preSetInherit', $document)) { + if(empty($this->errormsg)) + $this->errormsg = 'hook_preSetInherit_failed'; + return null; + } + if(!$document->clearAccessList() || !$document->setInheritAccess(true)) { + return false; + } + + if(false === $this->callHook('postSetInherit', $document)) { + if(empty($this->errormsg)) + $this->errormsg = 'hook_postSetInherit_failed'; + return null; + } + } elseif ($action == "setdefault") { + if(false === $this->callHook('preSetDefault', $document)) { + if(empty($this->errormsg)) + $this->errormsg = 'hook_preSetDefault_failed'; + return null; + } + + $mode = $this->params['mode']; + if(!$document->setDefaultAccess($mode)) { + return false; + } + + if(false === $this->callHook('postSetDefault', $document)) { + if(empty($this->errormsg)) + $this->errormsg = 'hook_postSetDefault_failed'; + return null; + } + } elseif ($action == "editaccess") { + $mode = $this->params['mode']; + $userid = $this->params['userid']; + $groupid = $this->params['groupid']; + if ($userid) { + $document->changeAccess($mode, $userid, true); + } + elseif ($groupid) { + $document->changeAccess($mode, $groupid, false); + } + } elseif ($action == "delaccess") { + $userid = $this->params['userid']; + $groupid = $this->params['groupid']; + if ($userid) { + $document->removeAccess($userid, true); + } + elseif ($groupid) { + $document->removeAccess($groupid, false); + } + } elseif ($action == "addaccess") { + $mode = $this->params['mode']; + $userid = $this->params['userid']; + $groupid = $this->params['groupid']; + if ($userid && $userid != -1) { + $document->addAccess($mode, $userid, true); + } + elseif ($groupid && $groupid != -1) { + $document->addAccess($mode, $groupid, false); + } + } + + return true; + } +} diff --git a/controllers/class.EditDocument.php b/controllers/class.EditDocument.php new file mode 100644 index 000000000..356907ae6 --- /dev/null +++ b/controllers/class.EditDocument.php @@ -0,0 +1,161 @@ + + * @copyright Copyright (C) 2010-2013 Uwe Steinmann + * @version Release: @package_version@ + */ + +/** + * Class which does the busines logic for editing a document + * + * @category DMS + * @package SeedDMS + * @author Uwe Steinmann + * @copyright Copyright (C) 2010-2013 Uwe Steinmann + * @version Release: @package_version@ + */ +class SeedDMS_Controller_EditDocument extends SeedDMS_Controller_Common { + + public function run() { + $dms = $this->params['dms']; + $user = $this->params['user']; + $settings = $this->params['settings']; + $document = $this->params['document']; + $name = $this->params['name']; + + if(false === $this->callHook('preEditDocument')) { + if(empty($this->errormsg)) + $this->errormsg = 'hook_preEditDocument_failed'; + return null; + } + + $result = $this->callHook('editDocument', $document); + if($result === null) { + $name = $this->params['name']; + $oldname = $document->getName()); + if($oldname != $name) + if(!$document->setName($name)) + return false; + + $comment = $this->params['comment']; + if(($oldcomment = $document->getComment()) != $comment) + if(!$document->setComment($comment)) + return false; + + $expires = $this->params['expires']; + $oldexpires = $document->getExpires(); + if ($expires != $oldexpires) { + if(!$this->callHook('preSetExpires', $document, $expires)) { + } + + if(!$document->setExpires($expires)) { + return false; + } + + $document->verifyLastestContentExpriry(); + + if(!$this->callHook('postSetExpires', $document, $expires)) { + } + } + + $keywords = $this->params['keywords']; + $oldkeywords = $document->getKeywords(); + if ($oldkeywords != $keywords) { + if(!$this->callHook('preSetKeywords', $document, $keywords, $oldkeywords)) { + } + + if(!$document->setKeywords($keywords)) { + return false; + } + + if(!$this->callHook('postSetKeywords', $document, $keywords, $oldkeywords)) { + } + } + + $categories = $this->params['categories']; + $oldcategories = $document->getCategories(); + if($categories) { + $categoriesarr = array(); + foreach($categories as $catid) { + if($cat = $dms->getDocumentCategory($catid)) { + $categoriesarr[] = $cat; + } + + } + $oldcatsids = array(); + foreach($oldcategories as $oldcategory) + $oldcatsids[] = $oldcategory->getID(); + + if (count($categoriesarr) != count($oldcategories) || + array_diff($categories, $oldcatsids)) { + if(!$this->callHook('preSetCategories', $document, $categoriesarr, $oldcategories)) { + } + if(!$document->setCategories($categoriesarr)) { + return false; + } + if(!$this->callHook('postSetCategories', $document, $categoriesarr, $oldcategories)) { + } + } + } elseif($oldcategories) { + if(!$this->callHook('preSetCategories', $document, array(), $oldcategories)) { + } + if(!$document->setCategories(array())) { + return false; + } + if(!$this->callHook('postSetCategories', $document, array(), $oldcategories)) { + } + } + + $attributes = $this->params['attributes']; + $oldattributes = $document->getAttributes(); + if($attributes) { + foreach($attributes as $attrdefid=>$attribute) { + $attrdef = $dms->getAttributeDefinition($attrdefid); + if($attribute) { + if(!$attrdef->validate($attribute)) { + $this->errormsg = getAttributeValidationText($attrdef->getValidationError(), $attrdef->getName(), $attribute); + return false; + } + + if(!isset($oldattributes[$attrdefid]) || $attribute != $oldattributes[$attrdefid]->getValue()) { + if(!$document->setAttributeValue($dms->getAttributeDefinition($attrdefid), $attribute)) + return false; + } + } elseif($attrdef->getMinValues() > 0) { + $this->errormsg = getMLText("attr_min_values", array("attrname"=>$attrdef->getName())); + } elseif(isset($oldattributes[$attrdefid])) { + if(!$document->removeAttribute($dms->getAttributeDefinition($attrdefid))) + return false; + } + } + } + foreach($oldattributes as $attrdefid=>$oldattribute) { + if(!isset($attributes[$attrdefid])) { + if(!$document->removeAttribute($dms->getAttributeDefinition($attrdefid))) + return false; + } + } + + $sequence = $this->params['sequence']; + if(strcasecmp($sequence, "keep")) { + if($document->setSequence($sequence)) { + } else { + return false; + } + } + + if(!$this->callHook('postEditDocument')) { + } + + } else + return $result; + + return true; + } +}