user photo add
This commit is contained in:
parent
2790105a7d
commit
b5b7befd34
@ -36,7 +36,9 @@ class FileUpload
|
|||||||
$newFileName = md5(time() . $this->fileName) . '.' . $this->fileExtension;
|
$newFileName = md5(time() . $this->fileName) . '.' . $this->fileExtension;
|
||||||
if (in_array($this->fileExtension, $this->allowedFileExtensions)) {
|
if (in_array($this->fileExtension, $this->allowedFileExtensions)) {
|
||||||
$this->uploadDir = $uploadDir . mb_substr($newFileName, 0, 2) . '/' . mb_substr($newFileName, 2, 2) . '/';
|
$this->uploadDir = $uploadDir . mb_substr($newFileName, 0, 2) . '/' . mb_substr($newFileName, 2, 2) . '/';
|
||||||
mkdir(ROOT_DIR . $this->uploadDir, 0777, true);
|
$oldMask = umask(0);
|
||||||
|
mkdir(ROOT_DIR . $this->uploadDir, 0775, true);
|
||||||
|
umask($oldMask);
|
||||||
$uploadFileDir = ROOT_DIR . $this->uploadDir;
|
$uploadFileDir = ROOT_DIR . $this->uploadDir;
|
||||||
$this->destPath = $uploadFileDir . $newFileName;
|
$this->destPath = $uploadFileDir . $newFileName;
|
||||||
$this->uploadFile = $this->uploadDir . $newFileName;
|
$this->uploadFile = $this->uploadDir . $newFileName;
|
||||||
@ -49,7 +51,9 @@ class FileUpload
|
|||||||
} else {
|
} else {
|
||||||
if (in_array($this->fileExtension, $this->allowedFileExtensions)) {
|
if (in_array($this->fileExtension, $this->allowedFileExtensions)) {
|
||||||
$this->uploadDir = $uploadDir;
|
$this->uploadDir = $uploadDir;
|
||||||
mkdir(ROOT_DIR . $this->uploadDir, 0777, true);
|
$oldMask = umask(0);
|
||||||
|
mkdir(ROOT_DIR . $this->uploadDir, 0775, true);
|
||||||
|
umask($oldMask);
|
||||||
$uploadFileDir = ROOT_DIR . $this->uploadDir;
|
$uploadFileDir = ROOT_DIR . $this->uploadDir;
|
||||||
$this->destPath = $uploadFileDir . $this->fileName;
|
$this->destPath = $uploadFileDir . $this->fileName;
|
||||||
$this->uploadFile = $this->uploadDir . $this->fileName;
|
$this->uploadFile = $this->uploadDir . $this->fileName;
|
||||||
|
@ -27,7 +27,11 @@
|
|||||||
<nav id="sidebar">
|
<nav id="sidebar">
|
||||||
<div class="p-4 pt-5">
|
<div class="p-4 pt-5">
|
||||||
<a href="#" class="img logo rounded-circle mb-5"
|
<a href="#" class="img logo rounded-circle mb-5"
|
||||||
style="background-image: url(/resources/admin_theme/images/logo.jpg);"></a>
|
style="background-image: url(<?= \kernel\modules\user\service\UserService::getAuthUserPhoto() ?? '/resources/images/noPhoto.png' ?>);"></a>
|
||||||
|
|
||||||
|
|
||||||
|
<!-- style="background-image: url(/resources/images/noPhoto.png);"></a>-->
|
||||||
|
|
||||||
<p>
|
<p>
|
||||||
<?= \kernel\modules\user\service\UserService::getAuthUsername() ?>
|
<?= \kernel\modules\user\service\UserService::getAuthUsername() ?>
|
||||||
</p>
|
</p>
|
||||||
|
@ -6,7 +6,7 @@ use itguild\forms\builders\SelectBuilder;
|
|||||||
use Itguild\Tables\Filter\Filter;
|
use Itguild\Tables\Filter\Filter;
|
||||||
use kernel\helpers\Debug;
|
use kernel\helpers\Debug;
|
||||||
|
|
||||||
class CustomSelectFilterForAssociativeArr extends Filter
|
class BootstrapSelectFilter extends Filter
|
||||||
{
|
{
|
||||||
|
|
||||||
public function fetch(): string
|
public function fetch(): string
|
@ -1,23 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace kernel\filters;
|
|
||||||
|
|
||||||
use Itguild\Tables\Filter\Filter;
|
|
||||||
|
|
||||||
class CustomSelectFilter extends Filter
|
|
||||||
{
|
|
||||||
|
|
||||||
public function fetch()
|
|
||||||
{
|
|
||||||
$this->html = "<td><select class='form-control' name='$this->name'>";
|
|
||||||
foreach ($this->param as $value) {
|
|
||||||
if ($value === $this->value) {
|
|
||||||
$this->html .= "<option value='$value' selected>$value</option>";
|
|
||||||
} else {
|
|
||||||
$this->html .= "<option value='$value'>$value</option>";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
$this->html .= "value='$this->value'</select></td>";
|
|
||||||
return $this->html;
|
|
||||||
}
|
|
||||||
}
|
|
@ -19,12 +19,15 @@ $table = new ListEloquentTable(new EloquentDataProvider(Menu::class, [
|
|||||||
'baseUrl' => "/admin/settings/menu",
|
'baseUrl' => "/admin/settings/menu",
|
||||||
]));
|
]));
|
||||||
$table->columns([
|
$table->columns([
|
||||||
'parent_id' => (function ($data) {
|
'parent_id' => function ($data) {
|
||||||
if ($data == 0) return null;
|
if ($data == 0) return null;
|
||||||
return Menu::find($data)->label;
|
return Menu::find($data)->label;
|
||||||
}),
|
},
|
||||||
'icon_file' => function ($data) {
|
'icon_file' => function ($data) {
|
||||||
return $data ? "<img src='$data' width='150px'>" : "";
|
return $data ? "<img src='$data' width='150px'>" : "";
|
||||||
|
},
|
||||||
|
'status' => function ($data) {
|
||||||
|
return Menu::getStatus()[$data];
|
||||||
}
|
}
|
||||||
]);
|
]);
|
||||||
$table->beforePrint(function () {
|
$table->beforePrint(function () {
|
||||||
|
@ -187,6 +187,7 @@ class ModuleShopClientController extends AdminController
|
|||||||
'per_page' => $per_page,
|
'per_page' => $per_page,
|
||||||
'kernelService' => new KernelService(),
|
'kernelService' => new KernelService(),
|
||||||
'adminThemeService' => new AdminThemeService(),
|
'adminThemeService' => new AdminThemeService(),
|
||||||
|
'filterValues' => $filters
|
||||||
]);
|
]);
|
||||||
} else {
|
} else {
|
||||||
$this->cgView->render("module_shop_error_connection.php");
|
$this->cgView->render("module_shop_error_connection.php");
|
||||||
|
@ -7,11 +7,11 @@
|
|||||||
* @var \kernel\services\ModuleService $moduleService
|
* @var \kernel\services\ModuleService $moduleService
|
||||||
* @var \kernel\services\KernelService $kernelService
|
* @var \kernel\services\KernelService $kernelService
|
||||||
* @var \kernel\services\AdminThemeService $adminThemeService
|
* @var \kernel\services\AdminThemeService $adminThemeService
|
||||||
|
* @var array $filterValues
|
||||||
*/
|
*/
|
||||||
|
|
||||||
use Itguild\Tables\ListJsonTable;
|
use Itguild\Tables\ListJsonTable;
|
||||||
use kernel\widgets\ActionButtonWidget;
|
use kernel\widgets\ActionButtonWidget;
|
||||||
|
|
||||||
$meta = [];
|
$meta = [];
|
||||||
$meta['columns'] = [
|
$meta['columns'] = [
|
||||||
"name" => "Название",
|
"name" => "Название",
|
||||||
@ -42,9 +42,12 @@ $table->addAction(function ($row, $url) use ($moduleService) {
|
|||||||
$table->columns([
|
$table->columns([
|
||||||
'type' => [
|
'type' => [
|
||||||
'filter' => [
|
'filter' => [
|
||||||
'class' => \kernel\filters\CustomSelectFilter::class,
|
'class' => \kernel\filters\BootstrapSelectFilter::class,
|
||||||
'param' => ['kernel', 'entity'],
|
'param' => [
|
||||||
'value' => "kernel"
|
'kernel' => 'kernel',
|
||||||
|
'entity' => 'entity',
|
||||||
|
],
|
||||||
|
'value' => $filterValues['type'] ?? ''
|
||||||
],
|
],
|
||||||
]
|
]
|
||||||
]);
|
]);
|
||||||
|
@ -72,7 +72,7 @@ $table->columns([
|
|||||||
return User::find($data)->username;
|
return User::find($data)->username;
|
||||||
},
|
},
|
||||||
'filter' => [
|
'filter' => [
|
||||||
'class' => \kernel\filters\CustomSelectFilterForAssociativeArr::class,
|
'class' => \kernel\filters\BootstrapSelectFilter::class,
|
||||||
'param' => \kernel\modules\user\service\UserService::createUsernameArr(),
|
'param' => \kernel\modules\user\service\UserService::createUsernameArr(),
|
||||||
'value' => $get['user_id'] ?? ''
|
'value' => $get['user_id'] ?? ''
|
||||||
]
|
]
|
||||||
|
@ -6,6 +6,8 @@ use Exception;
|
|||||||
use JetBrains\PhpStorm\NoReturn;
|
use JetBrains\PhpStorm\NoReturn;
|
||||||
use kernel\AdminController;
|
use kernel\AdminController;
|
||||||
use kernel\EntityRelation;
|
use kernel\EntityRelation;
|
||||||
|
use kernel\FileUpload;
|
||||||
|
use kernel\helpers\Debug;
|
||||||
use kernel\modules\user\models\forms\CreateUserForm;
|
use kernel\modules\user\models\forms\CreateUserForm;
|
||||||
use kernel\modules\user\models\User;
|
use kernel\modules\user\models\User;
|
||||||
use kernel\modules\user\service\UserService;
|
use kernel\modules\user\service\UserService;
|
||||||
@ -35,10 +37,17 @@ class UserController extends AdminController
|
|||||||
{
|
{
|
||||||
$userForm = new CreateUserForm();
|
$userForm = new CreateUserForm();
|
||||||
$userForm->load($_REQUEST);
|
$userForm->load($_REQUEST);
|
||||||
|
|
||||||
|
|
||||||
|
if (isset($_FILES['user_photo']) && $_FILES['user_photo']['error'] === UPLOAD_ERR_OK) {
|
||||||
|
$file = new FileUpload($_FILES['user_photo'], ['jpg', 'jpeg', 'png']);
|
||||||
|
$file->upload();
|
||||||
|
$userForm->setItem('user_photo', $file->getUploadFile());
|
||||||
|
}
|
||||||
|
|
||||||
if ($userForm->validate()){
|
if ($userForm->validate()){
|
||||||
$user = $this->userService->create($userForm);
|
$user = $this->userService->create($userForm);
|
||||||
|
|
||||||
|
|
||||||
$entityRelation = new EntityRelation();
|
$entityRelation = new EntityRelation();
|
||||||
$entityRelation->saveEntityRelation(entity: "user", model: $user, request: new Request());
|
$entityRelation->saveEntityRelation(entity: "user", model: $user, request: new Request());
|
||||||
|
|
||||||
@ -98,6 +107,13 @@ class UserController extends AdminController
|
|||||||
$userForm = new CreateUserForm();
|
$userForm = new CreateUserForm();
|
||||||
$userService = new UserService();
|
$userService = new UserService();
|
||||||
$userForm->load($_REQUEST);
|
$userForm->load($_REQUEST);
|
||||||
|
|
||||||
|
if (isset($_FILES['user_photo']) && $_FILES['user_photo']['error'] === UPLOAD_ERR_OK) {
|
||||||
|
$file = new FileUpload($_FILES['user_photo'], ['jpg', 'jpeg', 'png']);
|
||||||
|
$file->upload();
|
||||||
|
$userForm->setItem('user_photo', $file->getUploadFile());
|
||||||
|
}
|
||||||
|
|
||||||
if ($userForm->validateForUpdate()){
|
if ($userForm->validateForUpdate()){
|
||||||
$user = $userService->update($userForm, $user);
|
$user = $userService->update($userForm, $user);
|
||||||
|
|
||||||
|
@ -20,6 +20,7 @@ return new class extends Migration
|
|||||||
$table->string('username', 255)->nullable(false);
|
$table->string('username', 255)->nullable(false);
|
||||||
$table->string('email', 255);
|
$table->string('email', 255);
|
||||||
$table->string('password_hash', 255);
|
$table->string('password_hash', 255);
|
||||||
|
$table->string('user_photo', 255)->nullable();
|
||||||
$table->integer('role')->default(1);
|
$table->integer('role')->default(1);
|
||||||
$table->string('access_token', 255)->nullable(true);
|
$table->string('access_token', 255)->nullable(true);
|
||||||
$table->dateTime('access_token_expires_at')->nullable(true);
|
$table->dateTime('access_token_expires_at')->nullable(true);
|
||||||
|
@ -7,6 +7,7 @@ use Illuminate\Database\Eloquent\Model;
|
|||||||
* @property string $username
|
* @property string $username
|
||||||
* @property string $email
|
* @property string $email
|
||||||
* @property string $password_hash
|
* @property string $password_hash
|
||||||
|
* @property string $user_photo
|
||||||
* @property string $access_token
|
* @property string $access_token
|
||||||
* @property string $access_token_expires_at
|
* @property string $access_token_expires_at
|
||||||
* @method static find($id)
|
* @method static find($id)
|
||||||
@ -17,7 +18,7 @@ class User extends Model {
|
|||||||
const ADMIN_USER_ROLE = 9;
|
const ADMIN_USER_ROLE = 9;
|
||||||
|
|
||||||
protected $table = 'user';
|
protected $table = 'user';
|
||||||
protected $fillable = ['username', 'email', 'password_hash', 'role', 'access_token', 'access_token_expires_at'];
|
protected $fillable = ['username', 'email', 'password_hash', 'user_photo', 'role', 'access_token', 'access_token_expires_at'];
|
||||||
protected array $dates = ['deleted at'];
|
protected array $dates = ['deleted at'];
|
||||||
|
|
||||||
public static function labels(): array
|
public static function labels(): array
|
||||||
@ -25,6 +26,7 @@ class User extends Model {
|
|||||||
return [
|
return [
|
||||||
'username' => 'Логин',
|
'username' => 'Логин',
|
||||||
'email' => 'Email',
|
'email' => 'Email',
|
||||||
|
'user_photo' => 'Фото профиля',
|
||||||
'created_at' => 'Создан',
|
'created_at' => 'Создан',
|
||||||
'updated_at' => 'Обновлен',
|
'updated_at' => 'Обновлен',
|
||||||
];
|
];
|
||||||
|
@ -12,7 +12,8 @@ class CreateUserForm extends FormModel
|
|||||||
return [
|
return [
|
||||||
'username' => 'required|min-str-len:5|max-str-len:30',
|
'username' => 'required|min-str-len:5|max-str-len:30',
|
||||||
'password' => 'required|min-str-len:5|max-str-len:30',
|
'password' => 'required|min-str-len:5|max-str-len:30',
|
||||||
'email' => 'required|email'
|
'email' => 'required|email',
|
||||||
|
'user_photo' => ''
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -21,7 +22,9 @@ class CreateUserForm extends FormModel
|
|||||||
return [
|
return [
|
||||||
'username' => 'required|min-str-len:5|max-str-len:30',
|
'username' => 'required|min-str-len:5|max-str-len:30',
|
||||||
'password' => '',
|
'password' => '',
|
||||||
'email' => 'required|email'
|
'email' => 'required|email',
|
||||||
|
'user_photo' => ''
|
||||||
|
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -15,6 +15,7 @@ class UserService
|
|||||||
$model->username = $form_model->getItem('username');
|
$model->username = $form_model->getItem('username');
|
||||||
$model->email = $form_model->getItem('email');
|
$model->email = $form_model->getItem('email');
|
||||||
$model->password_hash = password_hash($form_model->getItem('password'), PASSWORD_DEFAULT);
|
$model->password_hash = password_hash($form_model->getItem('password'), PASSWORD_DEFAULT);
|
||||||
|
$model->user_photo = $form_model->getItem('user_photo');
|
||||||
if ($model->save()){
|
if ($model->save()){
|
||||||
return $model;
|
return $model;
|
||||||
}
|
}
|
||||||
@ -29,6 +30,7 @@ class UserService
|
|||||||
if ($form_model->getItem('password')) {
|
if ($form_model->getItem('password')) {
|
||||||
$user->password_hash = password_hash($form_model->getItem('password'), PASSWORD_DEFAULT);
|
$user->password_hash = password_hash($form_model->getItem('password'), PASSWORD_DEFAULT);
|
||||||
}
|
}
|
||||||
|
$user->user_photo = $form_model->getItem('user_photo');
|
||||||
if ($user->save()){
|
if ($user->save()){
|
||||||
return $user;
|
return $user;
|
||||||
}
|
}
|
||||||
@ -80,6 +82,18 @@ class UserService
|
|||||||
return '';
|
return '';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static function getAuthUserPhoto(): string|null
|
||||||
|
{
|
||||||
|
$user = self::getAuthUser();
|
||||||
|
if ($user){
|
||||||
|
if ($user->user_photo) {
|
||||||
|
return $user->user_photo;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
public function getByAccessToken(string $token)
|
public function getByAccessToken(string $token)
|
||||||
{
|
{
|
||||||
return $this->getByField("access_token", $token);
|
return $this->getByField("access_token", $token);
|
||||||
|
@ -32,6 +32,16 @@ $form->field(class: \itguild\forms\inputs\TextInput::class, name: "email", param
|
|||||||
->setLabel("Email")
|
->setLabel("Email")
|
||||||
->render();
|
->render();
|
||||||
|
|
||||||
|
if (!empty($model->user_photo)){
|
||||||
|
echo "<div><img src='$model->user_photo' width='200px'></div>";
|
||||||
|
}
|
||||||
|
$form->field(class: \itguild\forms\inputs\File::class, name: "user_photo", params: [
|
||||||
|
'class' => "form-control",
|
||||||
|
'value' => $model->user_photo ?? ''
|
||||||
|
])
|
||||||
|
->setLabel("Фото профиля")
|
||||||
|
->render();
|
||||||
|
|
||||||
$entityRelations = new \kernel\EntityRelation();
|
$entityRelations = new \kernel\EntityRelation();
|
||||||
if (!isset($model)) {
|
if (!isset($model)) {
|
||||||
$model = new User();
|
$model = new User();
|
||||||
|
@ -40,6 +40,9 @@ $table->columns([
|
|||||||
'class' => \Itguild\Tables\Filter\InputTextFilter::class
|
'class' => \Itguild\Tables\Filter\InputTextFilter::class
|
||||||
]
|
]
|
||||||
],
|
],
|
||||||
|
'user_photo' => function ($data) {
|
||||||
|
return $data ? "<img src='$data' width='150px'>" : "";
|
||||||
|
},
|
||||||
'created_at' => function ($data) {
|
'created_at' => function ($data) {
|
||||||
if (!$data){
|
if (!$data){
|
||||||
return null;
|
return null;
|
||||||
|
@ -35,6 +35,9 @@ foreach ($additionals as $key => $additional) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
$table->rows([
|
$table->rows([
|
||||||
|
'user_photo' => function ($data) {
|
||||||
|
return $data ? "<img src='$data' width='300px'>" : "";
|
||||||
|
},
|
||||||
'created_at' => function ($data) {
|
'created_at' => function ($data) {
|
||||||
if (!$data){
|
if (!$data){
|
||||||
return null;
|
return null;
|
||||||
|
@ -51,6 +51,16 @@ $table = new \Itguild\Tables\ListJsonTable(json_encode(
|
|||||||
]
|
]
|
||||||
));
|
));
|
||||||
|
|
||||||
|
// Пример фильтра
|
||||||
|
$table->columns([
|
||||||
|
'title' => [
|
||||||
|
'filter' => [
|
||||||
|
'class' => \Itguild\Tables\Filter\InputTextFilter::class,
|
||||||
|
'value' => $get['title'] ?? ''
|
||||||
|
]
|
||||||
|
],
|
||||||
|
]
|
||||||
|
|
||||||
$table->beforePrint(function () {
|
$table->beforePrint(function () {
|
||||||
return IconBtnCreateWidget::create(['url' => '/admin/{slug}/create'])->run();
|
return IconBtnCreateWidget::create(['url' => '/admin/{slug}/create'])->run();
|
||||||
});
|
});
|
||||||
|
BIN
resources/images/noPhoto.png
Normal file
BIN
resources/images/noPhoto.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 4.0 KiB |
Loading…
Reference in New Issue
Block a user