Example #1
0
 public function generate($return = false, $skip_credits = false)
 {
     if ($return) {
         ob_start();
     }
     $this->header();
     $cnt = 0;
     foreach ($this->orig as $o) {
         // Если нет версий перевода или выбран пропуск отрицательных вариантов и у лучшего из них отрицательный рейтинг
         if (count($o->trs) == 0 || $this->options->skip_neg && $o->trs[0]->rating < 0) {
             if ($this->options->untr == "s") {
                 continue;
             } else {
                 $tr_body = $o->body;
             }
         } else {
             $tr_body = $o->trs[0]->body;
             $this->translators[$o->trs[0]->user->login]++;
         }
         $this->verse($o->stdtime("t1"), $o->stdtime("t2"), $tr_body, $o->ord);
         $cnt++;
     }
     if ($cnt == 0) {
         $o = new Orig();
         $o->setAttributes(array("t1" => "00:00:00.000", "t2" => "00:00:00.000", "ord" => 0), false);
     }
     if ($this->chap->status != Chapter::STATUS_NONE && $this->chap->status != Chapter::STATUS_READY) {
         $o->t1 = Orig::ms2std($o->mstime("t2") + 10);
         $o->t2 = Orig::ms2std($o->mstime("t2") + 1500);
         $this->verse($o->t1, $o->t2, "Внимание! Этот перевод, возможно, ещё не готов.{$this->eol}Его статус: " . Yii::app()->params["translation_statuses"][$this->chap->status]);
     }
     if (!$skip_credits) {
         // Переведено пользователями
         $this->verse(Orig::ms2std($o->mstime("t2") + 10), Orig::ms2std($o->mstime("t2") + 2500), "Переведено на Нотабеноиде{$this->eol}http://" . Yii::app()->params["domain"] . $this->chap->url);
         // Первые 16 переводчиков
         arsort($this->translators);
         if (($nt = count($this->translators)) > 16) {
             $this->translators = array_slice($this->translators, 0, 16);
         }
         $this->translators = array_keys($this->translators);
         $t = $o->mstime("t2") + 2510;
         for ($i = 0; $i < ceil(count($this->translators) / 4); $i++) {
             $t1 = Orig::ms2std($t);
             $t2 = Orig::ms2std($t + 990);
             $txt = "";
             if ($i == 0) {
                 $txt .= "Переводчики: ";
             }
             for ($j = 0; $j < 4; $j++) {
                 if (!isset($this->translators[$i * 4 + $j])) {
                     break;
                 }
                 if ($j) {
                     $txt .= ", ";
                 }
                 $txt .= $this->translators[$i * 4 + $j];
             }
             if ($i == 3 && $nt > 16) {
                 $txt .= " и ещё " . Yii::t("app", "{n} человек|{n} человека|{n} человек", $nt - 16);
             }
             $this->verse($t1, $t2, $txt);
             $t += 1000;
         }
     }
     $this->footer();
     if ($return) {
         return ob_get_clean();
     } else {
         return true;
     }
 }