diff --git a/plugins/tps/tps/Plugin.php b/plugins/tps/tps/Plugin.php index aa594547b..639a134f1 100644 --- a/plugins/tps/tps/Plugin.php +++ b/plugins/tps/tps/Plugin.php @@ -6,6 +6,9 @@ class Plugin extends PluginBase { public function registerComponents() { + return [ + 'Tps\Tps\Components\MediaView' => 'mediaView', + ]; } public function registerSettings() diff --git a/plugins/tps/tps/components/MediaView.php b/plugins/tps/tps/components/MediaView.php new file mode 100644 index 000000000..dc4759208 --- /dev/null +++ b/plugins/tps/tps/components/MediaView.php @@ -0,0 +1,53 @@ + 'Media View', + 'description' => 'media view counter' + ]; + } + + // public function defineProperties() + // { + // return [ + // 'id' => [ + // 'title' => 'Media Id', + // 'description' => 'media view', + // 'default' => '{{ :mediaId }}', + // 'type' => 'string' + // ] + // ]; + // } + + + public function init() + { + // $this->loadMedia(); + } + + + protected function onCountView() + { + $data = post(); + // dump($data); + if($data && $data['mediaId']){ + $mediaView = MediaViewCount::firstOrCreate(['media_id' => $data['mediaId'], 'date' => Carbon::today()]); + $mediaView->increment('view'); + } + return MediaViewCount::where('media_id', $data['mediaId'])->sum('view'); + } + + +} diff --git a/plugins/tps/tps/controllers/MediaView.php b/plugins/tps/tps/controllers/MediaView.php new file mode 100644 index 000000000..90d4c20c9 --- /dev/null +++ b/plugins/tps/tps/controllers/MediaView.php @@ -0,0 +1,18 @@ + + = e(trans('backend::lang.form.create')) ?> + + diff --git a/plugins/tps/tps/controllers/mediaview/config_form.yaml b/plugins/tps/tps/controllers/mediaview/config_form.yaml new file mode 100644 index 000000000..2ee6e5c34 --- /dev/null +++ b/plugins/tps/tps/controllers/mediaview/config_form.yaml @@ -0,0 +1,10 @@ +name: MediaView +form: $/tps/tps/models/mediaview/fields.yaml +modelClass: Tps\Tps\Models\MediaView +defaultRedirect: tps/tps/mediaview +create: + redirect: 'tps/tps/mediaview/update/:id' + redirectClose: tps/tps/mediaview +update: + redirect: tps/tps/mediaview + redirectClose: tps/tps/mediaview diff --git a/plugins/tps/tps/controllers/mediaview/config_list.yaml b/plugins/tps/tps/controllers/mediaview/config_list.yaml new file mode 100644 index 000000000..5731b6e25 --- /dev/null +++ b/plugins/tps/tps/controllers/mediaview/config_list.yaml @@ -0,0 +1,12 @@ +list: $/tps/tps/models/mediaview/columns.yaml +modelClass: Tps\Tps\Models\MediaView +title: MediaView +noRecordsMessage: 'backend::lang.list.no_records' +showSetup: true +showCheckboxes: true +recordsPerPage: 20 +toolbar: + buttons: list_toolbar + search: + prompt: 'backend::lang.list.search_prompt' +recordUrl: 'tps/tps/mediaview/update/:id' diff --git a/plugins/tps/tps/controllers/mediaview/create.htm b/plugins/tps/tps/controllers/mediaview/create.htm new file mode 100644 index 000000000..c99bb2ebd --- /dev/null +++ b/plugins/tps/tps/controllers/mediaview/create.htm @@ -0,0 +1,46 @@ + +
= e(trans('backend::lang.form.return_to_list')) ?>
+ \ No newline at end of file diff --git a/plugins/tps/tps/controllers/mediaview/index.htm b/plugins/tps/tps/controllers/mediaview/index.htm new file mode 100644 index 000000000..ea43a3636 --- /dev/null +++ b/plugins/tps/tps/controllers/mediaview/index.htm @@ -0,0 +1 @@ += $this->listRender() ?> diff --git a/plugins/tps/tps/controllers/mediaview/preview.htm b/plugins/tps/tps/controllers/mediaview/preview.htm new file mode 100644 index 000000000..bce9b1171 --- /dev/null +++ b/plugins/tps/tps/controllers/mediaview/preview.htm @@ -0,0 +1,22 @@ + ++ + = e(trans('backend::lang.form.return_to_list')) ?> + +
\ No newline at end of file diff --git a/plugins/tps/tps/controllers/mediaview/update.htm b/plugins/tps/tps/controllers/mediaview/update.htm new file mode 100644 index 000000000..42a53fe64 --- /dev/null +++ b/plugins/tps/tps/controllers/mediaview/update.htm @@ -0,0 +1,54 @@ + += e(trans('backend::lang.form.return_to_list')) ?>
+ \ No newline at end of file diff --git a/plugins/tps/tps/models/Media.php b/plugins/tps/tps/models/Media.php index 39d4e8cec..5c3b8337c 100644 --- a/plugins/tps/tps/models/Media.php +++ b/plugins/tps/tps/models/Media.php @@ -9,18 +9,23 @@ class Media extends Model { use \October\Rain\Database\Traits\Validation; public $implement = ['@RainLab.Translate.Behaviors.TranslatableModel']; - + + public $hasMany = [ + 'media_view' => [ + 'Tps\Tps\Models\MediaView', + ], + ]; /** * @var string The database table used by the model. */ public $table = 'tps_tps_media'; - + public $jsonable = ['media_file']; - - public $translatable = [ - 'name', - ]; + + public $translatable = [ + 'name', + ]; /** * @var array Validation rules diff --git a/plugins/tps/tps/models/MediaView.php b/plugins/tps/tps/models/MediaView.php new file mode 100644 index 000000000..31f9ef5c6 --- /dev/null +++ b/plugins/tps/tps/models/MediaView.php @@ -0,0 +1,37 @@ + [ + 'Tps\Tps\Models\Media', + 'key' => 'media_id', + 'table' => 'tps_tps_media' + ], + ]; + + /** + * @var array Validation rules + */ + public $rules = [ + ]; +} diff --git a/plugins/tps/tps/models/mediaview/columns.yaml b/plugins/tps/tps/models/mediaview/columns.yaml new file mode 100644 index 000000000..715b4c6e3 --- /dev/null +++ b/plugins/tps/tps/models/mediaview/columns.yaml @@ -0,0 +1,30 @@ +columns: + id: + label: id + type: number + sortable: true + created_at: + label: created_at + type: datetime + searchable: false + sortable: true + updated_at: + label: updated_at + type: datetime + searchable: false + sortable: true + media_id: + label: media_id + type: number + searchable: true + sortable: true + view: + label: view + type: number + searchable: true + sortable: true + click: + label: click + type: number + searchable: true + sortable: true diff --git a/plugins/tps/tps/models/mediaview/fields.yaml b/plugins/tps/tps/models/mediaview/fields.yaml new file mode 100644 index 000000000..63a65f4c0 --- /dev/null +++ b/plugins/tps/tps/models/mediaview/fields.yaml @@ -0,0 +1,13 @@ +fields: + view: + label: View + span: auto + type: number + click: + label: Click + span: auto + type: text + media_id: + label: Media + span: auto + type: number diff --git a/plugins/tps/tps/plugin.yaml b/plugins/tps/tps/plugin.yaml index 671e6fe11..cc4845d28 100644 --- a/plugins/tps/tps/plugin.yaml +++ b/plugins/tps/tps/plugin.yaml @@ -18,6 +18,10 @@ navigation: icon: icon-users permissions: - media.authors + side-menu-item2: + label: 'Media View' + url: tps/tps/mediaview + icon: icon-signal permissions: media.media: tab: Media diff --git a/plugins/tps/tps/updates/builder_table_create_tps_tps_media_view.php b/plugins/tps/tps/updates/builder_table_create_tps_tps_media_view.php new file mode 100644 index 000000000..17cdd1e31 --- /dev/null +++ b/plugins/tps/tps/updates/builder_table_create_tps_tps_media_view.php @@ -0,0 +1,27 @@ +engine = 'InnoDB'; + $table->increments('id')->unsigned(); + $table->timestamp('created_at')->nullable(); + $table->timestamp('updated_at')->nullable(); + $table->timestamp('deleted_at')->nullable(); + $table->integer('media_id')->nullable(); + $table->integer('view')->nullable(); + $table->integer('click')->nullable(); + }); + } + + public function down() + { + Schema::dropIfExists('tps_tps_media_view'); + } +} diff --git a/plugins/tps/tps/updates/builder_table_update_tps_tps_media_view.php b/plugins/tps/tps/updates/builder_table_update_tps_tps_media_view.php new file mode 100644 index 000000000..db00fda1b --- /dev/null +++ b/plugins/tps/tps/updates/builder_table_update_tps_tps_media_view.php @@ -0,0 +1,25 @@ +integer('view')->default(0)->change(); + $table->integer('click')->default(0)->change(); + }); + } + + public function down() + { + Schema::table('tps_tps_media_view', function($table) + { + $table->integer('view')->default(null)->change(); + $table->integer('click')->default(null)->change(); + }); + } +} diff --git a/plugins/tps/tps/updates/builder_table_update_tps_tps_media_view_2.php b/plugins/tps/tps/updates/builder_table_update_tps_tps_media_view_2.php new file mode 100644 index 000000000..1d4a6000d --- /dev/null +++ b/plugins/tps/tps/updates/builder_table_update_tps_tps_media_view_2.php @@ -0,0 +1,23 @@ +dateTime('date')->nullable(); + }); + } + + public function down() + { + Schema::table('tps_tps_media_view', function($table) + { + $table->dropColumn('date'); + }); + } +} diff --git a/plugins/tps/tps/updates/version.yaml b/plugins/tps/tps/updates/version.yaml index b590c3809..3890e3cab 100644 --- a/plugins/tps/tps/updates/version.yaml +++ b/plugins/tps/tps/updates/version.yaml @@ -15,3 +15,12 @@ 1.0.6: - 'Updated table tps_tps_authors' - builder_table_update_tps_tps_authors_2.php +1.0.7: + - 'Created table tps_tps_media_view' + - builder_table_create_tps_tps_media_view.php +1.0.8: + - 'Updated table tps_tps_media_view' + - builder_table_update_tps_tps_media_view.php +1.0.9: + - 'Updated table tps_tps_media_view' + - builder_table_update_tps_tps_media_view_2.php diff --git a/themes/modern2/pages/new/group.htm b/themes/modern2/pages/new/group.htm index 76a50f04d..a81c36093 100644 --- a/themes/modern2/pages/new/group.htm +++ b/themes/modern2/pages/new/group.htm @@ -17,66 +17,74 @@ noPostsMessage = "No posts found" sortOrder = "published_at desc" categoryPage = "new/category" postPage = "new/newPost" + +[mediaView] == param('id'); // $currentPost = RainLab\Blog\Models\Post::where('id', $postId)->with(['category_groups'])->first(); - + $currentLocale = $this->activeLocale; - + $this['group'] = $this->param('categoryGroup'); $this['categorySlug'] = $this->param('slug'); $this['groupName'] = RainLab\Blog\Models\CategoryGroup::where('slug', $this['group'])->first(); - + $currentCatLink = '/'.$this['categorySlug']; $currentUrl = '/'.$currentLocale.'/new/posts/'.$this['group'].$currentCatLink; - + if(!$this['categorySlug'] && $this['group'] != 'media'){ - $this->page->meta_title = $this['groupName']->name; + $this->page->meta_title = $this['groupName']->name; }elseif(!$this['categorySlug'] && $this['group'] == 'media'){ - $this->page->meta_title = 'Media'; + $this->page->meta_title = 'Media'; } - - + + //dd($currentUrl); if($this->menuItems && $this['group']){ - + foreach ($this->menuItems as $menu){ //dump($currentUrl); if(!$this['categorySlug']){ if($menu->url.'/' === $currentUrl){ - $menu->isActive = true; + $menu->isActive = true; break; } }else{ - + foreach ($menu->items as $menuItem){ if($menuItem->url === $currentUrl){ // dump($menuItem); - $menuItem->isActive = true; - $menuItem->isChildActive = true; + $menuItem->isActive = true; + $menuItem->isChildActive = true; break; } - + } } - - } + + } } - - + + //$this['backendUsers'] = Backend\Models\User::all(); - + if($this['categorySlug']){ - $this['mediaPostsFilter'] = Tps\Tps\Models\Media::where('type', $this['categorySlug'])->orderBy('published_at', 'DESC')->paginate(9); + $this['mediaPostsFilter'] = Tps\Tps\Models\Media::where('type', $this['categorySlug'])->orderBy('published_at', 'DESC') + //->with(['media_view' ]) + ->withCount(['media_view AS view' => function ($query) { + $query->select(DB::raw("SUM(view) as media_view")); + } + ]) + ->paginate(9); }else{ $this['mediaPostsFilter'] = Tps\Tps\Models\Media::orderBy('published_at', 'DESC')->paginate(9); } - - + + } ?> @@ -98,10 +106,10 @@ function onStart(){No posts found
{% endfor %}{{post.name}}