用户报告库

发布于 2024-08-03 21:03:13 字数 446 浏览 4 评论 0原文

我想构建(或找到)一个 php 报告库,我可以使用它来允许我的用户报告任何类型的不良内容。实际上,如果他们能够将内容报告为良好(我想这意味着评级系统)那就更好了。因此,如果有人知道这样的图书馆,我很想听听。

无论如何,这就是我想象的数据库工作方式,我想知道这听起来是否正确。

  1. ID - 行 ID
  2. USER_ID - 投票/报告用户的 ID
  3. ITEM_ID - 报告项目的唯一表行 ID(帖子、其他用户、链接等...)
  4. TYPE - 所属表的名称(帖子、用户、链接等...)
  5. 日期 - 报告的日期时间
  6. 值 - 我想这可能是赞成票或反对票

通过包含 [类型] 列,我可以在网站上的所有内容类型中使用此投票系统,而不仅仅是一个(如论坛帖子)。通过存储 user_id,我可以确保每个用户的每个项目仅投一票/报告。

I would like to build (or find) a php reporting library that I can use to allow my users to report any type of content as bad. Actually, if they could report content as good (which I guess would mean a rating system) that would be even better. So if anyone knows of a library like this I would love to hear about it.

Anyway, this is how I imagine the database working and I would like to know if this sounds correct.

  1. ID - ID of row
  2. USER_ID - ID of the user voting/reporting
  3. ITEM_ID - UNIQUE table row ID of the item reported (post, other user, link, etc...)
  4. TYPE - the name of the table this pertains to (posts, users, links, etc...)
  5. DATE - datetime of report
  6. VALUE - I guess this could be an UP vote or DOWN vote

By including the [TYPE] column I can use this voting system across all content types on my site instead of just one (like forum posts). By storing the user_id I can be sure that only one vote/report is cast per item per user.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

乄_柒ぐ汐 2024-08-10 21:03:13

好吧,我按照我说的继续建造它。弗兰克是对的,这并不难。下面是代码,以防其他人想要在支持 AR 风格的数据库调用(如 CodeIgniter 或 MicroMVC)的 MVC 上使用它:

/*
 * Multi-table user voting model
 */
class votes extends model {

    public static $table = 'votes';


    function cast( $user_id = NULL, $item_id = NULL, $type = NULL, $vote = TRUE) {

        $where = array(
            'user_id'   => $user_id,
            'item_id'   => $item_id,
            'type'      => $type
        );

        //Try to fetch this row
        $row = $this->db->get_where(self::$table, $where );

        //Look for an existing vote row
        if( $row && ! empty($row[0]) ) {

            //Fetch row
            $row = $row[0];

            //If they already voted this way... then we're done!
            if( $row->vote == $vote) {
                return;
            }

            //Else update the row to the new vote
            $row->vote = $vote;
            $row->date = convert_time(time());

            $this->db->update( self::$table, $row, array('id' => $row->id) );

            return;
        }

        //Else create a new vote for this item
        $row = array(
            'user_id'   => $user_id,
            'item_id'   => $item_id,
            'type'      => $type,
            'date'      => convert_time(time()),
            'vote'      => $vote,
        );

        $this->db->insert( self::$table, $row);
    }
}

Well, I went ahead and built it like I said. Frank was right, it wasn't too hard. Here is the code incase anyone else wants to use it on a MVC that supports AR styled DB calls like CodeIgniter or MicroMVC:

/*
 * Multi-table user voting model
 */
class votes extends model {

    public static $table = 'votes';


    function cast( $user_id = NULL, $item_id = NULL, $type = NULL, $vote = TRUE) {

        $where = array(
            'user_id'   => $user_id,
            'item_id'   => $item_id,
            'type'      => $type
        );

        //Try to fetch this row
        $row = $this->db->get_where(self::$table, $where );

        //Look for an existing vote row
        if( $row && ! empty($row[0]) ) {

            //Fetch row
            $row = $row[0];

            //If they already voted this way... then we're done!
            if( $row->vote == $vote) {
                return;
            }

            //Else update the row to the new vote
            $row->vote = $vote;
            $row->date = convert_time(time());

            $this->db->update( self::$table, $row, array('id' => $row->id) );

            return;
        }

        //Else create a new vote for this item
        $row = array(
            'user_id'   => $user_id,
            'item_id'   => $item_id,
            'type'      => $type,
            'date'      => convert_time(time()),
            'vote'      => $vote,
        );

        $this->db->insert( self::$table, $row);
    }
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文