]> git.mxchange.org Git - quix0rs-gnu-social.git/blobdiff - plugins/Poll/Poll.php
merge 0.9.x into 1.0.x
[quix0rs-gnu-social.git] / plugins / Poll / Poll.php
index 8d02f7de34a10e6ad358b25084de7fb1983be5ce..0c274341b2bbca204e32fed2b6c8b1cedf14690f 100644 (file)
@@ -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: <a href="%s">%s</a>'),
-                            htmlspecialchars($p->uri),
-                            htmlspecialchars($question));
+        $link = '<a href="' . htmlspecialchars($p->uri) . '">' . htmlspecialchars($question) . '</a>';
+        // 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();