/**
* Set the sort order for data on an arbitrary database table.
*
* Expect post values TransientKey, Target (redirect URL), Table (database table name),
* and TableID (an array of sort order => unique ID).
*
* @since 2.0.0
* @access public
*/
public function sort()
{
$this->permission('Garden.Settings.Manage');
if (Gdn::request()->isAuthenticatedPostBack()) {
$TableID = Gdn::request()->Post('TableID');
if ($TableID) {
$Rows = Gdn::request()->Post($TableID);
if (is_array($Rows)) {
$Table = str_replace(array('Table', '`'), '', $TableID);
$ModelName = $Table . 'Model';
if (class_exists($ModelName)) {
$TableModel = new $ModelName();
} else {
$TableModel = new Gdn_Model($Table);
}
foreach ($Rows as $Sort => $ID) {
if (strpos($ID, '_') !== false) {
list(, $ID) = explode('_', $ID, 2);
}
if (!$ID) {
continue;
}
$TableModel->setField($ID, 'Sort', $Sort);
}
$this->setData('Result', true);
}
}
}
$this->render('Blank');
}