/
Catalog.php
executable file
·95 lines (78 loc) · 3.12 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
<?php
class App_Model_Db_Table_Catalog extends Zend_Db_Table_Abstract
{
protected $_name = 'KutuCatalog';
protected $_rowClass = 'App_Model_Db_Table_Row_Catalog';
protected $_rowsetClass = 'App_Model_Db_Table_Rowset_Catalog';
protected $_dependentTables = array('App_Model_Db_Table_CatalogAttribute','App_Model_Db_Table_CatalogFolder');
protected function _setupDatabaseAdapter()
{
$zl = Zend_Registry::get('Zend_Locale');
if ($zl->getLanguage() == 'id')
$this->_db = Zend_Registry::get('db1');
else
$this->_db = Zend_Registry::get('db3');
parent::_setupDatabaseAdapter();
}
public function convert($entity)
{
return new App_Model_Catalog($entity);
}
public function fetchCatalogInFolder($folderGuid = null, $start = null, $end = null, $order = null, $attr = null)
{
$select = $this->select()->from('KutuCatalog');
if (in_array($folderGuid, ['lt4b11ece54d870','lt4b11e8fde1e42','lt4b11ecf5408d2','lt4b11e8c86c8a4'])) {
$select->where('profileGuid=?', 'klinik');
}
// Approved, Draft, NA, Published
if ($folderGuid !== null & !in_array($folderGuid, ['lt4b11ece54d870','lt4b11e8fde1e42','lt4b11ecf5408d2','lt4b11e8c86c8a4'])) {
$select->join('KutuCatalogFolder','KutuCatalog.guid=KutuCatalogFolder.catalogGuid',array())
->where('KutuCatalogFolder.folderGuid=?',$folderGuid);
}
if ($attr) {
if (isset($attr['status']) && ($attr['status']!== '')) {
$select->where('status = ?', $attr['status']);
}
}
if ($order !== null) {
$select->order('KutuCatalog.'.$order);
}
if ($start !== null || $end !== null) {
$select->limit($end,$start);
}
/*$sql = $select->__toString();
print_r($sql);die;*/
$rs = $select->query()->fetchAll();
return new Pandamp_Model_RecordSet($rs, $this);
}
public function getCountCatalogInFolder($folderGuid=null, $attr = null)
{
$select = $this->select()
->from('KutuCatalog',array('num_files'=>'COUNT(*)'));
if (in_array($folderGuid, ['lt4b11ece54d870','lt4b11e8fde1e42','lt4b11ecf5408d2','lt4b11e8c86c8a4'])) {
$select->where('profileGuid=?', 'klinik');
}
// Approved, Draft, NA, Published
if ($folderGuid !== null & !in_array($folderGuid, ['lt4b11ece54d870','lt4b11e8fde1e42','lt4b11ecf5408d2','lt4b11e8c86c8a4'])) {
$select->join('KutuCatalogFolder','KutuCatalog.guid=KutuCatalogFolder.catalogGuid',array())
->where('KutuCatalogFolder.folderGuid=?',$folderGuid);
}
if ($attr) {
if (isset($attr['status']) && !empty($attr['status'])) {
$select->where('status = ?', $attr['status']);
}
}
$row = $select->query()->fetch();
return ($row) ? $row['num_files'] : 0;
}
public function exportToExcel($folderGuid)
{
$select = $this->select()
->from($this)
->join('KutuCatalogFolder','KutuCatalog.guid=KutuCatalogFolder.catalogGuid',array())
->where('KutuCatalogFolder.folderGuid=?',$folderGuid)
->order('KutuCatalog.publishedDate DESC');
$rows = $this->fetchAll($select);
return $rows;
}
}