Initial import
This commit is contained in:
@@ -0,0 +1,110 @@
|
||||
<?php
|
||||
|
||||
|
||||
namespace app\widgets\services;
|
||||
|
||||
|
||||
class Image
|
||||
{
|
||||
public function crateThumb($media_key, $object_key, $file_name, $file_type, $temp)
|
||||
{
|
||||
$file_dest = $this->getFileDest($media_key, $object_key, $file_name, 'thumb');
|
||||
$this->scaleImage($temp, $file_type, $file_dest, 0.3, 50);
|
||||
}
|
||||
|
||||
public function createCrop($crop, $file, $media_key, $object_key)
|
||||
{
|
||||
$file_dest = $this->getFileDest($media_key, $object_key, $file['name'], $crop);
|
||||
$this->scaleImage($file['tmp_name'], $file['type'], $file_dest, 0.7, 55);
|
||||
}
|
||||
|
||||
private function getFileDest($media_key, $object_key, $file_name, $last_dir)
|
||||
{
|
||||
$dir_ready = $_SERVER['DOCUMENT_ROOT'] . '/_files/ready';
|
||||
$dir_media = $_SERVER['DOCUMENT_ROOT'] . '/_files/ready/' . $media_key;
|
||||
$dir_object = $_SERVER['DOCUMENT_ROOT'] . '/_files/ready/' . $media_key . '/' . $object_key;
|
||||
$dir_last = "$dir_object/$last_dir";
|
||||
$file_dest = "$dir_last/$file_name";
|
||||
if (!file_exists($dir_ready))
|
||||
mkdir($dir_ready, 0777);
|
||||
if (!file_exists($dir_media))
|
||||
mkdir($dir_media, 0777);
|
||||
if (!file_exists($dir_object))
|
||||
mkdir($dir_object, 0777);
|
||||
if (!file_exists($dir_last))
|
||||
mkdir($dir_last, 0777);
|
||||
return $file_dest;
|
||||
}
|
||||
|
||||
|
||||
private function cropImage($file, $file_type, $destination, $thumb_width = 0, $thumb_height = 0, $quality = 100)
|
||||
{
|
||||
switch ($file_type) {
|
||||
case 'image/jpg':
|
||||
case 'image/jpeg':
|
||||
$image = imagecreatefromjpeg($file);
|
||||
break;
|
||||
case 'image/png':
|
||||
$image = imagecreatefrompng($file);
|
||||
$quality = 9;
|
||||
break;
|
||||
default:
|
||||
echo json_encode(['error', 'Unsupported file format: ' . $file_type]);
|
||||
exit;
|
||||
}
|
||||
|
||||
$width = imagesx($image);
|
||||
$height = imagesy($image);
|
||||
$original_aspect = $width / $height;
|
||||
$thumb_aspect = $thumb_width / $thumb_height;
|
||||
if ($original_aspect >= $thumb_aspect) {
|
||||
$new_height = $thumb_height;
|
||||
$new_width = $width / ($height / $thumb_height);
|
||||
} else {
|
||||
$new_width = $thumb_width;
|
||||
$new_height = $height / ($width / $thumb_width);
|
||||
}
|
||||
$thumb = imagecreatetruecolor($thumb_width, $thumb_height);
|
||||
imagecopyresampled($thumb,
|
||||
$image,
|
||||
0 - ($new_width - $thumb_width) / 2,
|
||||
0 - ($new_height - $thumb_height) / 2,
|
||||
0, 0,
|
||||
$new_width, $new_height,
|
||||
$width, $height);
|
||||
if ($file_type == 'image/png') {
|
||||
imagealphablending($thumb, false);
|
||||
imagesavealpha($thumb, true);
|
||||
imagepng($thumb, $destination, $quality);
|
||||
} else {
|
||||
imagejpeg($thumb, $destination, $quality);
|
||||
}
|
||||
}
|
||||
|
||||
private function scaleImage($file, $file_type, $destination, $scale, $quality)
|
||||
{
|
||||
switch ($file_type) {
|
||||
case 'image/jpg':
|
||||
case 'image/jpeg':
|
||||
$image = imagecreatefromjpeg($file);
|
||||
break;
|
||||
case 'image/png':
|
||||
$image = imagecreatefrompng($file);
|
||||
$quality = 9;
|
||||
break;
|
||||
default:
|
||||
echo json_encode(['error', 'Unsupported file format: ' . $file_type]);
|
||||
exit;
|
||||
}
|
||||
|
||||
list($width, $height) = getimagesize($file);
|
||||
$scaledImage = imagescale($image, ($width * $scale), ($height * $scale));
|
||||
if ($file_type == 'image/png') {
|
||||
imagealphablending($scaledImage, false);
|
||||
imagesavealpha($scaledImage, true);
|
||||
imagepng($scaledImage, $destination, $quality);
|
||||
} else {
|
||||
imagejpeg($scaledImage, $destination, $quality);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
<?php
|
||||
|
||||
|
||||
namespace app\widgets\services;
|
||||
|
||||
|
||||
class Includes
|
||||
{
|
||||
public static function top($title, $data = [], $title_edit = null)
|
||||
{
|
||||
echo \Yii::$app->view->render('/../widgets/views/includes/top', [
|
||||
'title' => $title,
|
||||
'title_edit' => $title_edit,
|
||||
'data' => $data
|
||||
]);
|
||||
}
|
||||
|
||||
public static function wl($tabs = [])
|
||||
{
|
||||
echo \Yii::$app->view->render('/../widgets/views/includes/wl', ['tabs' => $tabs]);
|
||||
}
|
||||
|
||||
public static function setTabs($tabs = [])
|
||||
{
|
||||
echo \Yii::$app->view->render('/../widgets/views/includes/tabs', ['tabs' => $tabs]);
|
||||
}
|
||||
|
||||
public static function setListTabs($listTabs = []) {
|
||||
echo \Yii::$app->view->render('/../widgets/views/includes/listtabs', ['tabs' => $listTabs]);
|
||||
}
|
||||
|
||||
public static function formButtons($list_url)
|
||||
{
|
||||
return \Yii::$app->view->render('/../widgets/views/includes/fbuttons', [
|
||||
'list_url' => $list_url
|
||||
]);
|
||||
}
|
||||
|
||||
public static function inLocales($tab)
|
||||
{
|
||||
$locales = ['ts_en'];
|
||||
return in_array($tab, $locales);
|
||||
}
|
||||
|
||||
public static function tab($tab)
|
||||
{
|
||||
if (self::inLocales($tab))
|
||||
return 'ts';
|
||||
return $tab;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,65 @@
|
||||
<?php
|
||||
|
||||
|
||||
namespace app\widgets\services;
|
||||
|
||||
|
||||
use app\services\Auth;
|
||||
|
||||
class UserRight
|
||||
{
|
||||
/** @var \app\models\UserPartner */
|
||||
public static $partner;
|
||||
|
||||
public static function add()
|
||||
{
|
||||
if (self::$partner) {
|
||||
if (!self::$partner->getRightsIds(1)) return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public static function edit()
|
||||
{
|
||||
if (self::$partner) {
|
||||
if (!self::$partner->getRightsIds(2)) return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public static function del()
|
||||
{
|
||||
if (self::$partner) {
|
||||
if (!self::$partner->getRightsIds(4)) return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public static function pub()
|
||||
{
|
||||
if (self::$partner) {
|
||||
if (!self::$partner->getRightsIds(5)) return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public static function isAdmin()
|
||||
{
|
||||
if (self::$partner)
|
||||
if (self::$partner->role_id != 1) return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
public static function getPartner()
|
||||
{
|
||||
if (self::$partner)
|
||||
return self::$partner->id;
|
||||
}
|
||||
|
||||
public static function setPartner($partner)
|
||||
{
|
||||
if ($partner) {
|
||||
self::$partner = $partner;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
<?php
|
||||
/**
|
||||
* Created by PhpStorm.
|
||||
* User: W10
|
||||
* Date: 2/17/2021
|
||||
* Time: 3:24 PM
|
||||
*/
|
||||
|
||||
namespace app\widgets\services;
|
||||
|
||||
|
||||
use app\extensions\simplex\SimpleXLSX;
|
||||
use app\extensions\XLSXWriter;
|
||||
use app\extensions\XLSXReader;
|
||||
|
||||
class XLSx
|
||||
{
|
||||
public static function toXlsWriter($data, $fileName, $sheet, $header)
|
||||
{
|
||||
$headerRow = [];
|
||||
foreach ($header as $headerTitle => $headerElement) $headerRow[] = $headerTitle;
|
||||
|
||||
$filename = $fileName . '.csv';
|
||||
header('Content-Type: text/csv');
|
||||
header('Content-Disposition: attachment; filename="' . $filename . '"');
|
||||
$dataAsString = implode(';', $headerRow) . "\r\n";
|
||||
foreach ($data as $row) {
|
||||
$dataAsString .= implode(';', $row) . "\r\n";
|
||||
}
|
||||
echo $dataAsString;
|
||||
exit;
|
||||
}
|
||||
|
||||
|
||||
public static function toArrayWriter($targetFile, $sheet)
|
||||
{
|
||||
try {
|
||||
$xlsx = new XLSXReader($targetFile);
|
||||
return $xlsx->getSheetData($sheet);
|
||||
} catch (\Exception $e) {
|
||||
return ['error' => 'The Sheet not exists in this file'];
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user