Skip to content

Instantly share code, notes, and snippets.

@ianbarber
Created February 22, 2014 11:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ianbarber/9152764 to your computer and use it in GitHub Desktop.
Save ianbarber/9152764 to your computer and use it in GitHub Desktop.
<?php
namespace Quiz;
use Symfony\Component\HttpFoundation\Request;
class Question {
public $questionid;
public $starttime;
public $questiontext;
public $questionbadge; // The image that accompanies the question.
public $answer1;
public $answer2;
public $answer3;
public $answer4;
public $correctanswer;
public static function fromEntity(\Google_Service_Datastore_Entity $entity) {
$q = new Question();
$properties = $entity->getProperties();
$q->questionid = $properties['questionid']->getIntegerValue();
$q->starttime = $properties['starttime']->getIntegerValue();
$q->questiontext = $properties['questiontext']->getStringValue();
if (isset($properties['questionbadge'])) {
$q->questionbadge = $properties['questionbadge']->getStringValue();
}
$q->answer1 = $properties['answer1']->getStringValue();
$q->answer2 = $properties['answer2']->getStringValue();
$q->answer3 = $properties['answer3']->getStringValue();
$q->answer4 = $properties['answer4']->getStringValue();
$q->correctanswer = $properties['correctanswer']->getIntegerValue();
return $q;
}
public function getProperties() {
$props = array();
// Question ID and start time used in queries, so indexed.
$props['questionid'] = new \Google_Service_Datastore_Property();
$props['questionid']->setIntegerValue($this->questionid);
$props['questionid']->setIndexed(true);
$props['starttime'] = new \Google_Service_Datastore_Property();
$props['starttime']->setIntegerValue($this->starttime);
$props['starttime']->setIndexed(true);
$props['questiontext'] = new \Google_Service_Datastore_Property();
$props['questiontext']->setStringValue($this->questiontext);
if($this->questionbadge) {
$props['questionbadge'] = new \Google_Service_Datastore_Property();
$props['questionbadge']->setStringValue($this->questionbadge);
}
$props['answer1'] = new \Google_Service_Datastore_Property();
$props['answer1']->setStringValue($this->answer1);
$props['answer2'] = new \Google_Service_Datastore_Property();
$props['answer2']->setStringValue($this->answer2);
$props['answer3'] = new \Google_Service_Datastore_Property();
$props['answer3']->setStringValue($this->answer3);
$props['answer4'] = new \Google_Service_Datastore_Property();
$props['answer4']->setStringValue($this->answer4);
$props['correctanswer'] = new \Google_Service_Datastore_Property();
$props['correctanswer']->setIntegerValue($this->correctanswer);
return $props;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment