Php 用户报告库

Php 用户报告库,php,reporting,Php,Reporting,我想建立(或找到)一个php报告库,我可以使用它让我的用户报告任何类型的内容为坏。事实上,如果他们能把内容报道得很好(我想这意味着评级系统),那就更好了。所以如果有人知道这样的图书馆,我很想听听 无论如何,这就是我想象的数据库工作的方式,我想知道这听起来是否正确 ID-行的ID USER_ID-用户投票/报告的ID ITEM_ID-报告项目的唯一表行ID(帖子、其他用户、链接等) 类型-与此相关的表的名称(帖子、用户、链接等) 日期-报告的日期时间 价值-我猜这可能是一个赞成票或反对票 通过加入

我想建立(或找到)一个php报告库,我可以使用它让我的用户报告任何类型的内容为坏。事实上,如果他们能把内容报道得很好(我想这意味着评级系统),那就更好了。所以如果有人知道这样的图书馆,我很想听听

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

  • ID-行的ID
  • USER_ID-用户投票/报告的ID
  • ITEM_ID-报告项目的唯一表行ID(帖子、其他用户、链接等)
  • 类型-与此相关的表的名称(帖子、用户、链接等)
  • 日期-报告的日期时间
  • 价值-我猜这可能是一个赞成票或反对票

  • 通过加入[TYPE]专栏,我可以在我网站上的所有内容类型中使用这个投票系统,而不仅仅是一个(比如论坛帖子)。通过存储用户id,我可以确保每个用户对每个项目只投一次票/一份报告。

    好吧,我按照我说的做了。弗兰克是对的,这并不难。下面是代码,以防其他人希望在支持AR样式的DB调用(如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);
        }
    }
    

    好吧,我照我说的做了。弗兰克是对的,这并不难。下面是代码,以防其他人希望在支持AR样式的DB调用(如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);
        }
    }
    

    这是其中一件非常简单、非常特定于应用程序的事情,因此自己构建它可能更容易。除非您使用的是一个流行的框架或平台,在这种情况下,可能存在一个模块,但您需要指定您使用的框架/平台。这是一个非常简单,并且非常特定于应用程序的东西,您自己可能更容易构建它。除非您使用的是流行的框架或平台,在这种情况下,可能存在一个模块,但您需要指定您使用的框架/平台