Ejemplo n.º 1
0
 function addComment()
 {
     global $current_user;
     if (!$current_user->id) {
         return;
     }
     $comment = isset(Request::$post['comment']) ? Request::$post['comment'] : false;
     $comment = trim(prepare_review($comment, ''));
     if (!$comment) {
         throw new Exception('comment body expected');
     }
     $id = (int) Request::$post['id'];
     if (!$id) {
         throw new Exception('target id missed');
     }
     switch (Request::$post['type']) {
         case 'serie':
             $type = BiberLog::TargetType_serie;
             break;
         case 'author':
             $type = BiberLog::TargetType_person;
             break;
         case 'book':
             $type = BiberLog::TargetType_book;
             break;
     }
     if ($id) {
         MongoDatabase::addSimpleComment($type, $id, $current_user->id, $comment);
     }
 }
Ejemplo n.º 2
0
    public static function setStatus($id_user, $id_book, $status, $state)
    {
        global $current_user;
        $book = Books::getInstance()->getByIdLoaded($id_book);
        /* @var $book Book */
        if ($book->getQuality() >= BOOK::BOOK_QUALITY_BEST) {
            throw new Exception('book quality is best, you cant fix states');
        }
        if (!isset(self::$statuses[$status])) {
            throw new Exception('no status #' . $status);
        }
        if (!isset(self::$states[$state])) {
            throw new Exception('no status #' . $state);
        }
        $can_comment = false;
        if ($state > 0) {
            $query = 'SELECT `time` FROM `ocr` WHERE  `id_book`=' . $id_book . ' AND `id_user`=' . $id_user . ' AND `status`=' . $status . ' AND `state`=' . $state;
            $last_time = Database::sql2single($query);
            if (time() - $last_time > 24 * 60 * 60) {
                $can_comment = true;
            }
        }
        if ($state == 0 && $status !== 0) {
            // delete
            $query = 'DELETE FROM `ocr` WHERE  `id_book`=' . $id_book . ' AND `id_user`=' . $id_user . ' AND `status`=' . $status . '';
        } else {
            // upsert
            $query = 'INSERT INTO `ocr` SET `id_book`=' . $id_book . ', `id_user`=' . $id_user . ', `status`=' . $status . ',`state`=' . $state . ',`time`=' . time() . '
			ON DUPLICATE KEY UPDATE
			`time`=' . time() . ', `state`=' . $state;
        }
        if (!Database::query($query, false)) {
            throw new Exception('Duplicating #book ' . $id_book . ' #status' . $status . ' #state' . $state);
        }
        if ($state == 0) {
            $comment = 'User ' . $current_user->id . ' drop status ' . $status . ' state ' . $state . ' user_id ' . $id_user;
        } else {
            $comment = 'User ' . $current_user->id . ' set status ' . $status . ' state ' . $state . ' user_id ' . $id_user;
        }
        $comUser = Users::getById($id_user);
        /* @var $comUser User */
        if ($can_comment && ($part = self::getMessagePart($status, $state))) {
            $comment = mb_strtolower($part, 'UTF-8') . ' книгу';
            MongoDatabase::addSimpleComment(BiberLog::TargetType_book, $id_book, $id_user, $comment);
        }
    }