cvs: pearweb /include/pepr pepr.php

From: Date: Wed, 21 Jan 2004 16:10:41 +0000
Subject: cvs: pearweb /include/pepr pepr.php
Groups: php.pear.cvs 
Request: Send a blank email to pear-cvs+get-15842@lists.php.net to get a copy of this message
toby Wed Jan 21 11:10:41 2004 EDT Modified files: /pearweb/include/pepr pepr.php Log: * Proposal comments are now saved into database. http://cvs.php.net/diff.php/pearweb/include/pepr/pepr.php?r1=1.18&r2=1.19&ty=u Index: pearweb/include/pepr/pepr.php diff -u pearweb/include/pepr/pepr.php:1.18 pearweb/include/pepr/pepr.php:1.19 --- pearweb/include/pepr/pepr.php:1.18 Thu Jan 15 14:14:44 2004 +++ pearweb/include/pepr/pepr.php Wed Jan 21 11:10:40 2004 @@ -182,12 +182,12 @@ return true; } - function addComment ( $comment ) { + function addComment ( $comment, $table = 'package_proposal_changelog' ) { $commentData = array("pkg_prop_id" => $this->id, "user_handle" => $_COOKIE['PEAR_USER'], "comment" => $comment); - - $this->comment = new ppComment( $commentData ); + $comment = new ppComment( $commentData, $table ); + $comment->store($this->id); return true; } @@ -264,6 +264,16 @@ if (DB::isError($res)) { return $res; } + $sql = "DELETE FROM package_proposal_changelog WHERE pkg_prop_id = ".$this->id; + $res = $dbh->query($sql); + if (DB::isError($res)) { + return $res; + } + $sql = "DELETE FROM package_proposal_comments WHERE pkg_prop_id = ".$this->id; + $res = $dbh->query($sql); + if (DB::isError($res)) { + return $res; + } return true; } @@ -381,16 +391,20 @@ var $timestamp; var $comment; + + var $table; - function ppComment ( $dbhResArr ) { + function ppComment ( $dbhResArr, $table = 'package_proposal_changelog' ) { foreach ($dbhResArr as $name => $value) { $value = (is_string($value)) ? stripslashes($value) : $value; $this->$name = $value; } + $this->table = $table; } - function get ( &$dbh, $proposalId, $handle, $timestamp ) { - $sql = "SELECT *, UNIX_TIMESTAMP(timestamp) AS timestamp FROM package_proposal_changelog WHERE pkg_prop_id = ".$proposalId." AND user_handle='".$handle."' AND timestamp = FROM_UNIXTIME(".$timestamp.")"; + function get ( $proposalId, $handle, $timestamp, $table = 'package_proposal_changelog') { + global $dbh; + $sql = "SELECT *, timestamp FROM ".$table." WHERE pkg_prop_id = ".$proposalId." AND user_handle='".$handle."' AND timestamp = FROM_UNIXTIME(".$timestamp.")"; $res = $dbh->query($sql); if (DB::isError($res)) { return $res; @@ -401,8 +415,9 @@ return $comment; } - function &getAll ( &$dbh, $proposalId ) { - $sql = "SELECT *, UNIX_TIMESTAMP(timestamp) AS timestamp FROM package_proposal_changelog WHERE pkg_prop_id = ".$proposalId; + function &getAll ( $proposalId, $table = 'package_proposal_changelog' ) { + global $dbh; + $sql = "SELECT *, timestamp FROM ".$table." WHERE pkg_prop_id = ".$proposalId; $res = $dbh->query($sql); if (DB::isError($res)) { return $res; @@ -415,15 +430,26 @@ return $comments; } - function store ( $dbh, $proposalId ) { + function store ( $proposalId ) { + global $dbh; if (empty($this->user_handle)) { return PEAR::raiseError("Not initialized"); } - $sql = "INSERT INTO package_proposal_changelog (pkg_prop_id, user_handle, comment) - VALUES (".$proposalId.", ".$dbh->quote($this->user_handle).", ".$dbh->quote($this->comment).")"; + $sql = "INSERT INTO ".$this->table." (pkg_prop_id, user_handle, comment, timestamp) + VALUES (".$proposalId.", ".$dbh->quote($this->user_handle).", ".$dbh->quote($this->comment).", ".time().")"; $res = $dbh->query($sql); return $res; - } + } + + function delete ( ) { + global $dbh; + if (empty($this->table) || empty($this->user_handle) || empty($this->pkg_prop_id) || empty($this->timestamp)) { + return PEAR::raiseError("Inconsistant comment data. Can not delete comment."); + } + $sql = "DELETE FROM ".$this->table." WHERE user_handle = '".$this->user_handle."' AND pkg_prop_id = ".$this->pkg_prop_id." AND timestamp = ".$this->timestamp; + $res = $dbh->query($sql); + return true; + } } global $proposalReviewsMap;

« previous php.pear.cvs (#15842) next »