Changeset 893 for trunk/Modules/Export/Export.php
- Timestamp:
- Mar 6, 2023, 1:48:45 AM (21 months ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Modules/Export/Export.php
r891 r893 1 1 <?php 2 2 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&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 } 3 include_once(dirname(__FILE__).'/ModuleExport.php'); 4 include_once(dirname(__FILE__).'/Page.php'); 5 include_once(dirname(__FILE__).'/ExportOutput.php'); 64 6 65 7 class Export extends Model 66 8 { 67 var$Id;68 var$AnoNe = array('Ne', 'Ano');9 public int $Id; 10 public array $AnoNe = array('Ne', 'Ano'); 69 11 var $WhereLang; 70 12 var $WhereUsers; … … 73 15 var $ClientVersion; 74 16 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; 77 22 78 23 function Init() 79 24 { 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.'/'; 81 26 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']; 85 30 if (!file_exists($this->SourceDir)) mkdir($this->SourceDir, 0777, true); 86 31 } … … 158 103 // $Columns = substr($Columns, 0, -2); 159 104 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`'. 161 107 ' JOIN `ExportUser` ON (`ExportUser`.`User`=`T`.`User`) AND (`ExportUser`.`Export`='.$this->Id.') '. 162 108 ' JOIN `User` ON `User`.`ID`=`T`.`User`'. … … 179 125 $Query = 'SELECT `T4`.*, '.$OriginalColumns.' FROM ('.$Query.') AS `T4` '. 180 126 ' 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 '. 182 128 '(`T3`.`VersionStart` = `T4`.`VersionStart`) AND (`T3`.`VersionEnd` = `T4`.`VersionEnd`)'; 183 129 … … 219 165 function ExportToMangosSQL() 220 166 { 167 $User = ModuleUser::Cast($this->System->GetModule('User'))->User; 221 168 $TranslationTree = $this->System->ModuleManager->Modules['Translation']->GetTranslationTree(); 222 169 … … 227 174 "-- ===========================================\n". 228 175 "--\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". 230 177 "-- 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". 232 179 "-- Diakritika: ".$this->AnoNe[$this->Export['WithDiacritic']]."\n". 233 "-- Vygeneroval uživatel: ".$ this->System->User->Name."\n".180 "-- Vygeneroval uživatel: ".$User->Name."\n". 234 181 "-- Vzato od uživatelů: ".$this->UserNames."\n". 235 182 "-- Generované tabulky: "; … … 370 317 } 371 318 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 } 378 328 } 379 329 … … 723 673 function ExportToXML() 724 674 { 675 $User = ModuleUser::Cast($this->System->GetModule('User'))->User; 725 676 $TranslationTree = $this->System->ModuleManager->Modules['Translation']->GetTranslationTree(); 726 677 … … 730 681 "<document>\n". 731 682 " <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". 733 684 " <time>".date('r')."</time>\n". 734 685 " <diacritics mode=".'"'.$this->Export['WithDiacritic'].'"'." />\n". 735 " <author>".$ this->System->User->Name."</author>\n".686 " <author>".$User->Name."</author>\n". 736 687 " <contributors>\n"; 737 688 foreach (explode(',', $this->UserNames) as $UserName) 738 $Buffer .= " <user>".$UserName."</user>\n"; 689 { 690 $Buffer .= " <user>".trim($UserName)."</user>\n"; 691 } 739 692 $Buffer .= 740 693 " </contributors>\n". … … 755 708 while ($Line = $DbResult2->fetch_assoc()) 756 709 { 757 $Buffer .= ' <item id="'.$Line['Entry'].'" user="'.$Line['UserName'].'">'."\n"; 758 $Values = ''; 710 $Buffer .= ' <item id="'.$Line['Entry'].'" user="'.$Line['User'].'">'."\n"; 759 711 foreach ($TranslationTree[$Group['Id']]['Items'] as $GroupItem) 760 712 { … … 774 726 } 775 727 } 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.