array( 'Title' => "Title", 'Description' => "Description", 'SourceUrl' => "SourceUrl", 'ItemUrl' => "ItemUrl" ), 'numeric' => array( 'Type' => "Type", 'Provider' => "Provider", 'Views' => "Views", 'TopicId' => "TopicId", 'ParentId' => "ParentId" ), 'boolean' => array( 'HasTopic' => "HasTopic" ), 'timestamp' => array( 'CreationDate' => "Date", 'StartDate' => "StartDate", 'EndDate' => "EndDate" ), 'topic' => array( 'Topic' => "TopicId" ), 'item' => array( 'Parent' => "ParentId" ) ); public function __get($name) { switch($name) { case "sTypeName": return $this->GetTypeName(); break; case "sProviderName": return $this->GetProviderName(); break; default: return parent::__get($name); break; } } public function GetTypeName() { switch($this->sType) { case 1: return "topic"; case 2: return "course"; case 3: return "video"; case 4: return "article"; case 5: return "exercise"; case 6: return "quiz"; case 7: return "test"; case 8: return "book"; case 9: return "audiobook"; default: return "unknown"; } } public function GetProviderName() { switch($this->sProvider) { case 1: return "Khan University"; case 2: return "Coursera"; case 3: return "University of Reddit"; default: return "Unknown"; } } public function GetChildren() { try { return Item::CreateFromQuery("SELECT * FROM items WHERE `ParentId` = :ParentId", array(':ParentId' => $this->sId)); } catch (NotFoundException $e) { return array(); } } public function AsDataset($fetch_children = true) { $child_data = array(); if($fetch_children == true) { foreach($this->GetChildren() as $child) { $child_data[] = $child->AsDataset(); } } return array( "title" => $this->uTitle, "description" => $this->uDescription, "url" => $this->uItemUrl, "source" => $this->uSourceUrl, "created" => $this->sCreationDate, "start" => $this->sStartDate, "end" => $this->sEndDate, "type" => $this->sTypeName, "provider" => $this->sProviderName, "views" => $this->sViews, "children" => $child_data ); } }