Initial import
This commit is contained in:
@@ -0,0 +1,43 @@
|
||||
<?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;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user