Ignore:
Timestamp:
Dec 30, 2020, 11:52:07 PM (4 years ago)
Author:
chronos
Message:
  • Added: More modules models installation.
File:
1 edited

Legend:

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

    r887 r891  
    133133  function DoInstall(): void
    134134  {
    135     $this->Database->query("CREATE TABLE IF NOT EXISTS `Subject` (
    136   `Id` int(11) NOT NULL AUTO_INCREMENT,
    137   `Name` varchar(64) NOT NULL DEFAULT '',
    138   `AddressStreet` varchar(64) NOT NULL DEFAULT '',
    139   `AddressTown` varchar(64) NOT NULL DEFAULT '',
    140   `AddressPSC` int(11) NOT NULL DEFAULT '0',
    141   `AddressCountry` int(11) NOT NULL,
    142   `IC` varchar(32) NOT NULL,
    143   `DIC` varchar(32) NOT NULL DEFAULT '',
    144   `PayVAT` int(11) NOT NULL,
    145   `MapPosition` int(11) DEFAULT NULL,
    146   `WWW` varchar(255) NOT NULL,
    147   `Note` varchar(255) NOT NULL,
    148   PRIMARY KEY (`Id`)
    149 ) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8;");
    150     $this->Database->query("CREATE TABLE IF NOT EXISTS `Contact` (
    151   `Id` int(11) NOT NULL AUTO_INCREMENT,
    152   `Category` int(11) NOT NULL,
    153   `Value` varchar(255) NOT NULL,
    154   `Subject` int(11) DEFAULT NULL,
    155   `User` int(11) DEFAULT NULL,
    156   `Description` varchar(255) NOT NULL,
    157   `Receive` tinyint(1) NOT NULL,
    158   PRIMARY KEY (`Id`)
    159 ) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8;");
    160     $this->System->Database->query("CREATE TABLE IF NOT EXISTS `ContactCategory` (
    161   `Id` int(11) NOT NULL AUTO_INCREMENT,
    162   `Name` varchar(255) NOT NULL,
    163   PRIMARY KEY (`Id`)
    164 ) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8;");
    165 
    166     $this->Database->query("ALTER TABLE `Subject`
    167 ADD CONSTRAINT `Subject_ibfk_1` FOREIGN KEY (`AddressCountry`) REFERENCES `Country` (`Id`),
    168 ADD CONSTRAINT `Subject_ibfk_2` FOREIGN KEY (`MapPosition`) REFERENCES `MapPosition` (`Id`);");
    169     $this->Database->query("ALTER TABLE `Contact`
    170     ADD CONSTRAINT `Contact_ibfk_1` FOREIGN KEY (`Category`) REFERENCES `ContactCategory` (`Id`),
    171     ADD CONSTRAINT `Contact_ibfk_2` FOREIGN KEY (`Subject`) REFERENCES `Subject` (`Id`),
    172     ADD CONSTRAINT `Contact_ibfk_3` FOREIGN KEY (`User`) REFERENCES `User` (`Id`);");
     135    $this->InstallModel(Country::GetDesc());
     136    $this->InstallModel(Subject::GetDesc());
     137    $this->InstallModel(ContactCategory::GetDesc());
     138    $this->InstallModel(Contact::GetDesc());
    173139  }
    174140
    175141  function DoUninstall(): void
    176142  {
    177     $this->Database->query('DROP TABLE `Contact`');
    178     $this->Database->query('DROP TABLE `ContactCategory`');
    179     $this->Database->query('DROP TABLE `Subject`');
     143    $this->UninstallModel(Contact::GetDesc());
     144    $this->UninstallModel(ContactCategory::GetDesc());
     145    $this->UninstallModel(Subject::GetDesc());
     146    $this->UninstallModel(Country::GetDesc());
    180147  }
    181148
     
    188155  }
    189156}
     157
     158class Subject extends Model
     159{
     160  static function GetDesc(): ModelDesc
     161  {
     162    $Desc = new ModelDesc('Subject');
     163    $Desc->AddString('Name');
     164    $Desc->AddString('AddressStreet');
     165    $Desc->AddString('AddressTown');
     166    $Desc->AddString('AddressPSC');
     167    $Desc->AddReference('AddressCountry', 'Country', true);
     168    $Desc->AddString('IC');
     169    $Desc->AddString('DIC');
     170    $Desc->AddBoolean('PayVAT');
     171    $Desc->AddReference('MapPosition', 'MapPosition', true);
     172    $Desc->AddString('WWW');
     173    $Desc->AddString('Note');
     174    return $Desc;
     175  }
     176}
     177
     178class Country extends Model
     179{
     180  static function GetDesc(): ModelDesc
     181  {
     182    $Desc = new ModelDesc('Country');
     183    $Desc->AddString('Name');
     184    return $Desc;
     185  }
     186}
     187
     188class Contact extends Model
     189{
     190  static function GetDesc(): ModelDesc
     191  {
     192    $Desc = new ModelDesc('Contact');
     193    $Desc->AddReference('Category', 'ContactCategory', true);
     194    $Desc->AddString('Value');
     195    $Desc->AddReference('Subject', 'Subject', true);
     196    $Desc->AddReference('User', 'User', true);
     197    $Desc->AddString('Description');
     198    $Desc->AddBoolean('Receive');
     199    return $Desc;
     200  }
     201}
     202
     203class ContactCategory extends Model
     204{
     205  static function GetDesc(): ModelDesc
     206  {
     207    $Desc = new ModelDesc('ContactCategory');
     208    $Desc->AddString('Name');
     209    return $Desc;
     210  }
     211}
Note: See TracChangeset for help on using the changeset viewer.