Commit ad351f59 by Aan Choesni Herlingga

translate En post

parent 80814a1d
...@@ -5,15 +5,24 @@ namespace App\Http\Controllers\Webprofile\Backend; ...@@ -5,15 +5,24 @@ namespace App\Http\Controllers\Webprofile\Backend;
use Illuminate\Http\Request; use Illuminate\Http\Request;
use App\Http\Controllers\Controller; use App\Http\Controllers\Controller;
use App\Models\Webprofile\Categories; use App\Models\Webprofile\Categories;
use App\Repositories\Webprofile\En\PostRepository as EnPostRepository;
use App\Repositories\Webprofile\PostRepository; use App\Repositories\Webprofile\PostRepository;
use Statickidz\GoogleTranslate;
class PostController extends Controller class PostController extends Controller
{ {
private $repo; private $repo;
private $repoEn;
public function __construct(PostRepository $repo) private $SOURCE = 'id';
{ private $TARGET = 'en';
public function __construct(
PostRepository $repo,
EnPostRepository $repoEn
){
$this->repo = $repo; $this->repo = $repo;
$this->repoEn = $repoEn;
} }
/** /**
* Display a listing of the resource. * Display a listing of the resource.
...@@ -23,7 +32,7 @@ class PostController extends Controller ...@@ -23,7 +32,7 @@ class PostController extends Controller
public function index(Request $request) public function index(Request $request)
{ {
if ($request->ajax()) { if ($request->ajax()) {
$data = $this->repo->get(); $data = $this->repo->get(['rEn']);
return $this->repo->datatable($data); return $this->repo->datatable($data);
} }
...@@ -59,11 +68,28 @@ class PostController extends Controller ...@@ -59,11 +68,28 @@ class PostController extends Controller
array_key_exists('post_status', $data) ? $data['post_status'] = 1 : $data['post_status'] = 0; array_key_exists('post_status', $data) ? $data['post_status'] = 1 : $data['post_status'] = 0;
array_key_exists('cover_status', $data) ? $data['cover_status'] = 1 : $data['cover_status'] = 0; array_key_exists('cover_status', $data) ? $data['cover_status'] = 1 : $data['cover_status'] = 0;
$this->repo->store($data);
$save = $this->repo->store($data);
// save translate
$this->createEn($data, $save);
return redirect()->route('posts.index'); return redirect()->route('posts.index');
} }
private function createEn($data, $post)
{
$trans = new GoogleTranslate();
$title = $trans->translate($this->SOURCE, $this->TARGET, $data['title']);
$content = $trans->translate($this->SOURCE, $this->TARGET, strip_tags($data['content']));
$dataEn['post_id'] = $post->id;
$dataEn['title'] = $title;
$dataEn['content'] = $content;
$this->repoEn->store($dataEn);
}
/** /**
* Display the specified resource. * Display the specified resource.
* *
...@@ -83,7 +109,7 @@ class PostController extends Controller ...@@ -83,7 +109,7 @@ class PostController extends Controller
*/ */
public function edit($id) public function edit($id)
{ {
$data = $this->repo->findId($id); $data = $this->repo->findId($id, ['rEn']);
$categories = Categories::pluck('name', 'id'); $categories = Categories::pluck('name', 'id');
$data = [ $data = [
...@@ -103,17 +129,28 @@ class PostController extends Controller ...@@ -103,17 +129,28 @@ class PostController extends Controller
*/ */
public function update(Request $request, $id) public function update(Request $request, $id)
{ {
$data = $request->except(['_token', 'id']); $data = $request->except(['_token', 'id', 'title_en', 'content_en']);
$dataEn = $request->except(['_token', 'id']);
array_key_exists('post_status', $data) ? $data['post_status'] = 1 : $data['post_status'] = 0; array_key_exists('post_status', $data) ? $data['post_status'] = 1 : $data['post_status'] = 0;
array_key_exists('cover_status', $data) ? $data['cover_status'] = 1 : $data['cover_status'] = 0; array_key_exists('cover_status', $data) ? $data['cover_status'] = 1 : $data['cover_status'] = 0;
$post = $this->repo->findId($id); $post = $this->repo->findId($id, ['rEn']);
$edit = $this->repo->update($data, $post); $edit = $this->repo->update($data, $post);
$this->updateEn($dataEn, $post);
return redirect()->route('posts.index'); return redirect()->route('posts.index');
} }
public function updateEn($data, $post)
{
$dataEn['title'] = $data['title_en'];
$dataEn['content'] = $data['content_en'];
$this->repo->update($dataEn, $post->rEn);
}
/** /**
* Remove the specified resource from storage. * Remove the specified resource from storage.
* *
......
<?php
namespace App\Models\Webprofile\En;
use App\Http\Traits\UuidTrait;
use Illuminate\Database\Eloquent\Model;
class Posts extends Model
{
use UuidTrait;
public $incrementing = false;
protected $table = 'swp_posts_en';
protected $guarded = [];
}
...@@ -5,6 +5,7 @@ namespace App\Models\Webprofile; ...@@ -5,6 +5,7 @@ namespace App\Models\Webprofile;
use App\Http\Traits\UuidTrait; use App\Http\Traits\UuidTrait;
use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\Model;
use App\Models\Webprofile\Categories; use App\Models\Webprofile\Categories;
use App\Models\Webprofile\En\Posts as EnPosts;
class Posts extends Model class Posts extends Model
{ {
...@@ -19,4 +20,9 @@ class Posts extends Model ...@@ -19,4 +20,9 @@ class Posts extends Model
{ {
return $this->belongsTo(Categories::class, 'categories', 'id'); return $this->belongsTo(Categories::class, 'categories', 'id');
} }
public function rEn()
{
return $this->hasOne(EnPosts::class, 'post_id', 'id');
}
} }
<?php
namespace App\Repositories\Webprofile\En;
use App\Models\Webprofile\En\Posts;
use App\Repositories\Repository;
class PostRepository extends Repository
{
public function __construct(Posts $model)
{
$this->model = $model;
}
public function get(){}
public function paginate(){}
}
...@@ -89,7 +89,13 @@ class PostRepository extends Repository ...@@ -89,7 +89,13 @@ class PostRepository extends Repository
return $str; return $str;
}) })
->rawColumns(['action', 'status', 'category', 'post_date', 'sum']) ->addColumn('title', function ($row) {
$str = $row->title . '<br>';
$str .= '<i style="color: blue;">' . $row->rEn['title'] . '</i>';
return $str;
})
->rawColumns(['action', 'status', 'category', 'post_date', 'sum', 'title'])
->make(true); ->make(true);
} }
} }
{ {
"_readme": [ "_readme": [
"This file locks the dependencies of your project to a known state", "This file locks the dependencies of your project to a known state",
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file", "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"This file is @generated automatically" "This file is @generated automatically"
], ],
"content-hash": "b61881df596933b3371ed365f3644712", "content-hash": "9c68facdf749909bd9a37e534700e060",
"packages": [ "packages": [
{ {
"name": "anhskohbo/no-captcha", "name": "anhskohbo/no-captcha",
...@@ -2692,6 +2692,65 @@ ...@@ -2692,6 +2692,65 @@
"time": "2019-02-22T07:42:52+00:00" "time": "2019-02-22T07:42:52+00:00"
}, },
{ {
"name": "statickidz/php-google-translate-free",
"version": "1.1.1",
"source": {
"type": "git",
"url": "https://github.com/statickidz/php-google-translate-free.git",
"reference": "f13f952af0718b4590bdaa2209133f10d0534dea"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/statickidz/php-google-translate-free/zipball/f13f952af0718b4590bdaa2209133f10d0534dea",
"reference": "f13f952af0718b4590bdaa2209133f10d0534dea",
"shasum": ""
},
"require": {
"php": ">=5.4"
},
"require-dev": {
"phpdocumentor/phpdocumentor": "2.*",
"phpunit/phpunit": ">=4.8",
"squizlabs/php_codesniffer": "^2.3"
},
"type": "library",
"autoload": {
"psr-4": {
"Statickidz\\": "src/"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"GPL-3.0+"
],
"authors": [
{
"name": "Paris Niarfe Baltazar Salguero",
"email": "sieg.sb@gmail.com",
"homepage": "http://www.pbaltazar.com",
"role": "Developer"
},
{
"name": "Adrián Barrio Andrés",
"email": "statickidz@gmail.com",
"homepage": "https://statickidz.com",
"role": "Developer"
}
],
"description": "Google Translate Free library for PHP",
"homepage": "https://github.com/statickidz/php-google-translate-free/",
"keywords": [
"api",
"free",
"google",
"siegsb",
"statickidz",
"translate",
"translator"
],
"time": "2019-06-13T16:07:11+00:00"
},
{
"name": "swiftmailer/swiftmailer", "name": "swiftmailer/swiftmailer",
"version": "v6.2.3", "version": "v6.2.3",
"source": { "source": {
......
<?php
use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class CreatePostEnTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('swp_posts_en', function (Blueprint $table) {
$table->string('id', 36)->primary();
$table->string('post_id', 36);
$table->string('title');
$table->text('content')->nullable();
$table->string('userid_created', 36)->nullable();
$table->string('userid_updated', 36)->nullable();
$table->timestamps();
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('post_en');
}
}
@extends('webprofile.backend.layouts.master') @extends('webprofile.backend.layouts.master')
@section('content') @section('content')
<div class="row"> <div class="panel panel-default">
<div class="col-lg-12"> <div class="panel-heading">Dashboard</div>
<!-- START DEFAULT DATATABLE -->
<div class="panel panel-default">
<div class="container">
<div class="row justify-content-center">
<div class="col-md-8">
<div class="card">
<div class="card-header">Dashboard</div>
<div class="card-body"> <div class="panel-body">
@if (session('status')) You are logged in Administrator!
<div class="alert alert-success" role="alert">
{{ session('status') }}
</div>
@endif
You are logged in!
</div>
</div>
</div>
</div>
</div>
</div>
</div> </div>
</div> </div>
@endsection @endsection
...@@ -39,20 +39,20 @@ ...@@ -39,20 +39,20 @@
@endif @endif
</div> </div>
</div> </div>
</div> </div>
<div class="col-md-12"> <div class="col-md-12">
<div class="form-group @if ($errors->has('categories')) has-error @endif" style="margin-top: 5px;"> <div class="form-group @if ($errors->has('categories')) has-error @endif" style="margin-top: 5px;">
<div class="col-md-12"> <div class="col-md-12">
{{ Form::select('categories', $categories, old('categories'), ['class' => 'form-control select2', 'style' => 'width: 100%; font-size: 14pt;', 'id' => 'categories', 'placeholder' => app('translator')->getFromJson('feature.category'), 'required']) }} {{ Form::select('categories', $categories, old('categories'), ['class' => 'form-control select2', 'style' => 'width: 100%; font-size: 14pt;', 'id' => 'categories', 'placeholder' => app('translator')->getFromJson('feature.category'), 'required']) }}
@if ($errors->has('categories')) @if ($errors->has('categories'))
<label id="login-error" class="error" for="login">{{$errors->first('categories')}}</label> <label id="login-error" class="error" for="login">{{$errors->first('categories')}}</label>
@endif @endif
</div> </div>
</div> </div>
</div> </div>
<div class="col-md-12"> <div class="col-md-12">
<div class="block"> <div class="block">
{{ Form::textarea('content', null, array('id'=>'content')) }} {{ Form::textarea('content', null, array('id'=>'content')) }}
</div> </div>
</div> </div>
</div> </div>
......
...@@ -30,6 +30,9 @@ ...@@ -30,6 +30,9 @@
</div> </div>
<div class="panel-body"> <div class="panel-body">
<div class="row"> <div class="row">
<div style="padding: 10px 10px 10px 10px; font-weight: bold; font-size: 14pt;">
Bahasa Indonesia
</div>
<div class="col-md-12"> <div class="col-md-12">
<div class="form-group @if ($errors->has('title')) has-error @endif"> <div class="form-group @if ($errors->has('title')) has-error @endif">
<div class="col-md-12"> <div class="col-md-12">
...@@ -39,20 +42,40 @@ ...@@ -39,20 +42,40 @@
@endif @endif
</div> </div>
</div> </div>
</div> </div>
<div class="col-md-12"> <div class="col-md-12">
<div class="form-group @if ($errors->has('categories')) has-error @endif" style="margin-top: 5px;"> <div class="form-group @if ($errors->has('categories')) has-error @endif" style="margin-top: 5px;">
<div class="col-md-12"> <div class="col-md-12">
{{ Form::select('categories', $categories, old('categories'), ['class' => 'form-control select2', 'style' => 'width: 100%; font-size: 14pt;', 'id' => 'categories', 'placeholder' => app('translator')->getFromJson('feature.category'), 'required']) }} {{ Form::select('categories', $categories, old('categories'), ['class' => 'form-control select2', 'style' => 'width: 100%; font-size: 14pt;', 'id' => 'categories', 'placeholder' => app('translator')->getFromJson('feature.category'), 'required']) }}
@if ($errors->has('categories')) @if ($errors->has('categories'))
<label id="login-error" class="error" for="login">{{$errors->first('categories')}}</label> <label id="login-error" class="error" for="login">{{$errors->first('categories')}}</label>
@endif @endif
</div> </div>
</div>
</div>
<div class="col-md-12">
<div class="block">
{{ Form::textarea('content', null, array('id'=>'content')) }}
</div>
</div>
</div>
<div class="row">
<div style="padding: 10px 10px 10px 10px; font-weight: bold; font-size: 14pt;">
English Language
</div>
<div class="col-md-12">
<div class="form-group @if ($errors->has('title')) has-error @endif">
<div class="col-md-12">
{{ Form::text('title_en', $data->rEn->title, array('class' => 'form-control', 'placeholder'=>app('translator')->getFromJson('label.title'), 'style'=>'font-size: 14pt;')) }}
@if ($errors->has('title'))
<label id="login-error" class="error" for="login">{{$errors->first('title')}}</label>
@endif
</div>
</div> </div>
</div> </div>
<div class="col-md-12"> <div class="col-md-12">
<div class="block"> <div class="block">
{{ Form::textarea('content', null, array('id'=>'content')) }} {{ Form::textarea('content_en', $data->rEn->content, array('id'=>'content_en')) }}
</div> </div>
</div> </div>
</div> </div>
...@@ -84,7 +107,7 @@ ...@@ -84,7 +107,7 @@
<label class="col-md-2 control-label">@lang('label.status')</label> <label class="col-md-2 control-label">@lang('label.status')</label>
<div class="col-md-6"> <div class="col-md-6">
<center><label class="switch"> <center><label class="switch">
{{ Form::checkbox('post_status', $data->post_status, $data->post_status) }} {{ Form::checkbox('post_status', 1, true) }}
<span></span> <span></span>
</label></center> </label></center>
</div> </div>
...@@ -111,22 +134,18 @@ ...@@ -111,22 +134,18 @@
<label class="col-md-2 control-label"></label> <label class="col-md-2 control-label"></label>
<div class="col-md-12"> <div class="col-md-12">
<center> <center>
<div class="form-group"> <div class="form-group">
@if($data->thumbnail) <img id="uploadPreview" style="width: 200px; height: 100%;" src="https://statik.unesa.ac.id/profileunesa_konten_statik/images/preview.png"/><br>
<img id="uploadPreview" style="width: 200px; height: 100%;" src="{{URL::to('https://statik.unesa.ac.id/profileunesa_konten_statik/uploads'. Session::get('ss_setting')['statik_konten'] .'/posts/'.$data->thumbnail)}}"/><br>
@else
<img id="uploadPreview" style="width: 200px; height: 100%;" src="//placehold.it/200x100&text=Preview"/><br>
@endif
</div> </div>
<div class="form-group"> <div class="form-group">
{{ Form::file('thumbnail', array('class'=>'fileinput btn-danger', 'id'=>'uploadImage', 'data-filename-placement'=>'inside', 'title'=>'Gambar cover', 'onchange'=>'PreviewImage();')) }} {{ Form::file('thumbnail', array('class'=>'fileinput btn-danger', 'id'=>'uploadImage', 'data-filename-placement'=>'inside', 'title'=>app('translator')->getFromJson('label.cover_image'), 'onchange'=>'PreviewImage();')) }}
</div> </div>
<div class="form-group" style="padding-top: 10px;"> <div class="form-group" style="padding-top: 10px;">
<div class="col-md-12"> <div class="col-md-12">
<div class="form-group"> <div class="form-group">
<label style="vertical-align: middle;">@lang('label.show_in_post')</label> <label style="vertical-align: middle;">@lang('label.show_in_post')</label>
<label class="switch" style="vertical-align: middle;"> <label class="switch" style="vertical-align: middle;">
{{ Form::checkbox('cover_status', $data->cover_status, $data->cover_status) }} {{ Form::checkbox('cover_status', 1, true) }}
<span></span> <span></span>
</label> </label>
</div> </div>
...@@ -175,8 +194,12 @@ ...@@ -175,8 +194,12 @@
$('#content').summernote({ $('#content').summernote({
height: 400 height: 400
}); });
$('#content_en').summernote({
height: 400
});
}); });
$('#categories').select2(); $('#categories').select2();
$('#categories_en').select2();
</script> </script>
@stop @stop
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment