-
Notifications
You must be signed in to change notification settings - Fork 0
/
audiotrack.php
executable file
·1069 lines (894 loc) · 28.9 KB
/
audiotrack.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
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<?php
/**
* @package Joomla 1.6.x
* @copyright Copyright (C) 2005 - 2010 Open Source Matters. All rights reserved.
* @license GNU/GPL, see LICENSE.php
* Joomla! is free software. This version may have been modified pursuant to the
* GNU General Public License, and as distributed it includes or is derivative
* of works licensed under the GNU General Public License or other free or open
* source software licenses. See COPYRIGHT.php for copyright notices and
* details.
*
* @PlayJoom Component
* @copyright Copyright (C) 2010 by www.teglo.info
* @license http://www.gnu.org/copyleft/gpl.html GNU/GPL
* @date $Date$
* @revision $Revision$
* @author $Author$
* @headurl $HeadURL$
*/
// No direct access to this file
defined('_JEXEC') or die('Restricted access');
// import Joomla modelform library
jimport('joomla.application.component.modeladmin');
/**
* PlayJoom Model
*/
class PlayJoomModelAudioTrack extends JModelAdmin {
/**
* Method to perform batch operations on a track.
*
* @param array $commands An array of commands to perform.
* @param array $pks An array of item ids.
* @param array $contexts An array of item contexts.
*
* @return boolean Returns true on success, false on failure.
*
* @since 0.9.5xx
*/
public function batch($commands, $pks, $contexts) {
// Sanitize user ids.
$pks = array_unique($pks);
JArrayHelper::toInteger($pks);
// Remove any values of zero.
if (array_search(0, $pks, true)) {
unset($pks[array_search(0, $pks, true)]);
}
if (empty($pks)) {
$this->setError(JText::_('JGLOBAL_NO_ITEM_SELECTED'));
return false;
}
$done = false;
if (strlen($commands['user_id']) > 0) {
if (!$this->batchUser($commands['user_id'], $pks, $contexts)) {
return false;
}
$done = true;
}
if (strlen($commands['category_id']) > 0) {
if (!$this->batchGenre($commands['category_id'], $pks, $contexts)) {
return false;
}
$done = true;
}
if (strlen($commands['trackfilter_id']) > 0) {
if (!$this->batchTrackfilter($commands['trackfilter_id'], $pks, $contexts)) {
return false;
}
$done = true;
}
if (strlen($commands['assetgroup_id']) > 0) {
if (!$this->batchAccesslevel($commands['assetgroup_id'], $pks, $contexts)) {
return false;
}
$done = true;
}
if (strlen($commands['artist']) > 0) {
if (!$this->batchArtist($commands['artist'], $pks, $contexts)) {
return false;
}
$done = true;
}
if (strlen($commands['album']) > 0) {
if (!$this->batchAlbum($commands['album'], $pks, $contexts)) {
return false;
}
$done = true;
}
if (strlen($commands['year']) > 0) {
if (!$this->batchYear($commands['year'], $pks, $contexts)) {
return false;
}
$done = true;
}
if (strlen($commands['tag']) > 0) {
if (!$this->batchTag($commands['tag'], $pks, $contexts)) {
return false;
}
$done = true;
}
//TODO Batch function for Tags
/*
if (strlen($commands['id3tags']) == 1) {
if (!$this->batchID3Tags($commands['id3tags'], $pks, $contexts)) {
return false;
}
$done = true;
}
*/
if (!$done) {
$this->setError(JText::_('JLIB_APPLICATION_ERROR_INSUFFICIENT_BATCH_INFORMATION'));
return false;
}
// Clear the cache
$this->cleanCache();
return true;
}
/**
* Batch to change the year of a track which was released.
*
* @param integer $value The new value matching a User ID.
* @param array $pks An array of row IDs.
* @param array $contexts An array of item contexts.
*
* @return boolean True if successful, false otherwise and internal error is set.
*
* @since 0.9.5xx
*/
protected function batchYear($value, $pks, $contexts)
{
// Set the variables
$user = JFactory::getUser();
$canDo = PlayJoomHelper::getActions();
$userId = $user->get('id');
$table = $this->getTable();
// Get UTC datetime for now.
$dNow = new JDate;
$DateTime = clone $dNow;
foreach ($pks as $pk) {
if ($canDo->get('core.edit')
|| JAccess::check($user->get('id'), 'core.admin') == 1) {
$table->reset();
$table->load($pk);
$table->year = $value;
$table->mod_datetime = $DateTime->format('Y-m-d H:i:s');
$table->mod_by = $userId;
if (!$table->store()) {
$this->setError($table->getError());
return false;
}
}
else {
$this->setError(JText::_('JLIB_APPLICATION_ERROR_BATCH_CANNOT_EDIT'));
return false;
}
}
// Clean the cache
$this->cleanCache();
return true;
}
/**
* Batch to change an name of the album of a track.
*
* @param integer $value The new value matching a User ID.
* @param array $pks An array of row IDs.
* @param array $contexts An array of item contexts.
*
* @return boolean True if successful, false otherwise and internal error is set.
*
* @since 0.9.5xx
*/
protected function batchAlbum($value, $pks, $contexts)
{
// Set the variables
$user = JFactory::getUser();
$canDo = PlayJoomHelper::getActions();
$userId = $user->get('id');
$table = $this->getTable();
// Get UTC datetime for now.
$dNow = new JDate;
$DateTime = clone $dNow;
foreach ($pks as $pk) {
if ($canDo->get('core.edit')
|| JAccess::check($user->get('id'), 'core.admin') == 1) {
$table->reset();
$table->load($pk);
$table->album = $value;
$table->mod_datetime = $DateTime->format('Y-m-d H:i:s');
$table->mod_by = $userId;
if (!$table->store()) {
$this->setError($table->getError());
return false;
}
}
else {
$this->setError(JText::_('JLIB_APPLICATION_ERROR_BATCH_CANNOT_EDIT'));
return false;
}
}
// Clean the cache
$this->cleanCache();
return true;
}
/**
* Batch to change an name of the artist of a track.
*
* @param integer $value The new value matching a User ID.
* @param array $pks An array of row IDs.
* @param array $contexts An array of item contexts.
*
* @return boolean True if successful, false otherwise and internal error is set.
*
* @since 0.9.5xx
*/
protected function batchArtist($value, $pks, $contexts)
{
// Set the variables
$user = JFactory::getUser();
$canDo = PlayJoomHelper::getActions();
$userId = $user->get('id');
$table = $this->getTable();
$datetime = JFactory::getDate('now', null);
foreach ($pks as $pk) {
if ($canDo->get('core.edit')
|| JAccess::check($user->get('id'), 'core.admin') == 1) {
$table->reset();
$table->load($pk);
$table->artist = $value;
$table->mod_datetime = $datetime;
$table->mod_by = $userId;
if (!$table->store()) {
$this->setError($table->getError());
return false;
}
}
else {
$this->setError(JText::_('JLIB_APPLICATION_ERROR_BATCH_CANNOT_EDIT'));
return false;
}
}
// Clean the cache
$this->cleanCache();
return true;
}
/**
* Batch to change an owner of a track.
*
* @param integer $value The new value matching a User ID.
* @param array $pks An array of row IDs.
* @param array $contexts An array of item contexts.
*
* @return boolean True if successful, false otherwise and internal error is set.
*
* @since 0.9.5xx
*/
protected function batchUser($value, $pks, $contexts)
{
// Set the variables
$user = JFactory::getUser();
$canDo = PlayJoomHelper::getActions();
$userId = $user->get('id');
$table = $this->getTable();
// Get UTC datetime for now.
$dNow = new JDate;
$DateTime = clone $dNow;
foreach ($pks as $pk) {
if ($canDo->get('core.edit')
|| JAccess::check($user->get('id'), 'core.admin') == 1) {
$table->reset();
$table->load($pk);
$table->add_by = (int) $value;
$table->mod_datetime = $DateTime->format('Y-m-d H:i:s');
$table->mod_by = $userId;
if (!$table->store()) {
$this->setError($table->getError());
return false;
}
}
else {
$this->setError(JText::_('JLIB_APPLICATION_ERROR_BATCH_CANNOT_EDIT'));
return false;
}
}
// Clean the cache
$this->cleanCache();
return true;
}
/**
* Batch to write ID3Tags into audio file.
*
* @param integer $value The new value matching a User ID.
* @param array $pks An array of row IDs.
* @param array $contexts An array of item contexts.
*
* @return boolean True if successful, false otherwise and internal error is set.
*
* @since 0.9.5xx
*/
protected function batchID3Tags($value, $pks, $contexts) {
foreach ($pks as $pk) {
if ($canDo->get('core.edit')
|| JAccess::check($user->get('id'), 'core.admin') == 1) {
}
else {
$this->setError(JText::_('JLIB_APPLICATION_ERROR_BATCH_CANNOT_EDIT'));
return false;
}
}
// Clean the cache
$this->cleanCache();
return true;
}
/**
* Batch to change the access level of a track.
*
* @param integer $value The new value matching a User ID.
* @param array $pks An array of row IDs.
* @param array $contexts An array of item contexts.
*
* @return boolean True if successful, false otherwise and internal error is set.
*
* @since 0.9.5xx
*/
protected function batchAccesslevel($value, $pks, $contexts)
{
// Set the variables
$user = JFactory::getUser();
$canDo = PlayJoomHelper::getActions();
$userId = $user->get('id');
$table = $this->getTable();
$datetime = JFactory::getDate('now', null);
foreach ($pks as $pk) {
if ($canDo->get('core.edit')
|| JAccess::check($user->get('id'), 'core.admin') == 1) {
$table->reset();
$table->load($pk);
$table->access = (int) $value;
$table->mod_datetime = $datetime;
$table->mod_by = $userId;
if (!$table->store()) {
$this->setError($table->getError());
return false;
}
}
else
{
$this->setError(JText::_('JLIB_APPLICATION_ERROR_BATCH_CANNOT_EDIT'));
return false;
}
}
// Clean the cache
$this->cleanCache();
return true;
}
/**
* Batch to change the genre of a track.
*
* @param integer $value The new value matching a User ID.
* @param array $pks An array of row IDs.
* @param array $contexts An array of item contexts.
*
* @return boolean True if successful, false otherwise and internal error is set.
*
* @since 0.9.5xx
*/
protected function batchGenre($value, $pks, $contexts) {
// Set the variables
$user = JFactory::getUser();
$canDo = PlayJoomHelper::getActions();
$userId = $user->get('id');
$table = $this->getTable();
$datetime = JFactory::getDate('now', null);
foreach ($pks as $pk) {
if ($canDo->get('core.edit')
|| JAccess::check($user->get('id'), 'core.admin') == 1) {
$table->reset();
$table->load($pk);
$table->catid = (int) $value;
$table->mod_datetime = $datetime;
$table->mod_by = $userId;
if (!$table->store()) {
$this->setError($table->getError());
return false;
}
}
else
{
$this->setError(JText::_('JLIB_APPLICATION_ERROR_BATCH_CANNOT_EDIT'));
return false;
}
}
// Clean the cache
$this->cleanCache();
return true;
}
/**
* Batch to change the filter of a track.
*
* @param integer $value The new value matching a User ID.
* @param array $pks An array of row IDs.
* @param array $contexts An array of item contexts.
*
* @return boolean True if successful, false otherwise and internal error is set.
*
* @since 0.9.5xx
*/
protected function batchTrackfilter($value, $pks, $contexts) {
// Set the variables
$user = JFactory::getUser();
$canDo = PlayJoomHelper::getActions();
$userId = $user->get('id');
$table = $this->getTable();
$datetime = JFactory::getDate('now', null);
foreach ($pks as $pk) {
if ($canDo->get('core.edit')
|| JAccess::check($user->get('id'), 'core.admin') == 1) {
$table->reset();
$table->load($pk);
$table->trackfilterid = (int) $value;
$table->mod_datetime = $datetime;
$table->mod_by = $userId;
if (!$table->store()) {
$this->setError($table->getError());
return false;
}
}
else
{
$this->setError(JText::_('JLIB_APPLICATION_ERROR_BATCH_CANNOT_EDIT'));
return false;
}
}
// Clean the cache
$this->cleanCache();
return true;
}
/**
* Batch to change the tags of a track.
*
* @param integer $value The new value matching a User ID.
* @param array $pks An array of row IDs.
* @param array $contexts An array of item contexts.
*
* @return boolean True if successful, false otherwise and internal error is set.
*
* @since 0.9.5xx
*/
protected function batchTag($value, $pks, $contexts) {
// Set the variables
$user = JFactory::getUser();
$table = $this->getTable();
$dispatcher = JEventDispatcher::getInstance();
$dispatcher->trigger('onEventLogging', array(array('method' => __METHOD__.":".__LINE__, 'message' => 'Vaule content:.'.print_r($contexts, true), 'priority' => JLog::INFO, 'section' => 'admin')));
foreach ($pks as $pk)
{
if ($user->authorise('core.edit', $contexts[$pk]))
{
$table->reset();
$table->load($pk);
$tags = array($value);
//$dispatcher->trigger('onEventLogging', array(array('method' => __METHOD__.":".__LINE__, 'message' => 'Vaule content:.'.print_r($table, true), 'priority' => JLog::INFO, 'section' => 'admin')));
/**
* @var JTableObserverTags $tagsObserver
*/
$tagsObserver = $table->getObserverOfClass('JTableObserverTags');
$result = $tagsObserver->setNewTags($tags, false);
if (!$result)
{
$this->setError($table->getError());
return false;
}
//self::setPublishStateForTags($table);
//self::setTagTrackTitle($tags);
//self::setTagCoreParams($tags);
}
else
{
$this->setError(JText::_('JLIB_APPLICATION_ERROR_BATCH_CANNOT_EDIT'));
return false;
}
}
// Clean the cache
$this->cleanCache();
return true;
}
/**
* Method override to check if you can edit an existing record.
*
* @param array $data An array of input data.
* @param string $key The name of the key for the primary key.
*
* @return boolean
* @since 1.6
*/
protected function allowEdit($data = array(), $key = 'id') {
// Check specific edit permission then general edit permission.
return JFactory::getUser()->authorise('core.edit', 'com_playjoom.audiotrack.'.((int) isset($data[$key]) ? $data[$key] : 0)) or parent::allowEdit($data, $key);
}
protected function canDelete($data = array(), $key = 'id') {
$user = JFactory::getUser();
return $user->authorise('core.delete', 'com_playjoom.audiotrack.'.(int) $data->id);
}
/**
* Returns a reference to the a Table object, always creating it.
*
* @param type The table type to instantiate
* @param string A prefix for the table class name. Optional.
* @param array Configuration array for model. Optional.
* @return JTable A database object
* @since 1.6
*/
public function getTable($type = 'AudioTrack', $prefix = 'PlayJoomTable', $config = array()) {
return JTable::getInstance($type, $prefix, $config);
}
/**
* Method to get a single record.
*
* @param integer The id of the primary key.
*
* @return mixed Object on success, false on failure.
*/
public function getItem($pk = null) {
if ($item = parent::getItem($pk)) {
if (!empty($item->id)) {
$item->tags = new JHelperTags;
$item->tags->getTagIds($item->id, 'com_playjoom.audiotrack');
}
}
return $item;
}
/**
* Method to store a row
*
* @param boolean $updateNulls True to update fields even if they are null.
*/
public function store($updateNulls = false) {
$this->tagsHelper->preStoreProcess($this);
$result = parent::store($updateNulls);
return $result && $this->tagsHelper->postStoreProcess($this);
}
/**
* Method to save the form data.
*
* @param array $data The form data.
*
* @return boolean True on success.
*
* @since 1.6
*/
public function save($data) {
if (parent::save($data)) {
$table = $this->getTable();
if ((!empty($data['tags']) && $data['tags'][0] != '')) {
$table->newTags = $data['tags'];
self::setPublishStateForTags($data);
self::setTagTrackTitle($data);
self::setTagCoreParams($data);
}
$asset = JTable::getInstance('Asset');
$asset->title = 'tee';
self::writeID3Tags($data);
return true;
}
return false;
}
/**
* Method for to write ID3Tags into file
*
* @param array $data ID3 tag items
* @param string Kind of text encoding, for example UTF-8
* @return boolean
*/
public function writeID3Tags($data, $TextEncoding = 'UTF-8') {
$dispatcher = JDispatcher::getInstance();
require_once(JPATH_COMPONENT_ADMINISTRATOR.DIRECTORY_SEPARATOR.'helpers'.DIRECTORY_SEPARATOR.'id3'.DIRECTORY_SEPARATOR.'getid3.php');
require_once(JPATH_COMPONENT_ADMINISTRATOR.DIRECTORY_SEPARATOR.'helpers'.DIRECTORY_SEPARATOR.'id3'.DIRECTORY_SEPARATOR.'write.php');
// Initialize getID3 engine
$getID3 = new getID3;
$getID3->setOption(array('encoding'=>$TextEncoding));
$tagwriter = new getid3_writetags;
$tagwriter->tagformats = array('id3v2.3');
// Set various options
$tagwriter->overwrite_tags = true;
$tagwriter->tag_encoding = $TextEncoding;
$tagwriter->remove_other_tags = true;
$dispatcher->trigger('onEventLogging', array(array('method' => __METHOD__.":".__LINE__, 'message' => 'Writing tags for: '.$data['pathatlocal'].'/'.$data['file'], 'priority' => JLog::INFO, 'section' => 'admin')));
// Data for ID3 Tag
$tagwriter->filename = $data['pathatlocal'].'/'.$data['file'];
// Get name for Genre ID
if ($data['catid']) {
$genre_name = self::getGenrename($data['catid'])->title;
} else {
$genre_name = null;
}
$dispatcher->trigger('onEventLogging', array(array('method' => __METHOD__.":".__LINE__, 'message' => 'Name for Genre id: '.$data['catid'].' is '.$genre_name, 'priority' => JLog::INFO, 'section' => 'admin')));
// Create data array for ID3 tag
$TagData = array(
'title' => array($data['title']),
'artist' => array($data['artist']),
'album' => array($data['album']),
'year' => array($data['year']),
'genre' => array($genre_name),
'comment' => array('Edited by PlayJoom streaming server'),
'track' => array($data['tracknumber'])
);
$tagwriter->tag_data = $TagData;
// write ID3 tag
if ($tagwriter->WriteTags()) {
$dispatcher->trigger('onEventLogging', array(array('method' => __METHOD__.":".__LINE__, 'message' => 'Writting of ID3 Tag successfully.', 'priority' => JLog::INFO, 'section' => 'admin')));
if (!empty($tagwriter->warnings)) {
$dispatcher->trigger('onEventLogging', array(array('method' => __METHOD__.":".__LINE__, 'message' => 'Attention! '.implode('<br>', $tagwriter->warnings), 'priority' => JLog::WARNING, 'section' => 'admin')));
return false;
}
} else {
$dispatcher->trigger('onEventLogging', array(array('method' => __METHOD__.":".__LINE__, 'message' => 'Failed to write tags! '.implode('<br>', $tagwriter->errors), 'priority' => JLog::WARNING, 'section' => 'admin')));
return true;
}
}
/**
* Method to get the name of a category id
*
* @param int $cat_id ID of category
*
* @return object
*/
public function getGenrename($cat_id) {
// Create a new query object.
$db = $this->getDbo();
$query = $db->getQuery(true);
// Construct the query
$query->select('c.id, c.title');
$query->from('#__categories AS c');
$query->where('c.id = '.$cat_id);
// Setup the query
$db->setQuery($query->__toString());
// Return the result
return $db->loadObject();
}
/**
* Method for to set title extendend title value
*
*
*/
public function setTagTrackTitle($data) {
$dispatcher = JEventDispatcher::getInstance();
$dispatcher->trigger('onEventLogging', array(array('method' => __METHOD__.":".__LINE__, 'message' => 'Get ucm_content column for track IDs: '.$data[id], 'priority' => JLog::INFO, 'section' => 'admin')));
$db = JFactory::getDbo();
$query = $db->getQuery(true)
->select($db->quoteName('core_content_id'))
->from($db->quoteName('#__ucm_content'))
->where($db->quoteName('core_type_alias') . ' = ' . $db->quote('com_playjoom.audiotrack'))
->where($db->quoteName('core_content_item_id') . ' IN (' . $data[id] .')');
$db->setQuery($query);
$ccIds = $db->loadColumn();
self::change($ccIds, $data);
return true;
}
/**
* Method for to set the core params values
*
*
*/
public function setTagCoreParams($data) {
$dispatcher = JEventDispatcher::getInstance();
$dispatcher->trigger('onEventLogging', array(array('method' => __METHOD__.":".__LINE__, 'message' => 'Get ucm_content column for track IDs: '.$data[id], 'priority' => JLog::INFO, 'section' => 'admin')));
$db = JFactory::getDbo();
$query = $db->getQuery(true)
->select($db->quoteName('core_content_id'))
->from($db->quoteName('#__ucm_content'))
->where($db->quoteName('core_type_alias') . ' = ' . $db->quote('com_playjoom.audiotrack'))
->where($db->quoteName('core_content_item_id') . ' IN (' . $data[id] .')');
$db->setQuery($query);
$ccIds = $db->loadColumn();
self::changeParams($ccIds, $data);
return true;
}
/**
* Method to update the title and alias items for a row or list of rows in the database table.
*
* @param mixed $pks An optional array of primary key values to update. If not set the instance property value is used.
* @param integer $state The publishing state. eg. [0 = unpublished, 1 = published]
*
* @return boolean True on success.
*
*/
public function change($pks = null, $data) {
$dispatcher = JEventDispatcher::getInstance();
JArrayHelper::toInteger($pks);
// If there are no primary keys set check to see if the instance key is set.
if (empty($pks)) {
if ($this->$k) {
$pks = array($this->$k);
} else {
// Nothing to change, return false.
$this->setError(JText::_('JLIB_DATABASE_ERROR_NO_ROWS_SELECTED'));
return false;
}
}
$pksImploded = implode(',', $pks);
// Get the JDatabaseQuery object
$query = $this->_db->getQuery(true);
// Update the title and alias items for rows with the given primary keys.
$query->update($this->_db->quoteName('#__ucm_content'))
->set($this->_db->quoteName('core_title') . ' = \'' . $data['artist'].' - '.$data['title'].' ('.$data['album'].')\'')
->set($this->_db->quoteName('core_alias') . ' = \'' . JApplication::stringURLSafe($data['artist']).'-'.JApplication::stringURLSafe($data['title']).'-'.JApplication::stringURLSafe($data['album']).'\'')
->where($this->_db->quoteName('core_content_id') . ' = ' . $pksImploded );
$this->_db->setQuery($query);
try {
$this->_db->execute();
} catch (RuntimeException $e) {
$this->setError($e->getMessage());
$dispatcher->trigger('onEventLogging', array(array('method' => __METHOD__.":".__LINE__, 'message' => $e->getMessage(), 'priority' => JLog::ERROR, 'section' => 'admin')));
return false;
}
$this->setError('');
return true;
}
/**
* Method to update the title and alias items for a row or list of rows in the database table.
*
* @param mixed $pks An optional array of primary key values to update. If not set the instance property value is used.
* @param integer $state The publishing state. eg. [0 = unpublished, 1 = published]
*
* @return boolean True on success.
*
*/
public function changeParams($pks = null, $data) {
$dispatcher = JEventDispatcher::getInstance();
JArrayHelper::toInteger($pks);
// If there are no primary keys set check to see if the instance key is set.
if (empty($pks)) {
if ($this->$k) {
$pks = array($this->$k);
} else {
// Nothing to change, return false.
$this->setError(JText::_('JLIB_DATABASE_ERROR_NO_ROWS_SELECTED'));
return false;
}
}
$pksImploded = implode(',', $pks);
//Create params array
$CoreParams = array(
'artist' => $data['artist'],
'title' => $data['title'],
'album' => $data['album'],
'length' => $data['length'],
'pathatlocal' => $data['pathatlocal'],
'file' => $data['file'],
'year' => $data['year'],
'mediatype' => $data['mediatype'],
'catid' => $data['catid']
);
$ParamsString = json_encode($CoreParams, JSON_FORCE_OBJECT);
// Get the JDatabaseQuery object
$query = $this->_db->getQuery(true);
// Update the title and alias items for rows with the given primary keys.
$query->update($this->_db->quoteName('#__ucm_content'))
->set($this->_db->quoteName('core_params') . ' = \''.$this->_db->escape($ParamsString).'\'')
->where($this->_db->quoteName('core_content_id') . ' = ' . $pksImploded );
$this->_db->setQuery($query);
try {
$this->_db->execute();
} catch (RuntimeException $e) {
$this->setError($e->getMessage());
$dispatcher->trigger('onEventLogging', array(array('method' => __METHOD__.":".__LINE__, 'message' => $e->getMessage(), 'priority' => JLog::ERROR, 'section' => 'admin')));
return false;
}
$this->setError('');
return true;
}
/**
* Method to change the published state of one or more records.
*
* @param array &$pks A list of the primary keys to change.
* @param integer $value The value of the published state. [optional]
*
* @return boolean True on success.
*
* @since 2.5
*/
public function setPublishStateForTags($pks, $value = 1) {
$dispatcher = JEventDispatcher::getInstance();
$user = JFactory::getUser();
$table = $this->getTable();
//$pks = (array) $pks;
$pks[id] = (array) $pks[id];
// Include the content plugins for the change of state event.
JPluginHelper::importPlugin('content');
// Access checks.
foreach ($pks['tags'] as $i => $pk) {
$table->reset();
if ($table->load($pk)) {
if (!$this->canEditState($table)) {
// Prune items that you can't change.
unset($pks[$i]);
$this->setError(JText::_('JLIB_APPLICATION_ERROR_EDITSTATE_NOT_PERMITTED'));
return false;
}
}
}
// Attempt to change the state of the records.
if (!$table->publish($pks['tags'], $value, $user->get('id'))) {
$this->setError($table->getError());
return false;
}
// Trigger the onContentChangeState event.
$result = $dispatcher->trigger('onContentChangeState', array('com_playjoom.audiotrack', $pks[id], $value));
if (in_array(false, $result, true)) {
$this->setError($table->getError());
return false;
}
// Clear the component's cache
$this->cleanCache();
$dispatcher->trigger('onEventLogging', array(array('method' => __METHOD__.":".__LINE__, 'message' => 'Set of publish state done.', 'priority' => JLog::INFO, 'section' => 'admin')));
return true;
}
/**
* Method to get the record form.
*
* @param array $data Data for the form.
* @param boolean $loadData True if the form is to load its own data (default case), false if not.
* @return mixed A JForm object on success, false on failure
* @since 1.6
*/
public function getForm($data = array(), $loadData = true) {
// Get the form.
$form = $this->loadForm('com_playjoom.audiotrack', 'audiotrack', array('control' => 'jform', 'load_data' => $loadData));
if (empty($form)) {
return false;
}
return $form;
}
/**
* Method to get the script that have to be included on the form
*
* @return string Script files