Classes

File content/comments/CommentsTopicDAO.class.php

File content/comments/CommentsTopicDAO.class.php

  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: 108: 109: 110: 111: 112: 113: 114: 115: 116: 117: 118: 119: 120: 121: 122: 123: 124: 125: 126: 127: 128: 129: 130: 131: 132: 133: 134: 135: 136: 137: 138: 139: 140: 141: 142: 143: 144: 145: 146: 
<?php
/**
 * @package     Content
 * @subpackage  Comments
 * @copyright   &copy; 2005-2019 PHPBoost
 * @license     https://www.gnu.org/licenses/gpl-3.0.html GNU/GPL-3.0
 * @author      Kevin MASSY <reidlos@phpboost.com>
 * @version     PHPBoost 5.2 - last update: 2015 12 17
 * @since       PHPBoost 3.0 - 2011 09 25
 * @contributor Julien BRISWALTER <j1.seth@phpboost.com>
*/

class CommentsTopicDAO
{
    private static $comments_cache;
    private static $db_querier;

    public static function __static()
    {
        self::$comments_cache = CommentsCache::load();
        self::$db_querier = PersistenceContext::get_querier();
    }

    public static function comments_topic_exists_by_module_id($module_id)
    {
        $parameters = array(
            'module_id' => $module_id,
        );
        return self::$db_querier->row_exists(DB_TABLE_COMMENTS_TOPIC, "WHERE module_id = :module_id", $parameters);
    }

    public static function get_id_topic_module($module_id, $id_in_module, $topic_identifier = CommentsTopic::DEFAULT_TOPIC_IDENTIFIER)
    {
        $condition = "WHERE id_in_module = :id_in_module AND module_id = :module_id AND topic_identifier=:topic_identifier";
        $parameters = array(
            'module_id' => $module_id,
            'id_in_module' => $id_in_module,
            'topic_identifier' => $topic_identifier,
        );
        return self::$db_querier->get_column_value(DB_TABLE_COMMENTS_TOPIC, 'id_topic', $condition, $parameters);
    }

    public static function get_id_topics_module($module_id)
    {
        $condition = "WHERE module_id = :module_id";
        $parameters = array(
            'module_id' => $module_id
        );

        $id_topics = array();
        $result = self::$db_querier->select_rows(DB_TABLE_COMMENTS_TOPIC, array('id_topic'), $condition, $parameters);
        while ($row = $result->fetch())
        {
            $id_topics[] = $row['id_topic'];
        }
        $result->dispose();

        return $id_topics;
    }

    public static function create_topic($module_id, $id_in_module, $topic_identifier, $path)
    {
        $columns = array(
            'module_id' => $module_id,
            'id_in_module' => $id_in_module,
            'topic_identifier' => $topic_identifier,
            'number_comments' => 0,
            'is_locked' => 0,
            'path' => $path
        );
        $result = self::$db_querier->insert(DB_TABLE_COMMENTS_TOPIC, $columns);
        return $result->get_last_inserted_id();
    }

    public static function topic_exists($module_id, $id_in_module, $topic_identifier)
    {
        $condition = "WHERE id_in_module = :id_in_module AND module_id = :module_id AND topic_identifier=:topic_identifier";
        $parameters = array(
            'module_id' => $module_id,
            'id_in_module' => $id_in_module,
            'topic_identifier' => $topic_identifier
        );
        return self::$db_querier->row_exists(DB_TABLE_COMMENTS_TOPIC, $condition, $parameters);
    }

    public static function delete_topics_module($module_id)
    {
        $condition = "WHERE module_id = :module_id";
        $parameters = array('module_id' => $module_id);
        self::$db_querier->delete(DB_TABLE_COMMENTS_TOPIC, $condition, $parameters);
    }

    public static function delete_topic_module($module_id, $id_in_module)
    {
        $condition = "WHERE module_id = :module_id AND id_in_module = :id_in_module";
        $parameters = array('module_id' => $module_id, 'id_in_module' => $id_in_module);
        Debug::dump(self::$db_querier->delete(DB_TABLE_COMMENTS_TOPIC, $condition, $parameters));
    }

    public static function incremente_number_comments_topic($id_topic)
    {
        self::$db_querier->inject("UPDATE ". DB_TABLE_COMMENTS_TOPIC ." SET number_comments = number_comments + 1 WHERE id_topic = '" . $id_topic . "'");
    }

    public static function decremente_number_comments_topic($id_topic)
    {
        self::$db_querier->inject("UPDATE ". DB_TABLE_COMMENTS_TOPIC ." SET number_comments = number_comments - 1 WHERE id_topic = '" . $id_topic . "'");
    }

    public static function comments_topic_locked($module_id, $id_in_module, $topic_identifier)
    {
        $condition = "WHERE id_in_module = :id_in_module AND module_id = :module_id AND topic_identifier=:topic_identifier";
        $parameters = array(
            'id_in_module' => $id_in_module,
            'module_id' => $module_id,
            'topic_identifier' => $topic_identifier
        );
        return self::$db_querier->get_column_value(DB_TABLE_COMMENTS_TOPIC, 'is_locked', $condition, $parameters) > 0 ? true : false;
    }

    public static function lock_topic($module_id, $id_in_module, $topic_identifier)
    {
        $columns = array('is_locked' => 1);
        $condition = "WHERE id_in_module = :id_in_module AND module_id = :module_id AND topic_identifier=:topic_identifier";
        $parameters = array(
            'id_in_module' => $id_in_module,
            'module_id' => $module_id,
            'topic_identifier' => $topic_identifier
        );
        self::$db_querier->update(DB_TABLE_COMMENTS_TOPIC, $columns, $condition, $parameters);
    }

    public static function unlock_topic($module_id, $id_in_module, $topic_identifier)
    {
        $columns = array('is_locked' => 0);
        $condition = "WHERE id_in_module = :id_in_module AND module_id = :module_id AND topic_identifier=:topic_identifier";
        $parameters = array(
            'id_in_module' => $id_in_module,
            'module_id' => $module_id,
            'topic_identifier' => $topic_identifier
        );
        self::$db_querier->update(DB_TABLE_COMMENTS_TOPIC, $columns, $condition, $parameters);
    }
}
?>
Annonces