Ignore:
Timestamp:
Jan 4, 2021, 9:55:40 PM (3 years ago)
Author:
chronos
Message:
  • Modified: More work on modules models initialization.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Modules/Wiki/Wiki.php

    r887 r893  
    1515  }
    1616
    17   function DoInstall(): void
    18   {
    19     parent::Install();
    20     $this->Database->Query('CREATE TABLE IF NOT EXISTS `WikiPage` (
    21     `Id` int(11) NOT NULL AUTO_INCREMENT,
    22     `Name` varchar(255) NOT NULL,
    23     `NormalizedName` varchar(255) NOT NULL,
    24     `VisibleInMenu` int(11) NOT NULL,
    25     PRIMARY KEY (`Id`),
    26     UNIQUE KEY `Name` (`Name`),
    27     KEY `VisibleInMenu` (`VisibleInMenu`)
    28 ) ENGINE=InnoDB  DEFAULT CHARSET=utf8 AUTO_INCREMENT=1');
    29     $this->Database->Query('CREATE TABLE IF NOT EXISTS `WikiPageContent` (
    30     `Id` int(11) NOT NULL AUTO_INCREMENT,
    31     `Page` int(11) NOT NULL,
    32     `Time` datetime NOT NULL,
    33     `Content` text NOT NULL,
    34     `User` int(11) NOT NULL,
    35     PRIMARY KEY (`Id`),
    36     KEY `User` (`User`),
    37     KEY `Page` (`Page`)
    38 ) ENGINE=InnoDB  DEFAULT CHARSET=utf8 AUTO_INCREMENT=1');
    39     $this->Database->Query('ALTER TABLE `WikiPageContent`
    40 ADD CONSTRAINT `WikiPageContent_ibfk_2` FOREIGN KEY (`Page`) REFERENCES `WikiPage` (`Id`),
    41 ADD CONSTRAINT `WikiPageContent_ibfk_1` FOREIGN KEY (`User`) REFERENCES `User` (`ID`)');
    42   }
    43 
    44   function DoUnInstall(): void
    45   {
    46     $this->Database->query('DELETE TABLE `WikiPageContent`');
    47     $this->Database->query('DELETE TABLE `WikiPage`;');
     17  function GetModels(): array
     18  {
     19    return array('WikiPage', 'WikiPageContent');
    4820  }
    4921
     
    5123  {
    5224    $this->LoadPages();
    53   }
    54 
    55   function DoStop(): void
    56   {
    5725  }
    5826
     
    7139      ), 2);
    7240    }
     41  }
     42}
     43
     44class WikiPage extends Model
     45{
     46  static function GetDesc(): ModelDesc
     47  {
     48    $Desc = new ModelDesc('WikiPage');
     49    $Desc->AddString('Name');
     50    $Desc->AddString('NormalizedName');
     51    $Desc->AddBoolean('VisibleInMenu');
     52    return $Desc;
     53  }
     54}
     55
     56class WikiPageContent extends Model
     57{
     58  static function GetDesc(): ModelDesc
     59  {
     60    $Desc = new ModelDesc('WikiPageContent');
     61    $Desc->AddReference('Page', 'Page');
     62    $Desc->AddDateTime('Time');
     63    $Desc->AddText('Content');
     64    $Desc->AddReference('User', 'User');
     65    return $Desc;
    7366  }
    7467}
Note: See TracChangeset for help on using the changeset viewer.