refactor: replace custom CRM with Monica fork
Some checks failed
Build & Push Monica Image to Gitea Registry / build-and-push (push) Failing after 9s
Some checks failed
Build & Push Monica Image to Gitea Registry / build-and-push (push) Failing after 9s
This commit is contained in:
90
app/Models/Instance/AuditLog.php
Normal file
90
app/Models/Instance/AuditLog.php
Normal file
@@ -0,0 +1,90 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models\Instance;
|
||||
|
||||
use App\Models\User\User;
|
||||
use function Safe\json_decode;
|
||||
use App\Models\Account\Account;
|
||||
use App\Models\Contact\Contact;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
|
||||
class AuditLog extends Model
|
||||
{
|
||||
protected $table = 'audit_logs';
|
||||
|
||||
/**
|
||||
* The attributes that are mass assignable.
|
||||
*
|
||||
* @var array<string>
|
||||
*/
|
||||
protected $fillable = [
|
||||
'account_id',
|
||||
'author_id',
|
||||
'about_contact_id',
|
||||
'author_name',
|
||||
'action',
|
||||
'objects',
|
||||
'should_appear_on_dashboard',
|
||||
'audited_at',
|
||||
];
|
||||
|
||||
/**
|
||||
* The attributes that should be mutated to dates.
|
||||
*
|
||||
* @var array<string>
|
||||
*/
|
||||
protected $dates = [
|
||||
'audited_at',
|
||||
];
|
||||
|
||||
/**
|
||||
* The attributes that should be cast to native types.
|
||||
*
|
||||
* @var array<string, string>
|
||||
*/
|
||||
protected $casts = [
|
||||
'should_appear_on_dashboard' => 'boolean',
|
||||
];
|
||||
|
||||
/**
|
||||
* Get the Account record associated with the audit log.
|
||||
*
|
||||
* @return BelongsTo
|
||||
*/
|
||||
public function account()
|
||||
{
|
||||
return $this->belongsTo(Account::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the User record associated with the audit log.
|
||||
*
|
||||
* @return BelongsTo
|
||||
*/
|
||||
public function author()
|
||||
{
|
||||
return $this->belongsTo(User::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the Contact record associated with the audit log.
|
||||
*
|
||||
* @return BelongsTo
|
||||
*/
|
||||
public function contact()
|
||||
{
|
||||
return $this->belongsTo(Contact::class, 'about_contact_id');
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the JSON object.
|
||||
*
|
||||
* @param mixed $value
|
||||
* @return mixed
|
||||
*/
|
||||
public function getObjectAttribute($value)
|
||||
{
|
||||
return json_decode($this->objects);
|
||||
}
|
||||
}
|
||||
27
app/Models/Instance/Cron.php
Normal file
27
app/Models/Instance/Cron.php
Normal file
@@ -0,0 +1,27 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models\Instance;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class Cron extends Model
|
||||
{
|
||||
/**
|
||||
* The attributes that are mass assignable.
|
||||
*
|
||||
* @var array<string>
|
||||
*/
|
||||
protected $fillable = [
|
||||
'command',
|
||||
'last_run',
|
||||
];
|
||||
|
||||
/**
|
||||
* The attributes that should be cast to native types.
|
||||
*
|
||||
* @var array<string, string>
|
||||
*/
|
||||
protected $casts = [
|
||||
'last_run' => 'datetime',
|
||||
];
|
||||
}
|
||||
71
app/Models/Instance/Emotion/Emotion.php
Normal file
71
app/Models/Instance/Emotion/Emotion.php
Normal file
@@ -0,0 +1,71 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models\Instance\Emotion;
|
||||
|
||||
use App\Models\Contact\Call;
|
||||
use App\Models\Account\Activity;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
|
||||
|
||||
/**
|
||||
* An emotion (ex: Adoration) is defined into 3 categories:
|
||||
* - Primary: Love
|
||||
* - Secondary: Affection
|
||||
* - Tertiary: Adoration.
|
||||
*/
|
||||
class Emotion extends Model
|
||||
{
|
||||
protected $table = 'emotions';
|
||||
|
||||
/**
|
||||
* The attributes that aren't mass assignable.
|
||||
*
|
||||
* @var array<string>|bool
|
||||
*/
|
||||
protected $guarded = ['id'];
|
||||
|
||||
/**
|
||||
* Get the primary emotion record associated with the emotion.
|
||||
*
|
||||
* @return BelongsTo
|
||||
*/
|
||||
public function primary()
|
||||
{
|
||||
return $this->belongsTo(PrimaryEmotion::class, 'emotion_primary_id');
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the secondary emotion record associated with the emotion.
|
||||
*
|
||||
* @return BelongsTo
|
||||
*/
|
||||
public function secondary()
|
||||
{
|
||||
return $this->belongsTo(SecondaryEmotion::class, 'emotion_secondary_id');
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the call records associated with the emotion.
|
||||
*
|
||||
* @return BelongsToMany
|
||||
*/
|
||||
public function calls()
|
||||
{
|
||||
return $this->belongsToMany(Call::class, 'emotion_call', 'emotion_id', 'call_id')
|
||||
->withPivot('account_id', 'contact_id')
|
||||
->withTimestamps();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the activity records associated with the emotion.
|
||||
*
|
||||
* @return BelongsToMany
|
||||
*/
|
||||
public function activities()
|
||||
{
|
||||
return $this->belongsToMany(Activity::class, 'emotion_activity', 'emotion_id', 'activity_id')
|
||||
->withPivot('account_id')
|
||||
->withTimestamps();
|
||||
}
|
||||
}
|
||||
44
app/Models/Instance/Emotion/PrimaryEmotion.php
Normal file
44
app/Models/Instance/Emotion/PrimaryEmotion.php
Normal file
@@ -0,0 +1,44 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models\Instance\Emotion;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
|
||||
/**
|
||||
* An emotion (ex: Adoration) is defined into 3 categories:
|
||||
* - Primary: Love
|
||||
* - Secondary: Affection
|
||||
* - Tertiary: Adoration.
|
||||
*/
|
||||
class PrimaryEmotion extends Model
|
||||
{
|
||||
protected $table = 'emotions_primary';
|
||||
|
||||
/**
|
||||
* The attributes that aren't mass assignable.
|
||||
*
|
||||
* @var array<string>|bool
|
||||
*/
|
||||
protected $guarded = ['id'];
|
||||
|
||||
/**
|
||||
* Get the emotion records associated with the primary emotion.
|
||||
*
|
||||
* @return HasMany
|
||||
*/
|
||||
public function emotions()
|
||||
{
|
||||
return $this->hasMany(Emotion::class, 'emotion_primary_id');
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the secondary records associated with the primary emotion.
|
||||
*
|
||||
* @return HasMany
|
||||
*/
|
||||
public function secondaries()
|
||||
{
|
||||
return $this->hasMany(SecondaryEmotion::class, 'emotion_primary_id');
|
||||
}
|
||||
}
|
||||
45
app/Models/Instance/Emotion/SecondaryEmotion.php
Normal file
45
app/Models/Instance/Emotion/SecondaryEmotion.php
Normal file
@@ -0,0 +1,45 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models\Instance\Emotion;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
|
||||
/**
|
||||
* An emotion (ex: Adoration) is defined into 3 categories:
|
||||
* - Primary: Love
|
||||
* - Secondary: Affection
|
||||
* - Tertiary: Adoration.
|
||||
*/
|
||||
class SecondaryEmotion extends Model
|
||||
{
|
||||
protected $table = 'emotions_secondary';
|
||||
|
||||
/**
|
||||
* The attributes that aren't mass assignable.
|
||||
*
|
||||
* @var array<string>|bool
|
||||
*/
|
||||
protected $guarded = ['id'];
|
||||
|
||||
/**
|
||||
* Get the primary emotion record associated with the secondary emotion.
|
||||
*
|
||||
* @return BelongsTo
|
||||
*/
|
||||
public function primary()
|
||||
{
|
||||
return $this->belongsTo(PrimaryEmotion::class, 'emotion_primary_id');
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the emotion records associated with the secondary emotion.
|
||||
*
|
||||
* @return HasMany
|
||||
*/
|
||||
public function emotions()
|
||||
{
|
||||
return $this->hasMany(Emotion::class);
|
||||
}
|
||||
}
|
||||
21
app/Models/Instance/Instance.php
Normal file
21
app/Models/Instance/Instance.php
Normal file
@@ -0,0 +1,21 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models\Instance;
|
||||
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class Instance extends Model
|
||||
{
|
||||
/**
|
||||
* Once migrations have been run to add a new default contact field type,
|
||||
* we need to mark the field as being migrated so we don't create another
|
||||
* default contact field type if another migration will change this table
|
||||
* in the future.
|
||||
*/
|
||||
public function markDefaultContactFieldTypeAsMigrated()
|
||||
{
|
||||
DB::table('default_contact_field_types')
|
||||
->update(['migrated' => 1]);
|
||||
}
|
||||
}
|
||||
184
app/Models/Instance/SpecialDate.php
Normal file
184
app/Models/Instance/SpecialDate.php
Normal file
@@ -0,0 +1,184 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models\Instance;
|
||||
|
||||
use App\Traits\HasUuid;
|
||||
use App\Helpers\DateHelper;
|
||||
use Illuminate\Support\Carbon;
|
||||
use App\Models\Account\Account;
|
||||
use App\Models\Contact\Contact;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
|
||||
/**
|
||||
* A special date is a date that is not necessarily based on a year that we know.
|
||||
* This happens when we add a birthdate for instance. It can be based:
|
||||
* * on a real date, where we know the day, month and year
|
||||
* * on a date where we just know the day and the month but not the year
|
||||
* * on an age (we know this person is 33 but we don't know his birthdate,
|
||||
* so we'll give an estimation).
|
||||
*
|
||||
* Instead of adding a lot of logic in the Contact table, we've decided to
|
||||
* create this class that will deal with this complexity.
|
||||
*
|
||||
* @property bool $is_age_based
|
||||
* @property bool $is_year_unknown
|
||||
* @property \Carbon\Carbon|null $date
|
||||
*/
|
||||
class SpecialDate extends Model
|
||||
{
|
||||
use HasUuid;
|
||||
|
||||
/**
|
||||
* The table associated with the model.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $table = 'special_dates';
|
||||
|
||||
/**
|
||||
* The attributes that aren't mass assignable.
|
||||
*
|
||||
* @var array<string>|bool
|
||||
*/
|
||||
protected $guarded = ['id'];
|
||||
|
||||
/**
|
||||
* All of the relationships to be touched.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $touches = ['contact'];
|
||||
|
||||
/**
|
||||
* The attributes that should be mutated to dates.
|
||||
*
|
||||
* @var array<string>
|
||||
*/
|
||||
protected $dates = ['date'];
|
||||
|
||||
/**
|
||||
* The attributes that are mass assignable.
|
||||
*
|
||||
* @var array<string>
|
||||
*/
|
||||
protected $fillable = [
|
||||
'contact_id',
|
||||
'account_id',
|
||||
];
|
||||
|
||||
/**
|
||||
* The attributes that should be cast to native types.
|
||||
*
|
||||
* @var array<string, string>
|
||||
*/
|
||||
protected $casts = [
|
||||
'is_age_based' => 'boolean',
|
||||
'is_year_unknown' => 'boolean',
|
||||
];
|
||||
|
||||
/**
|
||||
* Get the account record associated with the special date.
|
||||
*
|
||||
* @return BelongsTo
|
||||
*/
|
||||
public function account()
|
||||
{
|
||||
return $this->belongsTo(Account::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the contact record associated with the special date.
|
||||
*
|
||||
* @return BelongsTo
|
||||
*/
|
||||
public function contact()
|
||||
{
|
||||
return $this->belongsTo(Contact::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a short version of the date, taking into account if the year is
|
||||
* unknown or not. This will return either `July 21` or `July 21, 2017`.
|
||||
*/
|
||||
public function toShortString()
|
||||
{
|
||||
if ($this->is_year_unknown) {
|
||||
return DateHelper::getShortDateWithoutYear($this->date);
|
||||
}
|
||||
|
||||
return DateHelper::getShortDate($this->date);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the age that the date represents, if the date is set and if it's
|
||||
* not based on a year we don't know.
|
||||
*
|
||||
* @return int|null
|
||||
*/
|
||||
public function getAge(): ?int
|
||||
{
|
||||
if (is_null($this->date)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if ($this->is_year_unknown) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return $this->date->diffInYears(now());
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a SpecialDate from an age.
|
||||
*
|
||||
* @param int $age
|
||||
*/
|
||||
public function createFromAge(int $age)
|
||||
{
|
||||
$this->is_age_based = true;
|
||||
$this->date = now(DateHelper::getTimezone())->subYears($age)->month(1)->day(1);
|
||||
$this->save();
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a SpecialDate from an actual date, that might not contain a year.
|
||||
*
|
||||
* @param int $year
|
||||
* @param int $month
|
||||
* @param int $day
|
||||
*/
|
||||
public function createFromDate(int $year, int $month, int $day)
|
||||
{
|
||||
// year 0 represents the `unknown` choice in the dropdown representing
|
||||
// the years
|
||||
if ($year != 0) {
|
||||
$date = Carbon::createFromDate($year, $month, $day);
|
||||
$this->is_year_unknown = false;
|
||||
} else {
|
||||
$date = Carbon::createFromDate(now()->year, $month, $day);
|
||||
$this->is_year_unknown = true;
|
||||
}
|
||||
|
||||
$this->date = $date;
|
||||
$this->save();
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Associates a special date to a contact.
|
||||
*
|
||||
* @param Contact $contact
|
||||
*/
|
||||
public function setToContact(Contact $contact)
|
||||
{
|
||||
$this->account_id = $contact->account_id;
|
||||
$this->contact_id = $contact->id;
|
||||
$this->save();
|
||||
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
9
app/Models/Instance/Statistic.php
Normal file
9
app/Models/Instance/Statistic.php
Normal file
@@ -0,0 +1,9 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models\Instance;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class Statistic extends Model
|
||||
{
|
||||
}
|
||||
Reference in New Issue
Block a user