-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDAO.php
93 lines (80 loc) · 3.4 KB
/
DAO.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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
<?php
class DAO
{
protected $conn;
function DAO($serverName, $uid, $pwd, $db)
{
$connectionInfo = array(
'UID' => $uid,
'PWD' => $pwd,
'Database' => $db);
/* Connect using SQL Server Authentication. */
$this->conn = sqlsrv_connect($serverName, $connectionInfo);
if ($this->conn === false) {
echo "Unable to connect.</br>";
die(print_r(sqlsrv_errors(), true));
}
}
function query($sql)
{
$stmt = sqlsrv_query($this->conn, $sql);
if ($stmt === false) {
echo "Error in executing query.</br>";
die(print_r(sqlsrv_errors(), true));
}
$result = array();
/* Retrieve and display the results of the query. */
while ($row = sqlsrv_fetch_array($stmt)) {
$result[] = $row;
}
sqlsrv_free_stmt($stmt);
return $result;
}
function getTopLevelCollections()
{
return $this->query("select * from wm_collection where company_id = " . JHU_COMPANY_ID .
" and parent_collection_id is null and export_date is null and is_active = 1 and is_public = 1");
}
function getChildCollections($collection)
{
return $this->query("select * from wm_collection where company_id = " . JHU_COMPANY_ID .
" and parent_collection_id = {$collection['COLLECTION_ID']} and export_date is null");
}
function getFilesForCollection($collection) {
return $this->query("select f.file_id as FILE_ID, f.file_path as FILE_PATH, f.name as NAME, convert(varchar,convert(date, catalog_date)) as CATALOG_DATE, ac.path as CATEGORY_PATH, f.notes as NOTES " .
"from wm_collection_to_asset wca " .
"join asset a on wca.asset_id = a.asset_id " .
"join wm_file f on a.current_file_id = f.file_id " .
"join asset_category ac on a.asset_category_id = ac.asset_category_id " .
"where wca.collection_id = " . $collection['COLLECTION_ID'] .
" and a.export_date is null");
}
function getUser($id) {
return $this->query("select * from wm_user where wmuser_id = $id");
}
function getMetadataForFile($file) {
$rawrows = $this->query("select mdl.name as name, md.string_object as value, " .
"mdl.data_type as type from wm_meta_data md " .
"join wm_meta_data_label mdl on md.meta_data_label_id = mdl.meta_data_label_id " .
"where md.object_id = {$file['FILE_ID']} and md.class_name = 'WMAssetMetaData'");
$result = array();
foreach ($rawrows as $item) {
if ($item['value']) {
$item['type'] = ($item['type'] == 3) ? 'date' : 'string';
$result[] = $item;
}
}
// add additional items:
if ($file['NOTES']) {
$result[] = array('name' => 'Notes', 'value' => $file['NOTES'], 'type' => 'string');
}
$result[] = array('name' => 'Date', 'value' => $file['CATALOG_DATE'], 'type' => 'date');
return $result;
}
function updateAssetExportDate($file) {
$this->query("update asset set export_date = CURRENT_TIMESTAMP where current_file_id = {$file['FILE_ID']}");
}
function updateCollectionExportDate($collection) {
$this->query("update wm_collection set export_date = CURRENT_TIMESTAMP where collection_id = {$collection['COLLECTION_ID']}");
}
}