-
Notifications
You must be signed in to change notification settings - Fork 0
/
album.php
277 lines (251 loc) · 8.81 KB
/
album.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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
<?php
use Pico\Data\Entity\Album;
use Pico\Database\PicoPagable;
use Pico\Database\PicoPage;
use Pico\Database\PicoSortable;
use Pico\Exceptions\NoRecordFoundException;
use Pico\Pagination\PicoPagination;
use Pico\Request\PicoFilterConstant;
use Pico\Request\PicoRequest;
use Pico\Utility\SpecificationUtil;
require_once "inc/auth-with-login-form.php";
require_once "inc/header.php";
$inputGet = new PicoRequest(INPUT_GET);
if($inputGet->equalsAction(PicoRequest::ACTION_DETAIL) && $inputGet->getAlbumId() != null)
{
$album = new Album(null, $database);
try
{
$album->findOneByAlbumId($inputGet->getAlbumId());
?>
<table class="table table-responsive">
<tbody>
<tr>
<td>Album ID</td>
<td><?php echo $album->getAlbumId();?></td>
</tr>
<tr>
<td>Name</td>
<td><?php echo $album->getName();?></td>
</tr>
<tr>
<td>Description</td>
<td><?php echo $album->getDescription();?></td>
</tr>
<tr>
<td>Release Date</td>
<td><?php echo $album->getReleaseDate();?></td>
</tr>
<tr>
<td>Number of Song</td>
<td><?php echo $album->getNumberOfSong();?></td>
</tr>
<tr>
<td>Duration</td>
<td><?php echo $album->getDuration();?></td>
</tr>
<tr>
<td>Active</td>
<td><?php echo $album->booleanToTextByActive('Yes', 'No');?></td>
</tr>
</tbody>
</table>
<?php
}
catch(NoRecordFoundException $e)
{
?>
<div class="alert alert-warning"><?php echo $e->getMessage();?></div>
<?php
}
catch(Exception $e)
{
// do something here
}
}
else
{
?>
<div class="filter-container">
<form action="" method="get">
<div class="filter-group">
<span>Name</span>
<input class="form-control" type="text" name="name" id="name" autocomplete="off" value="<?php echo $inputGet->getName(PicoFilterConstant::FILTER_SANITIZE_SPECIAL_CHARS);?>">
</div>
<input class="btn btn-success" type="submit" value="Show">
<input class="btn btn-primary add-data" type="button" value="Add">
</form>
</div>
<?php
$orderMap = array(
'name'=>'name',
'albumId'=>'albumId',
'album'=>'albumId',
'sortOrder'=>'sortOrder',
'numberOfSong'=>'numberOfSong',
'duration'=>'duration',
'active'=>'active',
'ad_draft'=>'ad_draft'
);
$defaultOrderBy = 'sortOrder';
$defaultOrderType = 'desc';
$pagination = new PicoPagination($cfg->getResultPerPage());
$spesification = SpecificationUtil::createAlbumSpecification($inputGet);
$sortable = new PicoSortable($pagination->getOrderBy($orderMap, $defaultOrderBy), $pagination->getOrderType($defaultOrderType));
$pagable = new PicoPagable(new PicoPage($pagination->getCurrentPage(), $pagination->getPageSize()), $sortable);
$albumEntity = new Album(null, $database);
$rowData = $albumEntity->findAll($spesification, $pagable, $sortable, true);
$result = $rowData->getResult();
?>
<script>
$(document).ready(function(e){
let pg = new Pagination('.pagination', '.page-selector', 'data-page-number', 'page');
pg.init();
$(document).on('change', '.filter-container form select', function(e2){
$(this).closest('form').submit();
});
});
</script>
<?php
if(!empty($result))
{
?>
<div class="pagination">
<div class="pagination-number">
<?php
foreach($rowData->getPagination() as $pg)
{
?><span class="page-selector<?php echo $pg['selected'] ? ' page-selected':'';?>" data-page-number="<?php echo $pg['page'];?>"><a href="#"><?php echo $pg['page'];?></a></span><?php
}
?>
</div>
</div>
<table class="table">
<thead>
<tr>
<th scope="col" width="20"><i class="ti ti-edit"></i></th>
<th scope="col" width="20"><i class="ti ti-trash"></i></th>
<th scope="col" width="20">#</th>
<th scope="col" class="col-sort" data-name="name">Name</th>
<th scope="col" class="col-sort" data-name="duration">Duration</th>
<th scope="col" class="col-sort" data-name="number_of_song">Song</th>
<th scope="col" class="col-sort" data-name="sort_order">Order</th>
<th scope="col" class="col-sort" data-name="active">Active</th>
<th scope="col" class="col-sort" data-name="ad_draft">Draft</th>
</tr>
</thead>
<tbody>
<?php
$no = $pagination->getOffset();
foreach($result as $album)
{
$no++;
$albumId = $album->getAlbumId();
$linkEdit = basename($_SERVER['PHP_SELF'])."?action=edit&album_id=".$albumId;
$linkdDelete = basename($_SERVER['PHP_SELF'])."?action=delete&album_id=".$albumId;
$linkDetail = basename($_SERVER['PHP_SELF'])."?action=detail&album_id=".$albumId;
?>
<tr data-id="<?php echo $albumId;?>">
<th scope="row"><a href="<?php echo $linkEdit;?>" class="edit-data"><i class="ti ti-edit"></i></a></th>
<th scope="row"><a href="<?php echo $linkdDelete;?>" class="delete-data"><i class="ti ti-trash"></i></a></th>
<th scope="row"><?php echo $no;?></th>
<td><a href="<?php echo $linkDetail;?>" class="text-data text-data-name"><?php echo $album->getName();?></a></td>
<td class="text-data text-data-duration"><?php echo sprintf("%.3f", $album->getDuration());?></td>
<td class="text-data text-data-number-of-song"><?php echo $album->getNumberOfSong();?></td>
<td class="text-data text-data-sort-order"><?php echo $album->getSortOrder();?></td>
<td class="text-data text-data-active"><?php echo $album->isActive() ? 'Yes' : 'No';?></td>
<td class="text-data text-data-ad-draft"><?php echo $album->isAsDraft() ? 'Yes' : 'No';?></td>
</tr>
<?php
}
?>
</tbody>
</table>
<div class="pagination">
<div class="pagination-number">
<?php
foreach($rowData->getPagination() as $pg)
{
?><span class="page-selector<?php echo $pg['selected'] ? ' page-selected':'';?>" data-page-number="<?php echo $pg['page'];?>"><a href="#"><?php echo $pg['page'];?></a></span><?php
}
?>
</div>
</div>
<div class="lazy-dom modal-container modal-add-data" data-url="lib.ajax/album-add-dialog.php"></div>
<div class="lazy-dom modal-container modal-update-data" data-url="lib.ajax/album-update-dialog.php"></div>
<script>
let addAlbumModal;
let updateAlbumModal;
$(document).ready(function(e){
$(document).on('click', '.add-data', function(e2){
e2.preventDefault();
e2.stopPropagation();
let dialogSelector = $('.modal-add-data');
dialogSelector.load(dialogSelector.attr('data-url'), function(data){
let addAlbumModalElem = document.querySelector('#addAlbumDialog');
addAlbumModal = new bootstrap.Modal(addAlbumModalElem, {
keyboard: false
});
addAlbumModal.show();
})
});
$(document).on('click', '.edit-data', function(e2){
e2.preventDefault();
e2.stopPropagation();
let albumId = $(this).closest('tr').attr('data-id') || '';
let dialogSelector = $('.modal-update-data');
dialogSelector.load(dialogSelector.attr('data-url')+'?album_id='+albumId, function(data){
let updateAlbumModalElem = document.querySelector('#updateAlbumDialog');
updateAlbumModal = new bootstrap.Modal(updateAlbumModalElem, {
keyboard: false
});
updateAlbumModal.show();
})
});
$(document).on('click', '.save-add-album', function(){
let dataSet = $(this).closest('form').serializeArray();
$.ajax({
type:'POST',
url:'lib.ajax/album-add.php',
data:dataSet,
dataType:'html',
success: function(data)
{
addAlbumModal.hide();
window.location.reload();
}
})
});
$(document).on('click', '.save-edit-album', function(){
let dataSet = $(this).closest('form').serializeArray();
$.ajax({
type:'POST',
url:'lib.ajax/album-update.php',
data:dataSet,
dataType:'json',
success: function(data)
{
updateAlbumModal.hide();
let formData = getFormData(dataSet);
let dataId = data.album_id;
let name = data.name;
let duration = data.duration.toFixed(3);
let numberOfSong = data.number_of_song;
let active = data.active == 1 || data.active == '1';
let draft = data.as_draft == 1 || data.as_draft == '1';
$('[data-id="'+dataId+'"] .text-data.text-data-name').text(name);
$('[data-id="'+dataId+'"] .text-data.text-data-sort-order').text(data.sort_order);
$('[data-id="'+dataId+'"] .text-data.text-data-duration').text(duration);
$('[data-id="'+dataId+'"] .text-data.text-data-number-of-song').text(numberOfSong);
$('[data-id="'+dataId+'"] .text-data.text-data-active').text(active?'Yes':'No');
$('[data-id="'+dataId+'"] .text-data.text-data-as-draft').text(draft?'Yes':'No');
}
})
});
});
</script>
<?php
}
}
require_once "inc/footer.php";
?>