Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Module.php
Original file line number Diff line number Diff line change
Expand Up @@ -279,4 +279,4 @@ public function getActions()
"/{$this->id}/confirm?key=zzzzz" => "Confirm email address. Automatically generated upon registration/email change",
];
}
}
}
29 changes: 29 additions & 0 deletions helpers/Timezone.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?php

namespace amnah\yii2\user\helpers;

use yii\helpers\ArrayHelper;

class Timezone
{

/**
* Get all of the time zones with the offsets sorted by their offset
*
* @return array
*/
public static function getAll() {
$timezones = [];
$time_zones = $timezone_identifiers = \DateTimeZone::listIdentifiers();

foreach ($time_zones as $time_zone) {
$date = new \DateTime('now', new \DateTimeZone($time_zone));
$offset_in_hours = $date->getOffset() / 60 / 60;
$timezones[] = ['timezone' => $time_zone, 'name' => "{$time_zone} (UTC " . ($offset_in_hours > 0 ? '+' : '') . "{$offset_in_hours})", 'offset' => $offset_in_hours];
}

ArrayHelper::multisort($timezones, 'offset', SORT_DESC, SORT_NUMERIC);

return $timezones;
}
}
1 change: 1 addition & 0 deletions migrations/m150214_044831_init_user.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ public function safeUp()
'create_time' => Schema::TYPE_TIMESTAMP . ' null default null',
'update_time' => Schema::TYPE_TIMESTAMP . ' null default null',
'full_name' => Schema::TYPE_STRING . ' null default null',
'timezone' => Schema::TYPE_STRING . ' null default null',
], $tableOptions);
$this->createTable('{{%user_auth}}', [
'id' => Schema::TYPE_PK,
Expand Down
22 changes: 19 additions & 3 deletions models/Profile.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
* @property string $create_time
* @property string $update_time
* @property string $full_name
* @property string $timezone
*
* @property User $user
*/
Expand All @@ -26,6 +27,19 @@ public static function tableName()
return static::getDb()->tablePrefix . "profile";
}

/** @var \app\modules\user\Module $module */
public $module;

/**
* @inheritdoc
*/
public function init()
{
if (!$this->module) {
$this->module = Yii::$app->getModule("user");
}
}

/**
* @inheritdoc
*/
Expand All @@ -35,7 +49,8 @@ public function rules()
// [['user_id'], 'required'],
// [['user_id'], 'integer'],
// [['create_time', 'update_time'], 'safe'],
[['full_name'], 'string', 'max' => 255]
[['full_name'], 'string', 'max' => 255],
[['timezone'], 'string', 'max' => 125],
];
}

Expand All @@ -50,6 +65,7 @@ public function attributeLabels()
'create_time' => Yii::t('user', 'Create Time'),
'update_time' => Yii::t('user', 'Update Time'),
'full_name' => Yii::t('user', 'Full Name'),
'timezone' => Yii::t('user', 'Time zone'),
];
}

Expand All @@ -75,7 +91,7 @@ public function behaviors()
*/
public function getUser()
{
$user = Yii::$app->getModule("user")->model("User");
$user = $this->module->model("User");
return $this->hasOne($user::className(), ['id' => 'user_id']);
}

Expand All @@ -90,4 +106,4 @@ public function setUser($userId)
$this->user_id = $userId;
return $this;
}
}
}
14 changes: 10 additions & 4 deletions models/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,9 @@ public function getProfiles()
*/
public function getProfile()
{
$profile = Yii::$app->getModule("user")->model("Profile");
/** @var Module $userModule */
$userModule = Yii::$app->getModule("user");
$profile = $userModule->model("Profile");
return $this->hasOne($profile::className(), ['user_id' => 'id']);
}

Expand All @@ -207,7 +209,9 @@ public function getProfile()
*/
public function getRole()
{
$role = Yii::$app->getModule("user")->model("Role");
/** @var Module $userModule */
$userModule = Yii::$app->getModule("user");
$role = $userModule->model("Role");
return $this->hasOne($role::className(), ['id' => 'role_id']);
}

Expand All @@ -216,7 +220,9 @@ public function getRole()
*/
public function getUserKeys()
{
$userKey = Yii::$app->getModule("user")->model("UserKey");
/** @var Module $userModule */
$userModule = Yii::$app->getModule("user");
$userKey = $userModule->model("UserKey");
return $this->hasMany($userKey::className(), ['user_id' => 'id']);
}

Expand Down Expand Up @@ -529,4 +535,4 @@ public static function statusDropdown()

return $dropdown;
}
}
}
1 change: 1 addition & 0 deletions views/admin/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@
],
'email:email',
'profile.full_name',
'profile.timezone',
'create_time',
// 'new_email:email',
// 'username',
Expand Down
2 changes: 1 addition & 1 deletion views/default/login.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
$this->title = Yii::t('user', 'Login');
$this->params['breadcrumbs'][] = $this->title;
?>
<div class="user-default-login">
<div class="user-default-login" style="height: 650px;">

<h1><?= Html::encode($this->title) ?></h1>

Expand Down
4 changes: 3 additions & 1 deletion views/default/profile.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@

<?= $form->field($profile, 'full_name') ?>

<?= $form->field($profile, 'timezone')->dropDownList(\yii\helpers\ArrayHelper::map(\amnah\yii2\user\helpers\Timezone::getAll(), 'timezone', 'name')); ?>

<div class="form-group">
<div class="col-lg-offset-2 col-lg-10">
<?= Html::submitButton(Yii::t('user', 'Update'), ['class' => 'btn btn-primary']) ?>
Expand All @@ -44,4 +46,4 @@

<?php ActiveForm::end(); ?>

</div>
</div>
6 changes: 3 additions & 3 deletions views/default/register.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,9 @@

<?= $form->field($user, 'newPassword')->passwordInput() ?>

<?php /* uncomment if you want to add profile fields here
<?php /* uncomment if you want to add profile fields here */ ?>
<?= $form->field($profile, 'full_name') ?>
*/ ?>
<?php /**/ ?>

<div class="form-group">
<div class="col-lg-offset-2 col-lg-10">
Expand All @@ -73,4 +73,4 @@

<?php endif; ?>

</div>
</div>