当前位置: 首页>>代码示例>>PHP>>正文


PHP Poll::saveNew方法代码示例

本文整理汇总了PHP中Poll::saveNew方法的典型用法代码示例。如果您正苦于以下问题:PHP Poll::saveNew方法的具体用法?PHP Poll::saveNew怎么用?PHP Poll::saveNew使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Poll的用法示例。


在下文中一共展示了Poll::saveNew方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: 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 $activity, Profile $profile, array $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::getKV('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");
             }
         }
     }
 }
开发者ID:bashrc,项目名称:gnusocial-debian,代码行数:64,代码来源:PollPlugin.php

示例2: newPoll

 /**
  * Add a new Poll
  *
  * @return void
  */
 function newPoll()
 {
     if ($this->boolean('ajax')) {
         StatusNet::setApi(true);
     }
     try {
         if (empty($this->question)) {
             // TRANS: Client exception thrown trying to create a poll without a question.
             throw new ClientException(_m('Poll must have a question.'));
         }
         if (count($this->options) < 2) {
             // TRANS: Client exception thrown trying to create a poll with fewer than two options.
             throw new ClientException(_m('Poll must have at least two options.'));
         }
         // Notice options; distinct from choices for the poll
         $options = array();
         // Does the heavy-lifting for getting "To:" information
         ToSelector::fillOptions($this, $options);
         $saved = Poll::saveNew($this->user->getProfile(), $this->question, $this->options, $options);
     } catch (ClientException $ce) {
         $this->error = $ce->getMessage();
         $this->showPage();
         return;
     }
     if ($this->boolean('ajax')) {
         header('Content-Type: text/xml;charset=utf-8');
         $this->xw->startDocument('1.0', 'UTF-8');
         $this->elementStart('html');
         $this->elementStart('head');
         // TRANS: Page title after sending a notice.
         $this->element('title', null, _m('Notice posted'));
         $this->elementEnd('head');
         $this->elementStart('body');
         $this->showNotice($saved);
         $this->elementEnd('body');
         $this->elementEnd('html');
     } else {
         common_redirect($saved->bestUrl(), 303);
     }
 }
开发者ID:Grasia,项目名称:bolotweet,代码行数:45,代码来源:newpoll.php


注:本文中的Poll::saveNew方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。