diff --git a/include/application.php b/include/application.php index 34a8001..b4c8a61 100644 --- a/include/application.php +++ b/include/application.php @@ -957,11 +957,19 @@ class Application { return 'appId'; } - public static function objectGetEntries($sState, $iRows = 0, $iStart = 0, $sOrderBy = "appId", $bAscending = TRUE, $oFilters = null) + public static function objectGetEntries($sState, $iRows = 0, $iStart = 0, $sOrderBy = 'default', $bAscending = TRUE, $oFilters = null) { $sLimit = ""; $sOrdering = $bAscending ? "ASC" : "DESC"; + if($sOrderBy == 'default') + { + if($sState == 'queued') + $sOrderBy = 'appId'; + else + $sOrderBy = 'appName'; + } + $sExtraTables = ''; $sWhereFilter = $oFilters ? $oFilters->getWhereClause() : ''; $aOptions = $oFilters ? $oFilters->getOptions() : array('onlyDownloadable' => 'false', 'appCategory' => null); diff --git a/include/objectManager.php b/include/objectManager.php index cfabde9..e44f6cc 100644 --- a/include/objectManager.php +++ b/include/objectManager.php @@ -842,6 +842,33 @@ class ObjectManager echo ''; } + /* Move the object to another parent entry */ + public function change_parent($iNewId) + { + $oObject = new $this->sClass($this->iId); + $oParent = $oObject->objectGetParent(); + $sParentClass = get_class($oParent); + $oNewParent = new $sParentClass($iNewId); + + /* The user needs to have edit rights to both the old and the new object + If you have edit rights to an object then you should have edit rights + to its child objects as well */ + if(!$oObject->canEdit() || !$oParent->canEdit() || !$oNewParent->canEdit()) + return FALSE; + + $oObject->objectSetParent($oNewParent->objectGetId()); + + if($oObject->update()) + { + addmsg('The entry was moved successfully', 'green'); + } else + { + addmsg('Failed to move the entry', 'red'); + } + + $this->return_to_url(APPDB_ROOT); + } + /* Move all the object's children to another object of the same type, and delete the original object afterwards */ public function move_children($iNewId) @@ -875,6 +902,56 @@ class ObjectManager $this->delete_entry("Duplicate entry"); } + /* Display a page where the user can move the current object to another parent */ + public function display_change_parent() + { + $oObject = new $this->sClass($this->iId); + if(!$oObject->canEdit()) + { + echo "Insufficient privileges.
\n"; + return FALSE; + } + + /* Display some help text */ + echo "

Move ".$oObject->objectMakeLink()." to the parent entry "; + echo "selected below:

\n"; + + echo "\n"; + echo html_tr(array( + "Name", + "Move here"), + "color4"); + + $oParent = $oObject->objectGetParent(); + + /* We only allow moving to non-queued objects */ + if(!$hResult = $oParent->objectGetEntries('accepted')) + { + echo "Failed to get list of objects.
\n"; + return FALSE; + } + + for($i = 0; $oRow = query_fetch_object($hResult); $i++) + { + $sParentClass = get_class($oParent); + $oCandidate = new $sParentClass(null, $oRow); + if($oCandidate->objectGetId() == $oParent->objectGetId()) + { + $i++; + continue; + } + + echo html_tr(array( + $oCandidate->objectMakeLink(), + "makeUrl('changeParent', $this->iId). + "&iNewId=".$oCandidate->objectGetId()."\">Move here"), + ($i % 2) ? "color0" : "color1"); + } + + + echo "
\n"; + } + /* Display a page where the user can select which object the children of the current object can be moved to */ public function display_move_children() @@ -1036,6 +1113,18 @@ class ObjectManager exit; } + private function displayChangeParent($oObject) + { + /* Display a link to the move child objects page if the class has the necessary + functions and the user has edit rights. Not all classes have child objects. */ + if(method_exists($oObject, "objectSetParent") && + method_exists($oObject, "objectGetId") && $oObject->canEdit()) + { + echo "makeUrl("showChangeParent", $this->iId, + "Move to another parent entry")."\">Move to another parent entry\n"; + } + } + private function displayMoveChildren($oObject) { /* Display a link to the move child objects page if the class has the necessary @@ -1115,6 +1204,8 @@ class ObjectManager // display the move children entry $this->displayMoveChildren($oObject); + echo "     "; + $this->displayChangeParent($oObject); echo html_back_link(1, $sBackLink); } diff --git a/include/version.php b/include/version.php index 6de74d3..52b0bae 100644 --- a/include/version.php +++ b/include/version.php @@ -774,6 +774,11 @@ class version { return TRUE; } + public function objectSetParent($iNewId, $sClass = '') + { + $this->iAppId = $iNewId; + } + /* Not standard OM function yet, but will be in the future */ public function objectGetParent($sClass = '') { diff --git a/objectManager.php b/objectManager.php index 90c79d0..012c845 100644 --- a/objectManager.php +++ b/objectManager.php @@ -85,6 +85,13 @@ if($sAction) $oObject->handle_anonymous_submission(); break; + case 'changeParent': + /* Provided the necessary values are present, an object may be moved + to another parent without any confirmation */ + if($oObject->getId() && getInput('iNewId', $aClean)) + $oObject->change_parent($aClean['iNewId']); + break; + case 'moveChildren': /* Provided the necessary values are present, an object's children may be moved without any confirmation */ @@ -121,6 +128,10 @@ if($oObject->getId() && $sAction != "add") $oObject->display_entry_for_editing($aClean, $sErrors); break; + case 'showChangeParent': + $oObject->display_change_parent(); + break; + case "showMoveChildren": $oObject->display_move_children(); break;