diff --git a/Controller/VideosController.php b/Controller/VideosController.php index c2f2a40..084c316 100644 --- a/Controller/VideosController.php +++ b/Controller/VideosController.php @@ -4,6 +4,7 @@ * * @author Noriko Arai * @author Mitsuru Mutaguchi + * @author Kazunori Sakamoto * @link http://www.netcommons.org NetCommons Project * @license http://www.netcommons.org/license.txt NetCommons License * @copyright Copyright 2014, NetCommons Project @@ -17,6 +18,7 @@ * Videos Controller * * @author Mitsuru Mutaguchi + * @author Kazunori Sakamoto * @package NetCommons\Videos\Controller */ class VideosController extends VideosAppController { @@ -119,7 +121,7 @@ public function beforeFilter() { } // ゲストアクセスOKのアクションを設定 - $this->Auth->allow('tag', 'embed'); + $this->Auth->allow('tag', 'embed', 'get_play_counts'); // FFMPEG有効フラグ /* @see VideoBehavior::isFfmpegEnable() */ @@ -333,6 +335,38 @@ public function download() { return $zip->download($zipFileName); } +/** + * ファイルのダウンロード数の取得 + * + * @return void + */ + public function get_play_counts() { + $query = [ + 'fields' => [ + 'Video.id', + 'Video.play_number', + ], + 'conditions' => [ + 'Video.id' => explode(',', $this->request->query('video_ids')), + ], + 'recursive' => -1, + ]; + $orgRecursive = $this->Video->recursive; + $this->Video->recursive = -1; + $videos = $this->Video->find('all', $query); + $this->Video->recursive = $orgRecursive; + + if ($this->request->query('increment')) { + foreach ($videos as &$video) { + $video['Video']['play_number'] = $this->Video->countUp($video); + } + unset($video); + } + + $this->set('_serialize', ['counts']); + $this->set('counts', $videos); + } + /** * _setFlashMessageAndRedirect * @@ -352,7 +386,7 @@ protected function _setFlashMessageAndRedirect($contentKey, $message) { 'key' => $contentKey ), true); // 暫定対応:どうゆう訳だか、ここだと?frame_idが上記でセットされないので直書き - $url .= '?frame_id=' . Current::read('Frame.id'); + $url .= '?frame_id=' . Current::read('Frame.id') . '&no-cache=1'; $this->redirect($url); } diff --git a/Model/Video.php b/Model/Video.php index e8dbfb8..41c0d98 100644 --- a/Model/Video.php +++ b/Model/Video.php @@ -4,6 +4,7 @@ * * @author Noriko Arai * @author Mitsuru Mutaguchi + * @author Kazunori Sakamoto * @link http://www.netcommons.org NetCommons Project * @license http://www.netcommons.org/license.txt NetCommons License * @copyright Copyright 2014, NetCommons Project @@ -16,6 +17,7 @@ * Video Model * * @author Mitsuru Mutaguchi + * @author Kazunori Sakamoto * @package NetCommons\Videos\Model */ class Video extends VideosAppModel { @@ -266,7 +268,9 @@ public function countUp($data) { } //トランザクションCommit + $this->invalidateCDN = false; $this->commit(); + $this->invalidateCDN = true; } catch (Exception $ex) { //トランザクションRollback diff --git a/View/Elements/Videos/list.ctp b/View/Elements/Videos/list.ctp index d3f151d..92c4346 100644 --- a/View/Elements/Videos/list.ctp +++ b/View/Elements/Videos/list.ctp @@ -7,6 +7,7 @@ * - $isFfmpegEnable: Ffmpegを使うか * * @author Mitsuru Mutaguchi + * @author Kazunori Sakamoto * @link http://www.netcommons.org NetCommons Project * @license http://www.netcommons.org/license.txt NetCommons License * @copyright Copyright 2014, NetCommons Project @@ -77,15 +78,16 @@ if (!isset($style)) {
- - + + + {{playCounts[]}} ContentComment->count($video, array('class' => 'video-count-icons')); ?> - Like->display($videoSetting, $video); ?> + Like->display('Video', $videoSetting, $video); ?> diff --git a/View/Videos/index.ctp b/View/Videos/index.ctp index afeaf9a..077ab39 100644 --- a/View/Videos/index.ctp +++ b/View/Videos/index.ctp @@ -4,6 +4,7 @@ * * @author Noriko Arai * @author Mitsuru Mutaguchi + * @author Kazunori Sakamoto * @link http://www.netcommons.org NetCommons Project * @license http://www.netcommons.org/license.txt NetCommons License * @copyright Copyright 2014, NetCommons Project @@ -113,15 +114,27 @@ echo $this->NetCommonsHtml->script('/videos/js/videos.js');
- -
- element('Videos.Videos/list', array( - 'video' => $video, - 'videoSetting' => $videoSetting, - 'isFfmpegEnable' => $isFfmpegEnable, - )); ?> -
- + CDNCache->isCacheable(); + foreach ($videos as $video) { + $value = $cacheable ? null : $video['Video']['play_number']; + $initialValues[$video['Video']['id']] = $value; + } + ?> +
+ +
+ element('Videos.Videos/list', array( + 'video' => $video, + 'videoSetting' => $videoSetting, + 'isFfmpegEnable' => $isFfmpegEnable, + )); ?> +
+ +
element('NetCommons.paginator'); ?> diff --git a/View/Videos/view.ctp b/View/Videos/view.ctp index ed30efc..e8c488a 100644 --- a/View/Videos/view.ctp +++ b/View/Videos/view.ctp @@ -4,6 +4,7 @@ * * @author Noriko Arai * @author Mitsuru Mutaguchi + * @author Kazunori Sakamoto * @link http://www.netcommons.org NetCommons Project * @license http://www.netcommons.org/license.txt NetCommons License * @copyright Copyright 2014, NetCommons Project @@ -59,7 +60,15 @@ echo $this->NetCommonsHtml->script(array( )); ?> -
+CDNCache->isCacheable(); + $value = $cacheable ? null : $video['Video']['play_number']; + $initialValues[$video['Video']['id']] = $value; +?> +
@@ -116,8 +125,9 @@ echo $this->NetCommonsHtml->script(array( - - + + + {{playCounts[]}} @@ -152,19 +162,30 @@ echo $this->NetCommonsHtml->script(array(