X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=plugins%2FPoll%2FPoll.php;h=0c274341b2bbca204e32fed2b6c8b1cedf14690f;hb=c97048d01bea468e0cf8865b60c3c250b4515c39;hp=8d02f7de34a10e6ad358b25084de7fb1983be5ce;hpb=cbf16a4974564fc33e31efe686393bb2f007e03b;p=quix0rs-gnu-social.git
diff --git a/plugins/Poll/Poll.php b/plugins/Poll/Poll.php
index 8d02f7de34..0c274341b2 100644
--- a/plugins/Poll/Poll.php
+++ b/plugins/Poll/Poll.php
@@ -47,6 +47,7 @@ class Poll extends Managed_DataObject
{
public $__table = 'poll'; // table name
public $id; // char(36) primary key not null -> UUID
+ public $uri;
public $profile_id; // int -> profile.id
public $question; // text
public $options; // text; newline(?)-delimited
@@ -63,7 +64,6 @@ class Poll extends Managed_DataObject
* @return User_greeting_count object found, or null for no hits
*
*/
-
function staticGet($k, $v=null)
{
return Memcached_DataObject::staticGet('Poll', $k, $v);
@@ -81,7 +81,6 @@ class Poll extends Managed_DataObject
* @return Bookmark object found, or null for no hits
*
*/
-
function pkeyGet($kv)
{
return Memcached_DataObject::pkeyGet('Poll', $kv);
@@ -116,7 +115,6 @@ class Poll extends Managed_DataObject
*
* @return Poll found poll or null
*/
-
function getByNotice($notice)
{
return self::staticGet('uri', $notice->uri);
@@ -127,6 +125,23 @@ class Poll extends Managed_DataObject
return explode("\n", $this->options);
}
+ /**
+ * Is this a valid selection index?
+ *
+ * @param numeric $selection (1-based)
+ * @return boolean
+ */
+ function isValidSelection($selection)
+ {
+ if ($selection != intval($selection)) {
+ return false;
+ }
+ if ($selection < 1 || $selection > count($this->getOptions())) {
+ return false;
+ }
+ return true;
+ }
+
function getNotice()
{
return Notice::staticGet('uri', $this->uri);
@@ -166,7 +181,9 @@ class Poll extends Managed_DataObject
$raw = array();
while ($pr->fetch()) {
- $raw[$pr->selection] = $pr->votes;
+ // Votes list 1-based
+ // Array stores 0-based
+ $raw[$pr->selection - 1] = $pr->votes;
}
$counts = array();
@@ -189,7 +206,6 @@ class Poll extends Managed_DataObject
*
* @return Notice saved notice
*/
-
static function saveNew($profile, $question, $opts, $options=null)
{
if (empty($options)) {
@@ -219,12 +235,15 @@ class Poll extends Managed_DataObject
common_log(LOG_DEBUG, "Saving poll: $p->id $p->uri");
$p->insert();
- $content = sprintf(_m('Poll: %s %s'),
+ // TRANS: Notice content creating a poll.
+ // TRANS: %1$s is the poll question, %2$s is a link to the poll.
+ $content = sprintf(_m('Poll: %1$s %2$s'),
$question,
$p->uri);
- $rendered = sprintf(_m('Poll: %s'),
- htmlspecialchars($p->uri),
- htmlspecialchars($question));
+ $link = '' . htmlspecialchars($question) . '';
+ // TRANS: Rendered version of the notice content creating a poll.
+ // TRANS: %s is a link to the poll with the question as link description.
+ $rendered = sprintf(_m('Poll: %s'), $link);
$tags = array('poll');
$replies = array();