2019-05-22 17:10:16 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
namespace App\Http\Controllers;
|
|
|
|
|
|
|
|
|
|
use Illuminate\Support\Facades\Auth;
|
|
|
|
|
use Illuminate\Http\Request;
|
2019-06-25 16:17:56 +02:00
|
|
|
use Illuminate\Support\Facades\Storage;
|
2019-05-22 17:10:16 +02:00
|
|
|
use App\Sujet;
|
2019-07-11 11:45:47 +02:00
|
|
|
use App\Format;
|
2019-05-23 15:09:28 +02:00
|
|
|
use App\Media;
|
2019-06-17 09:22:10 +02:00
|
|
|
use App\Typemedia;
|
|
|
|
|
use App\Langue;
|
|
|
|
|
use App\Copyright;
|
|
|
|
|
use App\Etiquette;
|
2019-06-25 16:17:56 +02:00
|
|
|
use App\Site;
|
|
|
|
|
use App\Marque;
|
2019-07-17 15:48:23 +02:00
|
|
|
use App\Dossier;
|
2019-07-11 11:45:47 +02:00
|
|
|
use App\Tag;
|
|
|
|
|
use App\Article;
|
2019-07-25 09:43:06 +02:00
|
|
|
use App\Recherche;
|
2019-07-22 14:54:42 +02:00
|
|
|
use App\Historique;
|
2019-07-31 12:22:24 +02:00
|
|
|
use App\Panier;
|
2019-07-11 11:45:47 +02:00
|
|
|
use App\Http\Traits\MediaTools;
|
2019-05-22 17:10:16 +02:00
|
|
|
|
|
|
|
|
class MediaController extends Controller
|
|
|
|
|
{
|
|
|
|
|
|
2019-07-11 11:45:47 +02:00
|
|
|
use MediaTools;
|
2019-05-22 17:10:16 +02:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Display a listing of the resource.
|
|
|
|
|
*
|
|
|
|
|
* @return \Illuminate\Http\Response
|
|
|
|
|
*/
|
2019-07-25 09:43:06 +02:00
|
|
|
public function index(Request $request)
|
2019-05-22 17:10:16 +02:00
|
|
|
{
|
2019-07-25 09:43:06 +02:00
|
|
|
$filters = "";
|
2019-06-17 09:22:10 +02:00
|
|
|
$sujets = Auth::user()->sujets;
|
2019-07-31 12:22:24 +02:00
|
|
|
$paniers = Auth::user()->paniersOwner;
|
2019-06-17 09:22:10 +02:00
|
|
|
$typemedias = Typemedia::all();
|
|
|
|
|
$langues = Langue::all();
|
|
|
|
|
$copyrights = Copyright::all();
|
|
|
|
|
$etiquettes = Etiquette::all();
|
2019-07-17 15:48:23 +02:00
|
|
|
$sites = Site::orderBy('libelle')->get();
|
2019-06-25 16:17:56 +02:00
|
|
|
$marques = Marque::all();
|
2019-07-25 09:43:06 +02:00
|
|
|
|
|
|
|
|
$dossier_id = $request->get('d');
|
|
|
|
|
$sujet_id = $request->get('s');
|
|
|
|
|
$textSearch = $request->get('t');
|
|
|
|
|
$recherche_id = $request->get('r');
|
|
|
|
|
|
|
|
|
|
// ---- Recherche type texte
|
|
|
|
|
if($textSearch != "" && $sujet_id != ""){
|
|
|
|
|
// on créé un object filtre
|
|
|
|
|
$filters = (object) [
|
|
|
|
|
"search" => array(
|
|
|
|
|
'type' => "search",
|
|
|
|
|
'legend' => "Recherche : ",
|
|
|
|
|
'value'=> $textSearch,
|
|
|
|
|
'libelle' => array($textSearch),
|
|
|
|
|
)
|
|
|
|
|
];
|
|
|
|
|
$filters = json_encode($filters);
|
|
|
|
|
|
|
|
|
|
// ---- Recherche favorite
|
|
|
|
|
}elseif ($recherche_id != "") {
|
|
|
|
|
$recherche = Recherche::where('id', $recherche_id)->first();
|
|
|
|
|
if($recherche){
|
|
|
|
|
$filters = $recherche->filters;
|
|
|
|
|
$sujet_id = $recherche->sujet_id;
|
|
|
|
|
$dossier_id = $recherche->dossier_id;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2019-06-17 09:22:10 +02:00
|
|
|
return view('media_manager')->with([
|
|
|
|
|
'sujets'=> $sujets,
|
|
|
|
|
'typemedias'=> $typemedias,
|
|
|
|
|
'langues'=> $langues,
|
|
|
|
|
'copyrights'=> $copyrights,
|
|
|
|
|
'etiquettes'=> $etiquettes,
|
2019-06-25 16:17:56 +02:00
|
|
|
'sites'=> $sites,
|
2019-07-25 09:43:06 +02:00
|
|
|
'marques'=> $marques,
|
|
|
|
|
'currentFolder'=> $dossier_id,
|
|
|
|
|
'currentSujet'=> $sujet_id,
|
|
|
|
|
'currentFilters'=> $filters,
|
2019-07-31 12:22:24 +02:00
|
|
|
'paniers' => $paniers,
|
2019-06-17 09:22:10 +02:00
|
|
|
]);
|
2019-05-22 17:10:16 +02:00
|
|
|
}
|
|
|
|
|
|
2019-05-23 15:09:28 +02:00
|
|
|
/**
|
|
|
|
|
* Chargement des médias
|
|
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
|
public function loadMedia(Request $request)
|
|
|
|
|
{
|
|
|
|
|
$response = array();
|
2019-07-11 11:45:47 +02:00
|
|
|
$userId = Auth::user()->id;
|
2019-05-23 15:09:28 +02:00
|
|
|
$dossier_id = $request->input('dossier_id');
|
|
|
|
|
$sujet_id = $request->input('sujet_id');
|
2019-07-17 15:48:23 +02:00
|
|
|
$filters = json_decode($request->input('filters'));
|
2019-05-23 15:09:28 +02:00
|
|
|
$offset = $request->input('offset');
|
|
|
|
|
$limit = $request->input('limit');
|
2019-06-25 16:17:56 +02:00
|
|
|
$orderField = $request->input('orderField');
|
|
|
|
|
$order = $request->input('order');
|
2019-07-25 09:43:06 +02:00
|
|
|
$saveSearch = $request->input('saveSearch');
|
2019-07-17 15:48:23 +02:00
|
|
|
$isDepot = 0;
|
2019-05-23 15:09:28 +02:00
|
|
|
|
2019-07-17 15:48:23 +02:00
|
|
|
if($dossier_id == "0"){ // dossier racine
|
|
|
|
|
$query= Media::where('sujet_id', $sujet_id)
|
2019-07-22 14:54:42 +02:00
|
|
|
->whereNull('dossier_id')
|
|
|
|
|
->where(function ($query) use ( $userId ) {
|
2019-07-25 15:08:33 +02:00
|
|
|
$query->where('statut', config('services.statut.public_etendu'))
|
2019-07-22 14:54:42 +02:00
|
|
|
->orWhere('statut', config('services.statut.public'))
|
|
|
|
|
->orWhere('created_by', $userId);
|
|
|
|
|
});
|
|
|
|
|
}elseif($dossier_id == "-1"){ // recherche global
|
2019-07-17 15:48:23 +02:00
|
|
|
$query = Media::where('sujet_id', $sujet_id)
|
2019-07-11 11:45:47 +02:00
|
|
|
->where(function ($query) use ( $userId ) {
|
2019-07-25 15:08:33 +02:00
|
|
|
$query->where('statut', config('services.statut.public_etendu'))
|
2019-07-11 11:45:47 +02:00
|
|
|
->orWhere('created_by', $userId);
|
2019-07-17 15:48:23 +02:00
|
|
|
});
|
2019-05-23 15:09:28 +02:00
|
|
|
}else{
|
2019-07-17 15:48:23 +02:00
|
|
|
$dossier= Dossier::where('id', $dossier_id)->first();
|
|
|
|
|
if($dossier->parent_id != 1 && $dossier->id != 1){ // dossier classic
|
|
|
|
|
$query = Media::where('sujet_id', $sujet_id)
|
|
|
|
|
->where('dossier_id', $dossier_id)
|
|
|
|
|
->where(function ($query) use ( $userId ) {
|
2019-07-22 14:54:42 +02:00
|
|
|
$query->where('statut', '<>', config('services.statut.brouillon'))
|
2019-07-17 15:48:23 +02:00
|
|
|
->orWhere('created_by', $userId);
|
|
|
|
|
});
|
|
|
|
|
}else{ // dossier dépôt
|
|
|
|
|
$isDepot = 1;
|
|
|
|
|
$query= Media::where('dossier_id', $dossier_id);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Filtre recherche texte
|
|
|
|
|
if(property_exists($filters, 'search')){
|
|
|
|
|
$search = strtolower(trim($filters->search->value));
|
|
|
|
|
$query->where(function ($query) use ( $search ) {
|
|
|
|
|
$query->whereRaw("LCASE(libelle) LIKE '%".$search."%'")
|
|
|
|
|
->orWhere('arcadia_id', $search)
|
|
|
|
|
->orWhereHas("articles", function($query) use ($search){
|
|
|
|
|
$query->where("noArt", $search)
|
|
|
|
|
->orWhereRaw("LCASE(libCcial) LIKE '%".$search."%'")
|
|
|
|
|
->orWhereRaw("LCASE(libMarq) LIKE '%".$search."%'")
|
|
|
|
|
->orWhereRaw("LCASE(libFamVte) LIKE '%".$search."%'")
|
|
|
|
|
->orWhere('codGencodAdm', $search)
|
|
|
|
|
->orWhere('codGencodSymb', $search)
|
|
|
|
|
->orWhere('codGencodPds', $search);
|
|
|
|
|
})
|
|
|
|
|
->orWhereHas("tags", function($query) use ($search){
|
|
|
|
|
$query->WhereRaw("LCASE(libelle) LIKE '%".$search."%'");
|
|
|
|
|
});
|
|
|
|
|
});
|
2019-07-25 09:43:06 +02:00
|
|
|
|
|
|
|
|
// ---- Sauvegarde de la recherche utilisateur
|
|
|
|
|
if($saveSearch == 1){
|
|
|
|
|
$recherche = Recherche::where('libelle', $search)->first();
|
|
|
|
|
if($recherche){
|
|
|
|
|
$recherche->user_id = $userId;
|
|
|
|
|
$recherche->sujet_id = $sujet_id;
|
|
|
|
|
$recherche->dossier_id = $dossier_id;
|
|
|
|
|
$recherche->filters = json_encode($filters);
|
|
|
|
|
$recherche->save();
|
|
|
|
|
}else{
|
|
|
|
|
$recherche = new Recherche();
|
|
|
|
|
$recherche->user_id = $userId;
|
|
|
|
|
$recherche->sujet_id = $sujet_id;
|
|
|
|
|
$recherche->dossier_id = $dossier_id;
|
|
|
|
|
$recherche->filters = json_encode($filters);
|
|
|
|
|
$recherche->libelle = $search;
|
|
|
|
|
$recherche->save();
|
|
|
|
|
}
|
|
|
|
|
}
|
2019-06-17 09:22:10 +02:00
|
|
|
}
|
2019-07-17 15:48:23 +02:00
|
|
|
// Filtre type de média
|
|
|
|
|
if(property_exists($filters, 'typemedia_id')){
|
|
|
|
|
$query->whereIn('typemedia_id', $filters->typemedia_id->value);
|
|
|
|
|
}
|
|
|
|
|
// Filtre type de vue
|
|
|
|
|
if(property_exists($filters, 'typevue_id')){
|
|
|
|
|
$query->whereIn('typevue_id', $filters->typevue_id->value);
|
|
|
|
|
}
|
|
|
|
|
// Filtre liason avec Arcadia
|
|
|
|
|
if(property_exists($filters, 'arcadia_id')){
|
|
|
|
|
$query->whereNotNull('arcadia_id' );
|
|
|
|
|
}
|
|
|
|
|
// Filtre etiquette
|
|
|
|
|
if(property_exists($filters, 'etiquette_id')){
|
|
|
|
|
$query->whereIn('etiquette_id', $filters->etiquette_id->value);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$query->with('Etiquette')
|
|
|
|
|
->offset($offset)
|
|
|
|
|
->limit($limit)
|
|
|
|
|
->orderBy($orderField, $order);
|
|
|
|
|
$response['data'] = $query->get();
|
|
|
|
|
|
2019-06-17 09:22:10 +02:00
|
|
|
if(Auth::user()->hasRole([config('roles.const.ADMIN'), config('roles.const.REDACTEUR')] )){
|
|
|
|
|
$response['draggable'] = true;
|
|
|
|
|
}else{
|
|
|
|
|
$response['draggable'] = false;
|
2019-05-23 15:09:28 +02:00
|
|
|
}
|
2019-07-17 15:48:23 +02:00
|
|
|
$response['role'] = Auth::user()->role;
|
|
|
|
|
$response['isDepot'] = $isDepot;
|
2019-05-23 15:09:28 +02:00
|
|
|
|
|
|
|
|
return json_encode($response);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Déplacement des médias
|
|
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
|
public function moveMedia(Request $request)
|
|
|
|
|
{
|
2019-06-17 09:22:10 +02:00
|
|
|
Auth::user()->authorizeRoles([config('roles.const.ADMIN'), config('roles.const.REDACTEUR')]);
|
2019-07-22 14:54:42 +02:00
|
|
|
$response = false;
|
2019-05-23 15:09:28 +02:00
|
|
|
$dossier_id = $request->input('dossier_id');
|
|
|
|
|
$data = $request->input('data');
|
2019-07-17 15:48:23 +02:00
|
|
|
$sujet_id = $request->input('sujet_id');
|
2019-05-23 15:09:28 +02:00
|
|
|
$data = explode(",", $data);
|
2019-07-22 14:54:42 +02:00
|
|
|
$user_id = Auth::user()->id;
|
|
|
|
|
$libelle = "";
|
|
|
|
|
|
|
|
|
|
if($dossier_id > 0){
|
|
|
|
|
$dossier = Dossier::where('id', $dossier_id)->first();
|
|
|
|
|
if($dossier){
|
|
|
|
|
$libelle = $dossier->libelle;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-05-23 15:09:28 +02:00
|
|
|
foreach ($data as $key => $media_id) {
|
|
|
|
|
$media = Media::where('id', $media_id)->first();
|
|
|
|
|
if($media){
|
2019-07-22 14:54:42 +02:00
|
|
|
$historique = new historique();
|
|
|
|
|
$historique->user_id = $user_id;
|
|
|
|
|
$historique->media_id = $media->id;
|
|
|
|
|
$historique->type = "Déplacement";
|
|
|
|
|
|
2019-07-17 15:48:23 +02:00
|
|
|
$media->sujet_id = $sujet_id;
|
2019-05-23 15:09:28 +02:00
|
|
|
if($dossier_id > 0){
|
|
|
|
|
$media->dossier_id = $dossier_id;
|
2019-07-22 14:54:42 +02:00
|
|
|
$historique->description = "Déplacement dans le dossier ".$libelle;
|
2019-05-23 15:09:28 +02:00
|
|
|
}else{
|
|
|
|
|
$media->dossier_id = null;
|
2019-07-22 14:54:42 +02:00
|
|
|
$historique->description = "Média déplacé à la racine";
|
2019-05-23 15:09:28 +02:00
|
|
|
}
|
|
|
|
|
$media->save();
|
2019-07-22 14:54:42 +02:00
|
|
|
$historique->save();
|
2019-05-23 15:09:28 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-07-22 14:54:42 +02:00
|
|
|
return json_encode($response);
|
2019-05-23 15:09:28 +02:00
|
|
|
}
|
2019-05-22 17:10:16 +02:00
|
|
|
|
2019-06-17 09:22:10 +02:00
|
|
|
/**
|
|
|
|
|
* supprimer des médias
|
|
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
|
public function removeMedia(Request $request)
|
|
|
|
|
{
|
2019-07-11 11:45:47 +02:00
|
|
|
$deletedMediasList = array();
|
2019-06-17 09:22:10 +02:00
|
|
|
Auth::user()->authorizeRoles([config('roles.const.ADMIN'), config('roles.const.REDACTEUR')]);
|
2019-07-22 14:54:42 +02:00
|
|
|
$user_id = Auth::user()->id;
|
2019-07-11 11:45:47 +02:00
|
|
|
$deleteMedias = $request->input('medias');
|
2019-06-17 09:22:10 +02:00
|
|
|
|
2019-07-11 11:45:47 +02:00
|
|
|
$medias = Media::whereIn('id', $deleteMedias)->whereNull('arcadia_id')->get();
|
|
|
|
|
foreach ($medias as $media) {
|
|
|
|
|
$deletedMediasList[] = $media->id;
|
2019-07-22 14:54:42 +02:00
|
|
|
|
|
|
|
|
// Historique des actions
|
|
|
|
|
$historique = new historique();
|
|
|
|
|
$historique->user_id =$user_id;
|
|
|
|
|
$historique->media_id = $media->id;
|
|
|
|
|
$historique->type = "Suppression";
|
|
|
|
|
$historique->description = "Le média a été supprimé";
|
|
|
|
|
$historique->save();
|
|
|
|
|
|
2019-07-11 11:45:47 +02:00
|
|
|
$media->delete();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return json_encode($deletedMediasList);
|
2019-06-17 09:22:10 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Obtenir toutes les informations d'un média
|
|
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
|
public function getOneMedia(Request $request)
|
|
|
|
|
{
|
2019-07-11 11:45:47 +02:00
|
|
|
$host = $request->getSchemeAndHttpHost();
|
2019-06-17 09:22:10 +02:00
|
|
|
$response = array();
|
|
|
|
|
$media_id = $request->input('media_id');
|
2019-07-11 11:45:47 +02:00
|
|
|
$media = Media::where('id', $media_id)->with('sujet')->with('sites')->with('marques')->with('articles')->with('tags:libelle')->first();
|
2019-06-17 09:22:10 +02:00
|
|
|
if($media){
|
2019-07-11 11:45:47 +02:00
|
|
|
// stock le média
|
2019-06-17 09:22:10 +02:00
|
|
|
$response['data'] = $media;
|
2019-07-11 11:45:47 +02:00
|
|
|
// stock les tags
|
2019-06-25 16:17:56 +02:00
|
|
|
foreach ($media->tags as $tag) {
|
|
|
|
|
$response['tags'][] = $tag->libelle;
|
|
|
|
|
}
|
2019-07-11 11:45:47 +02:00
|
|
|
// stock les vignettes existantes
|
|
|
|
|
$files = Storage::files($media->folder."/");
|
|
|
|
|
$filepath = preg_quote($media->folder.$media->uid, '/');
|
|
|
|
|
$matchingFiles = preg_grep('/^'.$filepath.'/', $files);
|
|
|
|
|
foreach ($matchingFiles as $matchingFile) {
|
|
|
|
|
$path_parts = pathinfo($matchingFile);
|
|
|
|
|
$fileInfo = array();
|
|
|
|
|
$fileInfo['url'] = $host."/".$matchingFile;
|
|
|
|
|
$fileInfo['libelle'] = $path_parts['filename'];
|
2019-07-17 15:48:23 +02:00
|
|
|
$fileInfo['extension'] = $path_parts['extension'];
|
|
|
|
|
$fileInfo['resolution'] = "";
|
|
|
|
|
|
|
|
|
|
if(in_array($path_parts['extension'], array("gif", "jpeg", "jpg", "png", "pdf", "ai", "psd")) ){
|
|
|
|
|
$im = new \imagick($matchingFile);
|
|
|
|
|
$im->setIteratorIndex(0);
|
|
|
|
|
$imageprops = $im->getImageGeometry();
|
|
|
|
|
$fileInfo['resolution'] = $imageprops['width']."x".$imageprops['height']."px";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2019-07-11 11:45:47 +02:00
|
|
|
if(strpos($fileInfo['libelle'], '_')){
|
|
|
|
|
$fileInfo['libelle'] = "Format ".substr($fileInfo['libelle'], strpos($fileInfo['libelle'], '_')+1);
|
|
|
|
|
}else{
|
|
|
|
|
$fileInfo['libelle'] = "Format original";
|
|
|
|
|
}
|
|
|
|
|
$response['vignettes'][] = $fileInfo;
|
|
|
|
|
}
|
2019-06-17 09:22:10 +02:00
|
|
|
}
|
2019-06-25 16:17:56 +02:00
|
|
|
|
2019-06-17 09:22:10 +02:00
|
|
|
return json_encode($response);
|
|
|
|
|
}
|
|
|
|
|
|
2019-06-25 16:17:56 +02:00
|
|
|
/**
|
|
|
|
|
* Sauvegarde toutes les informations d'un média
|
|
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
|
public function saveMedia(Request $request)
|
|
|
|
|
{
|
|
|
|
|
Auth::user()->authorizeRoles([config('roles.const.ADMIN'), config('roles.const.REDACTEUR'), config('roles.const.CONTRIBUTEUR')]);
|
2019-07-22 14:54:42 +02:00
|
|
|
$user_id = Auth::user()->id;
|
2019-06-25 16:17:56 +02:00
|
|
|
$response = array();
|
2019-07-11 11:45:47 +02:00
|
|
|
$mediaUpdate = (object) $request->input('media');
|
|
|
|
|
|
|
|
|
|
$media = Media::where('id', $mediaUpdate->id)->first();
|
|
|
|
|
if($media){
|
|
|
|
|
$media->libelle = $mediaUpdate->libelle;
|
|
|
|
|
$media->typevue_id = $mediaUpdate->typevue_id;
|
|
|
|
|
$media->variante_id = $mediaUpdate->variante_id;
|
|
|
|
|
$media->langue_id = $mediaUpdate->langue_id;
|
|
|
|
|
$media->commentaire = $mediaUpdate->commentaire;
|
|
|
|
|
$media->version = $mediaUpdate->version;
|
2019-08-06 14:18:36 +02:00
|
|
|
$media->published_at = $mediaUpdate->published_at;
|
2019-07-11 11:45:47 +02:00
|
|
|
$media->statut = $mediaUpdate->statut;
|
|
|
|
|
$media->copyright_id = $mediaUpdate->copyright_id;
|
2019-07-22 14:54:42 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
// ---- Historique des actions (etiquette seulement)
|
|
|
|
|
if($media->etiquette_id != $mediaUpdate->etiquette_id){
|
|
|
|
|
$curEtiquette = Etiquette::where('etiquette_id', $media->etiquette_id)->first();
|
|
|
|
|
$newEtiquette = Etiquette::where('etiquette_id', $mediaUpdate->etiquette_id)->first();
|
|
|
|
|
$historique = new historique();
|
|
|
|
|
$historique->user_id = $user_id;
|
|
|
|
|
$historique->media_id = $media->id;
|
|
|
|
|
$historique->type = "Etiquette";
|
|
|
|
|
$historique->description = $curEtiquette->libelle." -> ".$newEtiquette->libelle;
|
|
|
|
|
$historique->save();
|
|
|
|
|
$media->etiquette_id = $mediaUpdate->etiquette_id;
|
|
|
|
|
}
|
|
|
|
|
|
2019-07-11 11:45:47 +02:00
|
|
|
$media->save();
|
|
|
|
|
|
|
|
|
|
// MAJ des tags
|
|
|
|
|
$media->tags()->detach();
|
|
|
|
|
if(isset($mediaUpdate->tags)){
|
|
|
|
|
foreach($mediaUpdate->tags as $tag){
|
|
|
|
|
$oTag = Tag::where('libelle', $tag)->first();
|
|
|
|
|
if(!$oTag){
|
|
|
|
|
$oTag = new Tag();
|
|
|
|
|
$oTag->libelle = $tag;
|
|
|
|
|
$oTag->save();
|
|
|
|
|
}
|
|
|
|
|
$media->tags()->attach($oTag->id);
|
|
|
|
|
}
|
|
|
|
|
}
|
2019-06-25 16:17:56 +02:00
|
|
|
|
|
|
|
|
|
2019-07-11 11:45:47 +02:00
|
|
|
// ---- Les sites
|
|
|
|
|
$media->sites()->detach();
|
|
|
|
|
$sSites = $mediaUpdate->sites;
|
|
|
|
|
if($sSites != ""){
|
|
|
|
|
$sites = explode(",", $sSites);
|
|
|
|
|
foreach($sites as $siteId){
|
|
|
|
|
$media->sites()->attach($siteId);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// ---- Les marques
|
|
|
|
|
$media->marques()->detach();
|
|
|
|
|
$sMarques = $mediaUpdate->marques;
|
|
|
|
|
if($sMarques != ""){
|
|
|
|
|
$marques = explode(",", $sMarques);
|
|
|
|
|
foreach($marques as $marqueId){
|
|
|
|
|
$media->marques()->attach($marqueId);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// ---- Les articles
|
|
|
|
|
$media->articles()->detach();
|
|
|
|
|
$sArticles = $mediaUpdate->articles;
|
|
|
|
|
if($sArticles){
|
|
|
|
|
$articles = explode(",", $sArticles);
|
|
|
|
|
foreach($articles as $articleId){
|
|
|
|
|
$media->articles()->attach($articleId);
|
|
|
|
|
}
|
|
|
|
|
}
|
2019-07-22 14:54:42 +02:00
|
|
|
|
|
|
|
|
// ---- Historique des actions
|
|
|
|
|
$historique = new historique();
|
|
|
|
|
$historique->user_id = $user_id;
|
|
|
|
|
$historique->media_id = $media->id;
|
|
|
|
|
$historique->type = "Modification";
|
|
|
|
|
$historique->description = "Les informations du média on été modificées";
|
|
|
|
|
$historique->save();
|
|
|
|
|
|
2019-07-11 11:45:47 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$response = true;
|
2019-06-25 16:17:56 +02:00
|
|
|
return json_encode($response);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Sauvegarde toutes les informations d'un média
|
|
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
|
public function applySticker(Request $request)
|
|
|
|
|
{
|
|
|
|
|
Auth::user()->authorizeRoles([config('roles.const.ADMIN'), config('roles.const.REDACTEUR'), config('roles.const.CONTRIBUTEUR')]);
|
|
|
|
|
$response = array();
|
|
|
|
|
$medias = $request->input('medias');
|
|
|
|
|
$etiquette_id = $request->input('etiquette_id');
|
2019-07-22 14:54:42 +02:00
|
|
|
$user_id = Auth::user()->id;
|
2019-06-25 16:17:56 +02:00
|
|
|
|
|
|
|
|
$etiquette = Etiquette::where('etiquette_id', $etiquette_id)->first();
|
|
|
|
|
$response = $etiquette;
|
|
|
|
|
if($etiquette){
|
|
|
|
|
foreach ($medias as $media_id) {
|
|
|
|
|
$media = Media::where('id', $media_id)->first();
|
|
|
|
|
if($media){
|
2019-07-22 14:54:42 +02:00
|
|
|
// ---- Historique des actions
|
|
|
|
|
$curEtiquette = Etiquette::where('etiquette_id', $media->etiquette_id)->first();
|
|
|
|
|
$historique = new historique();
|
|
|
|
|
$historique->user_id = $user_id;
|
|
|
|
|
$historique->media_id = $media->id;
|
|
|
|
|
$historique->type = "Etiquette";
|
|
|
|
|
$historique->description = $curEtiquette->libelle." -> ".$etiquette->libelle;
|
|
|
|
|
$historique->save();
|
|
|
|
|
|
|
|
|
|
// ---- Sauvegarde de la nouvelle étiquette
|
2019-06-25 16:17:56 +02:00
|
|
|
$media->etiquette_id = $etiquette_id;
|
|
|
|
|
$media->save();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return json_encode($response);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Sauvegarde une retouche photo
|
|
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
|
public function editPhoto(Request $request)
|
|
|
|
|
{
|
|
|
|
|
Auth::user()->authorizeRoles([config('roles.const.ADMIN'), config('roles.const.REDACTEUR'), config('roles.const.CONTRIBUTEUR')]);
|
|
|
|
|
$response = array();
|
|
|
|
|
$media_id = $request->input('media_id');
|
2019-07-23 16:13:52 +02:00
|
|
|
$cropData = $request->input('cropData');
|
2019-06-25 16:17:56 +02:00
|
|
|
|
|
|
|
|
$media = Media::where('id', $media_id)->first();
|
|
|
|
|
if($media){
|
2019-07-11 11:45:47 +02:00
|
|
|
$mediaPath = $media->folder.$media->uid.".".$media->extension;
|
2019-07-23 16:13:52 +02:00
|
|
|
|
|
|
|
|
$im = new \imagick($mediaPath);
|
|
|
|
|
$im->setImageUnits(\imagick::RESOLUTION_PIXELSPERINCH);
|
|
|
|
|
$im->setImageFormat($media->extension);
|
|
|
|
|
list($top , $left , $width, $height) = $cropData;
|
|
|
|
|
|
|
|
|
|
$left = round($left * $media->largeur);
|
|
|
|
|
$top = round($top * $media->hauteur);
|
|
|
|
|
$width = round(min($width * $media->largeur, $media->largeur - $left));
|
|
|
|
|
$height = round(min($height * $media->hauteur, $media->hauteur - $top));
|
|
|
|
|
|
|
|
|
|
$im->setImagePage(0, 0, 0, 0);
|
|
|
|
|
$im->setImageResolution($media->resolution, $media->resolution);
|
|
|
|
|
$im->cropImage($width, $height, $left, $top);
|
|
|
|
|
Storage::put($mediaPath, $im->getImageBlob());
|
|
|
|
|
$im->destroy();
|
2019-07-11 11:45:47 +02:00
|
|
|
|
|
|
|
|
$im = new \imagick($mediaPath);
|
|
|
|
|
$imageprops = $im->getImageGeometry();
|
|
|
|
|
$media->largeur = $imageprops['width'];
|
|
|
|
|
$media->hauteur = $imageprops['height'];
|
2019-07-23 16:13:52 +02:00
|
|
|
|
2019-07-11 11:45:47 +02:00
|
|
|
$resolutions = $im->getImageResolution();
|
2019-07-23 16:13:52 +02:00
|
|
|
$media->resolution = round($resolutions['x'] * 2.54, 2);
|
2019-07-11 11:45:47 +02:00
|
|
|
if($media->resolution != 0){
|
|
|
|
|
$media->largeur_mm = ceil(($media->largeur * 2.54 / $media->resolution)*10);
|
|
|
|
|
$media->hauteur_mm = ceil(($media->hauteur * 2.54 / $media->resolution)*10);
|
|
|
|
|
}else{
|
|
|
|
|
$media->largeur_mm = "";
|
|
|
|
|
$media->hauteur_mm = "";
|
|
|
|
|
}
|
|
|
|
|
$media->taille = $this->formatBytes($this->get_file_size($mediaPath));
|
|
|
|
|
$media->save();
|
|
|
|
|
|
2019-07-22 14:54:42 +02:00
|
|
|
$historique = new historique();
|
|
|
|
|
$historique->user_id = Auth::user()->id;;
|
|
|
|
|
$historique->media_id = $media->id;
|
|
|
|
|
$historique->type = "Retouche";
|
|
|
|
|
$historique->description = "Retouche de l'image";
|
|
|
|
|
$historique->save();
|
|
|
|
|
|
2019-07-11 11:45:47 +02:00
|
|
|
// Regénération des miniatures de base
|
|
|
|
|
$this->create_sys_thumb($media);
|
|
|
|
|
// ---- Creation des vignettes en lien avec le sujet du média
|
|
|
|
|
$this->create_thumb($media);
|
2019-06-25 16:17:56 +02:00
|
|
|
$response = $media;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return json_encode($response);
|
|
|
|
|
}
|
2019-07-11 11:45:47 +02:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Applique un Id Arcadia à un média
|
|
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
|
public function setIdArcdadia(Request $request)
|
|
|
|
|
{
|
|
|
|
|
Auth::user()->authorizeRoles([config('roles.const.ADMIN')]);
|
|
|
|
|
$response = false;
|
|
|
|
|
$media_id = $request->input('media_id');
|
|
|
|
|
$arcadia_id = $request->input('arcadia_id');
|
2019-07-22 14:54:42 +02:00
|
|
|
|
|
|
|
|
$historique = new historique();
|
|
|
|
|
$historique->user_id = Auth::user()->id;
|
|
|
|
|
$historique->media_id = $media_id;
|
|
|
|
|
$historique->type = "Modification";
|
|
|
|
|
|
2019-07-17 15:48:23 +02:00
|
|
|
if($arcadia_id == "" || $arcadia_id == 0){
|
|
|
|
|
$arcadia_id = NULL;
|
2019-07-22 14:54:42 +02:00
|
|
|
$historique->description = "Suppression de la référence Arcadia";
|
2019-07-17 15:48:23 +02:00
|
|
|
}else{
|
2019-07-22 14:54:42 +02:00
|
|
|
$historique->description = "Ajout de la référence Arcadia ".$arcadia_id;
|
2019-07-17 15:48:23 +02:00
|
|
|
$media = Media::where('arcadia_id', $arcadia_id)->first();
|
|
|
|
|
if($media) return json_encode($response);
|
|
|
|
|
}
|
2019-07-11 11:45:47 +02:00
|
|
|
|
|
|
|
|
$media = Media::where('id', $media_id)->first();
|
|
|
|
|
if($media){
|
|
|
|
|
$media->arcadia_id = $arcadia_id;
|
|
|
|
|
$media->save();
|
|
|
|
|
$response = true;
|
2019-07-22 14:54:42 +02:00
|
|
|
$historique->save();
|
2019-07-11 11:45:47 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return json_encode($response);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Renvoie un article par ID Arcadia
|
|
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
|
public function getArticle(Request $request)
|
|
|
|
|
{
|
2019-07-22 14:54:42 +02:00
|
|
|
if(!$user = Auth::user()) abort(401, 'Cette action n\'est pas autorisée.');
|
2019-07-11 11:45:47 +02:00
|
|
|
$response = array();
|
|
|
|
|
$arcadia_id = $request->input('arcadia_id');
|
|
|
|
|
|
|
|
|
|
$article = Article::where('noArt', $arcadia_id)->first();
|
|
|
|
|
if($article){
|
|
|
|
|
$response['article'] = $article;
|
|
|
|
|
}else{
|
|
|
|
|
$response = false;
|
|
|
|
|
}
|
|
|
|
|
return json_encode($response);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2019-07-22 14:54:42 +02:00
|
|
|
* Téléchargement des médias
|
2019-07-11 11:45:47 +02:00
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
|
public function downloadMedia(Request $request)
|
|
|
|
|
{
|
|
|
|
|
if(!$user = Auth::user()) abort(404, 'Erreur lors du téléchargement');
|
2019-07-17 15:48:23 +02:00
|
|
|
$deleteFileAfterSend = false;
|
2019-07-11 11:45:47 +02:00
|
|
|
// obtention du format
|
|
|
|
|
$formatId = $request->input('format');
|
|
|
|
|
if($formatId != 0){
|
|
|
|
|
$format = Format::withoutGlobalScope('App\Scopes\SystemScope')->where('id', $formatId)->first();
|
|
|
|
|
if(!$format) abort(404, 'Erreur lors du téléchargement');
|
|
|
|
|
}else{
|
|
|
|
|
$format = "";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$mediasId = $request->input('medias');
|
|
|
|
|
$medias = explode(",", $mediasId);
|
|
|
|
|
if(sizeof($medias) == 1){
|
|
|
|
|
$media = Media::where('id', $mediasId)->first();
|
|
|
|
|
if($media){
|
|
|
|
|
$fp = $this->get_mediaPath($media, $format);
|
|
|
|
|
}
|
|
|
|
|
}else{
|
|
|
|
|
// create zip archive
|
|
|
|
|
$zip_file = public_path() . '/uploads/DAM_'.uniqid().'_'.date("Ymd").'.zip';
|
|
|
|
|
$zip = new \ZipArchive();
|
|
|
|
|
$zip->open($zip_file, \ZipArchive::CREATE | \ZipArchive::OVERWRITE);
|
|
|
|
|
|
|
|
|
|
// add file to archive
|
|
|
|
|
foreach ($medias as $mediaId) {
|
|
|
|
|
$media = Media::where('id', $mediaId)->first();
|
|
|
|
|
if($media){
|
|
|
|
|
$fp = $this->get_mediaPath($media, $format);
|
|
|
|
|
$zip->addFile($fp, basename($fp));
|
|
|
|
|
}
|
|
|
|
|
}
|
2019-07-17 15:48:23 +02:00
|
|
|
$deleteFileAfterSend = true;
|
2019-07-11 11:45:47 +02:00
|
|
|
$zip->close();
|
|
|
|
|
$fp = $zip_file;
|
|
|
|
|
}
|
2019-07-17 15:48:23 +02:00
|
|
|
return response()->download($fp)->deleteFileAfterSend($deleteFileAfterSend);
|
2019-07-11 11:45:47 +02:00
|
|
|
}
|
|
|
|
|
|
2019-07-22 14:54:42 +02:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Renvoie l'historique des actions d'un média
|
|
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
|
public function getMediaHistory(Request $request)
|
|
|
|
|
{
|
|
|
|
|
$response = array();
|
|
|
|
|
if(!$user = Auth::user()) abort(401, 'Cette action n\'est pas autorisée.');
|
|
|
|
|
$media_id = $request->input('media_id');
|
|
|
|
|
|
|
|
|
|
$media = Historique::where('media_id', $media_id)->with('user')->orderBy("created_date", "DESC")->get();
|
|
|
|
|
$response = $media;
|
|
|
|
|
return json_encode($response);
|
|
|
|
|
}
|
|
|
|
|
|
2019-08-06 14:18:36 +02:00
|
|
|
/**
|
|
|
|
|
* Ajoute un média sans fichier
|
|
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
|
public function addMedia(Request $request)
|
|
|
|
|
{
|
|
|
|
|
$response = false;
|
|
|
|
|
$sujet_id = $request->input('sujet_id');
|
|
|
|
|
$dossier_id = $request->input('dossier_id');
|
|
|
|
|
if($dossier_id == 0) $dossier_id = NULL;
|
|
|
|
|
|
|
|
|
|
// On déplace le média par défaut dans le répertoire des médias
|
|
|
|
|
$destinationPath = $this->get_mediaFolder()."/";
|
|
|
|
|
$uid = sprintf('%04x%04x-%04x-%04x-%04x-%04x%04x%04x', mt_rand(0, 0xffff), mt_rand(0, 0xffff), mt_rand(0, 0xffff), mt_rand(0, 0x0fff) | 0x4000, mt_rand(0, 0x3fff) | 0x8000, mt_rand(0, 0xffff), mt_rand(0, 0xffff), mt_rand(0, 0xffff));
|
|
|
|
|
$filename = $uid.".jpg";
|
|
|
|
|
Storage::copy("images/default.jpg", $destinationPath.$filename);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// on créé un média en bdd
|
|
|
|
|
$media = new Media();
|
|
|
|
|
$media->dossier_id = $dossier_id;
|
|
|
|
|
$media->sujet_id = $sujet_id;
|
|
|
|
|
$media->libelle = "Nouveau média";
|
|
|
|
|
$media->folder = $destinationPath;
|
|
|
|
|
$media->taille = $this->formatBytes($this->get_file_size($destinationPath.$filename));
|
|
|
|
|
if($user = Auth::user()){
|
|
|
|
|
$media->created_by= $user->id;
|
|
|
|
|
}
|
|
|
|
|
$media->uid = $uid;
|
|
|
|
|
$media->extension = "jpg";
|
|
|
|
|
$media->typemedia_id = 1;
|
|
|
|
|
$im = new \imagick($destinationPath.$filename);
|
|
|
|
|
$resolutions = $im->getImageResolution();
|
|
|
|
|
$media->resolution = round($resolutions['x'] * 2.54, 2);
|
|
|
|
|
$imageprops = $im->getImageGeometry();
|
|
|
|
|
$media->largeur = $imageprops['width'];
|
|
|
|
|
$media->hauteur = $imageprops['height'];
|
|
|
|
|
|
|
|
|
|
if($media->resolution != 0){
|
|
|
|
|
$media->largeur_mm = ceil(($media->largeur * 2.54 / $media->resolution)*10);
|
|
|
|
|
$media->hauteur_mm = ceil(($media->hauteur * 2.54 / $media->resolution)*10);
|
|
|
|
|
}else{
|
|
|
|
|
$media->largeur_mm = "";
|
|
|
|
|
$media->hauteur_mm = "";
|
|
|
|
|
}
|
|
|
|
|
$media->save();
|
|
|
|
|
$response = $media;
|
|
|
|
|
$im->destroy();
|
|
|
|
|
|
|
|
|
|
// ---- Creation des vignettes de base
|
|
|
|
|
$this->create_sys_thumb($media);
|
|
|
|
|
// ---- Creation des vignettes en lien avec le sujet du média
|
|
|
|
|
if(isset($sujet_id) ){
|
|
|
|
|
$this->create_thumb($media);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// ---- Historique des actions
|
|
|
|
|
$historique = new historique();
|
|
|
|
|
if($user = Auth::user()){
|
|
|
|
|
$historique->user_id = $user->id;
|
|
|
|
|
}
|
|
|
|
|
$historique->media_id = $media->id;
|
|
|
|
|
$historique->type = "Création";
|
|
|
|
|
$historique->description = "Média ajouté";
|
|
|
|
|
$historique->save();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return json_encode($response);
|
|
|
|
|
}
|
2019-05-22 17:10:16 +02:00
|
|
|
}
|