This repository has been archived by the owner on Jun 23, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
/
DownloadTag.php
72 lines (58 loc) · 2.01 KB
/
DownloadTag.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
<?php
/*
* Downloads Plugin for WolfCMS <http://www.wolfcms.org>
* Copyright (C) 2011 Shannon Brooks <http://www.brooksworks.com>
*
* This file is part of Downloads Plugin. Downloads Plugin is licensed under the GNU GPLv3 license.
* Please see license.txt for the full license text.
*/
// Security Measure
if (!defined('IN_CMS')) { exit(); }
// DownloadTag class represents a downloadtag record
class DownloadTag extends Record {
const TABLE_NAME = 'downloadtags';
// search function to perform query
public static function find($args = array()) {
// Collect attributes...
$where = isset($args['where']) ? trim($args['where']) : '1';
$order_by = isset($args['order']) ? trim($args['order']) : 'downloadtags.name ASC';
$offset = isset($args['offset']) ? (int)$args['offset'] : 0;
$limit = isset($args['limit']) ? (int)$args['limit'] : 0;
// Prepare query parts
$order_by_string = empty($order_by) ? '' : "ORDER BY $order_by";
$limit_string = $limit > 0 ? "LIMIT $limit" : '';
$offset_string = $offset > 0 ? "OFFSET $offset" : '';
$tablename = self::tableNameFromClassName('DownloadTag');
// Prepare SQL
$sql = "SELECT * FROM $tablename AS downloadtags WHERE $where $order_by_string $limit_string $offset_string";
$stmt = self::$__CONN__->prepare($sql);
$stmt->execute();
// Run!
if ($limit == 1) {
return $stmt->fetchObject('DownloadTag');
} else {
$objects = array();
while ($object = $stmt->fetchObject('DownloadTag'))
$objects[] = $object;
return $objects;
}
} //*/
// find all records
public static function findAll($args = array()) {
return self::find($args);
} //*/
// find a specific record by it's id
public static function findById($id) {
return self::find(array(
'where' => 'downloadtags.id=' . (int)$id,
'limit' => 1
));
} //*/
// find a specific record by it's name
public static function findByName($name) {
return self::find(array(
'where' => 'downloadtags.name='.Record::escape($name),
'limit' => 1
));
} //*/
} // end Banner class