5b5b2da5f8
This pull request adds support to multi users in one account. It also introduces the notion of subscriptions. Accounts can now have multiple users. Subscriptions are defined by a new env variable called REQUIRES_SUBSCRIPTION, and defaults to false. As promised, all the paid features on .com will be free if you download and host Monica on your own server.
131 lines
2.5 KiB
PHP
131 lines
2.5 KiB
PHP
<?php
|
|
|
|
namespace App;
|
|
|
|
use App\ActivityType;
|
|
use App\Helpers\DateHelper;
|
|
use Carbon\Carbon;
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
|
|
|
/**
|
|
* @property Account $account
|
|
* @property Contact $contact
|
|
* @property ActivityType $type
|
|
*/
|
|
class Activity extends Model
|
|
{
|
|
/**
|
|
* The table associated with the model.
|
|
*
|
|
* @var string
|
|
*/
|
|
protected $table = 'activities';
|
|
|
|
/**
|
|
* The attributes that aren't mass assignable.
|
|
*
|
|
* @var array
|
|
*/
|
|
protected $guarded = ['id'];
|
|
|
|
/**
|
|
* The attributes that should be mutated to dates.
|
|
*
|
|
* @var array
|
|
*/
|
|
protected $dates = ['date_it_happened'];
|
|
|
|
/**
|
|
* The relations to eager load on every query.
|
|
*
|
|
* @var array
|
|
*/
|
|
protected $with = ['type'];
|
|
|
|
/**
|
|
* Get the account record associated with the gift.
|
|
*
|
|
* @return BelongsTo
|
|
*/
|
|
public function account()
|
|
{
|
|
return $this->belongsTo(Account::class);
|
|
}
|
|
|
|
/**
|
|
* Get the contact record associated with the gift.
|
|
*
|
|
* @return BelongsTo
|
|
*/
|
|
public function contact()
|
|
{
|
|
return $this->belongsTo(Contact::class);
|
|
}
|
|
|
|
/**
|
|
* Get the activity type record associated with the activity.
|
|
*
|
|
* @return BelongsTo
|
|
*/
|
|
public function type()
|
|
{
|
|
return $this->belongsTo(ActivityType::class, 'activity_type_id');
|
|
}
|
|
|
|
/**
|
|
* Get the date_it_happened field according to user's timezone
|
|
*
|
|
* @param string $value
|
|
* @return string
|
|
*/
|
|
public function getDateItHappenedAttribute($value)
|
|
{
|
|
if (auth()->user()) {
|
|
return Carbon::parse($value, auth()->user()->timezone);
|
|
}
|
|
|
|
return Carbon::parse($value);
|
|
}
|
|
|
|
/**
|
|
* Get the summary for this activity.
|
|
*
|
|
* @return string or null
|
|
*/
|
|
public function getSummary()
|
|
{
|
|
return $this->summary;
|
|
}
|
|
|
|
/**
|
|
* Get the description for this activity.
|
|
*
|
|
* @return string or null
|
|
*/
|
|
public function getDescription()
|
|
{
|
|
return $this->description;
|
|
}
|
|
|
|
/**
|
|
* Get the date the activity happened.
|
|
*
|
|
* @return Carbon
|
|
*/
|
|
public function getDateItHappened()
|
|
{
|
|
return $this->date_it_happened;
|
|
}
|
|
|
|
/**
|
|
* Get the key of the title of the activity.
|
|
*
|
|
* @return string or null
|
|
*/
|
|
public function getTitle()
|
|
{
|
|
return $this->type ? $this->type->key : null;
|
|
}
|
|
}
|