[dev] [commit] r930 - patches phplib/models templates/admin wwwbase/admin

automailer at dexonline.ro automailer at dexonline.ro
Fri Aug 16 05:00:32 EEST 2013


Author: radu
Date: Fri Aug 16 05:00:31 2013
New Revision: 930

Log:
add suport for editing OCR definitions

Added:
   patches/00094.sql
   phplib/models/OCRLot.php
   templates/admin/ocrInput.ihtml
   wwwbase/admin/ocrInput.php
Modified:
   templates/admin/definitionEdit.ihtml
   wwwbase/admin/definitionEdit.php

Added: patches/00094.sql
==============================================================================
--- /dev/null	00:00:00 1970	(empty, because file is newly added)
+++ patches/00094.sql	Fri Aug 16 05:00:31 2013	(r930)
@@ -0,0 +1,15 @@
+CREATE TABLE `OCRLot` (
+  `id` int(11) NOT NULL AUTO_INCREMENT,
+  `sourceId` int(11) NOT NULL,
+  `userId` int(11) NOT NULL,
+  `fileName` varchar(100) COLLATE utf8_romanian_ci NOT NULL,
+  `fileSize` int(11) NOT NULL,
+  `status` enum('started','done') COLLATE utf8_romanian_ci DEFAULT 'started',
+  `lastModified` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
+  `startedAt` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00',
+  PRIMARY KEY (`id`),
+  UNIQUE KEY `line` (`sourceId`,`fileName`(50))
+) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_romanian_ci;
+
+alter table OCR add column lotId int(11) DEFAULT NULL after id;
+alter table OCR add unique index line(sourceId,ocrText(50));

Added: phplib/models/OCRLot.php
==============================================================================
--- /dev/null	00:00:00 1970	(empty, because file is newly added)
+++ phplib/models/OCRLot.php	Fri Aug 16 05:00:31 2013	(r930)
@@ -0,0 +1,7 @@
+<?php
+
+class OCRLot extends BaseObject {
+  public static $_table = 'OCRLot';
+}
+
+?>

Modified: templates/admin/definitionEdit.ihtml
==============================================================================
--- templates/admin/definitionEdit.ihtml	Wed Aug 14 17:27:06 2013	(r929)
+++ templates/admin/definitionEdit.ihtml	Fri Aug 16 05:00:31 2013	(r930)
@@ -1,7 +1,7 @@
 <form action="definitionEdit.php" method="post">
   <input type="hidden" name="definitionId" value="{$def->id}"/>
   {if $isOCR}
-  <input type="hidden" name="type" value="ocr"/>
+  <input type="hidden" name="ocr" value="1"/>
   {/if}
   <table class="editableFields">
     {foreach from=$homonyms item=h key=i}
@@ -98,11 +98,19 @@
 
       </td>
     </tr>
+    {if $isOCR}
     <tr>
       <td colspan="3" class="buttonRow">
-        <input type="submit" name="but_next_ocr" value="Adaugă următoarea definiție"/>
+        <input type="submit" name="but_next_ocr" value="Preia următoarea definiție OCR"/>
       </td>
     </tr>
+    {else}
+    <tr>
+      <td colspan="3" class="buttonRow">
+      OCR: {$isOCR}
+      </td>
+    </tr>
+    {/if}
   </table>
 </form>
 

Added: templates/admin/ocrInput.ihtml
==============================================================================
--- /dev/null	00:00:00 1970	(empty, because file is newly added)
+++ templates/admin/ocrInput.ihtml	Fri Aug 16 05:00:31 2013	(r930)
@@ -0,0 +1,6 @@
+<form method="post" enctype="multipart/form-data">
+Sursa: {include file="common/sourceDropDown.ihtml" sources=$allModeratorSources skipAnySource=true}<br/>
+<label for="file">Fișier:</label><input type="file" name="file" id="file"><br/>
+<input type="submit" name="submit" value="Încarcă">
+</form>
+<div class="{$msgClass}">{$message}</div>

Modified: wwwbase/admin/definitionEdit.php
==============================================================================
--- wwwbase/admin/definitionEdit.php	Wed Aug 14 17:27:06 2013	(r929)
+++ wwwbase/admin/definitionEdit.php	Fri Aug 16 05:00:31 2013	(r930)
@@ -3,10 +3,10 @@
 util_assertModerator(PRIV_EDIT);
 util_assertNotMirror();
 
-$addType = util_getRequestIntParameter('type');
+$isOCR = util_getRequestIntParameter('ocr');
 $next_ocr_but = util_getRequestParameter('but_next_ocr');
-if(!$next_ocr_but) {
-    $definitionId = util_getRequestIntParameter('definitionId');
+$definitionId = util_getRequestIntParameter('definitionId');
+if($definitionId && !$next_ocr_but) {
     $lexemIds = util_getRequestCsv('lexemIds');
     $sourceId = util_getRequestIntParameter('source');
     $internalRep = util_getRequestParameter('internalRep');
@@ -22,14 +22,13 @@
     $status = null;
     $commentContents = null;
     $preserveCommentUser = null;
+    $isOCR = 1;
 }
 $refreshButton = util_getRequestParameter('but_refresh');
 $acceptButton = util_getRequestParameter('but_accept');
 $moveButton = util_getRequestParameter('but_move');
 $hasErrors = false;
 
-$isOCR = ($addType == 'ocr');
-
 if (!$definitionId) {
   if ($isOCR) {
     $ocr = Model::factory('OCR')->where('status', 'raw')->order_by_asc('dateModified')->find_one();

Added: wwwbase/admin/ocrInput.php
==============================================================================
--- /dev/null	00:00:00 1970	(empty, because file is newly added)
+++ wwwbase/admin/ocrInput.php	Fri Aug 16 05:00:31 2013	(r930)
@@ -0,0 +1,72 @@
+<?php
+require_once("../../phplib/util.php"); 
+util_assertModerator(PRIV_EDIT);
+util_assertNotMirror();
+
+$sourceId = util_getRequestIntParameter('source');
+$class = "msgOK";
+$message = "";
+
+if ($_FILES && $_FILES["file"]) {
+  if ($_FILES["file"]["error"] > 0) {
+    $class = "msgErr";
+    $message =  "Eroare: " . $_FILES["file"]["error"];
+  }
+  else {
+    $userId = session_getUserId();
+    $ocrLot = Model::factory('OCRLot')->create();
+    $ocrLot->userId = $userId;
+    $ocrLot->sourceId = $sourceId;
+    $ocrLot->fileName = $_FILES["file"]["name"];
+    $ocrLot->fileSize = $_FILES["file"]["size"];
+    $ocrLot->startedAt = date('Y-m-d H:i:s');
+
+    try {
+      $ocrLot->save();
+    }
+    catch (Exception $e) {
+      $class = "msgErr";
+      $message = "<div> Eroare: " . $e->getMessage() . "</div>";
+    }
+
+    if ($class != "msgErr") {
+      $lotId = $ocrLot->id();
+      $errCount = 0;
+      $lineCount = 0;
+
+      $fp = fopen($_FILES["file"]["tmp_name"],'r');
+      while ($line = fgets($fp)) {
+        $line = trim($line);
+        if (!empty($line)) {
+          $lineCount++;
+          $ocr = Model::factory('OCR')->create();
+          $ocr->lotId = $lotId;
+          $ocr->userId = $userId;
+          $ocr->sourceId = $sourceId;
+          $ocr->ocrText = $line;
+          $ocr->dateAdded = date('Y-m-d H:i:s');
+          try {
+            $ocr->save();
+          }
+          catch (Exception $e) {
+            $errCount++;
+            $class = "msgErr";
+            $message .= "<div> Eroare: " . $e->getMessage() . "</div>";
+          }
+        }
+      }
+
+      $ocrLot->status = 'done';
+      $ocrLot->save();
+      $message .= "Fișierul " . $_FILES["file"]["name"] . " (" . $lineCount . " linii) a fost salvat" .  ($class == "msgErr" ? (" cu " . $errCount . " erori...") : "!");
+    }
+
+  }
+}
+
+SmartyWrap::assign("msgClass", $class);
+SmartyWrap::assign("message", $message);
+SmartyWrap::assign("allModeratorSources", Model::factory('Source')->where('canModerate', true)->order_by_asc('displayOrder')->find_many());
+SmartyWrap::displayAdminPage('admin/ocrInput.ihtml');
+
+?>


More information about the Dev mailing list