<commit_before><?php
/**
 * $Id$
 *
 * @author <NAME>, 2009-2011 <<EMAIL>>
 */

//STATUS: wip

// see views/user/comments.php for a default comment list view

require_once('SqlObject.php');
require_once('constants.php');

class CommentViewer
{
    public static function render($type, $owner)
    {
        $view = new ViewModel('views/user/comments.php');
        $view->registerVar('type', $type);
        $view->registerVar('owner', $owner);
        return $view->render();
    }
}

class Comment
{
    var $id;
    var $type;          ///< see constants.php
    var $msg;
    var $private;       ///< bool
    var $time_created;
    var $time_deleted;
    var $deleted_by;
    var $owner;         ///< object that the comment belongs to
    var $creator;       ///< userId of creator
    var $creator_ip;    ///< IP of creator (string)

    protected static $tbl_name = 'tblComments';

    public static function get($type, $owner)
    {
        if (!is_numeric($type) || !is_numeric($owner))
            throw new Exception ('hmmm');

        $q =
        'SELECT * FROM '.self::$tbl_name.
        ' WHERE type = ? AND owner = ?'.
        ' ORDER BY time_created DESC';

        $list = Sql::pSelect($q, 'ii', $type, $owner);
        return SqlObject::loadObjects($list, __CLASS__);
    }

    /**
     * Helper function to create new comments
     */
    public static function create($type, $owner, $msg, $private = false)
    {
        $session = SessionHandler::getInstance();
        $c = new Comment();
        $c->type = $type;
        $c->owner = $owner;
        $c->msg = $msg;
        $c->private = $private;
        $c->creator = $session->id;
        $c->creator_ip = client_ip();
        $c->time_created = sql_datetime( time() );
        self::store($c);
    }

    public static function store($obj)
    {
        return SqlObject::store($obj, self::$tbl_name, 'id');
    }

}
<commit_msg>Comment::deleteByOwner() helper added<commit_after><?php
/**
 * $Id$
 *
 * @author <NAME>, 2009-2011 <<EMAIL>>
 */

//STATUS: wip

// see views/user/comments.php for a default comment list view

require_once('SqlObject.php');
require_once('constants.php');

class CommentViewer
{
    public static function render($type, $owner)
    {
        $view = new ViewModel('views/user/comments.php');
        $view->registerVar('type', $type);
        $view->registerVar('owner', $owner);
        return $view->render();
    }
}

class Comment
{
    var $id;
    var $type;          ///< see constants.php
    var $msg;
    var $private;       ///< bool
    var $time_created;
    var $time_deleted;
    var $deleted_by;
    var $owner;         ///< object that the comment belongs to
    var $creator;       ///< userId of creator
    var $creator_ip;    ///< IP of creator (string)

    protected static $tbl_name = 'tblComments';

    public static function get($type, $owner)
    {
        if (!is_numeric($type) || !is_numeric($owner))
            throw new Exception ('hmmm');

        $q =
        'SELECT * FROM '.self::$tbl_name.
        ' WHERE type = ? AND owner = ?'.
        ' ORDER BY time_created DESC';

        $list = Sql::pSelect($q, 'ii', $type, $owner);
        return SqlObject::loadObjects($list, __CLASS__);
    }

    /**
     * Helper function to create new comments
     */
    public static function create($type, $owner, $msg, $private = false)
    {
        $session = SessionHandler::getInstance();

        $c = new Comment();
        $c->type = $type;
        $c->owner = $owner;
        $c->msg = $msg;
        $c->private = $private;
        $c->creator = $session->id;
        $c->creator_ip = client_ip();
        $c->time_created = sql_datetime( time() );
        self::store($c);
    }

    public static function store($obj)
    {
        return SqlObject::store($obj, self::$tbl_name, 'id');
    }

    public static function deleteByOwner($type, $owner)
    {
        $session = SessionHandler::getInstance();

        $q =
        'UPDATE '.self::$tbl_name.
        ' SET deleted_by = ?, time_deleted = NOW()'.
        ' WHERE type = ? AND owner = ?';
        Sql::pUpdate($q, 'iii', $session->id, $type, $owner);
    }

}

{'fraction_non_alphanumeric': 0.16174706023518118, 'fraction_numerical': 0.003839692824574034, 'mean_word_length': 2.2461059190031154, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 32, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7463258', 'n_tokens_mistral': 1322, 'n_tokens_neox': 1303, 'n_words': 327}