Callbacks   A
last analyzed

Complexity

Total Complexity 10

Size/Duplication

Total Lines 76
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 0
Metric Value
dl 0
loc 76
rs 10
c 0
b 0
f 0
wmc 10
lcom 0
cbo 1

2 Methods

Rating   Name   Duplication   Size   Complexity  
B data() 0 27 5
B record() 0 29 5
1
<?php
2
3
/**
4
 * Callbacks for members plugin
5
 *
6
 * PHP Version 5
7
 *
8
 * @category  Plugins
9
 * @package   Members
10
 * @author    Hans-Joachim Piepereit <[email protected]>
11
 * @copyright 2013 cSphere Team
12
 * @license   http://opensource.org/licenses/bsd-license Simplified BSD License
13
 * @link      http://www.csphere.eu
14
 **/
15
16
namespace csphere\plugins\members\classes;
17
18
/**
19
 * Callbacks for members plugin
20
 *
21
 * @category  Plugins
22
 * @package   Members
23
 * @author    Hans-Joachim Piepereit <[email protected]>
24
 * @copyright 2013 cSphere Team
25
 * @license   http://opensource.org/licenses/bsd-license Simplified BSD License
26
 * @link      http://www.csphere.eu
27
 **/
28
29
abstract class Callbacks
30
{
31
    /**
32
     * Add group and user name to data
33
     *
34
     * @param array $array Array with data for template
35
     *
36
     * @return array
37
     **/
0 ignored issues
show
Coding Style introduced by
There must be no blank lines after the function comment
Loading history...
38
39
    public static function data(array $array)
40
    {
41
        // User table
42
        $user_name = '';
43
44
        if (!empty($array['user_id'])) {
45
46
            $dm_users  = new \csphere\core\datamapper\Model('users');
47
            $user      = $dm_users->read($array['user_id']);
48
            $user_name = empty($user['user_name']) ? '' : $user['user_name'];
49
        }
50
51
        $array['user_name'] = $user_name;
52
53
        // Group table
54
        $group_name = '';
55
56
        if (!empty($array['group_id'])) {
57
            $dm_groups  = new \csphere\core\datamapper\Model('groups');
58
            $group      = $dm_groups->read($array['group_id']);
59
            $group_name = empty($group['group_name']) ? '' : $group['group_name'];
60
        }
61
62
        $array['group_name'] = $group_name;
63
64
        return $array;
65
    }
66
67
    /**
68
     * Add group and user serial to record
69
     *
70
     * @param array $array Array with data of record
71
     *
72
     * @return array
73
     **/
0 ignored issues
show
Coding Style introduced by
There must be no blank lines after the function comment
Loading history...
74
75
    public static function record(array $array)
76
    {
77
        // User table
78
        $user_id = '';
79
80
        if (!empty($array['user_name'])) {
81
82
            $dm_users  = new \csphere\core\datamapper\Model('users');
83
            $user      = $dm_users->read($array['user_name'], 'user_name');
84
            $user_id = empty($user['user_id']) ? '' : $user['user_id'];
85
        }
86
87
        $array['user_id'] = $user_id;
88
        unset($array['user_name']);
89
90
        // Group table
91
        $group_id = '';
92
93
        if (!empty($array['group_name'])) {
94
            $dm_groups  = new \csphere\core\datamapper\Model('groups');
95
            $group      = $dm_groups->read($array['group_name'], 'group_name');
96
            $group_id = empty($group['group_id']) ? '' : $group['group_id'];
97
        }
98
99
        $array['group_id'] = $group_id;
100
        unset($array['group_name']);
101
102
        return $array;
103
    }
104
}
105