Ignore:
Timestamp:
Mar 6, 2023, 1:48:45 AM (21 months ago)
Author:
chronos
Message:
  • Fixed: Class types casting for better type checking.
  • Fixed: XML direct export.
  • Modified: User class instance moved from Core class to ModuleUser class.
File:
1 edited

Legend:

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

    r891 r893  
    11<?php
    22
    3 class ModuleExport extends Module
    4 {
    5   function __construct(System $System)
    6   {
    7     parent::__construct($System);
    8     $this->Name = 'Export';
    9     $this->Version = '1.0';
    10     $this->Creator = 'Chronos';
    11     $this->License = 'GNU/GPL';
    12     $this->Description = 'Allow parametric export of translated texts to various supported output formats';
    13     $this->Dependencies = array('Translation');
    14   }
    15 
    16   function DoStart(): void
    17   {
    18     $this->System->RegisterPage(['export'], 'PageExport');
    19     $this->System->RegisterPage(['export', 'progress'], 'PageExportProgress');
    20     Core::Cast($this->System)->RegisterMenuItem(array(
    21       'Title' => 'Exporty',
    22       'Hint' => 'Zde si můžete stáhnout přeložené texty',
    23       'Link' => $this->System->Link('/export/'),
    24       'Permission' => LICENCE_ANONYMOUS,
    25       'Icon' => '',
    26     ), 2);
    27   }
    28 
    29   function GetTaskProgress($TaskId)
    30   {
    31     $Output = '';
    32     $DbResult = $this->Database->query('SELECT * FROM `ExportTask` '.
    33       'LEFT JOIN `Export` ON `Export`.`Id` = `ExportTask`.`Export` WHERE '.
    34       '((`Export`.`OutputType` = 9) OR (`Export`.`OutputType` = 10)) AND '.
    35       '(`TimeFinish` IS NULL) OR (`Export` ='.$TaskId.') ORDER BY `TimeQueued`'); // `Export`='.$Export->Id
    36     while ($Task = $DbResult->fetch_assoc())
    37     {
    38       $Export = '<a href="'.$this->System->Link('/export/?Action=View&amp;ExportId='.$Task['Export']).'">'.$Task['Export'].'</a>';
    39       if ($TaskId == $Task['Export'])
    40         $Export = ''.$Export.' (tento)';
    41 
    42       // Show progress bar
    43       $Output .= ' <strong>Export '.$Export.':</strong> <div id="progress'.$Task['Export'].'">'.
    44         '<strong>'.ProgressBar(300, $Task['Progress']).'</strong> ';
    45 
    46       // Show estimated time to complete
    47       $PrefixMultiplier = new PrefixMultiplier();
    48       if ($Task['Progress'] > 0) {
    49         $ElapsedTime = time() - MysqlDateTimeToTime($Task['TimeStart']);
    50         $Output .= T('Elapsed time').': <strong>'.$PrefixMultiplier->Add($ElapsedTime, '', 4, 'Time').'</strong> / ';
    51         $EstimatedTime = (time() - MysqlDateTimeToTime($Task['TimeStart'])) / $Task['Progress'] * (100 - $Task['Progress']);
    52         $Output .= T('Estimated remaining time').': <strong>'.$PrefixMultiplier->Add($EstimatedTime, '', 4, 'Time').'</strong><br/>';
    53       }
    54       $Output .= '</div>';
    55 
    56       if ($Task['Progress'] > 99)
    57         $Output .= '<script type="text/javascript" language="JavaScript" charset="utf-8">'.
    58         'setTimeout("parent.location.href=\''.$this->System->Link('/export/?Action=View&Tab=7&ExportId='.$TaskId).'\'", 500)'.
    59         '</script>';
    60     }
    61     return $Output;
    62   }
    63 }
     3include_once(dirname(__FILE__).'/ModuleExport.php');
     4include_once(dirname(__FILE__).'/Page.php');
     5include_once(dirname(__FILE__).'/ExportOutput.php');
    646
    657class Export extends Model
    668{
    67   var $Id;
    68   var $AnoNe = array('Ne', 'Ano');
     9  public int $Id;
     10  public array $AnoNe = array('Ne', 'Ano');
    6911  var $WhereLang;
    7012  var $WhereUsers;
     
    7315  var $ClientVersion;
    7416  var $OrderByUserList;
    75   var $TempDir;
    76   var $SourceDir;
     17  public string $TempDir;
     18  public string $TempDirRelative;
     19  public string $SourceDir;
     20  public string $SourceDirRelative;
     21  public array $Export;
    7722
    7823  function Init()
    7924  {
    80     $this->TempDir = dirname(__FILE__).'/../../'.$this->System->Config['Web']['TempFolder'].'Export/'.$this->Id.'/';
     25    $this->TempDir = dirname(__FILE__).'/../../'.Core::Cast($this->System)->Config['Web']['TempFolder'].'Export/'.$this->Id.'/';
    8126    if (!file_exists($this->TempDir)) mkdir($this->TempDir, 0777, true);
    82     $this->TempDirRelative = $this->System->Config['Web']['TempFolder'].'Export/'.$this->Id.'/';
    83     $this->SourceDir = dirname(__FILE__).'/../../'.$this->System->Config['Web']['SourceFolder'];
    84     $this->SourceDirRelative = $this->System->Config['Web']['SourceFolder'];
     27    $this->TempDirRelative = Core::Cast($this->System)->Config['Web']['TempFolder'].'Export/'.$this->Id.'/';
     28    $this->SourceDir = dirname(__FILE__).'/../../'.Core::Cast($this->System)->Config['Web']['SourceFolder'];
     29    $this->SourceDirRelative = Core::Cast($this->System)->Config['Web']['SourceFolder'];
    8530    if (!file_exists($this->SourceDir)) mkdir($this->SourceDir, 0777, true);
    8631  }
     
    158103  //  $Columns = substr($Columns, 0, -2);
    159104
    160     $Query = 'SELECT * FROM (SELECT ANY_VALUE(`TT`.`ID`) AS `TTID` FROM (SELECT '.$Columns.' T.`ID`,T.`Language`,T.`User`,T.`Entry`,T.`VersionEnd`,T.`VersionStart`, `User`.`Name` AS `UserName` FROM `'.$Group['TablePrefix'].'` AS `T`'.
     105    $Query = 'SELECT * FROM (SELECT MIN(`TT`.`ID`) AS `TTID` FROM
     106    (SELECT '.$Columns.' T.`ID`,T.`Language`,T.`User`,T.`Entry`,T.`VersionEnd`,T.`VersionStart`, `User`.`Name` AS `UserName` FROM `'.$Group['TablePrefix'].'` AS `T`'.
    161107    ' JOIN `ExportUser` ON (`ExportUser`.`User`=`T`.`User`) AND (`ExportUser`.`Export`='.$this->Id.') '.
    162108    ' JOIN `User` ON `User`.`ID`=`T`.`User`'.
     
    179125    $Query = 'SELECT `T4`.*, '.$OriginalColumns.' FROM ('.$Query.') AS `T4` '.
    180126    ' LEFT JOIN `'.$Group['TablePrefix'].'` AS `T3` ON (`T3`.`Entry` = `T4`.`Entry`) '.
    181     'AND (`T3`.`Language` = '.$this->System->Config['OriginalLanguage'].') AND '.
     127    'AND (`T3`.`Language` = '.Core::Cast($this->System)->Config['OriginalLanguage'].') AND '.
    182128    '(`T3`.`VersionStart` = `T4`.`VersionStart`) AND (`T3`.`VersionEnd` = `T4`.`VersionEnd`)';
    183129
     
    219165  function ExportToMangosSQL()
    220166  {
     167    $User = ModuleUser::Cast($this->System->GetModule('User'))->User;
    221168    $TranslationTree = $this->System->ModuleManager->Modules['Translation']->GetTranslationTree();
    222169
     
    227174      "-- ===========================================\n".
    228175      "--\n".
    229       "-- Web projektu: ".$this->System->Config['Web']['Host'].$this->System->Link('/')."\n".
     176      "-- Web projektu: ".Core::Cast($this->System)->Config['Web']['Host'].$this->System->Link('/')."\n".
    230177      "-- Datum exportu: ".date("j.n.Y  H:i:s")."\n".
    231       "-- Znaková sada: ".$this->System->Config['Database']['Charset']." / ".$this->System->Config['Web']['Charset']."\n".
     178      "-- Znaková sada: ".Core::Cast($this->System)->Config['Database']['Charset']." / ".Core::Cast($this->System)->Config['Web']['Charset']."\n".
    232179      "-- Diakritika: ".$this->AnoNe[$this->Export['WithDiacritic']]."\n".
    233       "-- Vygeneroval uživatel: ".$this->System->User->Name."\n".
     180      "-- Vygeneroval uživatel: ".$User->Name."\n".
    234181      "-- Vzato od uživatelů: ".$this->UserNames."\n".
    235182      "-- Generované tabulky: ";
     
    370317  }
    371318
    372   function AddProgress($add = 1)
    373   {
    374     $DbResult = $this->System->Database->query('SELECT Progress FROM `ExportTask` WHERE `Export`='.$this->Id);
    375     $Task = $DbResult->fetch_assoc();
    376     $per = $Task['Progress']+$add;
    377     $this->System->Database->query('UPDATE `ExportTask` SET `Progress`='.$per.' WHERE `Export`='.$this->Id);
     319  function AddProgress($Add = 1)
     320  {
     321    $DbResult = $this->System->Database->query('SELECT `Progress` FROM `ExportTask` WHERE `Export`='.$this->Id);   
     322    if ($DbResult->num_rows > 0)
     323    {
     324      $Task = $DbResult->fetch_assoc();
     325      $Progress = $Task['Progress'] + $Add;
     326      $this->System->Database->query('UPDATE `ExportTask` SET `Progress`='.$Progress.' WHERE `Export`='.$this->Id);
     327    }
    378328  }
    379329
     
    723673  function ExportToXML()
    724674  {
     675    $User = ModuleUser::Cast($this->System->GetModule('User'))->User;
    725676    $TranslationTree = $this->System->ModuleManager->Modules['Translation']->GetTranslationTree();
    726677
     
    730681    "<document>\n".
    731682    "  <meta>\n".
    732     "    <projecturl>".$this->System->Config['Web']['Host'].$this->System->Link('/')."</projecturl>\n".
     683    "    <projecturl>".Core::Cast($this->System)->Config['Web']['Host'].$this->System->Link('/')."</projecturl>\n".
    733684    "    <time>".date('r')."</time>\n".
    734685    "    <diacritics mode=".'"'.$this->Export['WithDiacritic'].'"'." />\n".
    735     "    <author>".$this->System->User->Name."</author>\n".
     686    "    <author>".$User->Name."</author>\n".
    736687    "    <contributors>\n";
    737688    foreach (explode(',', $this->UserNames) as $UserName)
    738       $Buffer .= "      <user>".$UserName."</user>\n";
     689    {
     690      $Buffer .= "      <user>".trim($UserName)."</user>\n";
     691    }
    739692    $Buffer .=
    740693    "    </contributors>\n".
     
    755708      while ($Line = $DbResult2->fetch_assoc())
    756709      {
    757         $Buffer .= '      <item id="'.$Line['Entry'].'" user="'.$Line['UserName'].'">'."\n";
    758         $Values = '';
     710        $Buffer .= '      <item id="'.$Line['Entry'].'" user="'.$Line['User'].'">'."\n";
    759711        foreach ($TranslationTree[$Group['Id']]['Items'] as $GroupItem)
    760712        {
     
    774726  }
    775727}
    776 
    777 include_once(dirname(__FILE__).'/Page.php');
    778 include_once(dirname(__FILE__).'/ExportOutput.php');
    779 
Note: See TracChangeset for help on using the changeset viewer.