Example #1
0
 /**
  * Инициализирует новый фрагмент в главе: для субтитров считает тайминг, для текста - ord
  */
 public function initNew($after_id = 0)
 {
     $after = false;
     if ($after_id) {
         $after = Orig::model()->findByPk((int) $_GET["after"], "chap_id = :chap_id", array(":chap_id" => $this->chap_id));
     }
     if ($this->chap->book->typ == "S") {
         if ($after) {
             $t1 = $after->mstime("t2") + 1;
             $next = Orig::model()->find(array("condition" => "chap_id = :chap_id AND t1 >= :t1 AND id != :id", "params" => array(":chap_id" => $this->chap_id, ":t1" => $after->t1, ":id" => $after->id), "order" => "t1"));
             if ($next) {
                 $t2 = $next->mstime("t1") - 1;
             } else {
                 $t2 = $after->mstime("t2") + 2001;
             }
             if ($t2 < $t1) {
                 $t2 = $t1;
             }
             $this->t1 = Orig::ms2std($t1);
             $this->t2 = Orig::ms2std($t2);
         } else {
             list($this->t1, $this->t2) = Yii::app()->db->createCommand("SELECT COALESCE(MAX(t2) + interval '0:0:1', '0:0:0') as t1, COALESCE(MAX(t2) + interval '0:0:2', '0:0:1') as t2 FROM orig WHERE chap_id = :chap_id")->queryRow(false, array(":chap_id" => $this->chap_id));
         }
     } else {
     }
     if ($after) {
         $this->ord = $after->ord + 1;
     } else {
         $this->ord = Yii::app()->db->createCommand("SELECT COALESCE(MAX(ord), 0) + 1 FROM orig WHERE chap_id = :chap_id")->queryScalar(array(":chap_id" => $this->chap_id));
     }
 }
Example #2
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;
     }
 }