d9c6298e27888bac12a6bbf31fdebab69ddb6274
[acontent.git] / docs / include / classes / DAO / LanguageTextDAO.class.php
1 <?php
2 /************************************************************************/
3 /* AContent                                                             */
4 /************************************************************************/
5 /* Copyright (c) 2010                                                   */
6 /* Inclusive Design Institute                                           */
7 /*                                                                      */
8 /* This program is free software. You can redistribute it and/or        */
9 /* modify it under the terms of the GNU General Public License          */
10 /* as published by the Free Software Foundation.                        */
11 /************************************************************************/
12
13 /**
14 * DAO for "language_text" table
15 * @access       public
16 * @author       Cindy Qi Li
17 * @package      DAO
18 */
19
20 if (!defined('TR_INCLUDE_PATH')) exit;
21
22 require_once(TR_INCLUDE_PATH. 'classes/DAO/DAO.class.php');
23
24 class LanguageTextDAO extends DAO {
25
26         /**
27         * Create a new entry
28         * @access  public
29         * @param   $language_code : language code
30         *          $variable: '_msgs', '_template', '_check', '_guideline', '_test'
31         *          $term
32         *          $text
33         *          $context
34         * @return  table rows
35         * @author  Cindy Qi Li
36         */
37         function Create($language_code, $variable, $term, $text, $context)
38         {
39                 global $addslashes;
40                 
41                 $sql = "INSERT INTO ".TABLE_PREFIX."language_text
42                         (`language_code`, `variable`, `term`, `text`, `revised_date`, `context`)
43                         VALUES
44                         ('".$addslashes($language_code)."', 
45                          '".$addslashes($variable)."', 
46                          '".$addslashes($term)."', 
47                          '".$addslashes($text)."', 
48                          now(), 
49                          '".$addslashes($context)."')";
50
51                 return $this->execute($sql);
52         }
53
54         /**
55         * Insert new record if not exists, replace the existing one if already exists. 
56         * Record is identified by primary key: $language_code, variable, $term
57         * @access  public
58         * @param   $language_code : language code
59         *          $variable: '_msgs', '_template', '_check', '_guideline', '_test'
60         *          $term
61         *          $text
62         *          $context
63         * @return  table rows
64         * @author  Cindy Qi Li
65         */
66         function Replace($language_code, $variable, $term, $text, $context)
67         {
68                 global $addslashes;
69                 
70                 $sql = "REPLACE INTO ".TABLE_PREFIX."language_text
71                         (`language_code`, `variable`, `term`, `text`, `revised_date`, `context`)
72                         VALUES
73                         ('".$addslashes($language_code)."', 
74                          '".$addslashes($variable)."', 
75                          '".$addslashes($term)."', 
76                          '".$addslashes($text)."', 
77                          now(), 
78                          '".$addslashes($context)."')";
79                         
80                 return $this->execute($sql);
81         }
82         
83         /**
84         * Delete a record by $variable and $term
85         * @access  public
86         * @param   $language_code : language code
87         *          $variable: '_msgs', '_template', '_check', '_guideline', '_test'
88         *          $term
89         * @return  true / false
90         * @author  Cindy Qi Li
91         */
92         function DeleteByVarAndTerm($variable, $term)
93         {
94                 global $addslashes;
95                 
96                 $sql = "DELETE FROM ".TABLE_PREFIX."language_text
97                         WHERE `variable` = '".$addslashes($variable)."'
98                           AND `term` = '".$addslashes($term)."'";
99                         
100                 return $this->execute($sql);
101         }
102         
103         /**
104         * Return message text of given term and language
105         * @access  public
106         * @param   term : language term
107         *          lang : language code
108         * @return  table rows
109         * @author  Cindy Qi Li
110         */
111         function getMsgByTermAndLang($term, $lang)
112         {
113                 $sql    = 'SELECT * FROM '.TABLE_PREFIX.'language_text 
114                                                 WHERE term="' . $term . '" 
115                                                 AND variable="_msgs" 
116                                                 AND language_code="'.$lang.'" 
117                                                 ORDER BY variable';
118
119     return $this->execute($sql);
120   }
121
122         /**
123         * Return text of given term and language
124         * @access  public
125         * @param   term : language term
126         *          lang : language code
127         * @return  table rows
128         * @author  Cindy Qi Li
129         */
130         function getByTermAndLang($term, $lang)
131         {
132                 $sql    = 'SELECT * FROM '.TABLE_PREFIX.'language_text 
133                                                 WHERE term="' . $term . '" 
134                                                 AND language_code="'.$lang.'" 
135                                                 ORDER BY variable';
136
137             return $this->execute($sql);
138         }
139
140         /**
141         * Return rows of handbook rows by matching given text and language
142         * @access  public
143         * @param   term : language term
144         *          lang : language code
145         * @return  table rows
146         * @author  Cindy Qi Li
147         */
148         function getHelpByMatchingText($text, $lang)
149         {
150                 $sql    = "SELECT * FROM ".TABLE_PREFIX."language_text 
151                                                 WHERE term like 'TR_HELP_%'
152                                                 AND lower(cast(text as char)) like '%".strtolower($text)."%' 
153                                                 AND language_code='".$lang."' 
154                                                 ORDER BY variable";
155
156             return $this->execute($sql);
157         }
158
159         /**
160         * Return all template info of given language
161         * @access  public
162         * @param   lang : language code
163         * @return  table rows
164         * @author  Cindy Qi Li
165         */
166         function getAllByLang($lang)
167         {
168                 $sql = "SELECT * FROM ".TABLE_PREFIX."language_text 
169                                                 WHERE language_code='".$lang."' 
170                                                 ORDER BY variable, term ASC";
171
172                 return $this->execute($sql);
173         }
174
175         /**
176         * Return all template info of given language
177         * @access  public
178         * @param   lang : language code
179         * @return  table rows
180         * @author  Cindy Qi Li
181         */
182         function getAllTemplateByLang($lang)
183         {
184                 $sql = "SELECT * FROM ".TABLE_PREFIX."language_text 
185                                                 WHERE language_code='".$lang."' 
186                                                 AND variable='_template' 
187                                                 ORDER BY variable ASC";
188
189         return $this->execute($sql);
190         }
191
192         /**
193         * Update text based on given primary key
194         * @access  public
195         * @param   $languageCode : language_text.language_code
196         *          $variable : language_text.variable
197         *          $term : language_text.term
198         *          $text : text to update into language_text.text
199         * @return  true : if successful
200         *          false: if unsuccessful
201         * @author  Cindy Qi Li
202         */
203         function setText($languageCode, $variable, $term, $text)
204         {
205                 global $addslashes;
206                 
207                 $sql = "UPDATE ".TABLE_PREFIX."language_text 
208                            SET text='".$addslashes($text)."',
209                                revised_date = now()
210                          WHERE language_code = '".$_SESSION['lang']."' 
211                            AND variable='".$variable."' 
212                            AND term = '".$term."'";
213
214     return $this->execute($sql);
215   }
216 }
217 ?>