本文整理汇总了PHP中Poll::insert方法的典型用法代码示例。如果您正苦于以下问题:PHP Poll::insert方法的具体用法?PHP Poll::insert怎么用?PHP Poll::insert使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Poll
的用法示例。
在下文中一共展示了Poll::insert方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: saveNew
/**
* Save a new poll notice
*
* @param Profile $profile
* @param string $question
* @param array $opts (poll responses)
*
* @return Notice saved notice
*/
static function saveNew($profile, $question, $opts, $options = null)
{
if (empty($options)) {
$options = array();
}
$p = new Poll();
$p->id = UUID::gen();
$p->profile_id = $profile->id;
$p->question = $question;
$p->options = implode("\n", $opts);
if (array_key_exists('created', $options)) {
$p->created = $options['created'];
} else {
$p->created = common_sql_now();
}
if (array_key_exists('uri', $options)) {
$p->uri = $options['uri'];
} else {
$p->uri = common_local_url('showpoll', array('id' => $p->id));
}
common_log(LOG_DEBUG, "Saving poll: {$p->id} {$p->uri}");
$p->insert();
// 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);
$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();
$options = array_merge(array('urls' => array(), 'rendered' => $rendered, 'tags' => $tags, 'replies' => $replies, 'object_type' => PollPlugin::POLL_OBJECT), $options);
if (!array_key_exists('uri', $options)) {
$options['uri'] = $p->uri;
}
$saved = Notice::saveNew($profile->id, $content, array_key_exists('source', $options) ? $options['source'] : 'web', $options);
return $saved;
}