Mercurial > hg > extraction-interface
diff develop/classes/basemodel.php @ 6:63e08b98032f
rewrite extraction interface into PHP MVC architecture.
(Although js hasn't been rewritten into MVC, it's fitted into the current PHP MVC architecture.)
- The root of the new PHP MVC is at 'develop/'.
- extraction interface is called "Extractapp" with several action, eg TaggingText, EditWordlist, EditTaglist, ExportTable.
author | Zoe Hong <zhong@mpiwg-berlin.mpg.de> |
---|---|
date | Thu, 05 Feb 2015 16:07:53 +0100 |
parents | |
children | 54a235d43694 |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/develop/classes/basemodel.php Thu Feb 05 16:07:53 2015 +0100 @@ -0,0 +1,95 @@ +<?php + +abstract class BaseModel { + // protected $database; + protected $systemNAME; + + public function __construct() { + global $mysql_database, $mysql_server, $mysql_user, $mysql_password, $systemNAME; + $this->systemNAME = $systemNAME; + + // $this->database = new PDO("mysql:host=localhost;dbname=test", "username", "password"); + set_time_limit(0); + ini_set('memory_limit', '-1'); + + $link_mysql = mysql_connect($mysql_server, $mysql_user, $mysql_password); + mysql_query("SET NAMES utf8"); + + if (!$link_mysql) { + die('Could not connect: ' . mysql_error()); + } + $db_selected = mysql_select_db($mysql_database, $link_mysql); + if (!$db_selected) { + + die ('Can\'t use foo : ' . mysql_error()); + } + } + + protected function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") { + $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue; + + $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue); + + switch ($theType) { + case "text": + $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL"; + break; + case "long": + case "int": + $theValue = ($theValue != "") ? intval($theValue) : "NULL"; + break; + case "double": + $theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL"; + break; + case "date": + $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL"; + break; + case "defined": + $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue; + break; + } + return $theValue; + } + + protected function GetWordlist() { + $query = sprintf("SELECT * FROM `wordlist` WHERE `systemName`='%s' ORDER BY `name` ASC", $this->systemNAME); + $result = mysql_query($query); + if (!$result){ + return json_encode("Failed during selecting wordlist table.");; + } + return $result; + } + + protected function GetSectionsByID($section_id) { + $query = sprintf("SELECT * FROM `sections` WHERE `id`=\"%s\"", $section_id); + $result = mysql_query($query); + if (!$result){ + echo json_encode("Failed during selecting sections table"); + return; + } + return $result; + } + + protected function GetTaglist() { + $query = sprintf("SELECT * FROM `taglist` WHERE `systemName`='%s' ORDER BY `tag` ASC", $this->systemNAME); + $result = mysql_query($query); + if (!$result) { + return json_encode("Failed during selecting taglist table."); + } + return $result; + } + + protected function GetBooksByID($bookId) { + $query = sprintf("SELECT * FROM `books` WHERE id=\"%s\"", $bookId); + $result = mysql_query($query); + if (!$result) { + return json_encode("Failed during selecting books table."); + } + return $result; + } + + + +} + +?>