本文整理汇总了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);
}
示例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
示例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;
}
示例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));
}