comparison controllers/extractapp.php @ 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 e542b161d907
children
comparison
equal deleted inserted replaced
113:e26945b2aa85 114:7d6a107c37da
14 * 14 *
15 * You should have received a copy of the GNU General Public License 15 * You should have received a copy of the GNU General Public License
16 * along with Extraction-interface. If not, see <http://www.gnu.org/licenses/>. 16 * along with Extraction-interface. If not, see <http://www.gnu.org/licenses/>.
17 */ 17 */
18 18
19 /** 19 /**
20 * Extractapp class is extended from the BaseController class. 20 * Extractapp class is extended from the BaseController class.
21 * It sends commands to the ExtractappModel to process or update the ExtractappModel's state. 21 * It sends commands to the ExtractappModel to process or update the ExtractappModel's state.
22 * It can also pass the commands or data (from ExtractappModel) to the associated view (files in views/Extractapp/), 22 * It can also pass the commands or data (from ExtractappModel) to the associated view (files in views/Extractapp/),
23 * for example views/Extractapp/TaggingText.php , to change the view's presentation. 23 * for example views/Extractapp/TaggingText.php , to change the view's presentation.
24 * 24 *
25 * There are five actions in Extractapp: tagging text, exporting a table, 25 * There are five actions in Extractapp: tagging text, exporting a table,
26 * editing the wordlist, editing the taglist, and configurating tags in one topic. 26 * editing the wordlist, editing the taglist, and configurating tags in one topic.
27 * Each action is one of the methods in Extractapp. 27 * Each action is one of the methods in Extractapp.
28 * 28 *
29 */ 29 */
30 30
31 class Extractapp extends BaseController { 31 class Extractapp extends BaseController {
32 32
33 33
34 protected $viewmodel; 34 protected $viewmodel;
35 35
36 36
37 public function __construct($action, $urlvalues, $postdata){ 37 public function __construct($action, $urlvalues, $postdata){
38 parent::__construct($action, $urlvalues, $postdata); 38 parent::__construct($action, $urlvalues, $postdata);
39 $this->viewmodel = new ExtractappModel(); 39 $this->viewmodel = new ExtractappModel();
40 } 40 }
41 41
42 protected function TaggingText() { 42 protected function TaggingText() {
43 /** 43 /**
44 * TaggingText action in Extractapp handles the taging related actions, for example, 44 * TaggingText action in Extractapp handles the taging related actions, for example,
45 * tagging itself, saving tag results, loading and saving regular expression for tagging. 45 * tagging itself, saving tag results, loading and saving regular expression for tagging.
46 * They are handled by 'func' variable in postdata, which could come from LGService or from extraction-interface application itself. 46 * They are handled by 'func' variable in postdata, which could come from LGService or from extraction-interface application itself.
47 * 47 *
48 * From LGService, the postdata contains essential information about the file/section of local gazetteers data. 48 * From LGService, the postdata contains essential information about the file/section of local gazetteers data.
49 * This happens when user entering to extraction-interface the first time, or after s/he saved her/is tagging results to LGService. 49 * This happens when user entering to extraction-interface the first time, or after s/he saved her/is tagging results to LGService.
50 * (default one, SaveFullTextToLGService, SmartRegexLoad, SmartRegexSave case) 50 * (default one, SaveFullTextToLGService, SmartRegexLoad, SmartRegexSave case)
51 * 51 *
52 * From extraction-interface itself, it contains the information from previous page. 52 * From extraction-interface itself, it contains the information from previous page.
53 * This happens when user choosing another topic in the extraction-interface, 53 * This happens when user choosing another topic in the extraction-interface,
54 * the page need to retrieve related information from database for the topic. 54 * the page need to retrieve related information from database for the topic.
55 * (ContinueTagging case) 55 * (ContinueTagging case)
56 */ 56 */
57 57
58 $viewmodel = $this->viewmodel; 58 $viewmodel = $this->viewmodel;
59 59
60 if (isset($this->postdata['func'])) { 60 if (isset($this->postdata['func'])) {
61 $func = $this->postdata['func']; 61 $func = $this->postdata['func'];
62 } else { 62 } else {
63 $func = ""; 63 $func = "";
64 } 64 }
65 switch ($func) { 65 switch ($func) {
66 case 'SaveFullText': 66 case 'SaveFullText':
67 $viewmodel->SaveFullText($this->postdata); 67 $viewmodel->SaveFullText($this->postdata);
68 $this->ReturnView($viewmodel->StartTagging(), true); 68 $this->ReturnView($viewmodel->StartTagging(), true);
69 break; 69 break;
70 case 'SaveFullTextToLGService': 70 case 'SaveFullTextToLGService':
71 global $AT_LOCAL; 71
72 $viewmodel->messages['info'] .= "SaveFullTextToLGService! ";
73
74 global $AT_LOCAL;
75
72 if ($AT_LOCAL) { 76 if ($AT_LOCAL) {
73 $viewmodel->messages['info'] .= "SaveFullTextToLGService! (local test) "; 77 $viewmodel->messages['info'] .= "(local test) ";
74 $viewmodel->SetInfoFromPreviousPage($this->postdata); 78 }
75 $response = $viewmodel->SaveFullTextToLGService($this->postdata); 79
76 80 $viewmodel->SetInfoFromPreviousPage($this->postdata);
77 $viewmodel->UpdateInfoResponsedFromLGService($response); // update file_id, branch_id, user_id 81
78 $viewmodel->SetTextFromFileId(); 82 $response = $viewmodel->SaveFullTextToLGService($this->postdata);
79 83
80 } else { 84 $viewmodel->UpdateInfoResponsedFromLGService($response); // update file_id, branch_id, user_id
81 85
82 $viewmodel->messages['info'] .= "SaveFullTextToLGService! "; 86 $viewmodel->SetTextFromFileId();
83 $viewmodel->SetInfoFromPreviousPage($this->postdata); 87
84 $response = $viewmodel->SaveFullTextToLGService($this->postdata); 88 $this->ReturnView($viewmodel->StartTagging(), true);
85
86 $viewmodel->UpdateInfoResponsedFromLGService($response); // update file_id, branch_id, user_id
87
88 $viewmodel->SetTextFromFileId();
89 }
90 $this->ReturnView($viewmodel->StartTagging(), true);
91 break; 89 break;
92 90
93 case 'SmartRegexLoad': 91 case 'SmartRegexLoad':
94 $viewmodel->LoadSmartRegex($this->postdata['topic_id']); 92 $viewmodel->LoadSmartRegex($this->postdata['topic_id']);
95 break; 93 break;
104 $this->ReturnView($viewmodel->StartTagging(), true); 102 $this->ReturnView($viewmodel->StartTagging(), true);
105 break; 103 break;
106 104
107 case 'ContinueTagging': 105 case 'ContinueTagging':
108 $viewmodel->messages['info'] .= "(Countinue tagging) "; 106 $viewmodel->messages['info'] .= "(Countinue tagging) ";
109 $viewmodel->SetInfoFromPreviousPage($this->postdata); 107 $viewmodel->SetInfoFromPreviousPage($this->postdata);
110 108
111 // when new section hasn't been saved to LGServices, no fileId and no branchId 109 // when new section hasn't been saved to LGServices, no fileId and no branchId
112 if ($this->postdata['fileId'] == 0) { 110 if ($this->postdata['fileId'] == 0) {
113 $viewmodel->SetTextFromSectionId(); 111 $viewmodel->SetTextFromSectionId();
114 } else { 112 } else {
115 $viewmodel->SetTextFromFileId(); // get text by fileId, from LGService 113 $viewmodel->SetTextFromFileId(); // get text by fileId, from LGService
116 } 114 }
117 115
118 $viewmodel->SetTopic($this->postdata['topic']); 116 $viewmodel->SetTopic($this->postdata['topic']);
119 117
120 $this->ReturnView($viewmodel->StartTagging(), true); 118 $this->ReturnView($viewmodel->StartTagging(), true);
121 break; 119 break;
122 120
123 case 'CreateNewTopic': 121 case 'CreateNewTopic':
124 $result = $viewmodel->CreateNewTopic($this->postdata); 122 $result = $viewmodel->CreateNewTopic($this->postdata);
125 if ($result == "error") { 123 if ($result == "error") {
126 $viewmodel->messages['error'] .= "Fail to create the new topic <br> "; 124 $viewmodel->messages['error'] .= "Fail to create the new topic <br> ";
127 } else { 125 } else {
128 // then act like ContinueTagging 126 // then act like ContinueTagging
129 $viewmodel->messages['info'] .= "Created a new topic <br>"; 127 $viewmodel->messages['info'] .= "Created a new topic <br>";
130 $viewmodel->SetInfoFromPreviousPage($result); 128 $viewmodel->SetInfoFromPreviousPage($result);
131 129
132 // when new section hasn't been saved to LGServices, no fileId and no branchId 130 // when new section hasn't been saved to LGServices, no fileId and no branchId
133 if ($this->postdata['fileId'] == 0) { 131 if ($this->postdata['fileId'] == 0) {
134 $viewmodel->SetTextFromSectionId(); 132 $viewmodel->SetTextFromSectionId();
135 } else { 133 } else {
136 $viewmodel->SetTextFromFileId(); // get text by fileId, from LGService 134 $viewmodel->SetTextFromFileId(); // get text by fileId, from LGService
137 } 135 }
138 $viewmodel->SetTopic($result['topic']); 136 $viewmodel->SetTopic($result['topic']);
139 137
140 } 138 }
141 $this->ReturnView($viewmodel->StartTagging(), true); 139 $this->ReturnView($viewmodel->StartTagging(), true);
142 140
143 break; 141 break;
144 142
145 default: 143 default:
146 // This is where the first time user visit extraction interface from LGService 144 // This is where the first time user visit extraction interface from LGService
147 $viewmodel->messages['info'] .= "Welcome to Extraction Interface. "; 145 $viewmodel->messages['info'] .= "Welcome to Extraction Interface. ";
148 146
149 if (isset($this->postdata['fileId'])) { 147 if (isset($this->postdata['fileId'])) {
150 if ($this->postdata['fileId'] != 0) { // ($this->postdata['branchId'] != 0) { 148 if ($this->postdata['fileId'] != 0) { // ($this->postdata['branchId'] != 0) {
158 } else if ($this->postdata['sectionId'] != 0 && $this->postdata['userId'] != 0) { 156 } else if ($this->postdata['sectionId'] != 0 && $this->postdata['userId'] != 0) {
159 // --- New branch case --- 157 // --- New branch case ---
160 $viewmodel->SetInfoFromPreviousPage($this->postdata); 158 $viewmodel->SetInfoFromPreviousPage($this->postdata);
161 $viewmodel->SetBookMetadataBySectionId(); 159 $viewmodel->SetBookMetadataBySectionId();
162 // get text by sectionId from LGService 160 // get text by sectionId from LGService
163 $viewmodel->SetTextFromSectionId(); 161 $viewmodel->SetTextFromSectionId();
164 162
165 } else if ($this->postdata['sectionId'] != 0) { 163 } else if ($this->postdata['sectionId'] != 0) {
166 $viewmodel->SetTextFromLocal($this->postdata['sectionId']); 164 $viewmodel->SetTextFromLocal($this->postdata['sectionId']);
167 $viewmodel->SetBookMetadataBySectionId(); 165 $viewmodel->SetBookMetadataBySectionId();
168 166
169 } else if (is_numeric($this->urlvalues['id'])) { 167 } else if (is_numeric($this->urlvalues['id'])) {
170 // get text from local file system (for development stage only) 168 // get text from local file system (for development stage only)
171 $viewmodel->SetTextFromLocal($this->urlvalues['id']); 169 $viewmodel->SetTextFromLocal($this->urlvalues['id']);
172 $viewmodel->SetBookMetadataBySectionId(); 170 $viewmodel->SetBookMetadataBySectionId();
173 $this->ReturnView_localtest($viewmodel->StartTagging(), true); 171 $this->ReturnView_localtest($viewmodel->StartTagging(), true);
174 break; 172 break;
175 173
176 } else { 174 } else {
177 $viewmodel->messages['error'] .= "wrong url!!"; 175 $viewmodel->messages['error'] .= "wrong url!!";
178 return; 176 return;
179 } 177 }
180 178
181 $this->ReturnView($viewmodel->StartTagging(), true); 179 $this->ReturnView($viewmodel->StartTagging(), true);
182 break; 180 break;
183 } 181 }
184 182
185 183
186 184
187 } 185 }
188 186
189 187
190 protected function ExportTabDelimited() { 188 protected function ExportTabDelimited() {
191 /** 189 /**
194 */ 192 */
195 $viewmodel = $this->viewmodel; 193 $viewmodel = $this->viewmodel;
196 194
197 if (isset($this->postdata['fileId'])) { 195 if (isset($this->postdata['fileId'])) {
198 $viewmodel->SetInfoFromPreviousPage($this->postdata); // fileId in postdata 196 $viewmodel->SetInfoFromPreviousPage($this->postdata); // fileId in postdata
199 197
200 $viewmodel->SetTextFromFileId(); // this will also set section_id 198 $viewmodel->SetTextFromFileId(); // this will also set section_id
201 $viewmodel->SetBookMetadataBySectionId(); 199 $viewmodel->SetBookMetadataBySectionId();
202 } 200 }
203 201
204 $this->ReturnView($viewmodel->ExportTable($this->postdata, true), false); 202 $this->ReturnView($viewmodel->ExportTable($this->postdata, true), false);
205 203
206 204
207 } 205 }
208 206
209 protected function ExportTable() { 207 protected function ExportTable() {
210 /** 208 /**
211 * ExportTable action returns "./views/Extractapp/ExportTable.php" view. 209 * ExportTable action returns "./views/Extractapp/ExportTable.php" view.
218 $func = ""; 216 $func = "";
219 } 217 }
220 switch ($func) { 218 switch ($func) {
221 case 'exportFromExtractionInterface': 219 case 'exportFromExtractionInterface':
222 $viewmodel->SetInfoFromPreviousPage($this->postdata); 220 $viewmodel->SetInfoFromPreviousPage($this->postdata);
223 221
224 $this->ReturnView($viewmodel->ExportTable($this->postdata, false), true); 222 $this->ReturnView($viewmodel->ExportTable($this->postdata, false), true);
225 break; 223 break;
226 224
227 default: // from file 225 default: // from file
228 // exportFromLGServicesHtmlTable 226 // exportFromLGServicesHtmlTable
229 if (isset($this->postdata['fileId'])) { 227 if (isset($this->postdata['fileId'])) {
230 $viewmodel->SetInfoFromPreviousPage($this->postdata); // only fileId in postdata 228 $viewmodel->SetInfoFromPreviousPage($this->postdata); // only fileId in postdata
231 229
232 $viewmodel->SetTextFromFileId(); // this will also set section_id 230 $viewmodel->SetTextFromFileId(); // this will also set section_id
233 $viewmodel->SetBookMetadataBySectionId(); 231 $viewmodel->SetBookMetadataBySectionId();
234 } 232 }
235 233
236 $this->ReturnView($viewmodel->ExportTable($this->postdata, true), false); 234 $this->ReturnView($viewmodel->ExportTable($this->postdata, true), false);
237 break; 235 break;
242 240
243 } 241 }
244 242
245 protected function EditWordlist() { 243 protected function EditWordlist() {
246 /** 244 /**
247 * EditWordlist action returns "./views/Extractapp/EditWordlist.php" view, 245 * EditWordlist action returns "./views/Extractapp/EditWordlist.php" view,
248 * It adds or saves wordlist based on the 'func' variable in postdata. 246 * It adds or saves wordlist based on the 'func' variable in postdata.
249 */ 247 */
250 248
251 $viewmodel = $this->viewmodel; 249 $viewmodel = $this->viewmodel;
252 if (isset($this->postdata['func'])) { 250 if (isset($this->postdata['func'])) {
260 break; 258 break;
261 case 'SaveWordlist': 259 case 'SaveWordlist':
262 $this->ReturnView($viewmodel->SaveWordlist($this->postdata), true); 260 $this->ReturnView($viewmodel->SaveWordlist($this->postdata), true);
263 break; 261 break;
264 default: // EditWordlist 262 default: // EditWordlist
265 $this->ReturnView($viewmodel->EditWordlist(), true); 263 $this->ReturnView($viewmodel->EditWordlist(), true);
266 break; 264 break;
267 } 265 }
268 } 266 }
269 267
270 268
271 protected function EditTaglist() { 269 protected function EditTaglist() {
272 /** 270 /**
280 } else { 278 } else {
281 $func = ""; 279 $func = "";
282 } 280 }
283 switch ($func) { 281 switch ($func) {
284 case 'NewTagElement': 282 case 'NewTagElement':
285 $this->ReturnView($viewmodel->NewTagElement($this->postdata), true); 283 $this->ReturnView($viewmodel->NewTagElement($this->postdata), false);
286 break; 284 break;
287 case 'SaveTagElement': 285 case 'SaveTagElement':
288 $this->ReturnView($viewmodel->SaveTagElement($this->postdata), true); 286 $this->ReturnView($viewmodel->SaveTagElement($this->postdata), false);
289 break; 287 break;
290 case 'DeleteTag': 288 case 'DeleteTag':
291 $this->ReturnView($viewmodel->DeleteTag($this->postdata), true); 289 $this->ReturnView($viewmodel->DeleteTag($this->postdata), true);
292 break; 290 break;
293 default: // EditTaglist 291 default: // EditTaglist
294 $this->ReturnView($viewmodel->EditTaglist($this->postdata), true); 292 $this->ReturnView($viewmodel->EditTaglist($this->postdata), true);
295 break; 293 break;
296 } 294 }
297 } 295 }
298 296
299 297
300 protected function ConfigTagsInTopic() { 298 protected function ConfigTagsInTopic() {
301 /** 299 /**
302 * ConfigTagsInTopic action returns "./views/Extractapp/ConfigTagsInTopic.php" view. 300 * ConfigTagsInTopic action returns "./views/Extractapp/ConfigTagsInTopic.php" view.
303 * It shows or updates the tags-in-topic relation. 301 * It shows or updates the tags-in-topic relation.
304 */ 302 */
313 case 'Update': 311 case 'Update':
314 $viewmodel->UpdateTagsInTopic($this->postdata); 312 $viewmodel->UpdateTagsInTopic($this->postdata);
315 break; 313 break;
316 /* 314 /*
317 case 'CreateNewTopic': 315 case 'CreateNewTopic':
318 $result = $viewmodel->CreateNewTopic($this->postdata); 316 $result = $viewmodel->CreateNewTopic($this->postdata);
319 if ($result == "error") { 317 if ($result == "error") {
320 echo "Fail to create the new topic. Please contact us."; 318 echo "Fail to create the new topic. Please contact us.";
321 } else { 319 } else {
322 $this->ReturnView($viewmodel->ConfigTagsInTopic($result), true); 320 $this->ReturnView($viewmodel->ConfigTagsInTopic($result), true);
323 } 321 }
324 break; 322 break;
325 */ 323 */
326 default: 324 default:
327 $this->ReturnView($viewmodel->ConfigTagsInTopic($this->postdata), true); 325 $this->ReturnView($viewmodel->ConfigTagsInTopic($this->postdata), true);
328 break; 326 break;
329 } 327 }
330 } 328 }
331 329
332 330
333 331
334 332
335 } 333 }
336 334
337 335
338 ?> 336 ?>