Skip to content

Instantly share code, notes, and snippets.

@ianbarber
Created May 20, 2014 21:54
Show Gist options
  • Save ianbarber/cfc8ef502c45d201fd49 to your computer and use it in GitHub Desktop.
Save ianbarber/cfc8ef502c45d201fd49 to your computer and use it in GitHub Desktop.
Simple model wrapper for datastore class
<?php
namespace Tek;
use Symfony\Component\HttpFoundation\Request;
class Session {
public $sessionid;
public $url;
public $title;
public $speaker;
public $starttime;
public $room;
public static function fromEntity(\Google_Service_Datastore_Entity $entity) {
$s = new Session();
$properties = $entity->getProperties();
$s->sessionid = $properties['sessionid']->getIntegerValue();
// 0 values seem to get supressed in response.
$s->starttime = isset($properties['starttime']) ? $properties['starttime']->getIntegerValue() : 0;
$s->url = $properties['url']->getStringValue();
$s->title = $properties['title']->getStringValue();
$s->speaker = $properties['speaker']->getStringValue();
$s->room = $properties['room']->getStringValue();
return $s;
}
public function getProperties() {
$props = array();
$props['sessionid'] = new \Google_Service_Datastore_Property();
$props['sessionid']->setIntegerValue($this->sessionid);
$props['sessionid']->setIndexed(true);
$props['url'] = new \Google_Service_Datastore_Property();
$props['url']->setStringValue($this->url);
$props['title'] = new \Google_Service_Datastore_Property();
$props['title']->setStringValue($this->title);
$props['speaker'] = new \Google_Service_Datastore_Property();
$props['speaker']->setStringValue($this->speaker);
$props['starttime'] = new \Google_Service_Datastore_Property();
$props['starttime']->setIntegerValue($this->starttime);
$props['starttime']->setIndexed(true);
$props['room'] = new \Google_Service_Datastore_Property();
$props['room']->setStringValue($this->room);
return $props;
}
/**
* Helper function for creating a hallway track session
*/
public static function makeHallway($starttime) {
$h = new Session();
$h->starttime = $starttime;
$h->sessionid = "hallway-" . $h->starttime;
$h->title = "Hallway Track";
$h->speaker = "Anyone";
$h->room = 'hallway';
$h->url = '/static/images/hallway.jpg';
return $h;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment