| Server IP : 69.72.244.102 / Your IP : 216.73.216.164 Web Server : LiteSpeed System : Linux s3434.fra1.stableserver.net 4.18.0-513.24.1.lve.2.el8.x86_64 #1 SMP Fri May 24 12:42:50 UTC 2024 x86_64 User : konzalta ( 1271) PHP Version : 7.4.33 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : ON | Sudo : OFF | Pkexec : OFF Directory : /home/konzalta/public_html/wp-content/plugins/wappointment/app/Models/ |
Upload File : |
<?php
namespace Wappointment\Models;
use Wappointment\ClassConnect\Model;
use Wappointment\Services\Settings;
use Wappointment\ClassConnect\ClientSoftDeletes as SoftDeletes;
use Wappointment\ClassConnect\Carbon;
class Client extends Model
{
use SoftDeletes;
use \Wappointment\Models\CanBook;
use \Wappointment\Models\CanBookLegacy;
use \Wappointment\Models\CanGetCustomFieldValue;
protected $table = 'wappo_clients';
public $generatingOrder = \true;
protected $fillable = ['name', 'email', 'options'];
protected $casts = ['options' => 'array'];
protected $appends = ['avatar'];
public function appointments()
{
return $this->hasMany(\Wappointment\Models\Appointment::class);
}
public function hasActiveBooking($staff_id)
{
$start_at_string = Carbon::now('UTC')->format(WAPPOINTMENT_DB_FORMAT);
$appointments_query = \Wappointment\Models\Appointment::where('client_id', $this->id)->where('start_at', '>=', $start_at_string);
if ((int) Settings::get('max_active_per_staff')) {
$appointments_query->where('staff_id', $staff_id);
}
return $appointments_query->count();
}
public function getEmailAttribute($value)
{
return sanitize_email($value);
}
public function generateEditKey($start_at)
{
return \md5($this->id . $start_at);
}
public function getFirstName()
{
return \strpos($this->name, ' ') !== \false ? \substr($this->name, 0, \strpos($this->name, ' ')) : $this->name;
}
public function getAvatarAttribute()
{
return get_avatar_url($this['email'], ['size' => 40]);
}
public function getLastName()
{
return \strpos($this->name, ' ') !== \false ? \substr($this->name, \strpos($this->name, ' ')) : '';
}
public function getEmailForDotcom()
{
return $this->email;
}
public function getNameForDotcom()
{
return $this->name;
}
public function getPhone()
{
return empty($this->options['phone']) ? '' : $this->options['phone'];
}
public function getSkype()
{
return empty($this->options['skype']) ? '' : $this->options['skype'];
}
public function getTimezone($defaultTz = 'UTC')
{
return empty($this->options['tz']) ? $defaultTz : $this->options['tz'];
}
public function getCustomField($tag = \false)
{
return empty($tag) || empty($this->options[$tag['key']]) ? '' : $this->getCfReadableValue($tag);
}
private function getCfReadableValue($tag)
{
if (\class_exists('\\WappointmentAddonServices\\Services\\CustomFields')) {
return $this->getCustomFieldFormattedValue($tag);
}
return $this->options[$tag['key']];
}
protected function getRealDuration($service)
{
return ((int) $service['duration'] + (int) Settings::get('buffer_time')) * 60;
}
public function mailableAddress()
{
return [$this->email => sanitize_text_field($this->name)];
}
public function getOrder()
{
$pendingOrder = \Wappointment\Models\Order::where('client_id', $this->id)->pending()->first();
if (empty($pendingOrder)) {
$pendingOrder = \Wappointment\Models\Order::create(['client_id' => $this->id, 'transaction_id' => \uniqid('onsite_' . $this->id), 'tax_percent' => $this->getTaxPercentage()]);
}
return $pendingOrder;
}
public function getTaxPercentage()
{
return !empty($this->client->options['tax_percent']) ? $this->client->options['tax_percent'] : Settings::get('tax');
}
public function generateOrder($ticket, $slots = 1)
{
if (!$this->generatingOrder) {
return null;
}
//if pending order already exist, just get that one
$pendingOrder = $this->getOrder();
$pendingOrder->add($ticket, $slots);
$ticket->recordOrderReference($pendingOrder);
$pendingOrder->refreshTotal();
$pendingOrder->load('prices');
return $pendingOrder;
}
}