This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "FusionForge".
The branch, master has been updated
via 9161aa452bcab01071e6b6c2805b2192f7e21cce (commit)
from dd2b31cddcae6bcebcecd87e72204ebf20f1e72b (commit)
Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.
- Log -----------------------------------------------------------------
https://scm.fusionforge.org/anonscm/gitweb/?p=fusionforge/fusionforge.git;a=commitdiff;h=9161aa452bcab01071e6b6c2805b2192f7e21cce
commit 9161aa452bcab01071e6b6c2805b2192f7e21cce
Author: Franck Villaume <[email protected]>
Date: Sun Sep 22 19:49:37 2019 +0200
vote for diary
diff --git a/src/common/diary/DiaryNote.class.php
b/src/common/diary/DiaryNote.class.php
index b849397..007d912 100644
--- a/src/common/diary/DiaryNote.class.php
+++ b/src/common/diary/DiaryNote.class.php
@@ -65,6 +65,18 @@ class DiaryNote extends FFObject {
var $User;
/**
+ * cached return value of getVotes
+ * @var int|bool $votes
+ */
+ var $votes = false;
+
+ /**
+ * cached return value of getVoters
+ * @var int|bool $voters
+ */
+ var $voters = false;
+
+ /**
* @param $User
*/
function __construct(&$User, $noteid = false, $arr = false) {
@@ -192,4 +204,118 @@ class DiaryNote extends FFObject {
$content .= html_e('div', array('class' =>
'widget-sticker-footer'), _('Posted')._(': ').$this->getDatePostedOn());
return html_e('div', array('class' =>
'widget-sticker-container'), $content);
}
+
+ /**
+ * castVote - Vote on this tracker item or retract the vote
+ * @param bool $value true to cast, false to retract
+ * @return bool success (false sets error message)
+ */
+ function castVote($value = true) {
+ if (!($uid = user_getid()) || $uid == 100) {
+ $this->setMissingParamsError(_('User ID not passed'));
+ return false;
+ }
+ if (!$this->canVote()) {
+ $this->setPermissionDeniedError();
+ return false;
+ }
+ $has_vote = $this->hasVote($uid);
+ if ($has_vote == $value) {
+ /* nothing changed */
+ return true;
+ }
+ if ($value) {
+ $res = db_query_params('INSERT INTO diary_votes
(diary_id, user_id) VALUES ($1, $2)',
+ array($this->getID(), $uid));
+ } else {
+ $res = db_query_params('DELETE FROM diary_votes WHERE
diary_id = $1 AND user_id = $2',
+ array($this->getID(), $uid));
+ }
+ if (!$res) {
+ $this->setError(db_error());
+ return false;
+ }
+ return true;
+ }
+
+ /**
+ * hasVote - Check if a user has voted on this group item
+ *
+ * @param int|bool $uid user ID (default: current user)
+ * @return bool true if a vote exists
+ */
+ function hasVote($uid = false) {
+ if (!$uid) {
+ $uid = user_getid();
+ }
+ if (!$uid || $uid == 100) {
+ return false;
+ }
+ $res = db_query_params('SELECT * FROM diary_votes WHERE
diary_id = $1 AND user_id = $2',
+ array($this->getID(), $uid));
+ return (db_numrows($res) == 1);
+ }
+
+ /**
+ * getVotes - get number of valid cast and potential votes
+ *
+ * @return array|bool (votes, voters, percent)
+ */
+ function getVotes() {
+ if ($this->votes !== false) {
+ return $this->votes;
+ }
+
+ $voters = $this->getVoters();
+ unset($voters[0]); /* just in case */
+ unset($voters[100]); /* need users */
+ if (($numvoters = count($voters)) < 1) {
+ $this->votes = array(0, 0, 0);
+ return $this->votes;
+ }
+
+ $res = db_query_params('SELECT COUNT(*) AS count FROM
diary_votes WHERE diary_id = $1 AND user_id = ANY($2)',
+ array($this->getID(),
db_int_array_to_any_clause($voters)));
+ $db_count = db_fetch_array($res);
+ $numvotes = $db_count['count'];
+
+ /* check for invalid values */
+ if ($numvotes < 0 || $numvoters < $numvotes) {
+ $this->votes = array(-1, -1, 0);
+ } else {
+ $this->votes = array($numvotes, $numvoters,
+ (int)($numvotes * 100 / $numvoters + 0.5));
+ }
+ return $this->votes;
+ }
+
+ /**
+ * canVote - check whether the current user can vote on
+ * items in this tracker
+ *
+ * @return bool true if they can
+ */
+ function canVote() {
+ if ((user_getid() != $this->getUser()->getID()) &&
in_array(user_getid(), $this->getVoters())) {
+ return true;
+ }
+ return false;
+ }
+
+ /**
+ * getVoters - get IDs of users that may vote on
+ * items in this tracker
+ *
+ * @return array list of user IDs
+ */
+ function getVoters() {
+ if ($this->voters !== false) {
+ return $this->voters;
+ }
+
+ $this->voters = array();
+ $res = db_query_params('SELECT user_id FROM users WHERE status
= $1 AND user_id != $2', array('A', $this->getUser()->getID()));
+ $this->voters = util_result_column_to_array($res);
+ return $this->voters;
+ }
}
diff --git a/src/common/diary/views/detailnote.php
b/src/common/diary/views/detailnote.php
index fcd9d36..70316c7 100644
--- a/src/common/diary/views/detailnote.php
+++ b/src/common/diary/views/detailnote.php
@@ -24,6 +24,7 @@
/* please do not add require here : use www/diary/index.php to add require */
global $diaryNoteFactoryObject;
+global $diary_user;
global $HTML;
$diary_id = getIntFromRequest('diary_id');
@@ -35,7 +36,23 @@ if (!$diary_id) {
if ($diary_id) {
if ($diaryNoteFactoryObject->getDiaryNote($diary_id)->isPublic()) {
echo
$HTML->boxTop($diaryNoteFactoryObject->getDiaryNote($diary_id)->getSummary());
- echo '<p>' . _('Posted on ') .
$diaryNoteFactoryObject->getDiaryNote($diary_id)->getDatePostedOn().'</p>';
+ echo html_e('p', array(), _('Posted on ') .
$diaryNoteFactoryObject->getDiaryNote($diary_id)->getDatePostedOn());
+
+ $votes =
$diaryNoteFactoryObject->getDiaryNote($diary_id)->getVotes();
+ if ($votes[1]) {
+ $content = html_e('span', array('id' => 'diary-votes'),
html_e('strong', array(), _('Votes') . _(': ')).sprintf('%1$d/%2$d (%3$d%%)',
$votes[0], $votes[1], $votes[2]));
+ if
($diaryNoteFactoryObject->getDiaryNote($diary_id)->canVote()) {
+ if
($diaryNoteFactoryObject->getDiaryNote($diary_id)->hasVote()) {
+ $key = 'pointer_down';
+ $txt = _('Retract Vote');
+ } else {
+ $key = 'pointer_up';
+ $txt = _('Cast Vote');
+ }
+ $content .=
util_make_link('/developer/?diary_id='.$diary_id.'&diary_user='.$diary_user.'&action='.$key,
html_image('ic/'.$key.'.png', 16, 16), array('id' => 'group-vote', 'alt' =>
$txt));
+ }
+ echo html_e('p', array(), $content);
+ }
echo
$diaryNoteFactoryObject->getDiaryNote($diary_id)->getDetails();
echo $HTML->boxBottom();
} else {
diff --git a/src/www/developer/index.php b/src/www/developer/index.php
index b6f0b9f..9165860 100644
--- a/src/www/developer/index.php
+++ b/src/www/developer/index.php
@@ -43,12 +43,6 @@ $user = user_get_object($diary_user);
if (!$user || !is_object($user) || !$user->isActive())
exit_no_user();
-/* everything sounds ok, now let's do the job */
-$action = getStringFromRequest('action');
-if
(file_exists(forge_get_config('source_path').'/common/diary/actions/'.$action.'.php'))
{
-
include(forge_get_config('source_path').'/common/diary/actions/'.$action.'.php');
-}
-
$diaryNoteFactoryObject = new diaryNoteFactory(user_get_object($diary_user));
if (!$diaryNoteFactoryObject) {
@@ -57,6 +51,12 @@ if (!$diaryNoteFactoryObject) {
exit_error($diaryNoteFactoryObject->getErrorMessage(),'home');
}
+/* everything sounds ok, now let's do the job */
+$action = getStringFromRequest('action');
+if
(file_exists(forge_get_config('source_path').'/common/diary/actions/'.$action.'.php'))
{
+
include(forge_get_config('source_path').'/common/diary/actions/'.$action.'.php');
+}
+
$title = _('Diary and Notes for') . ' ' .
$diaryNoteFactoryObject->getUser()->getRealName();
$HTML->header(array('title' => $title));
-----------------------------------------------------------------------
Summary of changes:
src/common/diary/DiaryNote.class.php | 126 ++++++++++++++++++++++++++++++++++
src/common/diary/views/detailnote.php | 19 ++++-
src/www/developer/index.php | 12 ++--
3 files changed, 150 insertions(+), 7 deletions(-)
hooks/post-receive
--
FusionForge
_______________________________________________
Fusionforge-commits mailing list
[email protected]
http://lists.fusionforge.org/cgi-bin/mailman/listinfo/fusionforge-commits