mirror of
https://git.code.sf.net/p/seeddms/code
synced 2025-02-06 07:04:57 +00:00
move most of the logic into the controller
This commit is contained in:
parent
262fa75c88
commit
0e9179a9e5
148
controllers/class.DocumentAccess.php
Normal file
148
controllers/class.DocumentAccess.php
Normal file
|
@ -0,0 +1,148 @@
|
|||
<?php
|
||||
/**
|
||||
* Implementation of DocumentAccess controller
|
||||
*
|
||||
* @category DMS
|
||||
* @package SeedDMS
|
||||
* @license GPL 2
|
||||
* @version @version@
|
||||
* @author Uwe Steinmann <uwe@steinmann.cx>
|
||||
* @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 <uwe@steinmann.cx>
|
||||
* @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;
|
||||
}
|
||||
}
|
161
controllers/class.EditDocument.php
Normal file
161
controllers/class.EditDocument.php
Normal file
|
@ -0,0 +1,161 @@
|
|||
<?php
|
||||
/**
|
||||
* Implementation of EditDocument 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 document
|
||||
*
|
||||
* @category DMS
|
||||
* @package SeedDMS
|
||||
* @author Uwe Steinmann <uwe@steinmann.cx>
|
||||
* @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;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user