Added commenting system

This commit is contained in:
Latif Khalifa
2013-10-14 13:52:29 +02:00
parent e9466ce592
commit 54f3b446e6
6 changed files with 1734 additions and 17 deletions

View File

@@ -25,7 +25,7 @@ class CrashStats
{
$ret = array();
$where = $this->filter->getWhere();
$q = "select count(r.id) as nr, s.id as signature_id, s.signature as signature_text from reports r join signature s on r.signature_id = s.id $where group by signature_id order by nr desc";
$q = "select count(r.id) as nr, s.id as signature_id, s.signature as signature_text, s.has_comments from reports r join signature s on r.signature_id = s.id $where group by signature_id order by nr desc";
$q .= kl_str_sql(" limit !i", 100);
if (false !== $cached = Memc::getq($q)) return $cached;
@@ -153,4 +153,41 @@ class CrashStats
Memc::setq($q, $ret);
return $ret;
}
function updateCommentCount($id)
{
$q = kl_str_sql("update signature set has_comments=(select count(*) as count from comment where signature_id=!i) where id=!i", $id, $id);
DBH::$db->query($q);
}
function addSignatureComment($id, $text)
{
global $S;
$q = kl_str_sql("insert into comment (signature_id, user_id, comment) values (!i, !i, !s)", $id, $S->user_id, $text);
DBH::$db->query($q);
self::updateCommentCount($id);
}
function getSignatureComments($id)
{
$ret = array();
$q = kl_str_sql("select c.*, u.name, u.email from comment c join users u on c.user_id = u.user_id where signature_id=!i order by id asc;", $id);
if (!$res = DBH::$db->query($q)) return;
while ($row = DBH::$db->fetchRow($res))
{
$c = new stdClass;
DBH::$db->loadFromDbRow($c, $res, $row);
$ret[] = $c;
}
return $ret;
}
function delSignatureComment($id, $del_id)
{
$q = kl_str_sql("delete from comment where id=!i", $del_id);
DBH::$db->query($q);
self::updateCommentCount($id);
}
}