svn: /pear/pearweb/trunk/include/pepr/ pepr-ppvote.php pepr.php

[email protected] (Till Klampaeckel) Fri, 18 Mar 2011 15:50:04 +0000
Newsgroups php.pear.cvs,php.pear.core
Message-ID <[email protected]>
till                                     Fri, 18 Mar 2011 15:50:04 +0000

Revision: http://svn.php.net/viewvc?view=revision&revision=309393

Log:
spin off class ppvote

Changed paths:
    A + pear/pearweb/trunk/include/pepr/pepr-ppvote.php
        (from pear/pearweb/trunk/include/pepr/pepr.php:r309392)
    U   pear/pearweb/trunk/include/pepr/pepr.php
svn-diffs-309393.txt (text/x-diff, 9.2 KB)
Copied: pear/pearweb/trunk/include/pepr/pepr-ppvote.php (from rev 309392, pear/pearweb/trunk/include/pepr/pepr.php)
===================================================================
--- pear/pearweb/trunk/include/pepr/pepr-ppvote.php	                        (rev 0)
+++ pear/pearweb/trunk/include/pepr/pepr-ppvote.php	2011-03-18 15:50:04 UTC (rev 309393)
@@ -0,0 +1,129 @@
+<?php
+/**
+ * Establishes the procedures, objects and variables used throughout PEPr.
+ *
+ * The <var>$proposalReviewsMap</var> arrays is defined here.
+ *
+ * NOTE: Proposal constants are defined in pearweb/include/pear-config.php.
+ *
+ * This source file is subject to version 3.0 of the PHP license,
+ * that is bundled with this package in the file LICENSE, and is
+ * available through the world-wide-web at the following URI:
+ * http://www.php.net/license/3_0.txt.
+ * If you did not receive a copy of the PHP license and are unable to
+ * obtain it through the world-wide-web, please send a note to
+ * [email protected] so we can mail you a copy immediately.
+ *
+ * @category  pearweb
+ * @package   PEPr
+ * @author    Tobias Schlitt <[email protected]>
+ * @author    Daniel Convissor <[email protected]>
+ * @copyright Copyright (c) 1997-2005 The PHP Group
+ * @license   http://www.php.net/license/3_0.txt  PHP License
+ * @version   $Id$
+ */
+
+global $proposalReviewsMap;
+$proposalReviewsMap = array(
+                            'cursory'   => 'Cursory source review',
+                            'deep'      => 'Deep source review',
+                            'test'      => 'Run examples');
+
+class ppVote
+{
+    var $pkg_prop_id;
+    var $user_handle;
+    var $value;
+    var $reviews;
+    var $is_conditional;
+    var $comment;
+    var $timestamp;
+
+    function __construct($dbhResArr)
+    {
+        foreach ($dbhResArr as $name => $value) {
+            $this->$name = $value;
+        }
+    }
+
+    function get(&$dbh, $proposalId, $handle)
+    {
+        $sql = "SELECT *, UNIX_TIMESTAMP(timestamp) AS timestamp FROM package_proposal_votes WHERE pkg_prop_id = ".$proposalId." AND user_handle='".$handle."'";
+        $res = $dbh->query($sql);
+        if (DB::isError($res)) {
+            return $res;
+        }
+        if (!$res->numRows()) {
+            return null;
+        }
+        $set = $res->fetchRow(DB_FETCHMODE_ASSOC);
+        $set['reviews'] = unserialize($set['reviews']);
+        $vote = new ppVote($set);
+        return $vote;
+    }
+
+    function &getAll(&$dbh, $proposalId)
+    {
+        $sql = "SELECT *, UNIX_TIMESTAMP(timestamp) AS timestamp FROM package_proposal_votes WHERE pkg_prop_id = ".$proposalId." ORDER BY timestamp ASC";
+        $res = $dbh->query($sql);
+        if (DB::isError($res)) {
+            return $res;
+        }
+        $votes = array();
+        while ($set = $res->fetchRow(DB_FETCHMODE_ASSOC)) {
+            $set['reviews'] = unserialize($set['reviews']);
+            $votes[$set['user_handle']] = new ppVote($set);
+        }
+        return $votes;
+    }
+
+    function store($dbh, $proposalId)
+    {
+        if (empty($this->user_handle)) {
+            return PEAR::raiseError("Not initialized");
+        }
+        $sql = "INSERT INTO package_proposal_votes (pkg_prop_id, user_handle, value, is_conditional, comment, reviews)
+                    VALUES (".$proposalId.", ".$dbh->quoteSmart($this->user_handle).", ".$this->value.", ".(int)$this->is_conditional.", ".$dbh->quoteSmart($this->comment).", ".$dbh->quoteSmart(serialize($this->reviews)).")";
+        $res = $dbh->query($sql);
+        return $res;
+    }
+
+    function getReviews($humanReadable = false)
+    {
+        if ($humanReadable) {
+            foreach ($this->reviews as $review) {
+                $res[] = $GLOBALS['proposalReviewsMap'][$review];
+            }
+            return $res;
+        }
+        return $this->reviews;
+    }
+
+    function getSum($dbh, $proposalId)
+    {
+        $sql = "SELECT SUM(value) FROM package_proposal_votes WHERE pkg_prop_id = ".$proposalId." GROUP BY pkg_prop_id";
+        $result = $dbh->getOne($sql);
+        $res['all'] = (is_numeric($result)) ? $result : 0;
+        $sql = "SELECT SUM(value) FROM package_proposal_votes WHERE pkg_prop_id = ".$proposalId." AND is_conditional = 1 GROUP BY pkg_prop_id";
+        $result = $dbh->getOne($sql);
+        $res['conditional'] = (is_numeric($result)) ? $result : 0;
+        return $res;
+    }
+
+    function getCount($dbh, $proposalId)
+    {
+        $sql = "SELECT COUNT(user_handle) FROM package_proposal_votes WHERE pkg_prop_id = ".$proposalId." GROUP BY pkg_prop_id";
+        $res = $dbh->getOne($sql);
+        return (!empty($res)) ? $res: " 0";
+    }
+
+    function hasVoted($dbh, $userHandle, $proposalId)
+    {
+        $sql = "SELECT count(pkg_prop_id) as votecount FROM package_proposal_votes
+                    WHERE pkg_prop_id = ".$proposalId." AND user_handle = '".$userHandle."'
+                    GROUP BY pkg_prop_id";
+        $votes = $dbh->query($sql);
+        return (bool)($votes->numRows());
+    }
+
+}

Modified: pear/pearweb/trunk/include/pepr/pepr.php
===================================================================
--- pear/pearweb/trunk/include/pepr/pepr.php	2011-03-18 15:42:12 UTC (rev 309392)
+++ pear/pearweb/trunk/include/pepr/pepr.php	2011-03-18 15:50:04 UTC (rev 309393)
@@ -114,112 +114,8 @@

 require_once __DIR__ . '/pepr-proposal.php';
 require_once __DIR__ . '/pepr-ppcomment.php';
+require_once __DIR__ . '/pepr-ppvote.php';

-global $proposalReviewsMap;
-$proposalReviewsMap = array(
-                            'cursory'   => 'Cursory source review',
-                            'deep'      => 'Deep source review',
-                            'test'      => 'Run examples');
-
-class ppVote
-{
-    var $pkg_prop_id;
-    var $user_handle;
-    var $value;
-    var $reviews;
-    var $is_conditional;
-    var $comment;
-    var $timestamp;
-
-    function __construct($dbhResArr)
-    {
-        foreach ($dbhResArr as $name => $value) {
-            $this->$name = $value;
-        }
-    }
-
-    function get(&$dbh, $proposalId, $handle)
-    {
-        $sql = "SELECT *, UNIX_TIMESTAMP(timestamp) AS timestamp FROM package_proposal_votes WHERE pkg_prop_id = ".$proposalId." AND user_handle='".$handle."'";
-        $res = $dbh->query($sql);
-        if (DB::isError($res)) {
-            return $res;
-        }
-        if (!$res->numRows()) {
-            return null;
-        }
-        $set = $res->fetchRow(DB_FETCHMODE_ASSOC);
-        $set['reviews'] = unserialize($set['reviews']);
-        $vote = new ppVote($set);
-        return $vote;
-    }
-
-    function &getAll(&$dbh, $proposalId)
-    {
-        $sql = "SELECT *, UNIX_TIMESTAMP(timestamp) AS timestamp FROM package_proposal_votes WHERE pkg_prop_id = ".$proposalId." ORDER BY timestamp ASC";
-        $res = $dbh->query($sql);
-        if (DB::isError($res)) {
-            return $res;
-        }
-        $votes = array();
-        while ($set = $res->fetchRow(DB_FETCHMODE_ASSOC)) {
-            $set['reviews'] = unserialize($set['reviews']);
-            $votes[$set['user_handle']] = new ppVote($set);
-        }
-        return $votes;
-    }
-
-    function store($dbh, $proposalId)
-    {
-        if (empty($this->user_handle)) {
-            return PEAR::raiseError("Not initialized");
-        }
-        $sql = "INSERT INTO package_proposal_votes (pkg_prop_id, user_handle, value, is_conditional, comment, reviews)
-                    VALUES (".$proposalId.", ".$dbh->quoteSmart($this->user_handle).", ".$this->value.", ".(int)$this->is_conditional.", ".$dbh->quoteSmart($this->comment).", ".$dbh->quoteSmart(serialize($this->reviews)).")";
-        $res = $dbh->query($sql);
-        return $res;
-    }
-
-    function getReviews($humanReadable = false)
-    {
-        if ($humanReadable) {
-            foreach ($this->reviews as $review) {
-                $res[] = $GLOBALS['proposalReviewsMap'][$review];
-            }
-            return $res;
-        }
-        return $this->reviews;
-    }
-
-    function getSum($dbh, $proposalId)
-    {
-        $sql = "SELECT SUM(value) FROM package_proposal_votes WHERE pkg_prop_id = ".$proposalId." GROUP BY pkg_prop_id";
-        $result = $dbh->getOne($sql);
-        $res['all'] = (is_numeric($result)) ? $result : 0;
-        $sql = "SELECT SUM(value) FROM package_proposal_votes WHERE pkg_prop_id = ".$proposalId." AND is_conditional = 1 GROUP BY pkg_prop_id";
-        $result = $dbh->getOne($sql);
-        $res['conditional'] = (is_numeric($result)) ? $result : 0;
-        return $res;
-    }
-
-    function getCount($dbh, $proposalId)
-    {
-        $sql = "SELECT COUNT(user_handle) FROM package_proposal_votes WHERE pkg_prop_id = ".$proposalId." GROUP BY pkg_prop_id";
-        $res = $dbh->getOne($sql);
-        return (!empty($res)) ? $res: " 0";
-    }
-
-    function hasVoted($dbh, $userHandle, $proposalId)
-    {
-        $sql = "SELECT count(pkg_prop_id) as votecount FROM package_proposal_votes
-                    WHERE pkg_prop_id = ".$proposalId." AND user_handle = '".$userHandle."'
-                    GROUP BY pkg_prop_id";
-        $votes = $dbh->query($sql);
-        return (bool)($votes->numRows());
-    }
-
-}
-
 global $proposalTypeMap;
 $proposalTypeMap = array(
                          'pkg_file'             => "PEAR package file (.tgz)",