PEPr
[ class tree: PEPr ] [ index: PEPr ] [ all elements ]

Source for file pepr-ppvote.php

Documentation is available at pepr-ppvote.php

  1. <?php
  2. /**
  3.  * Establishes the procedures, objects and variables used throughout PEPr.
  4.  *
  5.  * The <var>$proposalReviewsMap</var> arrays is defined here.
  6.  *
  7.  * NOTE: Proposal constants are defined in pearweb/include/pear-config.php.
  8.  *
  9.  * This source file is subject to version 3.0 of the PHP license,
  10.  * that is bundled with this package in the file LICENSE, and is
  11.  * available through the world-wide-web at the following URI:
  12.  * http://www.php.net/license/3_0.txt.
  13.  * If you did not receive a copy of the PHP license and are unable to
  14.  * obtain it through the world-wide-web, please send a note to
  15.  * license@php.net so we can mail you a copy immediately.
  16.  *
  17.  * @category  pearweb
  18.  * @package   PEPr
  19.  * @author    Tobias Schlitt <toby@php.net>
  20.  * @author    Daniel Convissor <danielc@php.net>
  21.  * @copyright Copyright (c) 1997-2005 The PHP Group
  22.  * @license   http://www.php.net/license/3_0.txt  PHP License
  23.  * @version   $Id: pepr-ppvote.php 312511 2011-06-27 10:33:02Z clockwerx $
  24.  */
  25.  
  26. global $proposalReviewsMap;
  27. $proposalReviewsMap = array(
  28.                             'cursory'   => 'Cursory source review',
  29.                             'deep'      => 'Deep source review',
  30.                             'test'      => 'Run examples');
  31.  
  32. class ppVote
  33. {
  34.     var $pkg_prop_id;
  35.     var $user_handle;
  36.     var $value;
  37.     var $reviews = array();
  38.     var $is_conditional;
  39.     var $comment;
  40.     var $timestamp;
  41.  
  42.     function __construct($dbhResArr)
  43.     {
  44.         foreach ($dbhResArr as $name => $value{
  45.             $this->$name $value;
  46.         }
  47.     }
  48.  
  49.     function get(&$dbh$proposalId$handle)
  50.     {
  51.         $sql "SELECT *, UNIX_TIMESTAMP(timestamp) AS timestamp FROM package_proposal_votes WHERE pkg_prop_id = "$dbh->quoteSmart($proposalId." AND user_handle= "$dbh->quoteSmart($handle);
  52.         $res $dbh->query($sql);
  53.         if (DB::isError($res)) {
  54.             return $res;
  55.         }
  56.         if (!$res->numRows()) {
  57.             return null;
  58.         }
  59.         $set $res->fetchRow(DB_FETCHMODE_ASSOC);
  60.         $set['reviews'unserialize($set['reviews']);
  61.         $vote = new ppVote($set);
  62.         return $vote;
  63.     }
  64.  
  65.     function &getAll(&$dbh$proposalId)
  66.     {
  67.         $sql "SELECT *, UNIX_TIMESTAMP(timestamp) AS timestamp FROM package_proposal_votes WHERE pkg_prop_id = "$dbh->quoteSmart($proposalId." ORDER BY timestamp ASC";
  68.         $res $dbh->query($sql);
  69.         if (DB::isError($res)) {
  70.             return $res;
  71.         }
  72.         $votes = array();
  73.         while ($set $res->fetchRow(DB_FETCHMODE_ASSOC)) {
  74.             $set['reviews'unserialize($set['reviews']);
  75.             $votes[$set['user_handle']] = new ppVote($set);
  76.         }
  77.         return $votes;
  78.     }
  79.  
  80.     function store($dbh$proposalId)
  81.     {
  82.         if (empty($this->user_handle)) {
  83.             return PEAR::raiseError("Not initialized");
  84.         }
  85.         $sql "INSERT INTO package_proposal_votes (pkg_prop_id, user_handle, value, is_conditional, comment, reviews)
  86.                     VALUES ("$dbh->quoteSmart($proposalId).", ".$dbh->quoteSmart($this->user_handle).", ".$this->value.", ".(int)$this->is_conditional.", ".$dbh->quoteSmart($this->comment).", ".$dbh->quoteSmart(serialize($this->reviews)).")";
  87.         $res $dbh->query($sql);
  88.         return $res;
  89.     }
  90.  
  91.     function getReviews($humanReadable = false)
  92.     {
  93.         if ($humanReadable{
  94.             $res = array();
  95.             if (!empty($this->reviews)) {
  96.                 foreach ((array)$this->reviews as $review{
  97.                     $res[$GLOBALS['proposalReviewsMap'][$review];
  98.                 }
  99.             }
  100.             return $res;
  101.         }
  102.         return $this->reviews;
  103.     }
  104.  
  105.     function getSum($dbh$proposalId)
  106.     {
  107.         $sql "SELECT SUM(value) FROM package_proposal_votes WHERE pkg_prop_id = ".$proposalId." GROUP BY pkg_prop_id";
  108.         $result $dbh->getOne($sql);
  109.         $res['all'(is_numeric($result)) $result : 0;
  110.         $sql "SELECT SUM(value) FROM package_proposal_votes WHERE pkg_prop_id = ".$proposalId." AND is_conditional = 1 GROUP BY pkg_prop_id";
  111.         $result $dbh->getOne($sql);
  112.         $res['conditional'(is_numeric($result)) $result : 0;
  113.         return $res;
  114.     }
  115.  
  116.     function getCount($dbh$proposalId)
  117.     {
  118.         $sql "SELECT COUNT(user_handle) FROM package_proposal_votes WHERE pkg_prop_id = ".$dbh->quoteSmart($proposalId)." GROUP BY pkg_prop_id";
  119.         $res $dbh->getOne($sql);
  120.         return (!empty($res)) $res" 0";
  121.     }
  122.  
  123.     function hasVoted($dbh$userHandle$proposalId)
  124.     {
  125.         $sql "SELECT count(pkg_prop_id) as votecount FROM package_proposal_votes
  126.                     WHERE pkg_prop_id = ".$dbh->quoteSmart($proposalId)." AND user_handle = ".$dbh->quoteSmart($userHandle)."
  127.                     GROUP BY pkg_prop_id";
  128.         $votes $dbh->query($sql);
  129.         return (bool)($votes->numRows());
  130.     }
  131.  
  132. }

Documentation generated on Mon, 11 Mar 2019 15:44:05 -0400 by phpDocumentor 1.4.4. PEAR Logo Copyright © PHP Group 2004.