Changeset 378


Ignore:
Timestamp:
Jan 20, 2012, 3:32:02 PM (13 years ago)
Author:
chronos
Message:
  • Přidáno: Model pro NetworkSegment.
  • Upraveno: Přepracován model systém pro načítání modelů modulů.
Location:
trunk
Files:
1 added
23 edited

Legend:

Unmodified
Added
Removed
  • trunk/Common/Model.php

    r377 r378  
    229229      if($Property['Type'] == PropertyOneToMany)
    230230      {
    231         if(!$this->Module->Models[$Property['TargetModel']]->Installed)
    232           $this->Module->Models[$Property['TargetModel']]->Install();
     231        if(array_key_exists($Property['TargetModel'], $this->Module->Models))
     232        {
     233          if(!$this->Module->Models[$Property['TargetModel']]->Installed)
     234            $this->Module->Models[$Property['TargetModel']]->Install();
     235        }
    233236        $this->Database->query('ALTER TABLE `'.$this->Name.'` ADD FOREIGN KEY (`'.$Property['Name'].'`) REFERENCES `'.$Property['TargetModel'].'` (`Id`);');
    234237      }
     
    238241  function UnInstall()
    239242  {
    240     foreach($Model->Properties as $Property)
     243    foreach($this->Properties as $Property)
    241244    {
    242245      if($Property['Type'] == PropertyManyToMany)
     
    244247    }
    245248    $this->Database->query('DROP TABLE IF EXISTS `'.$this->Name.'`');
     249    $this->Installed = false;
    246250  }
    247251}
  • trunk/Common/Module.php

    r377 r378  
    1212  var $Dependencies;
    1313  var $Models = array();
     14  var $SupportedModels = array();
    1415  var $Database;
    1516  var $Installed;
     
    3334      $this->System->Modules[$Dependency]->Install();
    3435    $this->LoadModels();
    35     foreach($this->Models as $ModelName)
    36     {
    37       $this->System->Models[$ModelName]->Install();
     36    foreach($this->Models as $Index => $Module)
     37    {
     38      $this->Models[$Index]->Install();
    3839    }
    3940    $this->Database->query('UPDATE SystemModule SET Installed=1 WHERE Name="'.$this->Name.'"');
     
    4344  {
    4445    DebugLog('Uninstalling module '.$this->Name.'...');
    45     foreach($this->Models as $ModelName)
    46     {
    47       $Model = new $ModelName($this->Database, $this->System);
    48       $Model->UnInstall();
    49       unset($Model);
     46    foreach($this->Models as $Index => $Model)
     47    {
     48      $this->Models[$Index]->UnInstall();
    5049    }
    5150    $this->Database->query('UPDATE SystemModule SET Installed=0 WHERE Name="'.$this->Name.'"');
     51    $this->Installed = false;
    5252  }
    5353 
     
    6262  function LoadModels()
    6363  {
    64     foreach($this->Models as $ModelName)
    65     {
    66       $this->System->Models[$ModelName] = new $ModelName($this->Database, $this->System);
    67       $this->System->Models[$ModelName]->Module = &$this;
     64    $this->Models = array();
     65    foreach($this->SupportedModels as $ModelName)
     66    {
     67      $NewModel = new $ModelName($this->Database, $this->System);
     68      $NewModel->Module = &$this;
     69      $this->Models[$ModelName] = $NewModel;
    6870    }       
    6971  }
  • trunk/Modules/Chat/Chat.php

    r358 r378  
    9191    $this->Description = 'Show history of IRC chat and previous SunriseChat';
    9292    $this->Dependencies = array();
    93     $this->Models = array();
     93    $this->SupportedModels = array();
    9494  }
    9595 
  • trunk/Modules/EmailQueue/EmailQueue.php

    r373 r378  
    2727    $this->Description = 'Queue for mass email send, log and review.';
    2828    $this->Dependencies = array('User');
    29     $this->Models = array('EmailQueue');
     29    $this->SupportedModels = array('EmailQueue');
    3030  }
    3131 
  • trunk/Modules/Finance/Finance.php

    r377 r378  
    287287    $this->Description = 'Accounting processing';
    288288    $this->Dependencies = array('User', 'Subject');
    289     $this->Models = array('FinanceYear', 'DocumentLine', 'DocumentLineSequence',
     289    $this->SupportedModels = array('FinanceYear', 'DocumentLine', 'DocumentLineSequence',
    290290      'FinanceTariff', 'FinanceOperation', 'FinanceClaimsLiabilities',
    291291      'FinanceBills', 'FinanceBillsItems', 'FinanceBillingPeriod', 'FinanceCharge',
     
    398398   
    399399    $this->SpravaUsers = $this->InternetUsers;
    400     $DbResult = $this->Database->query('SELECT SUM(`Consumption`) FROM `network_segments`');
     400    $DbResult = $this->Database->query('SELECT SUM(`Consumption`) FROM `NetworkSegments`');
    401401    $TotalConsumption = $DbResult->fetch_array();
    402402    $this->TotalConsumption = $TotalConsumption[0];
     
    459459      while($ID != 0)
    460460      {
    461         $DbResult2 = $this->Database->query('SELECT * FROM `network_segments` WHERE `id`='.$ID);
     461        $DbResult2 = $this->Database->query('SELECT * FROM `NetworkSegments` WHERE `Id`='.$ID);
    462462        $Device = $DbResult2->fetch_assoc();
    463         $NetworkDevice += $Device['price'] / $Device['users'];
    464         $Consumption += $Device['consumption'] / $Device['users_overheads'];
     463        $NetworkDevice += $Device['Price'] / $Device['Users'];
     464        $Consumption += $Device['Consumption'] / $Device['UsersOverheads'];
    465465        //echo($ID.' '.$InternetSegment.' '.$InternetSegmentId.' '.$Row['inet_hw'].' '.$Price.'<br>');
    466         $ID = $Device['parent'];
     466        $ID = $Device['Parent'];
    467467      }
    468468   
     
    497497  {
    498498    $Output = 'Aktualizuji parametry segmentů...<br />';
    499     $this->Database->query('UPDATE `network_segments` SET `users` = 0, `users_overheads` = 0');     // Vynulovat počty uživatelů
    500     $DbResult = $this->Database->query('SELECT * FROM `network_segments`');
     499    $this->Database->query('UPDATE `NetworkSegments` SET `Users` = 0, `UsersOverheads` = 0');     // Vynulovat počty uživatelů
     500    $DbResult = $this->Database->query('SELECT * FROM `NetworkSegments`');
    501501    while($NetworkSegment = $DbResult->fetch_array())
    502502    {
    503503      //echo('Segment '.$Row['name'].'<br>');
    504       $DbResult2 = $this->Database->query('SELECT `users` FROM `network_segments` WHERE `id`='.$NetworkSegment['id']);
     504      $DbResult2 = $this->Database->query('SELECT `Users` FROM `NetworkSegments` WHERE `Id`='.$NetworkSegment['Id']);
    505505      $RowP = $DbResult2->fetch_array();
    506       $DbResult2 = $this->Database->query('SELECT `users_overheads` FROM `network_segments` WHERE `id`='.$NetworkSegment['id']);
     506      $DbResult2 = $this->Database->query('SELECT `UsersOverheads` FROM `NetworkSegments` WHERE `Id`='.$NetworkSegment['Id']);
    507507      $RowP2 = $DbResult2->fetch_array();
    508508
    509       $DbResult2 = $this->Database->query('SELECT SUM(price) as Price, SUM(consumption) as Consumption FROM network_devices WHERE segment='.$NetworkSegment['id'].' AND used=1');
     509      $DbResult2 = $this->Database->query('SELECT SUM(Price) as Price, SUM(Consumption) as Consumption FROM NetworkDevices WHERE Segment='.$NetworkSegment['id'].' AND Used=1');
    510510      $Row2 = $DbResult2->fetch_array();
    511511      $DbResult2 = $this->Database->query('SELECT COUNT(*) FROM Member WHERE NetworkSegment='.$NetworkSegment['id']);
    512512      $Row3 = $DbResult2->fetch_array();
    513       $ID = $NetworkSegment['parent'];
     513      $ID = $NetworkSegment['Parent'];
    514514      while($ID != 0)
    515515      {
    516516        //echo($ID.', ');
    517         $DbResult2 = $this->Database->query('SELECT * FROM network_segments WHERE id='.$ID);
     517        $DbResult2 = $this->Database->query('SELECT * FROM NetworkSegments WHERE Id='.$ID);
    518518        $Row4 = $DbResult2->fetch_array();
    519         $this->Database->update('network_segments', 'id='.$Row4['id'], array('users' => ($Row4['users'] + $Row3[0]), 'users_overheads' => ($Row4['users_overheads'] + $Row3[0])));
    520         $ID = $Row4['parent'];
     519        $this->Database->update('NetworkSegments', 'Id='.$Row4['Id'], array('Users' => ($Row4['Users'] + $Row3[0]), 'UsersOverheads' => ($Row4['UsersOverheads'] + $Row3[0])));
     520        $ID = $Row4['Parent'];
    521521      }
    522       $this->Database->update('network_segments', 'id='.$NetworkSegment['id'], array('price' => $Row2['Price'], 'users' => ($Row3[0] + $RowP['users']), 'consumption' => $Row2['Consumption'], 'users_overheads' => ($Row3[0] + $RowP2['users_overheads'])));
     522      $this->Database->update('NetworkSegments', 'Id='.$NetworkSegment['Id'], array('Price' => $Row2['Price'], 'Users' => ($Row3[0] + $RowP['Users']), 'Consumption' => $Row2['Consumption'], 'UsersOverheads' => ($Row3[0] + $RowP2['UsersOverheads'])));
    523523    }
    524524
     
    526526    $DbResult = $this->Database->select('Member', 'COUNT(*)');
    527527    $Row = $DbResult->fetch_array();
    528     $DbResult = $this->Database->update('network_segments','id='.$this->InternetSegmentId, array('users' => $Row[0], 'users_overheads' => $Row[0]));
     528    $DbResult = $this->Database->update('NetworkSegments', 'Id='.$this->InternetSegmentId, array('Users' => $Row[0], 'UsersOverheads' => $Row[0]));
    529529    $this->System->Modules['Log']->NewRecord('Finance', 'RecalculateSegmentParameters');
    530530    return($Output);
  • trunk/Modules/FrontPage/FrontPage.php

    r372 r378  
    362362    $this->Description = 'Main page of community network portal';
    363363    $this->Dependencies = array('User', 'News', 'TV', 'Map', 'Chat', 'WebCam');
    364     $this->Models = array('Hyperlink', 'HyperlinkGroup', 'Panel', 'PanelColumn');
     364    $this->SupportedModels = array('Hyperlink', 'HyperlinkGroup', 'Panel', 'PanelColumn');
    365365  }
    366366 
  • trunk/Modules/Log/Log.php

    r375 r378  
    9292    $this->Description = 'Logging of user operations';
    9393    $this->Dependencies = array('User');
    94     $this->Models = array('Log');
     94    $this->SupportedModels = array('Log');
    9595  }
    9696 
  • trunk/Modules/Map/Map.php

    r358 r378  
    148148    $this->Description = 'Show objects on Google maps';
    149149    $this->Dependencies = array('Network');
    150     $this->Models = array();
     150    $this->SupportedModels = array();
    151151  }
    152152 
  • trunk/Modules/Meals/Meals.php

    r358 r378  
    216216    $this->Description = 'Module for management meals. Can print week menu.';
    217217    $this->Dependencies = array('Log');
    218     $this->Models = array('Meals', 'MealsInfo');
     218    $this->SupportedModels = array('Meals', 'MealsInfo');
    219219  }
    220220 
  • trunk/Modules/Member/Member.php

    r373 r378  
    5959    $this->Description = 'Customer and member management';
    6060    $this->Dependencies = array('User', 'Subject');
    61     $this->Models = array('Member', 'MemberPayment');
     61    $this->SupportedModels = array('Member', 'MemberPayment');
    6262    $this->View = array('MemberOptionsView');
    6363  }
  • trunk/Modules/Network/Network.php

    r377 r378  
    7878    $this->AddPropertyString('IPv6');
    7979    $this->AddPropertyString('ExternalIP');
    80     $this->AddPropertyOneToMany('Device', 'Device');
     80    $this->AddPropertyOneToMany('Device', 'NetworkDevice');
    8181    $this->AddPropertyBoolean('Online');
    8282    $this->AddPropertyDateTime('LastOnline');
     
    153153  }
    154154}
     155
     156class NetworkSegment extends Model
     157{
     158  function __construct($Database, $System)
     159  {
     160    parent::__construct($Database, $System);
     161    $this->Name = 'NetworkSegment';
     162    $this->AddPropertyString('Name');
     163    $this->AddPropertyInteger('Price');
     164    $this->AddPropertyOneToMany('Parent', 'NetworkSegment');
     165    $this->AddPropertyInteger('Users');
     166    $this->AddPropertyInteger('Consumption');
     167    $this->AddPropertyInteger('UsersOverheads');
     168  }
     169}
     170
    155171
    156172class EmailView extends ViewForm
     
    221237    $this->Description = 'Network device, interface and interconnection management';
    222238    $this->Dependencies = array('User', 'Member');
    223     $this->Models = array('NetworkDevice', 'NetworkDeviceType', 'NetworkInterface',
    224       'NetworkInterfaceType', 'NetworkPoint', 'NetworkLink', 'NetworkSubnet');
     239    $this->SupportedModels = array('NetworkDevice', 'NetworkDeviceType', 'NetworkInterface',
     240      'NetworkInterfaceType', 'NetworkPoint', 'NetworkLink', 'NetworkSubnet',
     241      'NetworkSegment');
    225242  }
    226243 
  • trunk/Modules/NetworkLinux/NetworkLinux.php

    r369 r378  
    1212    $this->Description = 'Network service configuration of Linux server';
    1313    $this->Dependencies = array('Network');
    14     $this->Models = array();
     14    $this->SupportedModels = array();
    1515  }
    1616 
  • trunk/Modules/NetworkRouterOS/NetworkRouterOS.php

    r369 r378  
    1212    $this->Description = 'Mikrotik RouterOS configuration';
    1313    $this->Dependencies = array('Network');
    14     $this->Models = array();
     14    $this->SupportedModels = array();
    1515  }
    1616 
  • trunk/Modules/NetworkShare/NetworkShare.php

    r377 r378  
    4343    $this->Description = 'System for loading network computer share file list and allow fast searching.';
    4444    $this->Dependencies = array('Network');
    45     $this->Models = array('NetworkShareItem', 'NetworkShareError');
     45    $this->SupportedModels = array('NetworkShareItem', 'NetworkShareError');
    4646  }
    4747 
  • trunk/Modules/NetworkTopology/NetworkTopology.php

    r358 r378  
    141141    $this->Description = 'Generate image of network device interconnection';
    142142    $this->Dependencies = array('Network');
    143     $this->Models = array();
     143    $this->SupportedModels = array();
    144144  }
    145145 
  • trunk/Modules/News/News.php

    r373 r378  
    101101    $this->Description = 'News and news groups management';
    102102    $this->Dependencies = array('User', 'Log');
    103     $this->Models = array('News', 'NewsCategory');
     103    $this->SupportedModels = array('News', 'NewsCategory');
    104104    $this->Views = array('News');
    105105  }
  • trunk/Modules/OpeningHours/OpeningHours.php

    r359 r378  
    249249    $this->Description = 'Show subject opening hours with time to open or time to close';
    250250    $this->Dependencies = array();
    251     $this->Models = array('SubjectOpenTime', 'SubjectOpenTimeDay');
     251    $this->SupportedModels = array('SubjectOpenTime', 'SubjectOpenTimeDay');
    252252  }
    253253 
  • trunk/Modules/Project/Project.php

    r377 r378  
    3535    $this->Description = 'Project and task management';
    3636    $this->Dependencies = array('User');
    37     $this->Models = array('Project', 'ProjectComment');
     37    $this->SupportedModels = array('Project', 'ProjectComment');
    3838  }
    3939 
  • trunk/Modules/Subject/Subject.php

    r373 r378  
    3232    $this->Description = 'Subject management';
    3333    $this->Dependencies = array();
    34     $this->Models = array('Subject');
     34    $this->SupportedModels = array('Subject');
    3535  }
    3636 
  • trunk/Modules/TV/TV.php

    r360 r378  
    1717  function ShowChannelList()
    1818  {
    19     global $Channels;
    20 
    2119    $Output = 'Stažení přehrávače: <a href="http://www.videolan.org/vlc/">VLC Media Player</a><br/>'.
    2220    'Seznam všech kanálů do přehrávače: <a href="playlist.m3u">Playlist</a><br/>'.
     
    2523    '<div align="center"><strong>Výpis kanálů:</strong><br>';
    2624
    27     $Where =
    2825    $DbResult = $this->Database->query('SELECT COUNT(*) FROM `TV` WHERE (`Stream` <> "") OR (`StreamWeb` <> "")');
    2926    $DbRow = $DbResult->fetch_row();
     
    132129    $this->Description = 'IPTV channel database management';
    133130    $this->Dependencies = array();
    134     $this->Models = array('TV');
     131    $this->SupportedModels = array('TV');
    135132  }
    136133 
  • trunk/Modules/TimeMeasure/TimeMeasure.php

    r373 r378  
    3333    $this->Description = 'Time measure or values';
    3434    $this->Dependencies = array('User');
    35     $this->Models = array();
     35    $this->SupportedModels = array();
    3636  }
    3737 
  • trunk/Modules/User/User.php

    r377 r378  
    372372    $this->Description = 'User management';
    373373    $this->Dependencies = array();
    374     $this->Models = array('User', 'UserOnline');
     374    $this->SupportedModels = array('User', 'UserOnline');
    375375    $this->Views = array('UserLogin', 'PasswordRecove', 'UserRegister', 'UserOptions',
    376376      'PermissionGroup', 'PermissionOperation', 'PermissionGroupAssignement',
  • trunk/Modules/WebCam/WebCam.php

    r358 r378  
    5454    $this->Description = 'Web camera image presentetation';
    5555    $this->Dependencies = array();
    56     $this->Models = array();
     56    $this->SupportedModels = array();
    5757  }
    5858 
Note: See TracChangeset for help on using the changeset viewer.