summaryrefslogtreecommitdiff
path: root/app/Models
diff options
context:
space:
mode:
Diffstat (limited to 'app/Models')
-rw-r--r--app/Models/File.php68
-rw-r--r--app/Models/Link.php2
-rw-r--r--app/Models/Role.php8
-rwxr-xr-xapp/Models/User.php15
4 files changed, 90 insertions, 3 deletions
diff --git a/app/Models/File.php b/app/Models/File.php
index e73ce08..8fb08ab 100644
--- a/app/Models/File.php
+++ b/app/Models/File.php
@@ -9,7 +9,71 @@ class File extends Model
{
use AutoFillable;
- public function tags(){
+ protected $fillable = [
+ 'filename',
+ 'path',
+ 'source',
+ 'description',
+ 'md5',
+ 'size',
+ 'mime_type',
+ 'user_id'
+ ];
+
+ public function tags()
+ {
return $this->belongsToMany(Tag::class);
}
-}
+
+ public function user()
+ {
+ return $this->belongsTo(User::class);
+ }
+
+ // Helper methods for tags
+ public function addTags(array $tagNames)
+ {
+ $tagIds = [];
+
+ foreach ($tagNames as $tagName) {
+ $tagName = trim($tagName);
+ if (empty($tagName)) continue;
+
+ // Find or create tag
+ $tag = Tag::firstOrCreate(
+ ['label' => $tagName],
+ ['refs' => 0]
+ );
+
+ // Increment ref count if new relationship
+ if (!$this->tags->contains($tag->id)) {
+ $tag->increment('refs');
+ }
+
+ $tagIds[] = $tag->id;
+ }
+
+ if (!empty($tagIds)) {
+ $this->tags()->syncWithoutDetaching($tagIds);
+ }
+
+ return $this;
+ }
+
+ public function removeTags(array $tagNames)
+ {
+ $tagsToRemove = Tag::whereIn('label', $tagNames)->get();
+
+ foreach ($tagsToRemove as $tag) {
+ $this->tags()->detach($tag->id);
+ $tag->decrement('refs');
+ }
+
+ return $this;
+ }
+
+ public function getTagsString()
+ {
+ return $this->tags->pluck('label')->implode(', ');
+ }
+} \ No newline at end of file
diff --git a/app/Models/Link.php b/app/Models/Link.php
index 3373510..6f3648c 100644
--- a/app/Models/Link.php
+++ b/app/Models/Link.php
@@ -8,7 +8,7 @@ use App\Models\Traits\AutoFillable;
class Link extends Model
{
//use AutoFillable;
- protected $fillable = ['label', 'url', 'description', 'user_id'];
+ public $fillable = ['label', 'url', 'description', 'user_id'];
public function tags(){
return $this->belongsToMany(Tag::class);
diff --git a/app/Models/Role.php b/app/Models/Role.php
index e9a5f86..78412c4 100644
--- a/app/Models/Role.php
+++ b/app/Models/Role.php
@@ -6,6 +6,14 @@ use Illuminate\Database\Eloquent\Model;
class Role extends Model
{
+
+ protected $fillable = [
+ 'name',
+ 'description',
+ 'max_filesize',
+ 'storage_quota'
+ ];
+
public function users()
{
return $this->belongsToMany(User::class);
diff --git a/app/Models/User.php b/app/Models/User.php
index e908679..3c5e429 100755
--- a/app/Models/User.php
+++ b/app/Models/User.php
@@ -60,4 +60,19 @@ class User extends Authenticatable
public function links(){
return $this->hasMany(Link::class);
}
+
+ public function getStorageQuota(){
+ $roles = $this->roles();
+ $quota = 0;
+ foreach ($roles as $r){
+ if ($role->storage_quota > $quota){
+ $quota = $role->storage_quota;
+ }
+ }
+ return $quota;
+ }
+
+ public function getStorageUsed(){
+
+ }
}