Pluf Framework

Pluf Framework Commit Details


Date:2008-11-05 08:24:42 (16 years 1 month ago)
Author:Loic d'Anterroches
Branch:develop, master
Commit:56247d099baffa704bf3e75a9d90494c51bc568d
Parents: f92797145045956156ff421ac3ab2707da609c2f
Message:Improved the Pluf_User class.

- Added a profile with the ability to get it with getProfile().
- Store now the timezone and the language within the user base
information as this is common information.
Changes:

File differences

src/Pluf/Migrations/5UserDetails.php
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
<?php
/* -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
# ***** BEGIN LICENSE BLOCK *****
# This file is part of Plume Framework, a simple PHP Application Framework.
# Copyright (C) 2001-2007 Loic d'Anterroches and contributors.
#
# Plume Framework is free software; you can redistribute it and/or modify
# it under the terms of the GNU Lesser General Public License as published by
# the Free Software Foundation; either version 2.1 of the License, or
# (at your option) any later version.
#
# Plume Framework is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
#
# ***** END LICENSE BLOCK ***** */
/**
* Add lang and timezone in the user model.
*/
function Pluf_Migrations_5UserDetails_up($params=null)
{
$db = Pluf::db();
$db->begin(); // Start a transaction
try {
// Add 2 new fields.
$guser = new Pluf_User();
$table = $guser->getSqlTable();
$sql = 'ALTER TABLE '.$table."\n"
.'ADD COLUMN language VARCHAR(5) DEFAULT \'en\','."\n"
.'ADD COLUMN timezone VARCHAR(50) DEFAULT \'Europe/Berlin\''."\n";
$db->execute($sql);
} catch (Exception $e) {
$db->rollback();
throw $e;
}
$db->commit();
}
function Pluf_Migrations_5UserDetails_down($params=null)
{
$db = Pluf::db();
$db->begin(); // Start a transaction
try {
$guser = new Pluf_User();
$table = $guser->getSqlTable();
$sql = 'ALTER TABLE '.$table."\n"
.'DROP COLUMN language,'."\n"
.'DROP COLUMN timezone'."\n";
$db->execute($sql);
} catch (Exception $e) {
$db->rollback();
throw $e;
}
$db->commit();
}
src/Pluf/User.php
114114
115115
116116
117
117
118118
119119
120120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
121139
122140
123141
124142
125143
144
126145
127146
128147
129148
130149
131150
151
132152
133153
134154
......
377397
378398
379399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
380425
'active' =>
array(
'type' => 'Pluf_DB_Field_Boolean',
'default' => false,
'default' => true,
'blank' => true,
'verbose' => __('active'),
),
'language' =>
array(
'type' => 'Pluf_DB_Field_Varchar',
'blank' => true,
'default' => 'en',
'size' => 5,
'verbose' => __('language'),
'help_text' => __('Prefered language of the user for the interface. Use the 2 or 5 letter code like "fr", "en", "fr_QC" or "en_US".')
),
'timezone' =>
array(
'type' => 'Pluf_DB_Field_Varchar',
'blank' => true,
'default' => 'Europe/Berlin',
'size' => 45,
'verbose' => __('time zone'),
'help_text' => __('Time zone of the user to display the time in local time.')
),
'date_joined' =>
array(
'type' => 'Pluf_DB_Field_Datetime',
'blank' => true,
'verbose' => __('date joined'),
'editable' => false,
),
'last_login' =>
array(
'type' => 'Pluf_DB_Field_Datetime',
'blank' => true,
'verbose' => __('last login'),
'editable' => false,
),
);
$this->_a['idx'] = array(
}
return $messages;
}
/**
* Get profile.
*
* Retrieve the profile of the current user. If not profile in the
* database a Pluf_Exception_DoesNotExist exception is thrown,
* just catch it and create a profile.
*
* @return Pluf_Model User profile
*/
function getProfile()
{
$pclass = Pluf::f('user_profile_class', false);
if (false == $pclass) {
throw new Pluf_Exception_SettingError(__('"user_profile_class" setting not defined.'));
}
$db = $this->getDbConnection();
$sql = new Pluf_SQL(sprintf('%s=%%s', $db->qn('user')),
array($this->id));
$users = Pluf::factory($pclass)->getList(array('filter' => $sql->gen()));
if ($users->count() != 1) {
throw new Pluf_Exception_DoesNotExist(sprintf(__('No profiles available for user: %s'), (string) $this));
}
return $users[0];
}
}

Archive Download the corresponding diff file

Branches

Tags

Number of commits:
Page rendered in 0.06635s using 13 queries.