本文整理汇总了PHP中Notify::notifyNewBookReview方法的典型用法代码示例。如果您正苦于以下问题:PHP Notify::notifyNewBookReview方法的具体用法?PHP Notify::notifyNewBookReview怎么用?PHP Notify::notifyNewBookReview使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Notify
的用法示例。
在下文中一共展示了Notify::notifyNewBookReview方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: write
function write()
{
global $current_user;
if (!$current_user->authorized) {
throw new Exception('Access Denied');
}
$data = array('target_id' => max(0, (int) Request::$post['target_id']), 'target_type' => max(0, (int) Request::$post['target_type']), 'comment' => prepare_review(Request::$post['annotation']), 'rate' => min(6, max(0, (int) Request::$post['rate'])) + 1);
$event = new Event();
$time = time();
//$old = MongoDatabase::findReviewEventData($current_user->id, $data['target_id']);
//$with_review = (isset($old['body']) && $old['body']) ? 1 : 0;
$with_review = 0;
// upsert rate into database
if ($data['rate']) {
$query = 'INSERT INTO `book_rate` SET `with_review`=' . $with_review . ', `id_book`=' . $data['target_id'] . ',`id_user`=' . $current_user->id . ',`rate`=' . ($data['rate'] - 1) . ',`time`=' . $time . ' ON DUPLICATE KEY UPDATE
`rate`=' . ($data['rate'] - 1) . ',`time`=' . $time . ',`with_review`=' . $with_review . '';
Database::query($query);
//recalculating rate
$query = 'SELECT COUNT(1) as cnt, SUM(`rate`) as rate FROM `book_rate` WHERE `id_book`=' . $data['target_id'];
$res = Database::sql2row($query);
$book_mark = round($res['rate'] / $res['cnt'] * 10);
$query = 'UPDATE `book` SET `mark`=' . $book_mark . ' WHERE `id`=' . $data['target_id'];
Database::query($query);
}
// insert data into mongo
if (!$data['comment']) {
unset($data['comment']);
}
if (isset($data['comment']) && $data['comment']) {
$event->event_BookReviewAdd($current_user->id, $data);
Notify::notifyNewBookReview($data['target_id'], $current_user->id);
} else {
if ($data['rate'] > 1) {
$event->event_BookRateAdd($current_user->id, $data);
}
}
$event->push();
}