Attendize/app/Models/Account.php

175 lines
3.8 KiB
PHP
Raw Normal View History

2016-03-05 00:18:10 +00:00
<?php
2016-02-29 15:59:36 +00:00
2016-03-05 00:18:10 +00:00
namespace App\Models;
use App\Attendize\Utils;
2016-02-29 15:59:36 +00:00
use Illuminate\Database\Eloquent\SoftDeletes;
use DB;
2016-02-29 15:59:36 +00:00
2016-03-05 00:18:10 +00:00
class Account extends MyBaseModel
{
2016-02-29 15:59:36 +00:00
use SoftDeletes;
2016-03-05 00:18:10 +00:00
2016-03-14 16:37:38 +00:00
/**
* The validation rules
*
* @var array $rules
*/
2016-02-29 15:59:36 +00:00
protected $rules = [
'first_name' => ['required'],
2016-03-05 00:18:10 +00:00
'last_name' => ['required'],
'email' => ['required', 'email'],
2016-02-29 15:59:36 +00:00
];
2016-03-05 00:18:10 +00:00
2016-03-14 16:37:38 +00:00
/**
* The attributes that should be mutated to dates.
*
* @var array $dates
*/
2016-03-09 22:05:39 +00:00
public $dates = ['deleted_at'];
2016-03-14 16:37:38 +00:00
/**
* The validation error messages.
*
* @var array $messages
*/
2016-02-29 15:59:36 +00:00
protected $messages = [];
2016-03-05 00:18:10 +00:00
2016-03-14 16:37:38 +00:00
/**
* The attributes that are mass assignable.
*
* @var array $fillable
*/
2016-03-09 22:05:39 +00:00
protected $fillable = [
'first_name',
'last_name',
'email',
'timezone_id',
'date_format_id',
'datetime_format_id',
'currency_id',
'name',
'last_ip',
'last_login_date',
'address1',
'address2',
'city',
'state',
'postal_code',
'country_id',
'email_footer',
'is_active',
'is_banned',
'is_beta',
'stripe_access_token',
'stripe_refresh_token',
'stripe_secret_key',
'stripe_publishable_key',
'stripe_data_raw'
];
2016-03-14 16:37:38 +00:00
/**
* The users associated with the account.
*
* @return \Illuminate\Database\Eloquent\Relations\HasMany
*/
2016-03-05 00:18:10 +00:00
public function users()
{
2016-02-29 15:59:36 +00:00
return $this->hasMany('\App\Models\User');
}
2016-03-05 00:18:10 +00:00
2016-03-14 16:37:38 +00:00
/**
* The orders associated with the account.
*
* @return \Illuminate\Database\Eloquent\Relations\HasMany
*/
2016-03-05 00:18:10 +00:00
public function orders()
{
2016-02-29 15:59:36 +00:00
return $this->hasMany('\App\Models\Order');
}
2016-03-05 00:18:10 +00:00
2016-03-14 16:37:38 +00:00
/**
* The currency associated with the account.
*
* @return \Illuminate\Database\Eloquent\Relations\HasOne
*/
2016-03-05 00:18:10 +00:00
public function currency()
{
return $this->belongsTo('\App\Models\Currency');
2016-02-29 15:59:36 +00:00
}
/**
* Payment gateways associated with an account
*
* @return \Illuminate\Database\Eloquent\Relations\HasMany
*/
public function account_payment_gateways()
{
return $this->hasMany('\App\Models\AccountPaymentGateway');
}
/**
* Alias for $this->account_payment_gateways()
*
* @return \Illuminate\Database\Eloquent\Relations\HasMany
*/
public function gateways() {
return $this->account_payment_gateways();
}
/**
* Get an accounts active payment gateway
*
* @return \Illuminate\Database\Eloquent\Relations\HasOne
*/
public function active_payment_gateway()
{
return $this->hasOne('\App\Models\AccountPaymentGateway', 'payment_gateway_id', 'payment_gateway_id')->where('account_id', $this->id);
}
/**
* Get an accounts gateways
*
* @param $gateway_id
* @return mixed
*/
public function getGateway($gateway_id)
{
return $this->gateways->where('payment_gateway_id', $gateway_id)->first();
}
/**
* Get a config value for a gateway
*
* @param $gateway_id
* @param $key
* @return mixed
*/
public function getGatewayConfigVal($gateway_id, $key)
{
$gateway = $this->getGateway($gateway_id);
if($gateway && is_array($gateway->config)) {
return isset($gateway->config[$key]) ? $gateway->config[$key] : false;
}
return false;
}
2016-03-14 16:37:38 +00:00
/**
* Get the stripe api key.
*
* @return \Illuminate\Support\Collection|mixed|static
*/
2016-03-05 00:18:10 +00:00
public function getStripeApiKeyAttribute()
{
if (Utils::isAttendize()) {
2016-02-29 15:59:36 +00:00
return $this->stripe_access_token;
}
return $this->stripe_secret_key;
}
}