StatsBar.php

Go to the documentation of this file.
00001 <?php
00015 class StatsBar {
00020     protected $stats;
00021 
00023     protected $group;
00024 
00026     protected $language;
00027 
00028     public static function getNew( $group, $language, array $stats = null ) {
00029         $self = new self();
00030         $self->group = $group;
00031         $self->language = $language;
00032 
00033         if ( is_array( $stats ) ) {
00034             $self->stats = $stats;
00035         } else {
00036             $self->stats = MessageGroupStats::forItem( $group, $language );
00037         }
00038 
00039         return $self;
00040     }
00041 
00042     public function getHtml( IContextSource $context ) {
00043         $context->getOutput()->addModules( 'ext.translate.statsbar' );
00044 
00045         $total = $this->stats[MessageGroupStats::TOTAL];
00046         $proofread = $this->stats[MessageGroupStats::PROOFREAD];
00047         $translated = $this->stats[MessageGroupStats::TRANSLATED];
00048         $fuzzy = $this->stats[MessageGroupStats::FUZZY];
00049 
00050         if ( !$total ) {
00051             $untranslated = null;
00052             $wproofread = $wtranslated = $wfuzzy = $wuntranslated = 0;
00053         } else {
00054             // Proofread is subset of translated
00055             $untranslated = $total - $translated - $fuzzy;
00056 
00057             $wproofread = round( 100 * $proofread / $total, 2 );
00058             $wtranslated = round( 100 * ( $translated - $proofread ) / $total, 2 );
00059             $wfuzzy = round( 100 * $fuzzy / $total, 2 );
00060             $wuntranslated = round( 100 - $wproofread - $wtranslated - $wfuzzy, 2 );
00061         }
00062 
00063         return Html::rawElement( 'div', array(
00064                 'class' => 'tux-statsbar',
00065                 'data-total' => $total,
00066                 'data-group' => $this->group,
00067                 'data-language' => $this->language,
00068             ),
00069             Html::element( 'span', array(
00070                 'class' => 'tux-proofread',
00071                 'style' => "width: $wproofread%",
00072                 'data-proofread' => $proofread,
00073             ) ) . Html::element( 'span', array(
00074                 'class' => 'tux-translated',
00075                 'style' => "width: $wtranslated%",
00076                 'data-translated' => $translated,
00077             ) ) . Html::element( 'span', array(
00078                 'class' => 'tux-fuzzy',
00079                 'style' => "width: $wfuzzy%",
00080                 'data-fuzzy' => $fuzzy,
00081             ) ) . Html::element( 'span', array(
00082                 'class' => 'tux-untranslated',
00083                 'style' => "width: $wuntranslated%",
00084                 'data-untranslated' => $untranslated,
00085             ) )
00086         );
00087     }
00088 }
Generated on Tue Oct 29 00:00:26 2013 for MediaWiki Translate Extension by  doxygen 1.6.3