Index: trunk/extensions/FreqPatternTagCloud/includes/Search.php |
— | — | @@ -1,71 +1,75 @@ |
2 | 2 | <?php |
3 | | - |
4 | 3 | /** |
5 | | -* Frequent Pattern Tag Cloud Plug-in |
6 | | -* Search checks, whether the attribute is available in the database. |
7 | | -* |
8 | | -* @author Tobias Beck, University of Heidelberg |
9 | | -* @author Andreas Fay, University of Heidelberg |
10 | | -* @version 1.0 |
11 | | -*/ |
12 | | -include_once ("exceptions/InvalidAttributeException.php"); |
| 4 | + * Frequent Pattern Tag Cloud Plug-in |
| 5 | + * Search checks, whether the attribute is available in the database. |
| 6 | + * |
| 7 | + * @author Tobias Beck, University of Heidelberg |
| 8 | + * @author Andreas Fay, University of Heidelberg |
| 9 | + * @version 1.0 |
| 10 | + */ |
| 11 | +include_once( "exceptions/InvalidAttributeException.php" ); |
13 | 12 | |
| 13 | +// @todo FIXME: this is a bit too generic class name... |
14 | 14 | class Search { |
15 | 15 | /** |
16 | 16 | * Attribute name for search |
17 | 17 | * |
18 | | - * @var string |
| 18 | + * @var string |
19 | 19 | */ |
20 | 20 | private $_attribute; |
21 | | - |
| 21 | + |
22 | 22 | /** |
23 | | - * Constructor |
24 | | - * |
25 | | - * @param string $attribute Attribute name for search |
26 | | - * @return |
27 | | - * @throws InvalidAttributeException If attribute is not valid, i.e. present in database |
28 | | - */ |
29 | | - public function __construct($attribute) { |
30 | | - if (!$this->attributeAvailable($attribute)) { |
| 23 | + * Constructor |
| 24 | + * |
| 25 | + * @param $attribute String: attribute name for search |
| 26 | + * @throws InvalidAttributeException If attribute is not valid, i.e. present in database |
| 27 | + */ |
| 28 | + public function __construct( $attribute ) { |
| 29 | + if ( !$this->attributeAvailable( $attribute ) ) { |
31 | 30 | // Check if attribute is available |
32 | | - throw new InvalidAttributeException($attribute); |
| 31 | + throw new InvalidAttributeException( $attribute ); |
33 | 32 | } |
34 | 33 | } |
35 | | - |
| 34 | + |
36 | 35 | /** |
37 | | - * Checks whether attribute is correct, i.e. it exists in database; if yes it fetches the name of the attribute |
| 36 | + * Checks whether attribute is correct, i.e. it exists in database; if yes, |
| 37 | + * it fetches the name of the attribute |
38 | 38 | * |
39 | | - * @param string $attribute Attribute |
40 | | - * @return bool |
| 39 | + * @param $attribute String: attribute |
| 40 | + * @return bool |
41 | 41 | */ |
42 | | - private function attributeAvailable($attribute) { |
| 42 | + private function attributeAvailable( $attribute ) { |
43 | 43 | // Category |
44 | | - if (wfMsg("fptc-categoryname") == $attribute) { |
| 44 | + if ( wfMsg( 'fptc-categoryname' ) == $attribute ) { |
45 | 45 | return true; |
46 | 46 | } |
47 | | - |
48 | | - $dbr = & wfGetDB(DB_SLAVE); |
49 | | - |
50 | | - $res = $dbr->query("SELECT smw_title |
51 | | - FROM " . $dbr->tableName("smw_ids") . " |
52 | | - WHERE smw_namespace = 102 |
53 | | - AND LENGTH(smw_iw) = 0 |
54 | | - AND smw_title = '" . mysql_real_escape_string($attribute) . "'"); |
55 | | - |
56 | | - if ($res->numRows() == 0) { |
| 47 | + |
| 48 | + $dbr = wfGetDB( DB_SLAVE ); |
| 49 | + |
| 50 | + $res = $dbr->select( |
| 51 | + 'smw_ids', |
| 52 | + 'smw_title', |
| 53 | + array( |
| 54 | + 'smw_namespace' => 102, |
| 55 | + 'LENGTH(smw_iw) = 0', |
| 56 | + 'smw_title' => $attribute |
| 57 | + ), |
| 58 | + __METHOD__ |
| 59 | + ); |
| 60 | + |
| 61 | + if ( $res->numRows() == 0 ) { |
57 | 62 | // Attribute not found |
58 | 63 | return false; |
59 | 64 | } |
60 | | - |
| 65 | + |
61 | 66 | $row = $res->fetchRow(); |
62 | | - |
| 67 | + |
63 | 68 | // Assign name |
64 | 69 | $this->_attribute = $row[0]; |
65 | | - |
66 | | - $res->free(); |
| 70 | + |
67 | 71 | return true; |
68 | 72 | } |
69 | | - |
| 73 | + |
70 | 74 | /** |
71 | 75 | * Gets the available Attribute |
72 | 76 | * |