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


PHP Survey::fromId方法代码示例

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


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

示例1: __get

 /**
  * Getter
  * 
  * @param string $property property to get
  * 
  * @throws PropertyAccessException
  * 
  * @return property value
  */
 public function __get($property)
 {
     if (in_array($property, array('id', 'survey_id', 'user_id', 'created', 'updated', 'answers'))) {
         return $this->{$property};
     }
     if ($property == 'survey') {
         return Survey::fromId($this->survey_id);
     }
     if (in_array($property, array('user', 'owner', 'author'))) {
         return User::fromId($this->user_id);
     }
     throw new PropertyAccessException($this, $property);
 }
开发者ID:eheb,项目名称:renater-decide,代码行数:22,代码来源:Vote.class.php

示例2: array_shift

<?php

$id = array_shift($path);
if (!$id) {
    throw new NotFoundException('survey', $id);
}
$survey = Survey::fromId($id);
if (!$survey->can->view) {
    throw new NotFoundException('survey access', $id);
}
?>

<pre class="row"><?php 
print_r($survey);
?>
</pre>

<pre class="row"><?php 
print_r($survey->votes);
?>
</pre>

<script type="text/javascript">
function foo(data) {
    console.log(data);
}
</script>

<script type="text/javascript" src="{url:rest.php/user/@me?callback=foo}"></script>

<?php 
开发者ID:eheb,项目名称:renater-decide,代码行数:31,代码来源:survey_page.php

示例3: delete

 /**
  * Delete a survey
  * 
  * @param int $id survey id
  * @param string $property
  * @param string $key id of sub-resource
  * 
  * @return bool
  * 
  * @throws RestMissingParameterException
  * @throws RestSurveyNotFoundException
  * @throws RestNotAllowedException
  */
 public static function delete($id, $property = null, $key = null)
 {
     if (!$id) {
         throw new RestMissingParameterException('id');
     }
     // Get survey
     $survey = Survey::fromId($id);
     if ($property) {
         if (!$key) {
             throw new RestBadParameterException('key');
         }
         // Check permissions
         if (!Auth::isAdmin() || !$survey->owner->is(Auth::user())) {
             throw new RestNotAllowedException('update survey ' . $survey->id);
         }
         if ($property == 'choice') {
             $survey->deleteChoice($key);
         }
         if ($property == 'guest') {
             $survey->deleteGuest($key);
         }
         $survey->save();
         return true;
     }
     // Check permissions
     if (!Auth::isAdmin() || !$survey->owner->is(Auth::user())) {
         throw new RestNotAllowedException('delete survey ' . $survey->id);
     }
     $survey->delete();
     return true;
 }
开发者ID:eheb,项目名称:renater-decide,代码行数:44,代码来源:SurveyEndpoint.class.php

示例4: post

 /**
  * Vote to a survey
  * 
  * Request body must be an object with properties :
  *   * survey_id : identifier of the survey the vote is to be added to
  *   * answers : array of objects with properties
  *     * key : choice key
  *     * value : answer value for choice
  * 
  * @return array
  * 
  * @throws RestBadParameterException
  * @throws RestMissingParameterException
  * @throws NotFoundException
  * @throws RestNotAllowedException
  */
 public static function post()
 {
     // Get creation data
     $data = RestServer::getRequest()->input;
     if (!is_object($data)) {
         throw new RestBadParameterException('vote');
     }
     // Get related survey
     if (!property_exists($data, 'survey_id')) {
         throw new RestMissingParameterException('vote.survey_id');
     }
     $survey = Survey::fromId($data->survey_id);
     // Check permissions
     if (!$survey->can->vote) {
         throw new RestNotAllowedException('add vote to survey ' . $survey->id);
     }
     // Check if vote did not exists already
     foreach ($survey->votes as $vote) {
         if ($vote->author->is(Auth::user())) {
             throw new RestVoteAlreadyExistsException($survey);
         }
     }
     // Check if there is answers
     if (!property_exists($data, 'answers')) {
         throw new RestMissingParameterException('vote.answers');
     }
     if (!is_array($data->answers)) {
         throw new RestBadParameterException('vote.answers');
     }
     // Create the vote and add answers
     $vote = Vote::create($survey);
     foreach ($data->answers as $answer) {
         if (!is_object($answer)) {
             throw new RestBadParameterException('vote.answers[]');
         }
         if (!property_exists($answer, 'key')) {
             throw new RestMissingParameterException('vote.answers[].key');
         }
         if (!property_exists($answer, 'value')) {
             throw new RestMissingParameterException('vote.answers[].value');
         }
         $vote->addAnswer($answer->key, $answer->value);
         // throws if anything wrong
     }
     $vote->save();
     return array('path' => '/vote/' . $vote->id, 'data' => self::cast($vote));
 }
开发者ID:eheb,项目名称:renater-decide,代码行数:63,代码来源:VoteEndpoint.class.php


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