diff --git a/app/Config/Schema/sonerezh_mysql.php b/app/Config/Schema/sonerezh_mysql.php index 1600cd8..6af9e1c 100644 --- a/app/Config/Schema/sonerezh_mysql.php +++ b/app/Config/Schema/sonerezh_mysql.php @@ -48,6 +48,8 @@ public function after($event = array()) { 'convert_to' => array('type' => 'string', 'null' => false, 'default' => 'mp3', 'length' => 5, 'collate' => 'utf8_general_ci', 'charset' => 'utf8'), 'quality' => array('type' => 'integer', 'null' => false, 'default' => '256', 'length' => 3, 'unsigned' => true), 'enable_mail_notification' => array('type' => 'boolean', 'null' => false, 'default' => '0'), + 'enable_random' => array('type' => 'boolean', 'null' => false, 'default' => '1'), + 'enable_recent' => array('type' => 'boolean', 'null' => false, 'default' => '1'), 'sync_token' => array('type' => 'integer', 'null' => true, 'default' => null, 'unsigned' => false), 'indexes' => array( 'PRIMARY' => array('column' => 'id', 'unique' => 1) diff --git a/app/Controller/SongsController.php b/app/Controller/SongsController.php index 1f6b6e8..2c9cab6 100755 --- a/app/Controller/SongsController.php +++ b/app/Controller/SongsController.php @@ -330,10 +330,17 @@ public function albums() { )); $latests = array(); + $rands = array(); // Is this the first page requested? $page = isset($this->request->params['named']['page']) ? $this->request->params['named']['page'] : 1; $db = $this->Song->getDataSource(); + if ($db->config['datasource'] == 'Database/Mysql') { + $random_order_by_method = 'RAND()'; + } else { + $random_order_by_method = 'RANDOM()'; + } + $this->Song->virtualFields['cover'] = 'MIN(Song.cover)'; if ($page == 1) { @@ -343,6 +350,12 @@ public function albums() { 'order' => 'MAX(Song.created) DESC', 'limit' => 6 )); + $rands = $this->Song->find('all', array( + 'fields' => array('Song.id', 'Song.band', 'Song.album', 'Song.cover'), + 'group' => 'Song.album', + 'order' => $random_order_by_method, + 'limit' => 6 + )); } $this->Paginator->settings = array( @@ -364,11 +377,15 @@ public function albums() { $latest['Song']['cover'] = empty($latest['Song']['cover']) ? "no-cover.png" : THUMBNAILS_DIR.'/'.$latest['Song']['cover']; } + foreach ($rands as &$r) { + $r['Song']['cover'] = empty($r['Song']['cover']) ? "no-cover.png" : THUMBNAILS_DIR.'/'.$r['Song']['cover']; + } + if (empty($songs)) { $this->Flash->info(__('Oops! The database is empty...')); } - $this->set(compact('songs', 'playlists', 'latests')); + $this->set(compact('songs', 'playlists', 'latests', 'rands')); } /** diff --git a/app/Locale/default.pot b/app/Locale/default.pot index b7ab100..33995ba 100644 --- a/app/Locale/default.pot +++ b/app/Locale/default.pot @@ -717,6 +717,10 @@ msgstr "" msgid "All albums" msgstr "" +#: View/Songs/albums.ctp:48 +msgid "Random albums" +msgstr "" + #: View/Songs/albums.ctp:52 msgid "Sort by album" msgstr "" diff --git a/app/Locale/fra/LC_MESSAGES/default.po b/app/Locale/fra/LC_MESSAGES/default.po index 9a3eaf3..2b9af32 100644 --- a/app/Locale/fra/LC_MESSAGES/default.po +++ b/app/Locale/fra/LC_MESSAGES/default.po @@ -742,6 +742,10 @@ msgstr "Ajoutés récemment" msgid "All albums" msgstr "Albums" +#: View/Songs/albums.ctp:48 +msgid "Random albums" +msgstr "Au hasard" + #: View/Songs/albums.ctp:52 msgid "Sort by album" msgstr "Trier par album" diff --git a/app/Model/Setting.php b/app/Model/Setting.php index 30e4412..74155bd 100644 --- a/app/Model/Setting.php +++ b/app/Model/Setting.php @@ -27,6 +27,18 @@ class Setting extends AppModel { 'rule' => array('boolean'), 'message' => 'Something went wrong!' ) + ), + 'enable_random' => array( + 'boolean' => array( + 'rule' => array('boolean'), + 'message' => 'Something went wrong!' + ) + ), + 'enable_recent' => array( + 'boolean' => array( + 'rule' => array('boolean'), + 'message' => 'Something went wrong!' + ) ) ); @@ -63,4 +75,4 @@ public function convConflicts($options = array()) { return true; } -} \ No newline at end of file +} diff --git a/app/View/Settings/index.ctp b/app/View/Settings/index.ctp index da88445..4545096 100644 --- a/app/View/Settings/index.ctp +++ b/app/View/Settings/index.ctp @@ -70,6 +70,16 @@ $this->end(); ?> + Form->input('enable_random', array( + 'type' => 'checkbox', + 'label' => __('Enable display of random albums.') + )); + echo $this->Form->input('enable_recent', array( + 'type' => 'checkbox', + 'label' => __('Enable display of recently added albums.') + )); + ?>