5 use Illuminate\Database\Eloquent\Model;
7 abstract class Entity extends Model
10 * Relation for the user that created this entity.
11 * @return \Illuminate\Database\Eloquent\Relations\BelongsTo
13 public function createdBy()
15 return $this->belongsTo('Oxbow\User', 'created_by');
19 * Relation for the user that updated this entity.
20 * @return \Illuminate\Database\Eloquent\Relations\BelongsTo
22 public function updatedBy()
24 return $this->belongsTo('Oxbow\User', 'updated_by');
28 * Compares this entity to another given entity.
29 * Matches by comparing class and id.
33 public function matches($entity)
35 return [get_class($this), $this->id] === [get_class($entity), $entity->id];
39 * Gets the activity for this entity.
40 * @return \Illuminate\Database\Eloquent\Relations\MorphMany
42 public function activity()
44 return $this->morphMany('Oxbow\Activity', 'entity')->orderBy('created_at', 'desc');
48 * Allows checking of the exact class, Used to check entity type.
49 * Cleaner method for is_a.
53 public function isA($type)
55 return $this->getName() === strtolower($type);
59 * Gets the class name.
62 public function getName()
64 $fullClassName = get_class($this);
65 return strtolower(array_slice(explode('\\', $fullClassName), -1, 1)[0]);
69 * Perform a full-text search on this entity.
70 * @param string[] $fieldsToSearch
71 * @param string[] $terms
72 * @param string[] array $wheres
75 public static function fullTextSearch($fieldsToSearch, $terms, $wheres = [])
78 foreach ($terms as $term) {
79 $termString .= $term . '* ';
81 $fields = implode(',', $fieldsToSearch);
82 $search = static::whereRaw('MATCH(' . $fields . ') AGAINST(? IN BOOLEAN MODE)', [$termString]);
83 foreach ($wheres as $whereTerm) {
84 $search->where($whereTerm[0], $whereTerm[1], $whereTerm[2]);
86 return $search->get();
90 * Get the url for this item.
93 abstract public function getUrl();