public function insert(Photo $photo) { $newPhoto = $this->db->table(self::TABLE_NAME)->insert(array(self::COLUMN_DESCRIPTION => $photo->description, self::COLUMN_SOURCE => $photo->source, self::COLUMN_FILEPATH => $photo->filepath, self::COLUMN_UPLOADED_AT => $photo->uploadedAt, self::COLUMN_LAST_MODIFIED_AT => $photo->lastModifiedAt, self::COLUMN_USER => $photo->user->id)); $photo->setId($newPhoto->id); $this->insertTags($photo, $photo->tags); return $photo; }
public static function loadFromDb(DbEntry $photo) { $instance = new Photo(); $instance->setId($photo->id); $instance->setDescription($photo->description); $instance->setSource($photo->source); $instance->setFilepath($photo->filepath); $instance->setUploadedAt($photo->uploaded_at); if ($photo->last_modified_at) { $instance->setLastModifiedAt($photo->last_modified_at); } $instance->setUser(UserService::loadFromDb($photo->user)); $instance->setTags(self::loadTagsFromDb($photo)); return $instance; }