Mercurial > hg > extraction-interface
changeset 114:7d6a107c37da extractapp
refactoring, make it more condensed.
author | Calvin Yeh <cyeh@mpiwg-berlin.mpg.de> |
---|---|
date | Thu, 28 Sep 2017 14:01:59 +0200 |
parents | e26945b2aa85 |
children | 507070df62e6 |
files | classes/basecontroller.php controllers/extractapp.php views/maintemplate.php views/maintemplate_local.php |
diffstat | 4 files changed, 93 insertions(+), 117 deletions(-) [+] |
line wrap: on
line diff
--- a/classes/basecontroller.php Thu Sep 28 13:44:57 2017 +0200 +++ b/classes/basecontroller.php Thu Sep 28 14:01:59 2017 +0200 @@ -16,63 +16,61 @@ * along with Extraction-interface. If not, see <http://www.gnu.org/licenses/>. */ -/** - * A controller can send commands to the model to process or update the model's state. +/** + * A controller can send commands to the model to process or update the model's state. * It can also pass the commands or data (from model) to the associated view to change the view's presentation. - * + * * An instance of the BaseController class can't be created directly. - * It can only be extended/inherited by other classes. - * For example in controllers/ folder, Extractapp is extended from the BaseController. + * It can only be extended/inherited by other classes. + * For example in controllers/ folder, Extractapp is extended from the BaseController. * An instance of Extractapp can be created directly. - * + * */ abstract class BaseController { - + protected $urlvalues; protected $action; - + public function __construct($action, $urlvalues, $postdata) { $this->action = $action; $this->urlvalues = $urlvalues; $this->postdata = $postdata; } - + public function ExecuteAction() { return $this->{$this->action}(); } - + protected function ReturnView($viewmodel, $fullview) { - /** - * Return the corresponding view in the views folder. + /** + * Return the corresponding view in the views folder. * We use the same class name as the folder's name and action name as the file's name in the folder hierarchy. * In this design, we can query the corresponding views php code by defining controller and action in url. - * - * If you also require the maintemplate.php, which now only contains scripts that need to be inclued, set $fullview to be true; + * + * If you also require the maintemplate.php, which now only contains scripts that need to be inclued, set $fullview to be true; * otherwise, the maintemplate.php will not be applied. */ $viewloc = 'views/' . get_class($this) . '/' . $this->action . '.php'; if ($fullview) { - require('views/maintemplate.php'); - require($viewloc); - } else { - require($viewloc); + //require('views/maintemplate.php'); } + + require($viewloc); } protected function ReturnView_localtest($viewmodel, $fullview) { - /** Return the corresponding view in the views folder. - * - * This is only been used when developing on local machine. + /** Return the corresponding view in the views folder. + * + * This is only been used when developing on local machine. */ $viewloc = 'views/' . get_class($this) . '/' . $this->action . '.php'; if ($fullview) { - require('views/maintemplate_local.php'); - require($viewloc); - } else { - require($viewloc); + //require('views/maintemplate_local.php'); } + + require($viewloc); } } -?> \ No newline at end of file +?>
--- a/controllers/extractapp.php Thu Sep 28 13:44:57 2017 +0200 +++ b/controllers/extractapp.php Thu Sep 28 14:01:59 2017 +0200 @@ -16,47 +16,47 @@ * along with Extraction-interface. If not, see <http://www.gnu.org/licenses/>. */ -/** +/** * Extractapp class is extended from the BaseController class. - * It sends commands to the ExtractappModel to process or update the ExtractappModel's state. - * It can also pass the commands or data (from ExtractappModel) to the associated view (files in views/Extractapp/), + * It sends commands to the ExtractappModel to process or update the ExtractappModel's state. + * It can also pass the commands or data (from ExtractappModel) to the associated view (files in views/Extractapp/), * for example views/Extractapp/TaggingText.php , to change the view's presentation. - * + * * There are five actions in Extractapp: tagging text, exporting a table, * editing the wordlist, editing the taglist, and configurating tags in one topic. * Each action is one of the methods in Extractapp. - * + * */ class Extractapp extends BaseController { - + protected $viewmodel; - + public function __construct($action, $urlvalues, $postdata){ - parent::__construct($action, $urlvalues, $postdata); + parent::__construct($action, $urlvalues, $postdata); $this->viewmodel = new ExtractappModel(); } protected function TaggingText() { /** - * TaggingText action in Extractapp handles the taging related actions, for example, + * TaggingText action in Extractapp handles the taging related actions, for example, * tagging itself, saving tag results, loading and saving regular expression for tagging. * They are handled by 'func' variable in postdata, which could come from LGService or from extraction-interface application itself. * * From LGService, the postdata contains essential information about the file/section of local gazetteers data. * This happens when user entering to extraction-interface the first time, or after s/he saved her/is tagging results to LGService. * (default one, SaveFullTextToLGService, SmartRegexLoad, SmartRegexSave case) - * + * * From extraction-interface itself, it contains the information from previous page. - * This happens when user choosing another topic in the extraction-interface, + * This happens when user choosing another topic in the extraction-interface, * the page need to retrieve related information from database for the topic. * (ContinueTagging case) */ $viewmodel = $this->viewmodel; - + if (isset($this->postdata['func'])) { $func = $this->postdata['func']; } else { @@ -64,30 +64,28 @@ } switch ($func) { case 'SaveFullText': - $viewmodel->SaveFullText($this->postdata); - $this->ReturnView($viewmodel->StartTagging(), true); - break; + $viewmodel->SaveFullText($this->postdata); + $this->ReturnView($viewmodel->StartTagging(), true); + break; case 'SaveFullTextToLGService': - global $AT_LOCAL; - if ($AT_LOCAL) { - $viewmodel->messages['info'] .= "SaveFullTextToLGService! (local test) "; - $viewmodel->SetInfoFromPreviousPage($this->postdata); - $response = $viewmodel->SaveFullTextToLGService($this->postdata); + + $viewmodel->messages['info'] .= "SaveFullTextToLGService! "; + + global $AT_LOCAL; - $viewmodel->UpdateInfoResponsedFromLGService($response); // update file_id, branch_id, user_id - $viewmodel->SetTextFromFileId(); - - } else { + if ($AT_LOCAL) { + $viewmodel->messages['info'] .= "(local test) "; + } + + $viewmodel->SetInfoFromPreviousPage($this->postdata); - $viewmodel->messages['info'] .= "SaveFullTextToLGService! "; - $viewmodel->SetInfoFromPreviousPage($this->postdata); - $response = $viewmodel->SaveFullTextToLGService($this->postdata); + $response = $viewmodel->SaveFullTextToLGService($this->postdata); + + $viewmodel->UpdateInfoResponsedFromLGService($response); // update file_id, branch_id, user_id - $viewmodel->UpdateInfoResponsedFromLGService($response); // update file_id, branch_id, user_id - - $viewmodel->SetTextFromFileId(); - } - $this->ReturnView($viewmodel->StartTagging(), true); + $viewmodel->SetTextFromFileId(); + + $this->ReturnView($viewmodel->StartTagging(), true); break; case 'SmartRegexLoad': @@ -106,43 +104,43 @@ case 'ContinueTagging': $viewmodel->messages['info'] .= "(Countinue tagging) "; - $viewmodel->SetInfoFromPreviousPage($this->postdata); - + $viewmodel->SetInfoFromPreviousPage($this->postdata); + // when new section hasn't been saved to LGServices, no fileId and no branchId if ($this->postdata['fileId'] == 0) { - $viewmodel->SetTextFromSectionId(); + $viewmodel->SetTextFromSectionId(); } else { $viewmodel->SetTextFromFileId(); // get text by fileId, from LGService } - + $viewmodel->SetTopic($this->postdata['topic']); - - $this->ReturnView($viewmodel->StartTagging(), true); + + $this->ReturnView($viewmodel->StartTagging(), true); break; case 'CreateNewTopic': - $result = $viewmodel->CreateNewTopic($this->postdata); + $result = $viewmodel->CreateNewTopic($this->postdata); if ($result == "error") { $viewmodel->messages['error'] .= "Fail to create the new topic <br> "; } else { // then act like ContinueTagging $viewmodel->messages['info'] .= "Created a new topic <br>"; - $viewmodel->SetInfoFromPreviousPage($result); + $viewmodel->SetInfoFromPreviousPage($result); // when new section hasn't been saved to LGServices, no fileId and no branchId if ($this->postdata['fileId'] == 0) { - $viewmodel->SetTextFromSectionId(); + $viewmodel->SetTextFromSectionId(); } else { $viewmodel->SetTextFromFileId(); // get text by fileId, from LGService } $viewmodel->SetTopic($result['topic']); } - $this->ReturnView($viewmodel->StartTagging(), true); - + $this->ReturnView($viewmodel->StartTagging(), true); + break; - default: + default: // This is where the first time user visit extraction interface from LGService $viewmodel->messages['info'] .= "Welcome to Extraction Interface. "; @@ -160,9 +158,9 @@ $viewmodel->SetInfoFromPreviousPage($this->postdata); $viewmodel->SetBookMetadataBySectionId(); // get text by sectionId from LGService - $viewmodel->SetTextFromSectionId(); + $viewmodel->SetTextFromSectionId(); - } else if ($this->postdata['sectionId'] != 0) { + } else if ($this->postdata['sectionId'] != 0) { $viewmodel->SetTextFromLocal($this->postdata['sectionId']); $viewmodel->SetBookMetadataBySectionId(); @@ -170,20 +168,20 @@ // get text from local file system (for development stage only) $viewmodel->SetTextFromLocal($this->urlvalues['id']); $viewmodel->SetBookMetadataBySectionId(); - $this->ReturnView_localtest($viewmodel->StartTagging(), true); - break; + $this->ReturnView_localtest($viewmodel->StartTagging(), true); + break; } else { $viewmodel->messages['error'] .= "wrong url!!"; return; } - $this->ReturnView($viewmodel->StartTagging(), true); + $this->ReturnView($viewmodel->StartTagging(), true); break; } - - + + } @@ -196,14 +194,14 @@ if (isset($this->postdata['fileId'])) { $viewmodel->SetInfoFromPreviousPage($this->postdata); // fileId in postdata - - $viewmodel->SetTextFromFileId(); // this will also set section_id + + $viewmodel->SetTextFromFileId(); // this will also set section_id $viewmodel->SetBookMetadataBySectionId(); } $this->ReturnView($viewmodel->ExportTable($this->postdata, true), false); - - + + } protected function ExportTable() { @@ -220,7 +218,7 @@ switch ($func) { case 'exportFromExtractionInterface': $viewmodel->SetInfoFromPreviousPage($this->postdata); - + $this->ReturnView($viewmodel->ExportTable($this->postdata, false), true); break; @@ -228,8 +226,8 @@ // exportFromLGServicesHtmlTable if (isset($this->postdata['fileId'])) { $viewmodel->SetInfoFromPreviousPage($this->postdata); // only fileId in postdata - - $viewmodel->SetTextFromFileId(); // this will also set section_id + + $viewmodel->SetTextFromFileId(); // this will also set section_id $viewmodel->SetBookMetadataBySectionId(); } @@ -244,7 +242,7 @@ protected function EditWordlist() { /** - * EditWordlist action returns "./views/Extractapp/EditWordlist.php" view, + * EditWordlist action returns "./views/Extractapp/EditWordlist.php" view, * It adds or saves wordlist based on the 'func' variable in postdata. */ @@ -262,9 +260,9 @@ $this->ReturnView($viewmodel->SaveWordlist($this->postdata), true); break; default: // EditWordlist - $this->ReturnView($viewmodel->EditWordlist(), true); + $this->ReturnView($viewmodel->EditWordlist(), true); break; - } + } } @@ -282,10 +280,10 @@ } switch ($func) { case 'NewTagElement': - $this->ReturnView($viewmodel->NewTagElement($this->postdata), true); + $this->ReturnView($viewmodel->NewTagElement($this->postdata), false); break; case 'SaveTagElement': - $this->ReturnView($viewmodel->SaveTagElement($this->postdata), true); + $this->ReturnView($viewmodel->SaveTagElement($this->postdata), false); break; case 'DeleteTag': $this->ReturnView($viewmodel->DeleteTag($this->postdata), true); @@ -296,7 +294,7 @@ } } - + protected function ConfigTagsInTopic() { /** * ConfigTagsInTopic action returns "./views/Extractapp/ConfigTagsInTopic.php" view. @@ -315,23 +313,23 @@ break; /* case 'CreateNewTopic': - $result = $viewmodel->CreateNewTopic($this->postdata); + $result = $viewmodel->CreateNewTopic($this->postdata); if ($result == "error") { echo "Fail to create the new topic. Please contact us."; } else { - $this->ReturnView($viewmodel->ConfigTagsInTopic($result), true); + $this->ReturnView($viewmodel->ConfigTagsInTopic($result), true); } break; */ - default: - $this->ReturnView($viewmodel->ConfigTagsInTopic($this->postdata), true); + default: + $this->ReturnView($viewmodel->ConfigTagsInTopic($this->postdata), true); break; - } + } } - - + + }
--- a/views/maintemplate.php Thu Sep 28 13:44:57 2017 +0200 +++ b/views/maintemplate.php Thu Sep 28 14:01:59 2017 +0200 @@ -1,6 +1,3 @@ -<html> -<head> -<title></title> <script src="../js/jquery-1.10.2.min.js"></script> <script src="../js/jquery-ui.js"></script> <script src="../js/taggingtext.js"></script> @@ -8,10 +5,3 @@ <script src="../js/bootstrap.min.js"></script> <link href="../css/taggingtext.css" rel="stylesheet"> <link href="../css/bootstrap.min.css" rel="stylesheet"> - -</head> -<body> - -</body> - -</html> \ No newline at end of file
--- a/views/maintemplate_local.php Thu Sep 28 13:44:57 2017 +0200 +++ b/views/maintemplate_local.php Thu Sep 28 14:01:59 2017 +0200 @@ -1,6 +1,3 @@ -<html> -<head> -<title></title> <script src="../../js/jquery-1.10.2.min.js"></script> <script src="../../js/jquery-ui.js"></script> <script src="../../js/taggingtext.js"></script> @@ -8,10 +5,3 @@ <script src="../../js/bootstrap.min.js"></script> <link href="../../css/taggingtext.css" rel="stylesheet"> <link href="../../css/bootstrap.min.css" rel="stylesheet"> - -</head> -<body> - -</body> - -</html> \ No newline at end of file