aboutsummaryrefslogtreecommitdiff
path: root/lib/models/Contact.php
diff options
context:
space:
mode:
Diffstat (limited to 'lib/models/Contact.php')
-rw-r--r--lib/models/Contact.php51
1 files changed, 51 insertions, 0 deletions
diff --git a/lib/models/Contact.php b/lib/models/Contact.php
new file mode 100644
index 0000000..bea5b95
--- /dev/null
+++ b/lib/models/Contact.php
@@ -0,0 +1,51 @@
+<?php
+
+/**
+ * Contact.php - model class for table contact
+ *
+ * @author <mlunzena@uos.de>
+ * @license GPL 2 or later
+ *
+ * @property array $id alias for pk
+ * @property string $owner_id database column
+ * @property string $user_id database column
+ * @property string $calendar_permissions database column
+ * An enum with the possible values "", "READ" and "WRITE".
+ * The empty string specifies that no calendar permissions are granted.
+ * @property User $owner belongs_to User
+ * @property User $friend belongs_to User
+ * @property string $mkdate database column
+ * @property string $chdate database column
+ */
+class Contact extends SimpleORMap
+{
+ protected static function configure($config = [])
+ {
+ $config['db_table'] = 'contact';
+
+ $config['belongs_to']['owner'] = [
+ 'class_name' => User::class,
+ 'foreign_key' => 'owner_id'
+ ];
+ $config['belongs_to']['friend'] = [
+ 'class_name' => User::class,
+ 'foreign_key' => 'user_id'
+ ];
+
+ $config['has_many']['groups'] = [
+ 'class_name' => ContactGroupItem::class,
+ 'assoc_func' => 'findByContact',
+ 'foreign_key' => function ($me) {
+ return [$me];
+ },
+ 'assoc_foreign_key' => function ($item, $params) {
+ //Nothing else here. But this has to be present
+ //so that storing a new contact works.
+ },
+ 'on_store' => 'store',
+ 'on_delete' => 'delete'
+ ];
+
+ parent::configure($config);
+ }
+}