/** * 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'); }