aboutsummaryrefslogtreecommitdiffhomepage
path: root/main/app/sprinkles/account/src/Database/Models/Group.php
diff options
context:
space:
mode:
Diffstat (limited to 'main/app/sprinkles/account/src/Database/Models/Group.php')
-rwxr-xr-xmain/app/sprinkles/account/src/Database/Models/Group.php69
1 files changed, 69 insertions, 0 deletions
diff --git a/main/app/sprinkles/account/src/Database/Models/Group.php b/main/app/sprinkles/account/src/Database/Models/Group.php
new file mode 100755
index 0000000..f10e066
--- /dev/null
+++ b/main/app/sprinkles/account/src/Database/Models/Group.php
@@ -0,0 +1,69 @@
+<?php
+/**
+ * UserFrosting (http://www.userfrosting.com)
+ *
+ * @link https://github.com/userfrosting/UserFrosting
+ * @license https://github.com/userfrosting/UserFrosting/blob/master/licenses/UserFrosting.md (MIT License)
+ */
+namespace UserFrosting\Sprinkle\Account\Database\Models;
+
+use Illuminate\Database\Capsule\Manager as Capsule;
+use UserFrosting\Sprinkle\Core\Database\Models\Model;
+
+/**
+ * Group Class
+ *
+ * Represents a group object as stored in the database.
+ *
+ * @package UserFrosting
+ * @author Alex Weissman
+ * @see http://www.userfrosting.com/tutorials/lesson-3-data-model/
+ *
+ * @property string slug
+ * @property string name
+ * @property string description
+ * @property string icon
+ */
+class Group extends Model
+{
+ /**
+ * @var string The name of the table for the current model.
+ */
+ protected $table = "groups";
+
+ protected $fillable = [
+ "slug",
+ "name",
+ "description",
+ "icon"
+ ];
+
+ /**
+ * @var bool Enable timestamps for this class.
+ */
+ public $timestamps = true;
+
+ /**
+ * Delete this group from the database, along with any user associations
+ *
+ * @todo What do we do with users when their group is deleted? Reassign them? Or, can a user be "groupless"?
+ */
+ public function delete()
+ {
+ // Delete the group
+ $result = parent::delete();
+
+ return $result;
+ }
+
+ /**
+ * Lazily load a collection of Users which belong to this group.
+ */
+ public function users()
+ {
+ /** @var UserFrosting\Sprinkle\Core\Util\ClassMapper $classMapper */
+ $classMapper = static::$ci->classMapper;
+
+ return $this->hasMany($classMapper->getClassMapping('user'), 'group_id');
+ }
+}