Created
February 22, 2014 11:52
-
-
Save ianbarber/9152764 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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