Esempio n. 1
0
 /**
  * Инициализация рейтинга звёздами
  * @param int $toid ID ресурса
  * @param int $owner владелец ресурса(ч/с создатель торрента)
  * @param array $res массив ресурса
  * @param int $stoid доп. ID ресурса(только для проверки на то, голосовал ли)
  * @return null
  */
 public function display($toid, $owner = null, $res = null, $stoid = 0)
 {
     if (!$this->state) {
         return;
     }
     if (is_array($toid)) {
         if ($toid["type"]) {
             $this->change_type($toid["type"]);
         }
         $owner = $toid["owner"];
         $res = $toid["res"];
         $stoid = $toid["stoid"];
         if ($toid["stype"]) {
             $this->change_stype($toid["stype"]);
         }
         $toid = $toid["toid"];
     }
     $type = $this->type;
     $stype = $this->stype;
     lang::o()->get('rating');
     $owner = (int) $owner;
     $toid = (int) $toid;
     $stoid = (int) $stoid;
     $count = 0;
     if (is_numeric($res["rate_count"]) && is_numeric($res["rnum_count"])) {
         $count = $res["rnum_count"];
         $cur_votes = $res["rnum_count"] ? $res["rate_count"] / $res["rnum_count"] : 0;
     } else {
         $where = 'toid = ? AND type = ?';
         $count = db::o()->p($toid, $type)->count_rows("ratings", $where);
         $cur_votes = db::o()->p($toid, $type)->act_rows("ratings", "value", "avg", $where);
     }
     $this->min[$type] = (double) $this->min[$type];
     $this->max[$type] = (double) $this->max[$type];
     $this->part[$type] = (double) $this->part[$type];
     $disabled = $this->check_voted($owner, $toid, $stoid);
     $this->value_to_part($cur_votes);
     self::$count++;
     tpl::o()->assign('subratingid', 'cb' . self::$count . 'ce');
     tpl::o()->assign("rtoid", $toid);
     tpl::o()->assign("rtype", $type);
     tpl::o()->assign("total", $cur_votes);
     tpl::o()->assign("disabled", $disabled);
     tpl::o()->assign("count", $count);
     tpl::o()->assign("min", $this->min[$type]);
     tpl::o()->assign("loop", $this->part[$type] ? ($this->max[$type] - $this->min[$type]) / $this->part[$type] + 1 : 1);
     // section почему-то не хочет обрабатывать последнее значение
     tpl::o()->assign("per", $this->part[$type]);
     tpl::o()->assign("split", $this->part[$type] ? $this->part[$type] > 0 && $this->part[$type] <= 1 ? 1 / $this->part[$type] : 1 : 0);
     tpl::o()->assign("rating_inited", self::$inited);
     if (!self::$inited) {
         self::$inited = true;
     }
     tpl::o()->display("content/rating.tpl");
 }