Completed
Push — master ( 9d011a...df45e0 )
by Ariel
07:48
created

Business::getRouteKey()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
dl 0
loc 4
ccs 0
cts 2
cp 0
rs 10
c 1
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
crap 2
1
<?php
2
3
namespace Timegridio\Concierge\Models;
4
5
use Illuminate\Database\Eloquent\Model as EloquentModel;
6
use Illuminate\Database\Eloquent\SoftDeletes;
7
use McCool\LaravelAutoPresenter\HasPresenter;
8
use Timegridio\Concierge\Presenters\BusinessPresenter;
9
use Timegridio\Concierge\Traits\IsIntoDomain;
10
use Timegridio\Concierge\Traits\Preferenceable;
11
12
class Business extends EloquentModel implements HasPresenter
13
{
14
    use SoftDeletes, Preferenceable, IsIntoDomain;
15
16
    /**
17
     * The attributes that are mass assignable.
18
     *
19
     * @var array
20
     */
21
    protected $fillable = ['name', 'description', 'timezone', 'postal_address', 'phone', 'social_facebook', 'strategy',
22
        'plan', 'country_code', 'locale', ];
23
24
    /**
25
     * The attributes that should be mutated to dates.
26
     *
27
     * @var array
28
     */
29
    protected $dates = ['deleted_at'];
30
31
    /**
32
     * Define model events.
33
     *
34
     * @return void
35
     */
36 46
    public static function boot()
37
    {
38 46
        parent::boot();
39
40 46
        static::creating(function($business) {
41
42 45
            $business->slug = $business->makeSlug($business->name);
43
44 46
        });
45 46
    }
46
47
    /**
48
     * Make Slug.
49
     *
50
     * @param  string $name
51
     *
52
     * @return string
53
     */
54 45
    protected function makeSlug($name)
55
    {
56 45
        return str_slug($name);
57
    }
58
59
    ///////////////////
60
    // Relationships //
61
    ///////////////////
62
63
    /**
64
     * Belongs to a Category.
65
     *
66
     * @return \Illuminate\Database\Eloquent\Relations\BelongsTo
67
     */
68 1
    public function category()
69
    {
70 1
        return $this->belongsTo(Category::class);
71
    }
72
73
    /**
74
     * Has a Contact addressbook.
75
     *
76
     * @return Illuminate\Database\Eloquent\Relations\BelongsToMany
77
     */
78 2
    public function contacts()
79
    {
80 2
        return $this->belongsToMany(Contact::class)
81 2
                    ->with('user')
82 2
                    ->withPivot('notes')
83 2
                    ->withTimestamps();
84
    }
85
86
    /**
87
     * Provides a catalog of Services.
88
     *
89
     * @return \Illuminate\Database\Eloquent\Relations\HasMany
90
     */
91 10
    public function services()
92
    {
93 10
        return $this->hasMany(Service::class);
94
    }
95
96
    /**
97
     * Provides Services of Types.
98
     *
99
     * @return \Illuminate\Database\Eloquent\Relations\HasMany
100
     */
101 1
    public function servicetypes()
102
    {
103 1
        return $this->hasMany(ServiceType::class);
104
    }
105
106
    /**
107
     * Publishes Vacancies.
108
     *
109
     * @return \Illuminate\Database\Eloquent\Relations\HasMany
110
     */
111 23
    public function vacancies()
112
    {
113 23
        return $this->hasMany(Vacancy::class);
114
    }
115
116
    /**
117
     * Holds booked Appointments.
118
     *
119
     * @return \Illuminate\Database\Eloquent\Relations\HasMany
120
     */
121 1
    public function bookings()
122
    {
123 1
        return $this->hasMany(Appointment::class);
124
    }
125
126
    /**
127
     * Is owned by Users.
128
     *
129
     * @return \Illuminate\Database\Eloquent\Relations\BelongsToMany
130
     */
131 13
    public function owners()
132
    {
133 13
        return $this->belongsToMany(config('auth.providers.users.model'))->withTimestamps();
134
    }
135
136
    /**
137
     * Belongs to a User.
138
     *
139
     * @return User
140
     */
141 1
    public function owner()
142
    {
143 1
        return $this->owners()->first();
144
    }
145
146
    ///////////////
147
    // Overrides //
148
    ///////////////
149
150
    //
151
152
    ///////////////
153
    // Presenter //
154
    ///////////////
155
156
    /**
157
     * Get presenter.
158
     *
159
     * @return BusinessPresenter Presenter class
160
     */
161 1
    public function getPresenterClass()
162
    {
163 1
        return BusinessPresenter::class;
164
    }
165
166
    //////////////
167
    // Mutators //
168
    //////////////
169
170
    /**
171
     * Set Slug.
172
     *
173
     * @return string Generated slug
174
     */
175 46
    public function setSlugAttribute()
176
    {
177 46
        return $this->attributes['slug'] = str_slug($this->name);
0 ignored issues
show
Documentation introduced by
The property name does not exist on object<Timegridio\Concierge\Models\Business>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
178
    }
179
180
    /**
181
     * Set name of the business.
182
     *
183
     * @param string $name Name of business
184
     */
185 45
    public function setNameAttribute($name)
186
    {
187 45
        $this->attributes['name'] = trim($name);
188 45
        $this->setSlugAttribute();
189 45
    }
190
191
    /**
192
     * Set Phone.
193
     *
194
     * Expected phone number is international format numeric only
195
     *
196
     * @param string $phone Phone number
197
     */
198 46
    public function setPhoneAttribute($phone)
199
    {
200 46
        $this->attributes['phone'] = trim($phone) ?: null;
201 46
    }
202
203
    /**
204
     * Set Postal Address.
205
     *
206
     * @param string $postalAddress Postal address
207
     */
208 46
    public function setPostalAddressAttribute($postalAddress)
209
    {
210 46
        $this->attributes['postal_address'] = trim($postalAddress) ?: null;
211 46
    }
212
213
    /**
214
     * Set Social Facebook.
215
     *
216
     */
217 45
    public function setSocialFacebookAttribute($facebookPageUrl)
218
    {
219 45
        $this->attributes['social_facebook'] = trim($facebookPageUrl) ?: null;
220 45
    }
221
}
222