summaryrefslogtreecommitdiff
path: root/src/SemanticScuttle/Model/User.php
blob: e5d29af869474620a991d2c26e0d36f4db95aeef (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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
<?php
/**
 * SemanticScuttle - your social bookmark manager.
 *
 * PHP version 5.
 *
 * @category Bookmarking
 * @package  SemanticScuttle
 * @author   Benjamin Huynh-Kim-Bang <mensonge@users.sourceforge.net>
 * @author   Christian Weiske <cweiske@cweiske.de>
 * @author   Eric Dane <ericdane@users.sourceforge.net>
 * @license  GPL http://www.gnu.org/licenses/gpl.html
 * @link     http://sourceforge.net/projects/semanticscuttle
 */

/**
 * SemanticScuttle user object.
 * Rarely used fields are filled if required.
 *
 * @category Bookmarking
 * @package  SemanticScuttle
 * @author   Benjamin Huynh-Kim-Bang <mensonge@users.sourceforge.net>
 * @author   Christian Weiske <cweiske@cweiske.de>
 * @author   Eric Dane <ericdane@users.sourceforge.net>
 * @license  GPL http://www.gnu.org/licenses/gpl.html
 * @link     http://sourceforge.net/projects/semanticscuttle
 */
class SemanticScuttle_Model_User
{
    var $id;
    var $username;
    var $name;
    var $email;
    var $homepage;
    var $content;
    var $datetime;
    var $isAdmin;
    var $privateKey;

    /**
     * Create a new user object
     *
     * @param integer $id       User ID
     * @param string  $username Username
     */
    public function __construct($id, $username)
    {
        $this->id = $id;
        $this->username = $username;
    }

    /**
     * Returns user ID
     *
     * @return integer ID
     */
    public function getId()
    {
        return (int)$this->id;
    }

    /**
     * Returns logon user name
     *
     * @return string User name
     */
    public function getUsername()
    {
        return $this->username;
    }

    /**
     * Returns private key
     *
     * @param boolean return sanitized value which basically drops
     *                leading dash if exists
     *
     * @return string private key
     */
    public function getPrivateKey($sanitized = false)
    {
        // Look for value only if not already set
        if (!isset($this->privateKey)) {
            $us = SemanticScuttle_Service_Factory::get('User');
            $user = $us->getUser($this->id);
            $this->privateKey = $user['privateKey'];
        }
        if ($sanitized == true) {
            return substr($this->privateKey, -32);
        } else {
            return $this->privateKey;
        }
    }

    /**
     * Returns full user name as specified in the profile.
     *
     * @return string Full name
     */
    public function getName()
    {
        // Look for value only if not already set
        if (!isset($this->name)) {
            $us = SemanticScuttle_Service_Factory::get('User');
            $user = $us->getUser($this->id);
            $this->name = $user['name'];
        }
        return $this->name;
    }

    /**
     * Returns user email address
     *
     * @return string Email address
     */
    public function getEmail()
    {
        // Look for value only if not already set
        if (!isset($this->email)) {
            $us = SemanticScuttle_Service_Factory::get('User');
            $user = $us->getUser($this->id);
            $this->email = $user['email'];
        }
        return $this->email;
    }

    /**
     * Returns user homepage as specified in the profile.
     *
     * @return string Homepage
     */
    public function getHomepage()
    {
        // Look for value only if not already set
        if(!isset($this->homepage)) {
            $us = SemanticScuttle_Service_Factory::get('User');
            $user = $us->getUser($this->id);
            $this->homepage = $user['homepage'];
        }
        return $this->homepage;
    }

    /**
     * Returns custom user description as specified in the profile.
     *
     * @return string User description
     */
    public function getContent()
    {
        // Look for value only if not already set
        if(!isset($this->content)) {
            $us = SemanticScuttle_Service_Factory::get('User');
            $user = $us->getUser($this->id);
            $this->content = $user['uContent'];
        }
        return $this->content;
    }

    /**
     * Returns user creation time.
     * UTC/Zulu time zone is used.
     *
     * @return string Datetime value: "YYYY-MM-DD HH:MM:SS"
     */
    public function getDatetime()
    {
        // Look for value only if not already set
        if(!isset($this->content)) {
            $us = SemanticScuttle_Service_Factory::get('User');
            $user = $us->getUser($this->id);
            $this->datetime = $user['uDatetime'];
        }
        return $this->datetime;
    }

    /**
     * Tells you if the user is an administrator
     *
     * @return boolean True if the user is admin
     */
    public function isAdmin()
    {
        // Look for value only if not already set
        if(!isset($this->isAdmin)) {
            $us = SemanticScuttle_Service_Factory::get('User');
            $this->isAdmin = $us->isAdmin($this->username);
        }
        return $this->isAdmin;
    }

    /**
     * Returns the number of bookmarks the user owns
     *
     * @param string $range Range of bookmarks:
     *                      'public', 'shared', 'private'
     *                      or 'all'
     *
     * @return integer Number of bookmarks
     *
     * @uses SemanticScuttle_Service_Bookmark::countBookmarks()
     */
    public function getNbBookmarks($range = 'public')
    {
        $bs = SemanticScuttle_Service_Factory::get('Bookmark');
        return $bs->countBookmarks($this->getId(), $range);
    }

}
?>