*
* @see DB_DataObject
*/
-
class Poll_response extends Managed_DataObject
{
public $__table = 'poll_response'; // table name
* @return User_greeting_count object found, or null for no hits
*
*/
-
function staticGet($k, $v=null)
{
return Memcached_DataObject::staticGet('Poll_response', $k, $v);
* @return Bookmark object found, or null for no hits
*
*/
-
function pkeyGet($kv)
{
return Memcached_DataObject::pkeyGet('Poll_response', $kv);
*
* @return Poll_response found response or null
*/
-
function getByNotice($notice)
{
return self::staticGet('uri', $notice->uri);
return $this->getNotice()->bestUrl();
}
+ /**
+ *
+ * @return Poll
+ */
+ function getPoll()
+ {
+ return Poll::staticGet('id', $this->poll_id);
+ }
/**
* Save a new poll notice
*
*
* @return Notice saved notice
*/
-
static function saveNew($profile, $poll, $selection, $options=null)
{
if (empty($options)) {
$options = array();
}
- $opts = $poll->getOptions();
- if ($selection < 1 || $selection > count($opts)) {
+ if (!$poll->isValidSelection($selection)) {
+ // TRANS: Client exception thrown when responding to a poll with an invalid option.
throw new ClientException(_m('Invalid poll selection.'));
}
+ $opts = $poll->getOptions();
$answer = $opts[$selection - 1];
$pr = new Poll_response();
common_log(LOG_DEBUG, "Saving poll response: $pr->id $pr->uri");
$pr->insert();
+ // TRANS: Notice content voting for a poll.
+ // TRANS: %s is the chosen option in the poll.
$content = sprintf(_m('voted for "%s"'),
$answer);
- $rendered = sprintf(_m('voted for “<a href="%s">%s</a>”'),
- htmlspecialchars($poll->uri),
- htmlspecialchars($answer));
+ $link = '<a href="' . htmlspecialchars($poll->uri) . '">' . htmlspecialchars($answer) . '</a>';
+ // TRANS: Rendered version of the notice content voting for a poll.
+ // TRANS: %s a link to the poll with the chosen option as link description.
+ $rendered = sprintf(_m('voted for "%s"'), $link);
$tags = array();
$replies = array();