<commit_before><?php

namespace App;

use Carbon\Carbon;
use App\Presenters\AppointmentPresenter;
use Robbo\Presenter\PresentableInterface;

class Appointment extends Model implements PresentableInterface
{
    /**
     * The attributes that are mass assignable.
     *
     * @var array
     */
    protected $fillable = ['issuer_id', 'contact_id', 'business_id', 'service_id', 'start_at', 'duration', 'comments'];

    /**
     * The attributes that aren't mass assignable.
     *
     * @var array
     */
    protected $guarded = ['id', 'hash', 'status', 'finish_at', 'vacancy_id'];

    /**
     * The attributes that should be mutated to dates.
     *
     * @var array
     */
    protected $dates = ['start_at', 'finish_at'];

    /**
     * Appointment Hard Status Constants
     */
    const STATUS_RESERVED  = 'R';
    const STATUS_CONFIRMED = 'C';
    const STATUS_ANNULATED = 'A';
    const STATUS_SERVED    = 'S';

    /**
     * User Profile Constants
     *
     * Used to determine the detected behavior of the user depending
     * on if he acts as a user or a Business manager.
     */
    const PROFILE_USER    = 'user';
    const PROFILE_MANAGER = 'manager';

    /**
     * Create Appointment model
     * @param array $attributes Attributes for filling the model
     */
    public function __construct(array $attributes = [])
    {
        parent::__construct($attributes);
    }

    /**
     * Return a created presenter.
     *
     * @return Robbo\Presenter\Presenter
     */
    public function getPresenter()
    {
        return new AppointmentPresenter($this);
    }

    /**
     * Save the model to the database.
     *
     * @param  array  $options
     * @return bool
     */
    public function save(array $options = array())
    {
        return parent::save($options);
    }

    ///////////////////
    // Relationships //
    ///////////////////

    /**
     * Issuer
     *
     * @return Collection $user User who has created the appointment
     */
    public function issuer()
    {
        return $this->belongsTo('App\User');
    }

    /**
     * Contact
     *
     * @return Collection $contact Contact for whom the appointment is made
     */
    public function contact()
    {
        return $this->belongsTo('App\Contact');
    }

    /**
     * Business
     *
     * @return Collection $business Business for which the appointment is made
     */
    public function business()
    {
        return $this->belongsTo('App\Business');
    }

    /**
     * Service
     *
     * @return Collection $service Service for which the contact is set for appointment
     */
    public function service()
    {
        return $this->belongsTo('App\Service');
    }

    /**
     * Vacancy
     *
     * @return Collection $vacancy Vacancy that holds the appointment
     */
    public function vacancy()
    {
        return $this->belongsTo('App\Vacancy');
    }

    ///////////
    // Other //
    ///////////

    /**
     * User
     *
     * @return [type] [description]
     */
    public function user()
    {
        return $this->contact->first()->user()->first();
    }

    /**
     * Duplicates
     *
     * @return boolean Determines if the new Appointment will hash crash with an existing Appointment
     */
    public function duplicates()
    {
        return !self::where('hash', $this->hash)->get()->isEmpty();
    }

    ///////////////
    // Accessors //
    ///////////////

    public function getHashAttribute()
    {<commit_msg>Simplify relationship expression<commit_after><?php

namespace App;

use Carbon\Carbon;
use App\Presenters\AppointmentPresenter;
use Robbo\Presenter\PresentableInterface;

class Appointment extends Model implements PresentableInterface
{
    /**
     * The attributes that are mass assignable.
     *
     * @var array
     */
    protected $fillable = ['issuer_id', 'contact_id', 'business_id', 'service_id', 'start_at', 'duration', 'comments'];

    /**
     * The attributes that aren't mass assignable.
     *
     * @var array
     */
    protected $guarded = ['id', 'hash', 'status', 'finish_at', 'vacancy_id'];

    /**
     * The attributes that should be mutated to dates.
     *
     * @var array
     */
    protected $dates = ['start_at', 'finish_at'];

    /**
     * Appointment Hard Status Constants
     */
    const STATUS_RESERVED  = 'R';
    const STATUS_CONFIRMED = 'C';
    const STATUS_ANNULATED = 'A';
    const STATUS_SERVED    = 'S';

    /**
     * User Profile Constants
     *
     * Used to determine the detected behavior of the user depending
     * on if he acts as a user or a Business manager.
     */
    const PROFILE_USER    = 'user';
    const PROFILE_MANAGER = 'manager';

    /**
     * Create Appointment model
     * @param array $attributes Attributes for filling the model
     */
    public function __construct(array $attributes = [])
    {
        parent::__construct($attributes);
    }

    /**
     * Return a created presenter.
     *
     * @return Robbo\Presenter\Presenter
     */
    public function getPresenter()
    {
        return new AppointmentPresenter($this);
    }

    /**
     * Save the model to the database.
     *
     * @param  array  $options
     * @return bool
     */
    public function save(array $options = array())
    {
        return parent::save($options);
    }

    ///////////////////
    // Relationships //
    ///////////////////

    /**
     * Issuer
     *
     * @return Collection $user User who has created the appointment
     */
    public function issuer()
    {
        return $this->belongsTo('App\User');
    }

    /**
     * Contact
     *
     * @return Collection $contact Contact for whom the appointment is made
     */
    public function contact()
    {
        return $this->belongsTo('App\Contact');
    }

    /**
     * Business
     *
     * @return Collection $business Business for which the appointment is made
     */
    public function business()
    {
        return $this->belongsTo('App\Business');
    }

    /**
     * Service
     *
     * @return Collection $service Service for which the contact is set for appointment
     */
    public function service()
    {
        return $this->belongsTo('App\Service');
    }

    /**
     * Vacancy
     *
     * @return Collection $vacancy Vacancy that holds the appointment
     */
    public function vacancy()
    {
        return $this->belongsTo('App\Vacancy');
    }

    ///////////
    // Other //
    ///////////

    /**
     * User
     *
     * @return [type] [description]
     */
    public function user()
    {
        return $this->contact->user;
    }

    /**
     * Duplicates
     *
     * @return boolean Determines if the new Appointment will hash crash with an existing Appointment
     */
    public function duplicates()
    {
        return !self::where('hash', $this->hash)->get()->isEmpty();
    }

    ///////////////
    // Accessors //
    ///////////////

    public function getHashAttribute()
    {
{'fraction_non_alphanumeric': 0.14010557854187472, 'fraction_numerical': 0.0, 'mean_word_length': 1.8859613009468916, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 25, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4396961', 'n_tokens_mistral': 2021, 'n_tokens_neox': 1954, 'n_words': 538}