svn: /web/doc-editor/trunk/php/ DictionnaryManager.php

[email protected] (Yannick Torres)
Newsgroups php.doc.web
Message-ID <[email protected]>
yannick                                  Fri, 16 Apr 2010 21:03:17 +0000

Revision: http://svn.php.net/viewvc?view=revision&revision=298088

Log:
New functionnality : Dictionnary. Idea from pedram. Accessible from tools panel for PendingTranslate, StateFile, ErrorFile & RevieweFile

Changed paths:
    A   web/doc-editor/trunk/php/DictionnaryManager.php

Added: web/doc-editor/trunk/php/DictionnaryManager.php
===================================================================
--- web/doc-editor/trunk/php/DictionnaryManager.php	                        (rev 0)
+++ web/doc-editor/trunk/php/DictionnaryManager.php	2010-04-16 21:03:17 UTC (rev 298088)
@@ -0,0 +1,138 @@
+<?php
+/*
+ *  A class to manage a dictionnary
+ *
+ */
+
+class DictionnaryManager {
+
+    private static $instance;
+    public $acronyms;
+    public $entities;
+
+    public static function getInstance()
+    {
+        if (!isset(self::$instance)) {
+            $c = __CLASS__;
+            self::$instance = new $c;
+        }
+        return self::$instance;
+    }
+
+    public function __construct()
+    {
+    }
+
+    /**
+     * Delete a given word.
+     * @param $wordId : Database Id for the word we want to delete
+     *
+     */
+    public function delWord($wordId)
+    {
+        $s = sprintf(
+            'DELETE FROM
+                `dictionnary`
+             WHERE
+                `id` = "%s"',
+
+            $wordId
+        );
+
+        DBConnection::getInstance()->query($s);
+    }
+
+    /**
+     * Get all words for a given project/lang.
+     *
+     */
+    public function getWords()
+    {
+        $am = AccountManager::getInstance();
+        $project = $am->project;
+        $vcsLang = $am->vcsLang;
+
+        $s = sprintf(
+            'SELECT
+                `id`, `valueEn`, `valueLang`, `lastUser`, `lastDate`
+             FROM
+                `dictionnary`
+             WHERE
+                `project` = "%s" AND `lang`="%s"',
+
+            $project,
+            $vcsLang
+        );
+
+        $r = DBConnection::getInstance()->query($s);
+
+        $infos = array();
+        while ($a = $r->fetch_assoc()) {
+            $infos[] = $a;
+        }
+
+        return $infos;
+    }
+
+    /**
+     * Manage a word ; Add or update a word base on his wordId.
+     * If wordId is "new", the word is added, else it was updated
+     * @param $wordId : Database Id for the word or "new" if we want to add it
+     * @param $valueEn : New English value
+     * @param $valueLang : New lang value
+     *
+     */
+    public function manageDictionnaryWord($wordId, $valueEn, $valueLang)
+    {
+        $db = DBConnection::getInstance();
+        $am = AccountManager::getInstance();
+        $vcsLogin = $am->vcsLogin;
+        $project  = $am->project;
+        $vcsLang  = $am->vcsLang;
+
+        $time = @date("Y-m-d H:i:s");
+
+        if( $wordId == 'new' ) {
+
+            $s = sprintf(
+                'INSERT INTO
+                    `dictionnary`
+                 (`project`, `lang`, `valueEn`, `valueLang`, `lastUser`, `lastDate`)
+                 VALUES ("%s", "%s", "%s", "%s", "%s", "%s")',
+                $project,
+                $vcsLang,
+                $db->real_escape_string($valueEn),
+                $db->real_escape_string($valueLang),
+                $db->real_escape_string($vcsLogin),
+                $time
+            );
+
+        } else {
+
+            $s = sprintf(
+                'UPDATE
+                    `dictionnary`
+                 SET
+                    `valueEn`  = "%s",
+                    `valueLang`= "%s",
+                    `lastUser` = "%s",
+                    `lastDate` = "%s"
+                 WHERE
+                    `id` = %s',
+
+                $db->real_escape_string($valueEn),
+                $db->real_escape_string($valueLang),
+                $db->real_escape_string($vcsLogin),
+                $time,
+                $wordId
+            );
+
+        }
+
+        $db->query($s);
+
+        return $time;
+    }
+}
+
+?>
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.