Allow moving a version to another app
This commit is contained in:
committed by
Alexander Nicolaysen Sørnes
parent
8501de46ac
commit
c7da357a4c
@@ -957,11 +957,19 @@ class Application {
|
|||||||
return 'appId';
|
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 = "";
|
$sLimit = "";
|
||||||
$sOrdering = $bAscending ? "ASC" : "DESC";
|
$sOrdering = $bAscending ? "ASC" : "DESC";
|
||||||
|
|
||||||
|
if($sOrderBy == 'default')
|
||||||
|
{
|
||||||
|
if($sState == 'queued')
|
||||||
|
$sOrderBy = 'appId';
|
||||||
|
else
|
||||||
|
$sOrderBy = 'appName';
|
||||||
|
}
|
||||||
|
|
||||||
$sExtraTables = '';
|
$sExtraTables = '';
|
||||||
$sWhereFilter = $oFilters ? $oFilters->getWhereClause() : '';
|
$sWhereFilter = $oFilters ? $oFilters->getWhereClause() : '';
|
||||||
$aOptions = $oFilters ? $oFilters->getOptions() : array('onlyDownloadable' => 'false', 'appCategory' => null);
|
$aOptions = $oFilters ? $oFilters->getOptions() : array('onlyDownloadable' => 'false', 'appCategory' => null);
|
||||||
|
|||||||
@@ -842,6 +842,33 @@ class ObjectManager
|
|||||||
echo '</form>';
|
echo '</form>';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* 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
|
/* Move all the object's children to another object of the same type, and
|
||||||
delete the original object afterwards */
|
delete the original object afterwards */
|
||||||
public function move_children($iNewId)
|
public function move_children($iNewId)
|
||||||
@@ -875,6 +902,56 @@ class ObjectManager
|
|||||||
$this->delete_entry("Duplicate entry");
|
$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.<br>\n";
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Display some help text */
|
||||||
|
echo "<p>Move ".$oObject->objectMakeLink()." to the parent entry ";
|
||||||
|
echo "selected below:</p>\n";
|
||||||
|
|
||||||
|
echo "<table width=\"50%\" cellpadding=\"3\">\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.<br>\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(),
|
||||||
|
"<a href=\"".$this->makeUrl('changeParent', $this->iId).
|
||||||
|
"&iNewId=".$oCandidate->objectGetId()."\">Move here</a>"),
|
||||||
|
($i % 2) ? "color0" : "color1");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
echo "</table>\n";
|
||||||
|
}
|
||||||
|
|
||||||
/* Display a page where the user can select which object the children of the current
|
/* Display a page where the user can select which object the children of the current
|
||||||
object can be moved to */
|
object can be moved to */
|
||||||
public function display_move_children()
|
public function display_move_children()
|
||||||
@@ -1036,6 +1113,18 @@ class ObjectManager
|
|||||||
exit;
|
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 "<a href=\"".$this->makeUrl("showChangeParent", $this->iId,
|
||||||
|
"Move to another parent entry")."\">Move to another parent entry</a>\n";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private function displayMoveChildren($oObject)
|
private function displayMoveChildren($oObject)
|
||||||
{
|
{
|
||||||
/* Display a link to the move child objects page if the class has the necessary
|
/* 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
|
// display the move children entry
|
||||||
$this->displayMoveChildren($oObject);
|
$this->displayMoveChildren($oObject);
|
||||||
|
echo " ";
|
||||||
|
$this->displayChangeParent($oObject);
|
||||||
|
|
||||||
echo html_back_link(1, $sBackLink);
|
echo html_back_link(1, $sBackLink);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -774,6 +774,11 @@ class version {
|
|||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function objectSetParent($iNewId, $sClass = '')
|
||||||
|
{
|
||||||
|
$this->iAppId = $iNewId;
|
||||||
|
}
|
||||||
|
|
||||||
/* Not standard OM function yet, but will be in the future */
|
/* Not standard OM function yet, but will be in the future */
|
||||||
public function objectGetParent($sClass = '')
|
public function objectGetParent($sClass = '')
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -85,6 +85,13 @@ if($sAction)
|
|||||||
$oObject->handle_anonymous_submission();
|
$oObject->handle_anonymous_submission();
|
||||||
break;
|
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':
|
case 'moveChildren':
|
||||||
/* Provided the necessary values are present, an object's children may be moved
|
/* Provided the necessary values are present, an object's children may be moved
|
||||||
without any confirmation */
|
without any confirmation */
|
||||||
@@ -121,6 +128,10 @@ if($oObject->getId() && $sAction != "add")
|
|||||||
$oObject->display_entry_for_editing($aClean, $sErrors);
|
$oObject->display_entry_for_editing($aClean, $sErrors);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case 'showChangeParent':
|
||||||
|
$oObject->display_change_parent();
|
||||||
|
break;
|
||||||
|
|
||||||
case "showMoveChildren":
|
case "showMoveChildren":
|
||||||
$oObject->display_move_children();
|
$oObject->display_move_children();
|
||||||
break;
|
break;
|
||||||
|
|||||||
Reference in New Issue
Block a user