<?php
/*
Used in PLAY, EDIT, DISPLAY and CREATE chapter
Needed to
A chapter has
*/
class sql_chapter extends sql {
/*
returns an assoc arry of SCENE
*/
public function get($chapterid) {
$sql = "SELECT * from `originator`.`orig_chapter` WHERE `chapterid` = ". $chapterid;
return self::fetchQuery($sql);
}
/*
getAll - gets the entire scene and any conversations related to the scene, used mostly for play.
*/
public function getAll($chapterid){
$sql = "SELECT `originator`.`orig_chapter`.*, `originator`.`orig_chapter`.* FROM `originator`.`orig_chapter`, `originator`.`orig_scene` WHERE `orig_chapter`.`chapterid` = ". $chapterid ." AND `orig_chapter`.`chapterid` = `orig_scene`.`chapterid`";
return self::fetchQuery($sql);
}
/*
Pass an array to be parsed into the database.
*/
public function insert($chapter){
$sql = "INSERT INTO `originator`.`orig_chapter` (`chapterid`, `title`, `uniname`, `overview`, `outline`, `chapterorder`, `createdby`, `storyid`, `createdon`, `lastupdate`, `pageid`, `graphic`) VALUES (NULL, '";
$sql .= $chapter['title'] ."','";
$sql .= $chapter['uniname'] ."','";
$sql .= $chapter['overview'] ."','";
$sql .= $chapter['outline'] ."','";
$sql .= $chapter['chapterorder'] ."','";
$sql .= $chapter['createdby'] ."','";
$sql .= $chapter['storyid'] ."',";
$sql .=" CURDATE(), CURDATE(), '0', 'special.jpg')";
if (db::query($sql)) {
return db::lastInsertId();
}
return false;
}
/*
Delete Chapter method
*/
public function deleteChapter($storyid, $chapterid) {
// First we orphan all SCENES
$sql = "UPDATE `orig_scene` SET `chapterid` = '0', `lastupdate`= CURDATE() WHERE `chapterid` = '". $chapterid ."'";
$return['orphans'] = db::Query($sql)->rowCount();
// THEN we delete the chapter
$sql = "DELETE from `orig_chapter` WHERE `storyid` = '". $storyid ."' AND `chapterid` = '". $chapterid ."'";
$return['rows'] = db::query($sql)->rowCount();
//slightly redundant but it makes this clear.
if (0 == $return['rows']) {
$return['success'] = false;
} else {
$return['success'] = true; }
return $return;
}
/*
Count of Scenes
*/
public function countScenes($chapterid) {
$sql = "SELECT count(*) AS count FROM `orig_scene` WHERE `chapterid` = '". $chapterid."'";
$count =self::fetchQuery($sql);
return $count['count'];
}
/*
Update method for existing stories.
*/
public function update($chapter){
$setString = "";
foreach ($chapter as $key=>$val){
if ("chapterid" != $key) {
$setName .= "`" . $key ."` = '". $val ."'"; // may have to prep pre call
}
}
$sql = "UPDATE `originator`.`orig_chapter` SET ". $setString ." WHERE `orig_chapter`.`chapterid` =". $chapter["chapterid"] ." LIMIT 1" ;
return self::fetchQuery($sql);
}
public function isUniqueName($uniname,$storyid){
$sql = "SELECT count(*) as count FROM `orig_chapter` WHERE `uniname` = '". $uniname ."' AND `storyid` = '". $storyid ."'";
$count =self::fetchQuery($sql);
if (0 == $count['count']) {
return true;
}
return false;
}
/*
returns a count of chapters
*/
public function getChapterCount($storyid){
$sql = 'SELECT count(*) as count FROM `orig_chapter` WHERE `storyid`='.$storyid;
$count = self::fetchQuery($sql);
return $count['count'];
}
/*
translates database to XML for export
*/
public function toXML(){
//TODO
}
}
?>