/
Catalog.php
executable file
·129 lines (106 loc) · 4.2 KB
/
Catalog.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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
<?php
/**
* manage Table Catalog
*
* @author Nihki Prihadi <nihki@hukumonline.com>
* @package Kutu
*
*/
class Kutu_Core_Orm_Table_Catalog extends Zend_Db_Table_Abstract
{
protected $_name = 'KutuCatalog';
//protected $_sequence = false;
protected $_rowClass = 'Kutu_Core_Orm_Table_Row_Catalog';
protected $_rowsetClass = 'Kutu_Core_Orm_Table_Rowset_Catalog';
protected $_dependentTables = array('Kutu_Core_Orm_Table_CatalogAttribute','Kutu_Core_Orm_Table_CatalogFolder');
function fetchFromFolder($folderGuid,$start = 0 ,$end = 0)
{
// $db = $this->_db->query
// ("Select KutuCatalog.* From KutuCatalog,KutuCatalogFolder
// where KutuCatalog.guid=KutuCatalogFolder.catalogGuid AND KutuCatalogFolder.folderGuid='$folderGuid' ORDER BY KutuCatalogFolder.catalogGuid DESC LIMIT " . $start . ', '. $end);
$sql = $this->_db->select()
->from(array('KC' => 'KutuCatalog'))
->join(array('KCF' => 'KutuCatalogFolder'),
'KC.guid = KCF.catalogGuid')
->where('KCF.folderGuid=?',"$folderGuid");
$sql = $sql->order('KC.modifiedDate DESC')->limit($end, $start);
// $sql = $sql->__toString();
// print_r($sql);exit();
$db = $this->_db->query($sql);
$dataFetch = $db->fetchAll(Zend_Db::FETCH_ASSOC);
$data = array(
'table' => $this,
'data' => $dataFetch,
'rowClass' => $this->_rowClass,
'stored' => true
);
Zend_Loader::loadClass($this->_rowsetClass);
return new $this->_rowsetClass($data);
}
function implode_with_keys($glue, $array, $valwrap='')
{
if ($array) {
foreach($array AS $key => $value) {
$ret[] = $valwrap.$value.$valwrap;
}
return implode($glue, $ret);
}
}
function countCatalogsInFolder($folderGuid)
{
$db = $this->_db->query
("Select count(*) count From KutuCatalog,KutuCatalogFolder
where KutuCatalog.guid=KutuCatalogFolder.catalogGuid AND KutuCatalogFolder.folderGuid='$folderGuid'");
$dataFetch = $db->fetchAll(Zend_Db::FETCH_ASSOC);
return ($dataFetch[0]['count']);
}
function countCatalogsInFolderAndChildren($folderGuid)
{
$db = $this->_db->query
("Select count(*) count From KutuFolder,KutuCatalogFolder, KutuCatalog
where KutuCatalog.guid=KutuCatalogFolder.catalogGuid AND KutuFolder.guid=KutuCatalogFolder.folderGuid AND KutuFolder.path LIKE '%$folderGuid%'");
$dataFetch = $db->fetchAll(Zend_Db::FETCH_ASSOC);
return ($dataFetch[0]['count']) + $this->countCatalogsInFolder($folderGuid);
}
function getPublishedDate()
{
$sql = $this->_db->select()
->from('KutuCatalog', array('mpublish' => 'max(DATEDIFF( `expiredDate` , `publishedDate` ))'))
->where('profileGuid = ?','kutu_contentjp');
// $sql = $this->_db->select()
// ->from('KutuCatalog')
// ->where('DATEDIFF( `expiredDate` , `publishedDate` ) = ?',
// $this->_db->select()
// ->from('KutuCatalog', 'max(DATEDIFF( `expiredDate` , `publishedDate` ))')
// ->where('profileGuid = ?','kutu_contentjp'))
// ->where('profileGuid = ?','kutu_contentjp')
// ->where('status = ?',1);
$db = $this->_db->query($sql);
$dataFetch = $db->fetchAll(Zend_Db::FETCH_ASSOC);
return ($dataFetch[0]['mpublish']);
}
function fetchNews(array $folderGuid,$limit = 0)
{
$data = $this->implode_with_keys(", ", $folderGuid, "'");
$sql = $this->_db->select()
->from(array('KC' => 'KutuCatalog'))
->join(array('KCF' => 'KutuCatalogFolder'),
'KC.guid = KCF.catalogGuid')
->where("status=?",1)
->where("KCF.folderGuid IN ($data)")
->group("KCF.catalogGuid")
->order('KC.publishedDate DESC')->limit($limit);
// $sql = $sql->__toString();
// print_r($sql);exit();
$db = $this->_db->query($sql);
$dataFetch = $db->fetchAll(Zend_Db::FETCH_ASSOC);
$data = array(
'table' => $this,
'data' => $dataFetch,
'rowClass' => $this->_rowClass,
'stored' => true
);
Zend_Loader::loadClass($this->_rowsetClass);
return new $this->_rowsetClass($data);
}
}