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