Commit ad351f59 by Aan Choesni Herlingga

translate En post

parent 80814a1d
......@@ -5,15 +5,24 @@ namespace App\Http\Controllers\Webprofile\Backend;
use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use App\Models\Webprofile\Categories;
use App\Repositories\Webprofile\En\PostRepository as EnPostRepository;
use App\Repositories\Webprofile\PostRepository;
use Statickidz\GoogleTranslate;
class PostController extends Controller
{
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->repoEn = $repoEn;
}
/**
* Display a listing of the resource.
......@@ -23,7 +32,7 @@ class PostController extends Controller
public function index(Request $request)
{
if ($request->ajax()) {
$data = $this->repo->get();
$data = $this->repo->get(['rEn']);
return $this->repo->datatable($data);
}
......@@ -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('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');
}
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.
*
......@@ -83,7 +109,7 @@ class PostController extends Controller
*/
public function edit($id)
{
$data = $this->repo->findId($id);
$data = $this->repo->findId($id, ['rEn']);
$categories = Categories::pluck('name', 'id');
$data = [
......@@ -103,17 +129,28 @@ class PostController extends Controller
*/
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('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);
$this->updateEn($dataEn, $post);
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.
*
......
<?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;
use App\Http\Traits\UuidTrait;
use Illuminate\Database\Eloquent\Model;
use App\Models\Webprofile\Categories;
use App\Models\Webprofile\En\Posts as EnPosts;
class Posts extends Model
{
......@@ -19,4 +20,9 @@ class Posts extends Model
{
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
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);
}
}
{
"_readme": [
"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"
],
"content-hash": "b61881df596933b3371ed365f3644712",
"content-hash": "9c68facdf749909bd9a37e534700e060",
"packages": [
{
"name": "anhskohbo/no-captcha",
......@@ -2692,6 +2692,65 @@
"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",
"version": "v6.2.3",
"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')
@section('content')
<div class="row">
<div class="col-lg-12">
<!-- 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="panel panel-default">
<div class="panel-heading">Dashboard</div>
<div class="card-body">
@if (session('status'))
<div class="alert alert-success" role="alert">
{{ session('status') }}
</div>
@endif
You are logged in!
</div>
</div>
</div>
</div>
</div>
</div>
<div class="panel-body">
You are logged in Administrator!
</div>
</div>
@endsection
......@@ -30,6 +30,9 @@
</div>
<div class="panel-body">
<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="form-group @if ($errors->has('title')) has-error @endif">
<div class="col-md-12">
......@@ -56,6 +59,26 @@
</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 class="col-md-12">
<div class="block">
{{ Form::textarea('content_en', $data->rEn->content, array('id'=>'content_en')) }}
</div>
</div>
</div>
</div>
</div>
</div>
......@@ -84,7 +107,7 @@
<label class="col-md-2 control-label">@lang('label.status')</label>
<div class="col-md-6">
<center><label class="switch">
{{ Form::checkbox('post_status', $data->post_status, $data->post_status) }}
{{ Form::checkbox('post_status', 1, true) }}
<span></span>
</label></center>
</div>
......@@ -112,21 +135,17 @@
<div class="col-md-12">
<center>
<div class="form-group">
@if($data->thumbnail)
<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
<img id="uploadPreview" style="width: 200px; height: 100%;" src="https://statik.unesa.ac.id/profileunesa_konten_statik/images/preview.png"/><br>
</div>
<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 class="form-group" style="padding-top: 10px;">
<div class="col-md-12">
<div class="form-group">
<label style="vertical-align: middle;">@lang('label.show_in_post')</label>
<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>
</label>
</div>
......@@ -175,8 +194,12 @@
$('#content').summernote({
height: 400
});
$('#content_en').summernote({
height: 400
});
});
$('#categories').select2();
$('#categories_en').select2();
</script>
@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