mirror of
https://github.com/freescout-helpdesk/freescout.git
synced 2024-11-24 11:22:42 +01:00
Added function to save customer photo
This commit is contained in:
parent
ca173694f8
commit
e5bd0dfe49
@ -3,6 +3,8 @@
|
|||||||
namespace App;
|
namespace App;
|
||||||
|
|
||||||
use Illuminate\Database\Eloquent\Model;
|
use Illuminate\Database\Eloquent\Model;
|
||||||
|
use Illuminate\Support\Facades\Hash;
|
||||||
|
use Illuminate\Support\Facades\Storage;
|
||||||
use Watson\Rememberable\Rememberable;
|
use Watson\Rememberable\Rememberable;
|
||||||
|
|
||||||
class Customer extends Model
|
class Customer extends Model
|
||||||
@ -11,6 +13,10 @@ class Customer extends Model
|
|||||||
// This is obligatory.
|
// This is obligatory.
|
||||||
public $rememberCacheDriver = 'array';
|
public $rememberCacheDriver = 'array';
|
||||||
|
|
||||||
|
const PHOTO_DIRECTORY = 'customers';
|
||||||
|
const PHOTO_SIZE = 50; // px
|
||||||
|
const PHOTO_QUALITY = 77;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Genders.
|
* Genders.
|
||||||
*/
|
*/
|
||||||
@ -433,7 +439,7 @@ class Customer extends Model
|
|||||||
*
|
*
|
||||||
* @var [type]
|
* @var [type]
|
||||||
*/
|
*/
|
||||||
protected $fillable = ['first_name', 'last_name', 'company', 'job_title', 'address', 'city', 'state', 'zip', 'country'];
|
protected $fillable = ['first_name', 'last_name', 'company', 'job_title', 'address', 'city', 'state', 'zip', 'country', 'photo_url'];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Fields stored as JSON.
|
* Fields stored as JSON.
|
||||||
@ -852,11 +858,6 @@ class Customer extends Model
|
|||||||
return $date->format($format);
|
return $date->format($format);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getPhotoUrl()
|
|
||||||
{
|
|
||||||
return asset('/img/default-avatar.png');
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get full representation of customer.
|
* Get full representation of customer.
|
||||||
*/
|
*/
|
||||||
@ -952,4 +953,57 @@ class Customer extends Model
|
|||||||
|
|
||||||
return '';
|
return '';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function getPhotoUrl($default_if_empty = true)
|
||||||
|
{
|
||||||
|
if (!empty($this->photo_url) || !$default_if_empty) {
|
||||||
|
if (!empty($this->photo_url)) {
|
||||||
|
return Storage::url(self::PHOTO_DIRECTORY.DIRECTORY_SEPARATOR.$this->photo_url);
|
||||||
|
} else {
|
||||||
|
return '';
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
return asset('/img/default-avatar.png');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Resize and save photo.
|
||||||
|
*/
|
||||||
|
public function savePhoto($real_path, $mime_type)
|
||||||
|
{
|
||||||
|
$resized_image = \App\Misc\Helper::resizeImage($real_path, $mime_type, self::PHOTO_SIZE, self::PHOTO_SIZE);
|
||||||
|
|
||||||
|
if (!$resized_image) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
$file_name = md5(Hash::make($this->id)).'.jpg';
|
||||||
|
$dest_path = Storage::path(self::PHOTO_DIRECTORY.DIRECTORY_SEPARATOR.$file_name);
|
||||||
|
|
||||||
|
$dest_dir = pathinfo($dest_path, PATHINFO_DIRNAME);
|
||||||
|
if (!file_exists($dest_dir)) {
|
||||||
|
\File::makeDirectory($dest_dir, 0755);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Remove current photo
|
||||||
|
if ($this->photo_url) {
|
||||||
|
Storage::delete(self::PHOTO_DIRECTORY.DIRECTORY_SEPARATOR.$this->photo_url);
|
||||||
|
}
|
||||||
|
|
||||||
|
imagejpeg($resized_image, $dest_path, self::PHOTO_QUALITY);
|
||||||
|
|
||||||
|
return $file_name;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Remove user photo.
|
||||||
|
*/
|
||||||
|
public function removePhoto()
|
||||||
|
{
|
||||||
|
if ($this->photo_url) {
|
||||||
|
Storage::delete(self::PHOTO_DIRECTORY.DIRECTORY_SEPARATOR.$this->photo_url);
|
||||||
|
}
|
||||||
|
$this->photo_url = '';
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -582,8 +582,14 @@ class Helper
|
|||||||
|
|
||||||
if (preg_match('/png/i', $mime_type)) {
|
if (preg_match('/png/i', $mime_type)) {
|
||||||
$src = imagecreatefrompng($file);
|
$src = imagecreatefrompng($file);
|
||||||
|
|
||||||
|
$kek = imagecolorallocate($src, 255, 255, 255);
|
||||||
|
imagefill($src, 0, 0, $kek);
|
||||||
} elseif (preg_match('/gif/i', $mime_type)) {
|
} elseif (preg_match('/gif/i', $mime_type)) {
|
||||||
$src = imagecreatefromgif($file);
|
$src = imagecreatefromgif($file);
|
||||||
|
|
||||||
|
$kek = imagecolorallocate($src, 255, 255, 255);
|
||||||
|
imagefill($src, 0, 0, $kek);
|
||||||
} elseif (preg_match('/bmp/i', $mime_type)) {
|
} elseif (preg_match('/bmp/i', $mime_type)) {
|
||||||
$src = imagecreatefrombmp($file);
|
$src = imagecreatefrombmp($file);
|
||||||
} else {
|
} else {
|
||||||
|
18
app/Observers/EmailObserver.php
Normal file
18
app/Observers/EmailObserver.php
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Observers;
|
||||||
|
|
||||||
|
use App\Email;
|
||||||
|
|
||||||
|
class EmailObserver
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Email created.
|
||||||
|
*
|
||||||
|
* @param User $user
|
||||||
|
*/
|
||||||
|
public function created(Email $email)
|
||||||
|
{
|
||||||
|
\Eventy::action('email.created', $email);
|
||||||
|
}
|
||||||
|
}
|
@ -22,6 +22,7 @@ class AppServiceProvider extends ServiceProvider
|
|||||||
\App\Mailbox::observe(\App\Observers\MailboxObserver::class);
|
\App\Mailbox::observe(\App\Observers\MailboxObserver::class);
|
||||||
// Eloquent events for this table are not called automatically, so need to be called manually.
|
// Eloquent events for this table are not called automatically, so need to be called manually.
|
||||||
//\App\MailboxUser::observe(\App\Observers\MailboxUserObserver::class);
|
//\App\MailboxUser::observe(\App\Observers\MailboxUserObserver::class);
|
||||||
|
\App\Email::observe(\App\Observers\EmailObserver::class);
|
||||||
\App\User::observe(\App\Observers\UserObserver::class);
|
\App\User::observe(\App\Observers\UserObserver::class);
|
||||||
\App\Conversation::observe(\App\Observers\ConversationObserver::class);
|
\App\Conversation::observe(\App\Observers\ConversationObserver::class);
|
||||||
\App\Thread::observe(\App\Observers\ThreadObserver::class);
|
\App\Thread::observe(\App\Observers\ThreadObserver::class);
|
||||||
|
Loading…
Reference in New Issue
Block a user