Index: trunk/extensions/CentralNotice/CentralNotice.db.php |
— | — | @@ -32,33 +32,33 @@ |
33 | 33 | $encTimestamp = $dbr->addQuotes( $dbr->timestamp( $date ) ); |
34 | 34 | } |
35 | 35 | |
36 | | - $tables[] = "cn_notices"; |
| 36 | + $tables = array( 'cn_notices' ); |
37 | 37 | if ( $language ) { |
38 | | - $tables[] = "cn_notice_languages"; |
| 38 | + $tables[] = 'cn_notice_languages'; |
39 | 39 | } |
40 | 40 | |
| 41 | + $conds = array( |
| 42 | + 'not_project' => array( '', $project ), |
| 43 | + 'not_geo' => 0, |
| 44 | + "not_start <= $encTimestamp", |
| 45 | + "not_end >= $encTimestamp", |
| 46 | + ); |
41 | 47 | // Use whatever conditional arguments got passed in |
42 | 48 | if ( $language ) { |
43 | | - $conds[] = "nl_notice_id = cn_notices.not_id"; |
44 | | - $conds[] = "nl_language =" . $dbr->addQuotes( $language ); |
| 49 | + $conds[] = 'nl_notice_id = cn_notices.not_id'; |
| 50 | + $conds['nl_language'] = $language; |
45 | 51 | } |
46 | 52 | if ( $enabled ) { |
47 | | - $conds[] = "not_enabled = 1"; |
| 53 | + $conds['not_enabled'] = 1; |
48 | 54 | } |
49 | 55 | if ( $preferred ) { |
50 | | - $conds[] = "not_preferred = 1"; |
| 56 | + $conds['not_preferred'] = 1; |
51 | 57 | } |
52 | | - $conds[] = "not_project IN ( '', " . $dbr->addQuotes( $project ) . " )"; |
53 | | - $conds[] = "not_geo = 0"; |
54 | | - $conds[] = "not_start <= " . $encTimestamp; |
55 | | - $conds[] = "not_end >= " . $encTimestamp; |
56 | 58 | |
57 | 59 | // Pull db data |
58 | 60 | $res = $dbr->select( |
59 | 61 | $tables, |
60 | | - array( |
61 | | - 'not_id' |
62 | | - ), |
| 62 | + 'not_id', |
63 | 63 | $conds, |
64 | 64 | __METHOD__ |
65 | 65 | ); |
— | — | @@ -70,39 +70,35 @@ |
71 | 71 | |
72 | 72 | // If a location is passed, also pull geotargeted campaigns that match the location |
73 | 73 | if ( $location ) { |
74 | | - $tables = array(); |
75 | | - $tables[] = "cn_notices"; |
76 | | - $tables[] = "cn_notice_countries"; |
| 74 | + $tables = array( 'cn_notices', 'cn_notice_countries' ); |
77 | 75 | if ( $language ) { |
78 | | - $tables[] = "cn_notice_languages"; |
| 76 | + $tables[] = 'cn_notice_languages'; |
79 | 77 | } |
80 | 78 | |
81 | 79 | // Use whatever conditional arguments got passed in |
82 | | - $conds = array(); |
| 80 | + $conds = array( |
| 81 | + 'not_project' => array( '', $project ), |
| 82 | + 'not_geo' => 1, |
| 83 | + 'nc_notice_id = cn_notices.not_id', |
| 84 | + 'nc_country' => $location, |
| 85 | + "not_start <= $encTimestamp", |
| 86 | + "not_end >= $encTimestamp", |
| 87 | + ); |
83 | 88 | if ( $language ) { |
84 | 89 | $conds[] = "nl_notice_id = cn_notices.not_id"; |
85 | | - $conds[] = "nl_language =" . $dbr->addQuotes( $language ); |
| 90 | + $conds['nl_language'] = $language; |
86 | 91 | } |
87 | 92 | |
88 | 93 | if ( $enabled ) { |
89 | | - $conds[] = "not_enabled = 1"; |
| 94 | + $conds['not_enabled'] = 1; |
90 | 95 | } |
91 | 96 | if ( $preferred ) { |
92 | | - $conds[] = "not_preferred = 1"; |
93 | | - } |
94 | | - $conds[] = "not_project IN ( '', " . $dbr->addQuotes($project ) . " )"; |
95 | | - $conds[] = "not_geo = 1"; |
96 | | - $conds[] = "nc_notice_id = cn_notices.not_id"; |
97 | | - $conds[] = "nc_country =" . $dbr->addQuotes( $location ); |
98 | | - $conds[] = "not_start <= " . $encTimestamp; |
99 | | - $conds[] = "not_end >= " . $encTimestamp; |
100 | | - |
| 97 | + $conds['not_preferred'] = 1; |
| 98 | + } |
101 | 99 | // Pull db data |
102 | 100 | $res = $dbr->select( |
103 | 101 | $tables, |
104 | | - array( |
105 | | - 'not_id' |
106 | | - ), |
| 102 | + 'not_id' |
107 | 103 | $conds, |
108 | 104 | __METHOD__ |
109 | 105 | ); |
— | — | @@ -151,12 +147,12 @@ |
152 | 148 | } |
153 | 149 | $templates = array(); |
154 | 150 | foreach ( $res as $row ) { |
155 | | - $template = array(); |
156 | | - $template['name'] = $row->tmp_name; |
157 | | - $template['weight'] = intval( $row->total_weight ); |
158 | | - $template['display_anon'] = intval( $row->tmp_display_anon ); |
159 | | - $template['display_account'] = intval( $row->tmp_display_account ); |
160 | | - $templates[] = $template; |
| 151 | + $templates[] = array( |
| 152 | + 'name' => $row->tmp_name, |
| 153 | + 'weight' => intval( $row->total_weight ), |
| 154 | + 'display_anon' => intval( $row->tmp_display_anon ), |
| 155 | + 'display_account' => intval( $row->tmp_display_account ), |
| 156 | + ); |
161 | 157 | } |
162 | 158 | return $templates; |
163 | 159 | } |
— | — | @@ -166,7 +162,7 @@ |
167 | 163 | * (This should probably be moved to a core database table at some point.) |
168 | 164 | */ |
169 | 165 | static function getCountriesList() { |
170 | | - $countries = array( |
| 166 | + return array( |
171 | 167 | 'AF'=>'Afghanistan', |
172 | 168 | 'AL'=>'Albania', |
173 | 169 | 'DZ'=>'Algeria', |
— | — | @@ -408,6 +404,5 @@ |
409 | 405 | 'ZM'=>'Zambia', |
410 | 406 | 'ZW'=>'Zimbabwe' |
411 | 407 | ); |
412 | | - return $countries; |
413 | 408 | } |
414 | 409 | } |