1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40: 41: 42: 43: 44: 45: 46: 47: 48: 49: 50: 51: 52: 53: 54: 55: 56: 57: 58: 59: 60: 61: 62: 63: 64: 65: 66: 67: 68: 69: 70: 71: 72: 73: 74: 75: 76: 77: 78: 79: 80: 81: 82: 83: 84: 85: 86: 87: 88: 89: 90: 91: 92: 93: 94: 95: 96: 97: 98: 99: 100: 101: 102: 103: 104: 105: 106: 107:
<?php
class AjaxCommentsNotationController extends AbstractCommentsController
{
const LESS_NOTE = 'less';
const PLUS_NOTE = 'plus';
public function execute(HTTPRequestCustom $request)
{
parent::execute($request);
$note_type = $request->get_poststring('note_type', '');
$comment_id = $request->get_poststring('comment_id', '');
$comments_lang = LangLoader::get('comments-common');
if ($this->verificate_note_type($note_type) && $this->is_access_authorizations() && !empty($comment_id))
{
$this->register_note($note_type, $comment_id);
$object = array(
'success' => true,
'message' => $comments_lang['comment.note.success']
);
}
else if (!$this->is_access_authorizations())
{
$object = array(
'success' => false,
'message' => $comments_lang['comments.not-authorized.note']
);
}
else
{
$object = array(
'success' => false,
'message' => $comments_lang['comment.note.error']
);
}
return new JSONResponse($object);
}
private function register_note($note_type, $comment_id)
{
$comment = CommentsCache::load()->get_comment($comment_id);
$current_note = $comment['note'];
switch ($note_type) {
case self::LESS_NOTE:
$note = $current_note - 1;
break;
case self::PLUS_NOTE:
$note = $current_note + 1;
break;
}
$columns = array('note' => $note);
$condition = "WHERE id = :id";
$parameters = array('id' => $comment_id);
PersistenceContext::get_querier()->update(DB_TABLE_COMMENTS, $columns, $condition, $parameters);
$this->regenerate_cache();
}
private function verificate_note_type($type)
{
switch ($type) {
case self::LESS_NOTE:
case self::PLUS_NOTE:
return true;
break;
default:
return false;
break;
}
}
private function is_access_authorizations()
{
return $this->is_authorized_note() && $this->is_display() && $this->is_authorized_access();
}
private function is_authorized_note()
{
return $this->get_authorizations()->is_authorized_note();
}
private function is_authorized_access()
{
return $this->get_authorizations()->is_authorized_access_module();
}
private function regenerate_cache()
{
CommentsCache::invalidate();
}
}
?>