media view

This commit is contained in:
Kerim 2023-03-24 11:23:06 +05:00
parent f4df5200ca
commit 189368aec1
21 changed files with 485 additions and 48 deletions

View File

@ -6,6 +6,9 @@ class Plugin extends PluginBase
{
public function registerComponents()
{
return [
'Tps\Tps\Components\MediaView' => 'mediaView',
];
}
public function registerSettings()

View File

@ -0,0 +1,53 @@
<?php namespace Tps\Tps\Components;
use Event;
use BackendAuth;
use Cms\Classes\Page;
use Cms\Classes\ComponentBase;
use Tps\Tps\Models\MediaView as MediaViewCount;
use Tps\Tps\Models\Media;
use Carbon\Carbon;
class MediaView extends ComponentBase
{
public function componentDetails()
{
return [
'name' => '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');
}
}

View File

@ -0,0 +1,18 @@
<?php namespace Tps\Tps\Controllers;
use Backend\Classes\Controller;
use BackendMenu;
class MediaView extends Controller
{
public $implement = [ 'Backend\Behaviors\ListController', 'Backend\Behaviors\FormController' ];
public $listConfig = 'config_list.yaml';
public $formConfig = 'config_form.yaml';
public function __construct()
{
parent::__construct();
BackendMenu::setContext('Tps.Tps', 'main-menu-item', 'side-menu-item2');
}
}

View File

@ -0,0 +1,18 @@
<div data-control="toolbar">
<a href="<?= Backend::url('tps/tps/mediaview/create') ?>" class="btn btn-primary oc-icon-plus"><?= e(trans('backend::lang.form.create')) ?></a>
<button
class="btn btn-default oc-icon-trash-o"
disabled="disabled"
onclick="$(this).data('request-data', {
checked: $('.control-list').listWidget('getChecked')
})"
data-request="onDelete"
data-request-confirm="<?= e(trans('backend::lang.list.delete_selected_confirm')) ?>"
data-trigger-action="enable"
data-trigger=".control-list input[type=checkbox]"
data-trigger-condition="checked"
data-request-success="$(this).prop('disabled', true)"
data-stripe-load-indicator>
<?= e(trans('backend::lang.list.delete_selected')) ?>
</button>
</div>

View File

@ -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

View File

@ -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'

View File

@ -0,0 +1,46 @@
<?php Block::put('breadcrumb') ?>
<ul>
<li><a href="<?= Backend::url('tps/tps/mediaview') ?>">MediaView</a></li>
<li><?= e($this->pageTitle) ?></li>
</ul>
<?php Block::endPut() ?>
<?php if (!$this->fatalError): ?>
<?= Form::open(['class' => 'layout']) ?>
<div class="layout-row">
<?= $this->formRender() ?>
</div>
<div class="form-buttons">
<div class="loading-indicator-container">
<button
type="submit"
data-request="onSave"
data-hotkey="ctrl+s, cmd+s"
data-load-indicator="<?= e(trans('backend::lang.form.saving')) ?>"
class="btn btn-primary">
<?= e(trans('backend::lang.form.create')) ?>
</button>
<button
type="button"
data-request="onSave"
data-request-data="close:1"
data-hotkey="ctrl+enter, cmd+enter"
data-load-indicator="<?= e(trans('backend::lang.form.saving')) ?>"
class="btn btn-default">
<?= e(trans('backend::lang.form.create_and_close')) ?>
</button>
<span class="btn-text">
<?= e(trans('backend::lang.form.or')) ?> <a href="<?= Backend::url('tps/tps/mediaview') ?>"><?= e(trans('backend::lang.form.cancel')) ?></a>
</span>
</div>
</div>
<?= Form::close() ?>
<?php else: ?>
<p class="flash-message static error"><?= e(trans($this->fatalError)) ?></p>
<p><a href="<?= Backend::url('tps/tps/mediaview') ?>" class="btn btn-default"><?= e(trans('backend::lang.form.return_to_list')) ?></a></p>
<?php endif ?>

View File

@ -0,0 +1 @@
<?= $this->listRender() ?>

View File

@ -0,0 +1,22 @@
<?php Block::put('breadcrumb') ?>
<ul>
<li><a href="<?= Backend::url('tps/tps/mediaview') ?>">MediaView</a></li>
<li><?= e($this->pageTitle) ?></li>
</ul>
<?php Block::endPut() ?>
<?php if (!$this->fatalError): ?>
<div class="form-preview">
<?= $this->formRenderPreview() ?>
</div>
<?php else: ?>
<p class="flash-message static error"><?= e($this->fatalError) ?></p>
<?php endif ?>
<p>
<a href="<?= Backend::url('tps/tps/mediaview') ?>" class="btn btn-default oc-icon-chevron-left">
<?= e(trans('backend::lang.form.return_to_list')) ?>
</a>
</p>

View File

@ -0,0 +1,54 @@
<?php Block::put('breadcrumb') ?>
<ul>
<li><a href="<?= Backend::url('tps/tps/mediaview') ?>">MediaView</a></li>
<li><?= e($this->pageTitle) ?></li>
</ul>
<?php Block::endPut() ?>
<?php if (!$this->fatalError): ?>
<?= Form::open(['class' => 'layout']) ?>
<div class="layout-row">
<?= $this->formRender() ?>
</div>
<div class="form-buttons">
<div class="loading-indicator-container">
<button
type="submit"
data-request="onSave"
data-request-data="redirect:0"
data-hotkey="ctrl+s, cmd+s"
data-load-indicator="<?= e(trans('backend::lang.form.saving')) ?>"
class="btn btn-primary">
<?= e(trans('backend::lang.form.save')) ?>
</button>
<button
type="button"
data-request="onSave"
data-request-data="close:1"
data-hotkey="ctrl+enter, cmd+enter"
data-load-indicator="<?= e(trans('backend::lang.form.saving')) ?>"
class="btn btn-default">
<?= e(trans('backend::lang.form.save_and_close')) ?>
</button>
<button
type="button"
class="oc-icon-trash-o btn-icon danger pull-right"
data-request="onDelete"
data-load-indicator="<?= e(trans('backend::lang.form.deleting')) ?>"
data-request-confirm="<?= e(trans('backend::lang.form.confirm_delete')) ?>">
</button>
<span class="btn-text">
<?= e(trans('backend::lang.form.or')) ?> <a href="<?= Backend::url('tps/tps/mediaview') ?>"><?= e(trans('backend::lang.form.cancel')) ?></a>
</span>
</div>
</div>
<?= Form::close() ?>
<?php else: ?>
<p class="flash-message static error"><?= e(trans($this->fatalError)) ?></p>
<p><a href="<?= Backend::url('tps/tps/mediaview') ?>" class="btn btn-default"><?= e(trans('backend::lang.form.return_to_list')) ?></a></p>
<?php endif ?>

View File

@ -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

View File

@ -0,0 +1,37 @@
<?php namespace Tps\Tps\Models;
use Model;
/**
* Model
*/
class MediaView extends Model
{
use \October\Rain\Database\Traits\Validation;
use \October\Rain\Database\Traits\SoftDelete;
protected $dates = ['deleted_at'];
/**
* @var string The database table used by the model.
*/
public $table = 'tps_tps_media_view';
protected $fillable = ['media_id', 'date'];
public $belongsTo = [
'media' => [
'Tps\Tps\Models\Media',
'key' => 'media_id',
'table' => 'tps_tps_media'
],
];
/**
* @var array Validation rules
*/
public $rules = [
];
}

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -0,0 +1,27 @@
<?php namespace Tps\Tps\Updates;
use Schema;
use October\Rain\Database\Updates\Migration;
class BuilderTableCreateTpsTpsMediaView extends Migration
{
public function up()
{
Schema::create('tps_tps_media_view', function($table)
{
$table->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');
}
}

View File

@ -0,0 +1,25 @@
<?php namespace Tps\Tps\Updates;
use Schema;
use October\Rain\Database\Updates\Migration;
class BuilderTableUpdateTpsTpsMediaView extends Migration
{
public function up()
{
Schema::table('tps_tps_media_view', function($table)
{
$table->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();
});
}
}

View File

@ -0,0 +1,23 @@
<?php namespace Tps\Tps\Updates;
use Schema;
use October\Rain\Database\Updates\Migration;
class BuilderTableUpdateTpsTpsMediaView2 extends Migration
{
public function up()
{
Schema::table('tps_tps_media_view', function($table)
{
$table->dateTime('date')->nullable();
});
}
public function down()
{
Schema::table('tps_tps_media_view', function($table)
{
$table->dropColumn('date');
});
}
}

View File

@ -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

View File

@ -17,66 +17,74 @@ noPostsMessage = "No posts found"
sortOrder = "published_at desc"
categoryPage = "new/category"
postPage = "new/newPost"
[mediaView]
==
<?php
function onStart(){
// $postId = $this->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(){
<h2 style="text-transform: capitalize;">{% if category.name != "" %}{{category.name}}{% else %} {% if group == 'media' %} {{ group }} {% else %}{{ groupName.name }}{% endif %} {% endif %}</h2>
<span></span>
</div>
{% if group == 'media' %}
<div class="video-main-top {% if categorySlug == 'photo' %} photo-main-top {% endif %}">
{% for post in mediaPostsFilter %}
{% if post.type == 'photo' %}
@ -114,7 +122,7 @@ function onStart(){
{% endfor %}
</div>
{% partial 'new/pagination' items = mediaPostsFilter %}
{% else %}
<div class="rubric-items {% if group == 'poster' %} affiche-items {% endif %}">
{% for post in blogPosts.posts %}
@ -127,23 +135,23 @@ function onStart(){
<p>No posts found</p>
{% endfor %}
</div>
{% partial 'new/pagination' items = blogPosts.posts %}
{% endif %}
</div>
</div>
</main>
<section class="photo-scroller">
<div class="photo-scroller-inner">
<div class="swiper photoScrollerSwiper">
<div class="swiper-wrapper">
</div>
<div class="photo-scroller-prev video-prev">
<img src="{{'assets/new/icons/arrow-left-white.svg'|theme}}" alt="" />
@ -157,9 +165,23 @@ function onStart(){
</div>
</div>
</section>
{% put scripts %}
<script src="{{'assets/new/scripts/core/affiche-item.js'|theme}}"></script>
<script src="{{'assets/new/scripts/core/rubric.js'|theme}}"></script>
{% endput %}
<script>
function countView(id) {
$(this).request('onCountView', {
data: { mediaId: id },
success: function (data) {
// var data = JSON.parse(data);
console.log(data.result);
$('#media_view_'+id).html(data.result);
}
});
};
</script>
{% endput %}

View File

@ -2,21 +2,26 @@
==
<div class="video-item {% if post.type == 'photo' %} photo-item {% endif %}">
<div class="video {% if post.type == 'photo' %} photo {% endif %}">
{% if post.type == 'photo' %}
{% if post.type == 'photo' %}
<img src="{{post.poster_file|media|resize(683, 385, )}}" loading="lazy">
{% else %}
<video src="{{post.media_file[0].media|media}}" controls poster="{{post.poster_file|media|resize(513, 288, {mode: 'crop'})}}" ></video>
<a onClick="countView({{post.id}});">
<video src="{{post.media_file[0].media|media}}" controls poster="{{post.poster_file|media|resize(513, 288, {mode: 'crop'})}}" ></video>
</a>
{% endif %}
</div>
<div class="sub-news-left-content-item-content video-info">
<div class="sub-news-left-content-item-date-content-head">
<h4>{{post.published_at|date('d.m.Y')}}</h4>
<span>|</span>
<h4> {{post.published_at|date('H:i')}}</h4>
<span>|</span>
<img src="{{'assets/new/icons/eye.svg'|theme}}" alt="" style="width: 18px;" />
<span id="media_view_{{post.id}}">{% if post.view == null %} 0 {% else %} {{ post.view }} {% endif %}</span>
</div>
<p class="sub-news-left-content-item-date-content-info">
{{post.name}}
</p>
</div>
</div>
</div>