aboutsummaryrefslogtreecommitdiff
path: root/lib/models/Contact.class.php
blob: 9e9b1dd00b9e9a55a13094d6adb486fc9bcb3f11 (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
<?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 $mkdate database column
 * @property User $owner
 * @property User $friend
 * @property StatusgruppeUser[]|SimpleORMapCollection $group_assignments
 */
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']['group_assignments'] = [
            'class_name'        => 'StatusgruppeUser',
            'assoc_func'        => 'findByContact',
            'foreign_key'       => function ($me) {
                return [$me];
            },
            'assoc_foreign_key' => function ($group, $params) {
                $group->setValue('user_id', $params[0]->user_id);
            },
            'on_store'          => 'store',
            'on_delete'         => 'delete'
        ];

        parent::configure($config);
    }
}