1 : <?php
2 :
3 : /**
4 : * Dictionaries of Old French and Latin
5 : *
6 : * PHP 5
7 : *
8 : * @category DicFro
9 : * @package Model
10 : * @subpackage Query
11 : * @author Michel Corne <mcorne@yahoo.com>
12 : * @copyright 2008-2010 Michel Corne
13 : * @license http://opensource.org/licenses/gpl-3.0.html GNU General Public License, version 3 (GPLv3)
14 : * @link http://www.micmap.org/dicfro
15 : */
16 :
17 : require_once 'Model/Query.php';
18 :
19 : /**
20 : * Queries the ghostwords database
21 : *
22 : * @category DicFro
23 : * @package Model
24 : * @subpackage Query
25 : * @author Michel Corne <mcorne@yahoo.com>
26 : * @copyright 2008-2010 Michel Corne
27 : * @license http://opensource.org/licenses/gpl-3.0.html GNU General Public License, version 3 (GPLv3)
28 : */
29 :
30 : class Model_Query_Ghostwords extends Model_Query
31 : {
32 : /**
33 : * Constructor
34 : *
35 : * @param string $directory the dictionaries directory
36 : * @return void
37 : */
38 : public function __construct($directory = '.')
39 : {
40 9 : parent::__construct($directory . '/ghostwords');
41 9 : }
42 :
43 : /**
44 : * Search words between two words or from a word
45 : *
46 : * @param string $wordFrom the word to search from including this word
47 : * @param string $wordTo the word to search to excluding this word or null
48 : * @return string the list of words between those two words
49 : */
50 : public function searchWords($wordFrom, $wordTo)
51 : {
52 : return $wordTo?
53 7 : $this->searchWordsBetween($wordFrom, $wordTo) :
54 7 : $this->searchWordsFrom($wordFrom);
55 : }
56 :
57 : /**
58 : * Search words between two words
59 : *
60 : * @param string $wordFrom the word to search from including this word
61 : * @param string $wordTo the word to search to excluding this word
62 : * @return string the list of words between those two words
63 : */
64 : public function searchWordsBetween($wordFrom, $wordTo)
65 : {
66 6 : $wordFrom = $this->string->utf8toASCII($wordFrom);
67 6 : $wordTo = $this->string->utf8toASCII($wordTo);
68 :
69 6 : $sql = "SELECT original FROM word WHERE ascii >= :wordFrom AND ascii < :wordTo";
70 :
71 6 : return $this->execute($sql, array(':wordFrom' => $wordFrom, ':wordTo' => $wordTo), PDO::FETCH_COLUMN);
72 : }
73 :
74 : /**
75 : * Search words from a word
76 : *
77 : * @param string $wordFrom the word to search from including this word
78 : * @return string the list of words between those two words
79 : */
80 : public function searchWordsFrom($wordFrom)
81 : {
82 4 : $wordFrom = $this->string->utf8toASCII($wordFrom);
83 :
84 4 : $sql = "SELECT original FROM word WHERE ascii >= :wordFrom ";
85 :
86 4 : return $this->execute($sql, array(':wordFrom' => $wordFrom), PDO::FETCH_COLUMN);
87 : }
|