Location: PHPKode > projects > Originator - RPG Rapid Prototyper > originator/includes/origin/deprecated/sql_story.php
<?php

/*
	Used in PLAY, EDIT, DISPLAY and CREATE Story
		Needed to 
*/


class sql_story extends sql {
	/*
		returns an assoc arry of SCENE
	*/
	public function getStory($storyid) {
		$sql = "SELECT * from `originator`.`orig_story` WHERE `storyid` = ". $storyid;
		return self::fetchQuery($sql);
	}
	
	/*
		getAll - gets the entire scene and any conversations related to the scene, used mostly for play.
	*/
	public function getAll($storyid){
		$sql = "SELECT originator`.`orig_story`.*, originator`.`orig_chapter`.*  FROM `originator`.`orig_story` story , `originator`.`orig_chapter` chapter WHERE story.storyid = ". $storyid ." and story.storyid = chapter.storyid"; 
		return self::fetchQuery($sql);
	}
	
	/*
		Pass an array to be parsed into the database. 
	*/
	public function insert($story){
		$sql = "INSERT INTO `originator`.`orig_story` (`storyid`, `unidesc`, `title`, `subtitle`, `overview`, `owner`, `tags`, `createdate`, `lastupdate`, `graphic`) VALUES (NULL, '";
																																											  		$sql .= $story["unidesc"] . "','";
 		$sql .= $story["title"] . "','";
 		$sql .= $story["subtitle"] . "','";
 		$sql .= $story["overview"] . "','";
 		$sql .= $story["owner"] . "','";
 		$sql .= $story["tags"] . "',";
 		$sql .= " CURRENT_TIMESTAMP, CURRENT_TIMESTAMP,'";
 		$sql .= $story["graphic"] . "')";
		return db::query($sql);
	}
	
	/*
		Update method for existing stories. 
	*/
	
	public function update($story){
		$setString  = ""; 
		
		foreach ($story as $key=>$val){
			if ("storyid" != $key) {
				$setName .= "`" . $key ."` = '". $val ."'"; // may have to prep pre call 
			}
		}
		$sql = "UPDATE  `originator`.`orig_chapter` SET ". $setString ." WHERE  `orig_chapter`.`chapterid` =".  $story["storyid"] ." LIMIT 1" ;
		return self::fetchQuery($sql);
	}

	/*
		Get all the potential Contributors to a Story
	*/
	public function isEditor($userid, $storyid) {

		$sql  = "SELECT count(*) AS count FROM `originator`.`orig_user` user, `originator`.`orig_story` story ";
		$sql .= "WHERE user.`userid` = '". $userid ."' AND story.`owner` = user.`uid` AND story.`storyid` = ". $storyid; 

		$count = self::fetchQuery($sql);
		
		if (0 == $count["count"]){
			return false;
		} 
		return true;
	}
	
	/*
		Is this a unique description?
	*/

	public function isUniqueDesc($unidesc){
		$sql = "SELECT count(*) as count from `originator`.`orig_story` where `orig_story`.`unidesc` = '". $unidesc ."'";
		$count = self::fetchQuery($sql);
		if (0 == $count['count']) {
			return true;
		} 
		return false; 
	}
	
	public function getChapters ($storyid) {
		$sql = "SELECT * FROM `originator`.`orig_chapter` WHERE `orig_chapter`.`storyid` = ". $storyid ;
		return self::fetchQuery($sql);
	}
	
	public function softDelete ($storyid, $val) {
		$sql = "UPDATE `originator`.`orig_story` SET `attributes` = ". $val ." WHERE `orig_story`.`storyid` = ". $storyid;
		return self::fetchQuery($sql);
	}
	
	/*
		translates database to XML for export
	*/
	public function toXML(){
		//TODO 
	}
}


?>
Return current item: Originator - RPG Rapid Prototyper