public function Get($Begin, $End, $Offset = '0', $Limit = '') { // Validate parameters, set today as default $BeginDate = strtotime($Begin); if ($BeginDate <= 0) { $BeginDate = date('Y-m-d'); } else { $BeginDate = date('Y-m-d', $BeginDate); } $EndDate = strtotime($End); if ($EndDate <= 0) { $EndDate = date('Y-m-d'); } else { $EndDate = date('Y-m-d', $EndDate); } if (!is_numeric($Offset)) { $Offset = 0; } if (!is_numeric($Limit)) { $Limit = ''; } $Sql = GDN::SQL(); $Sql->Select('d.Name, d.Body, d.Format')->Select('d.InsertUserID', '', 'UserID')->Select('DAY FROM d.EventCalendarDate', 'EXTRACT', 'EventCalendarDay')->From('Discussion d')->Where('d.EventCalendarDate >=', $BeginDate)->Where('d.EventCalendarDate <=', $EndDate)->OrderBy('d.EventCalendarDate')->Limit($Limit, $Offset); // add permission restrictions if necessary $Perms = DiscussionModel::CategoryPermissions(); if ($Perms !== TRUE) { $Sql->WhereIn('d.CategoryID', $Perms); } // return $Sql->GetSelect(); return $Sql->Get()->ResultArray(); }
public function Structure() { $Px = Gdn::Database()->DatabasePrefix; // Preparing to capture SQL (not execute) for operations that may need to be performed manually by the user Gdn::Structure()->CaptureOnly = TRUE; Gdn::Structure()->Database->CapturedSql = array(); // Comment table threshold check $CurrentComments = GDN::SQL()->Query("show table status where Name = '{$Px}Comment'")->FirstRow()->Rows; if ($CurrentComments > $this->TableRowThreshold) { // Does the number of rows exceed the threshold? // Execute functions for generating the SQL related to structural updates. SQL is saved in CapturedSql Gdn::Structure()->Table('Comment')->Column('OldID', 'int', true, 'key')->Column('ForeignID', 'varchar(32)', true, 'key')->Set(); } // Allow execution of structural operations Gdn::Structure()->CaptureOnly = FALSE; /** * If any SQL commands were captured, it means we have a problem. Throw an exception and report the necessary * SQL commands back to the user */ $CapturedSql = Gdn::Structure()->Database->CapturedSql; if (!empty($CapturedSql)) { throw new Exception("Due to the size of some tables, the following MySQL commands will need to be manually executed:\n" . implode("\n", $CapturedSql)); } Gdn::Structure()->Table('Activity')->Column('OldID', 'int', TRUE, 'key')->Set(); Gdn::Structure()->Table('Category')->Column('OldID', 'int', TRUE, 'key')->Column('ForeignID', 'varchar(32)', TRUE, 'key')->Set(); Gdn::Structure()->Table('Comment')->Column('OldID', 'int', true, 'key')->Column('ForeignID', 'varchar(32)', true, 'key')->Set(); Gdn::Structure()->Table('Conversation')->Column('OldID', 'int', TRUE, 'key')->Set(); Gdn::Structure()->Table('ConversationMessage')->Column('OldID', 'int', TRUE, 'key')->Set(); Gdn::Structure()->Table('Discussion')->Column('OldID', 'int', TRUE, 'key')->Set(); Gdn::Structure()->Table('Media')->Column('OldID', 'int', TRUE, 'key')->Set(); Gdn::Structure()->Table('Role')->Column('OldID', 'int', TRUE, 'key')->Set(); Gdn::Structure()->Table('Tag')->Column('OldID', 'int', TRUE, 'key')->Set(); Gdn::Structure()->Table('TagDiscussion')->Column('OldCategoryID', 'int', TRUE, 'key')->Set(); Gdn::Structure()->Table('User')->Column('OldID', 'int', TRUE, 'key')->Set(); $Construct = Gdn::Database()->Structure(); $Construct->Table('Poll'); if ($Construct->TableExists()) { Gdn::Structure()->Table('Poll')->Column('OldID', 'int', TRUE, 'key')->Set(); Gdn::Structure()->Table('PollOption')->Column('OldID', 'int', TRUE, 'key')->Set(); } }