Mercurial > hg > extraction-interface
view classes/basemodel.php @ 122:a36bb5a48af4 extractapp tip
1. remove redundancy server side code.
2. All pop up sub-windows are made with dialog component of bootstrap v3.3.2
author | Calvin Yeh <cyeh@mpiwg-berlin.mpg.de> |
---|---|
date | Thu, 28 Sep 2017 22:26:48 +0200 |
parents | c1bb174a22f3 |
children |
line wrap: on
line source
<?php /* basemodel.php * This file is part of Extraction-interface. * * Extraction-interface is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * Extraction-interface is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with Extraction-interface. If not, see <http://www.gnu.org/licenses/>. */ /** * A model is notified by its associate controllers when there has been a change in its state, * and produces the output/data to corresponding views. * * (http://en.wikipedia.org/wiki/Model–view–controller) * * There are general methods/functions. * For example, setting related to outside services, connecting to database, get information from database, etc. * For other methods that are more related to each application, are defined in the files under "models/" folder. * */ abstract class BaseModel { protected $get_text_from_fileId_url, $get_text_from_sectionId_url, $save_to_LGService_url, $save_new_to_LGService_url; public function __construct() { global $mysql_database, $mysql_server, $mysql_user, $mysql_password, $systemNAME, $lgserver_url; $this->systemNAME = $systemNAME; $this->get_text_from_fileId_url = $lgserver_url."rest/text/getFileText?fileId="; $this->get_text_from_sectionId_url = $lgserver_url."rest/text/getSectionText?sectionId="; $this->save_to_LGService_url = $lgserver_url."rest/text/save"; $this->save_new_to_LGService_url = $lgserver_url."rest/text/saveNew"; $this->get_section_metadata_by_sectionId_url = $lgserver_url."rest/text/getSectionMetadata?sectionId="; 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()); } $this->topic = 2; // set the default topic to product_name (物產) } 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` ORDER BY `name` ASC"); $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_index` WHERE `id`=\"%s\"", $section_id); $result = mysql_query($query); if (!$result){ echo json_encode("Failed during selecting sections_index table"); return; } return $result; } */ protected function GetTaglist() { //$query = sprintf("SELECT * FROM `Taglist` WHERE `systemName`='%s' ORDER BY `tag` ASC", $this->systemNAME); $query = sprintf("SELECT * FROM `Taglist` ORDER BY `tag` ASC"); $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; } */ protected function GetTagIdByTag($tag) { $query = sprintf("SELECT * FROM `Taglist` WHERE `tag`='%s'", $tag); $result = mysql_query($query); if (!$result) { return json_encode("Failed during selecting Taglist table."); } return $result["id"]; } protected function GetTopicList() { //$query = sprintf("SELECT * FROM `topics`"); $query = sprintf("SELECT * FROM `Topic`"); $result = mysql_query($query); if (!$result) { return json_encode("Failed during selecting Topic table."); } return $result; } protected function GetTopicById($topic_id) { //$query = sprintf("SELECT * FROM `topics` WHERE id=\"%s\"", $topic_id); $query = sprintf("SELECT * FROM `Topic` WHERE id=\"%s\"", $topic_id); $result = mysql_query($query); if (!$result) { return json_encode("Failed during selecting Topic table."); } return $result; } } ?>