ForRo/app/Repositories/MemberRepository.php
ro d0c8def297 added member edit admin ui
needed way to edit existing members info if needed, so simple ui was
created for admins of the site to change specific info, not including a
members avi or password.

also consolidated memeber action and ui into it's own controller for the
sake of clearer organization
2024-09-24 16:21:59 -06:00

97 lines
2.9 KiB
PHP

<?php
namespace App\Repositories;
use App\Models\Member;
use Illuminate\Support\Facades\Hash;
class MemberRepository
{
protected $model;
public function __construct(Member $model)
{
$this->model = $model;
}
public function getAll()
{
return $this->model::all();
}
public function get($uuid)
{
return $this->model::where("uuid", $uuid)->first();
}
public function edit($request)
{
//get member to edit
$member = $this->get($request->id);
//save new avi if available
$publicPath = '../public/';
$refPath = 'assets/images/members/' . $member->uuid;
if ($request->hasfile("fresh_avi")) {
$file = $request->fresh_avi;
if (!is_dir($publicPath . $refPath)) {
mkdir($publicPath . $refPath, 0755, true);
}
$filename = urlencode($file->getClientOriginalName());
$file->move($publicPath . $refPath, $filename);
$freshAvi = '/' . $refPath . '/' . $filename;
$member->avatar = $freshAvi;
}
$member->handle = $request->handle;
$member->email = $request->email;
$member->pronoun = $request->pronouns;
$member->role = $request->role;
$member->active = $request->status;
if ($member->save()) {
return ['status' => true, 'message' => "Member Editited"];
} else {
return ['status' => false, 'message' => "Member Not Editited"];
}
}
public function editProfile($request)
{
//get member to edit
$member = $this->get($request->id);
//save new avi if available
$publicPath = '../public/';
$refPath = 'assets/images/members/' . $member->uuid;
if ($request->hasfile("fresh_avi")) {
$file = $request->fresh_avi;
if (!is_dir($publicPath . $refPath)) {
mkdir($publicPath . $refPath, 0755, true);
}
$filename = urlencode($file->getClientOriginalName());
$file->move($publicPath . $refPath, $filename);
$freshAvi = '/' . $refPath . '/' . $filename;
$member->avatar = $freshAvi;
}
//changing password
if (isset($request->fresh_pass) && $request->fresh_pass !== '') {
if ($request->fresh_pass === $request->fresh_pass_confirm) {
$member->password = Hash::make($request->fresh_pass);
} else {
return ['status' => false, 'message' => "Passwords Do Not Match"];
}
}
$member->handle = $request->handle;
$member->email = $request->email;
$member->pronoun = $request->pronouns;
if ($member->save()) {
return ['status' => true, 'message' => "Profile Editited"];
} else {
return ['status' => false, 'message' => "Profile Not Editited"];
}
}
}