本文整理汇总了PHP中Poll::staticGet方法的典型用法代码示例。如果您正苦于以下问题:PHP Poll::staticGet方法的具体用法?PHP Poll::staticGet怎么用?PHP Poll::staticGet使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Poll
的用法示例。
在下文中一共展示了Poll::staticGet方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: prepare
/**
* For initializing members of the class.
*
* @param array $argarray misc. arguments
*
* @return boolean true
*/
function prepare($argarray)
{
parent::prepare($argarray);
if ($this->boolean('ajax')) {
StatusNet::setApi(true);
}
$this->user = common_current_user();
if (empty($this->user)) {
// TRANS: Client exception thrown trying to respond to a poll while not logged in.
throw new ClientException(_m('You must be logged in to respond to a poll.'), 403);
}
if ($this->isPost()) {
$this->checkSessionToken();
}
$id = $this->trimmed('id');
$this->poll = Poll::staticGet('id', $id);
if (empty($this->poll)) {
// TRANS: Client exception thrown trying to respond to a non-existing poll.
throw new ClientException(_m('Invalid or missing poll.'), 404);
}
$selection = intval($this->trimmed('pollselection'));
if ($selection < 1 || $selection > count($this->poll->getOptions())) {
// TRANS: Client exception thrown responding to a poll with an invalid answer.
throw new ClientException(_m('Invalid poll selection.'));
}
$this->selection = $selection;
return true;
}
示例2: getNotice
function getNotice()
{
$this->id = $this->trimmed('id');
$this->poll = Poll::staticGet('id', $this->id);
if (empty($this->poll)) {
// TRANS: Client exception thrown trying to view a non-existing poll.
throw new ClientException(_m('No such poll.'), 404);
}
$notice = $this->poll->getNotice();
if (empty($notice)) {
// Did we used to have it, and it got deleted?
// TRANS: Client exception thrown trying to view a non-existing poll notice.
throw new ClientException(_m('No such poll notice.'), 404);
}
return $notice;
}
示例3: getPoll
/**
*
* @return Poll
*/
function getPoll()
{
return Poll::staticGet('id', $this->poll_id);
}
示例4: saveNoticeFromActivity
/**
* Save a poll from an activity
*
* @param Profile $profile Profile to use as author
* @param Activity $activity Activity to save
* @param array $options Options to pass to bookmark-saving code
*
* @return Notice resulting notice
*/
function saveNoticeFromActivity($activity, $profile, $options = array())
{
// @fixme
common_log(LOG_DEBUG, "XXX activity: " . var_export($activity, true));
common_log(LOG_DEBUG, "XXX profile: " . var_export($profile, true));
common_log(LOG_DEBUG, "XXX options: " . var_export($options, true));
// Ok for now, we can grab stuff from the XML entry directly.
// This won't work when reading from JSON source
if ($activity->entry) {
$pollElements = $activity->entry->getElementsByTagNameNS(self::POLL_OBJECT, 'poll');
$responseElements = $activity->entry->getElementsByTagNameNS(self::POLL_OBJECT, 'response');
if ($pollElements->length) {
$question = '';
$opts = array();
$data = $pollElements->item(0);
foreach ($data->getElementsByTagNameNS(self::POLL_OBJECT, 'question') as $node) {
$question = $node->textContent;
}
foreach ($data->getElementsByTagNameNS(self::POLL_OBJECT, 'option') as $node) {
$opts[] = $node->textContent;
}
try {
$notice = Poll::saveNew($profile, $question, $opts, $options);
common_log(LOG_DEBUG, "Saved Poll from ActivityStream data ok: notice id " . $notice->id);
return $notice;
} catch (Exception $e) {
common_log(LOG_DEBUG, "Poll save from ActivityStream data failed: " . $e->getMessage());
}
} else {
if ($responseElements->length) {
$data = $responseElements->item(0);
$pollUri = $data->getAttribute('poll');
$selection = intval($data->getAttribute('selection'));
if (!$pollUri) {
// TRANS: Exception thrown trying to respond to a poll without a poll reference.
throw new Exception(_m('Invalid poll response: No poll reference.'));
}
$poll = Poll::staticGet('uri', $pollUri);
if (!$poll) {
// TRANS: Exception thrown trying to respond to a non-existing poll.
throw new Exception(_m('Invalid poll response: Poll is unknown.'));
}
try {
$notice = Poll_response::saveNew($profile, $poll, $selection, $options);
common_log(LOG_DEBUG, "Saved Poll_response ok, notice id: " . $notice->id);
return $notice;
} catch (Exception $e) {
common_log(LOG_DEBUG, "Poll response save fail: " . $e->getMessage());
}
} else {
common_log(LOG_DEBUG, "YYY no poll data");
}
}
}
}