aboutsummaryrefslogtreecommitdiff
path: root/lib/models/Contact.class.php
blob: 16bff26611cfec7a78f95821450374183c54593e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
<?php

/**
 * Contact.class.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);
    }
}