Ignore:
Timestamp:
Mar 1, 2015, 3:38:19 PM (10 years ago)
Author:
chronos
Message:
  • Modified: Removed generation of user level to images as files. Level images ware replaced by HTML progress bar.
  • Modified: User XP level and translated count is now calculated during every translation save operation rather then calculated in user list and group view page show.
  • Fixed: Wrong indentation in some files.
File:
1 moved

Legend:

Unmodified
Added
Removed
  • trunk/Modules/Translation/UserLevel.php

    r824 r826  
    77$index_level = 100;
    88$from_diakrit = 3; // higher xp for word with diacritics
    9 $FontFile = dirname(__FILE__).'/images/FRIZQT__.ttf';
    109
    1110function CheckDiakrit($Word)
     
    2221}
    2322
    24 function CreateImg($prefix, $user, $xp)
    25 {
    26   global $index_level, $FontFile;
    27 
    28   if($xp > 0)
    29   {
    30     $level = sqrt($xp / $index_level);
    31     $level = substr($level, 0, strpos($level, '.'));
    32   } else $level = 0;
    33   $xp_min = $level * $level * $index_level;
    34   $xp_max = ($level + 1) * ($level + 1) * $index_level;
    35   $xp_max = $xp_max - $xp_min;
    36   $xp = $xp - $xp_min;
    37 
    38   if($xp_max > 0) $Percent = ( $xp / $xp_max) * 100;
    39     else $Percent = 0;
    40   $Percent = substr($Percent, 0, 5);
    41 
    42   $PercentBar = $Percent * 2.5;
    43   $Image = ImageCreateTrueColor(250, 15);
    44   $Color1 = imagecolorallocate($Image, 214, 214, 214);
    45   $Color2 = imagecolorallocate($Image, 239, 131, 166);
    46   $Color3 = imagecolorallocate($Image, 225, 0, 0);
    47   imagefilledrectangle($Image, 0, 0, 250, 15, $Color1);
    48   imagefilledrectangle($Image, 0, 0, $PercentBar, 59, $Color2);
    49   ImageTTFText($Image, 11, 0, 10, 12, $Color3, $FontFile, $level.' Level');
    50   ImageTTFText($Image, 8, 0, 80, 12, $Color3, $FontFile, $xp.'/'.$xp_max.' xp   '.$user);
    51 
    52   if(!file_exists(dirname(__FILE__).'/tmp/'.$prefix.'/')) mkdir(dirname(__FILE__).'/tmp/'.$prefix.'/');
    53   if(!file_exists(dirname(__FILE__).'/tmp/'.$prefix.'/'.$user.'/')) mkdir(dirname(__FILE__).'/tmp/'.$prefix.'/'.$user.'/');
    54   ImagePNG($Image, dirname(__FILE__).'/tmp/'.$prefix.'/'.$user.'/level.png');
    55 }
    56 
    5723function GetXPFromTranslation($UserId)
    5824{
     
    6733      foreach($TranslationTree[$Group['Id']]['Items'] as $Index => $TextItem)
    6834      {
    69          $GroupBy .= '`'.$TextItem['Column'].'`, ';
     35        $GroupBy .= '`'.$TextItem['Column'].'`, ';
    7036      }
    7137      $GroupBy = substr($GroupBy, 0, -2);
    7238
    73       $IDtran = $System->Database->query('SELECT * FROM `'.$Group['TablePrefix'].'` WHERE (`User` = '.$UserId.') AND (`Complete` = 1) AND (`Take` IS NOT NULL) '.$GroupBy);
     39      $IDtran = $System->Database->query('SELECT * FROM `'.$Group['TablePrefix'].'` WHERE '.
     40        '(`User` = '.$UserId.') AND (`Complete` = 1) AND (`Take` IS NOT NULL) '.$GroupBy);
    7441      while($Line = $IDtran->fetch_array())
    7542      {
     
    8047        foreach($TranslationTree[$Group['Id']]['Items'] as $Index => $TextItem)
    8148        {
    82           if(($Line[$TextItem['Column']] <> $LineComparison[$TextItem['Column']]) and (strlen($Line[$TextItem['Column']]) > (strlen($LineComparison[$TextItem['Column']]) * 0.5)))
     49          if(($Line[$TextItem['Column']] <> $LineComparison[$TextItem['Column']]) and
     50            (strlen($Line[$TextItem['Column']]) > (strlen($LineComparison[$TextItem['Column']]) * 0.5)))
    8351          {
    8452            $TextArr = explode(' ', $Line[$TextItem['Column']]);
     
    9159          } else
    9260          {
    93             if (($Line[$TextItem['Column']] == $LineComparison[$TextItem['Column']]) and ('0' == $LineComparison['Language']) and ($LineComparison[$TextItem['Column']] <> '') and ($TextItem['Column'] <> 'ShortCut')) $translated = false;
     61            if (($Line[$TextItem['Column']] == $LineComparison[$TextItem['Column']]) and
     62              ('0' == $LineComparison['Language']) and ($LineComparison[$TextItem['Column']] <> '') and
     63              ($TextItem['Column'] <> 'ShortCut')) $translated = false;
    9464          }
    9565        }
     
    10171}
    10272
    103 function ImgLevelUpdate()
     73function UserLevelUpdate($UserId)
    10474{
    10575  global $System, $TranslationTree, $Config;
    10676
    10777  // Main code for users
    108   $DbResult = $System->Database->query('SELECT `ID`, `Name` FROM `User` WHERE `NeedUpdate` = 1');
     78  $DbResult = $System->Database->query('SELECT `ID`, `Name` FROM `User` WHERE `Id` = '.$UserId);
    10979  if($DbResult->num_rows > 0)
    11080  {
     
    12797      $xp = GetXPFromTranslation($LineUser['ID']);
    12898      $System->Database->query('UPDATE `User` SET `XP` = '.$xp.', `TranslatedCount` = '.$TranslatedCount.' WHERE `User`.`ID` = '.$LineUser['ID']);
    129       CreateImg('user', $LineUser['Name'], $xp);
    13099    }
    131 
    132     // Main code for translation teams
    133     $DbResult = $System->Database->query('SELECT `ID`, `Name`, (SELECT AVG(`XP`) FROM `User` WHERE `Team` = `Team`.`Id`) AS `Average` '.
    134       'FROM `Team` WHERE `ID` IN (SELECT `Team` FROM `User` WHERE `NeedUpdate` = 1)');
    135     while($LineTeam = $DbResult->fetch_array())
    136     {
    137       CreateImg('team', $LineTeam['Name'], substr($LineTeam['Average'], 0, strpos($LineTeam['Average'],'.')));  //image creation
    138     }
    139     $System->Database->query('UPDATE `User` SET `NeedUpdate` = 0');
    140100  }
    141101}
    142 
    143 function ImgLevelShow()
    144 {
    145   global $System;
    146 
    147   // Do update for all users
    148   $System->Database->query('UPDATE `User` SET `NeedUpdate` = 1');
    149   ImgLevelUpdate();
    150 
    151   $Output = '<strong>Uživatelé</strong><br/>';
    152   $ID = $System->Database->query('SELECT `ID`, `Name` FROM `User`');
    153   while($LineUser = $ID->fetch_array())
    154   {
    155     $Output .= '<img src="'.$System->Link('/tmp/user/'.$LineUser['Name'].'/level.png').'"/> '.$LineUser['Name'].'<br />';
    156   }
    157 
    158   $Output .= '<br/><strong>Týmy</strong><br/>';
    159   $ID = $System->Database->query('SELECT `ID`, `Name` FROM `Team`');
    160   while($LineTeam = $ID->fetch_array())
    161   {
    162     $Output .= '<img src="'.$System->Link('/tmp/team/'.$LineTeam['Name'].'/level.png').'"/> '.$LineTeam['Name'].'<br />';
    163   }
    164   WriteLog('Přegenerovány obrázky úrovní překladatelů a týmů', LOG_TYPE_ADMINISTRATION);
    165   return($Output);
    166 }
Note: See TracChangeset for help on using the changeset viewer.