44 lines
788 B
PHP
44 lines
788 B
PHP
<?php
|
|
|
|
class User extends Model {
|
|
public static $table = "users";
|
|
|
|
public function is_favourite($doc) {
|
|
$f = Favourite::find([
|
|
["owner", "=", $this->id],
|
|
["document", "=", $doc]])->first();
|
|
if ($f) {
|
|
return true;
|
|
}
|
|
return false;
|
|
}
|
|
|
|
public function set_favourite($doc) {
|
|
$f = Favourite::find([
|
|
["owner", "=", $this->id],
|
|
["document", "=", $doc]])->first();
|
|
if (!$f) {
|
|
$f = new Favourite;
|
|
$f->owner = $this->id;
|
|
$f->document = $doc;
|
|
$f->save();
|
|
}
|
|
}
|
|
|
|
public function unset_favourite($doc) {
|
|
$f = Favourite::find([
|
|
["owner", "=", $this->id],
|
|
["document", "=", $doc]])->first();
|
|
if ($f) {
|
|
$f->delete();
|
|
}
|
|
}
|
|
|
|
public function favourites() {
|
|
$f = Favourite::find([
|
|
["owner", "=", $this->id],
|
|
])->all();
|
|
return $f;
|
|
}
|
|
}
|