%PDF- <> %âãÏÓ endobj 2 0 obj <> endobj 3 0 obj <>/ExtGState<>/ProcSet[/PDF/Text/ImageB/ImageC/ImageI] >>/Annots[ 28 0 R 29 0 R] /MediaBox[ 0 0 595.5 842.25] /Contents 4 0 R/Group<>/Tabs/S>> endobj ºaâÚÎΞ-ÌE1ÍØÄ÷{òò2ÿ ÛÖ^ÔÀá TÎ{¦?§®¥kuµùÕ5sLOšuY>endobj 2 0 obj<>endobj 2 0 obj<>endobj 2 0 obj<>endobj 2 0 obj<> endobj 2 0 obj<>endobj 2 0 obj<>es 3 0 R>> endobj 2 0 obj<> ox[ 0.000000 0.000000 609.600000 935.600000]/Fi endobj 3 0 obj<> endobj 7 1 obj<>/ProcSet[/PDF/Text/ImageB/ImageC/ImageI]>>/Subtype/Form>> stream
<?php
namespace mdm\admin\models;
use mdm\admin\components\Configs;
use mdm\admin\components\UserStatus;
use Yii;
use yii\base\NotSupportedException;
use yii\behaviors\TimestampBehavior;
use yii\behaviors\BlameableBehavior;
use yii\db\ActiveRecord;
use yii\web\IdentityInterface;
use yii\db\Expression;
// use yii\behaviors\BlameableBehavior;
// use yii\db\Expression;
/**
* User model
*
* @property integer $id
* @property string $username
* @property string $password_hash
* @property string $password_reset_token
* @property string $email
* @property string $auth_key
* @property integer $status
* @property integer $created_at
* @property integer $updated_at
* @property string $password write-only password
*
* @property UserProfile $profile
*/
class User extends ActiveRecord implements IdentityInterface
{
const STATUS_INACTIVE = 0;
const STATUS_ACTIVE = 10;
/**
* @inheritdoc
*/
public static function tableName()
{
return Configs::instance()->userTable;
}
/**
* @inheritdoc
*/
// public function behaviors()
// {
// return [
// TimestampBehavior::className(),
// ];
// }
public function behaviors()
{
return [
'timestamp' => [
'class' => 'yii\behaviors\TimestampBehavior',
'attributes' => [
ActiveRecord::EVENT_BEFORE_INSERT => ['created_at', 'updated_at'],
ActiveRecord::EVENT_BEFORE_UPDATE => ['updated_at'],
],
'value' => new Expression('NOW()'),
],
// 'blameable' => [
// 'class' => BlameableBehavior::className(),
// 'createdByAttribute' => 'created_by',
// 'updatedByAttribute' => 'updated_by',
// ],
];
}
/**
* @inheritdoc
*/
public function rules()
{
return [
['status', 'in', 'range' => [UserStatus::ACTIVE, UserStatus::INACTIVE]],
];
}
// public function behaviors()
// {
// return [
// 'timestamp' => [
// 'class' => 'yii\behaviors\TimestampBehavior',
// 'attributes' => [
// ActiveRecord::EVENT_BEFORE_INSERT => ['created_at', 'updated_at'],
// ActiveRecord::EVENT_BEFORE_UPDATE => ['updated_at'],
// ],
// 'value' => new Expression('NOW()'),
// ],
// 'blameable' => [
// 'class' => BlameableBehavior::className(),
// 'createdByAttribute' => 'created_by',
// 'updatedByAttribute' => 'updated_by',
// ],
// ];
// }
/**
* @inheritdoc
*/
public static function findIdentity($id)
{
return static::findOne(['id' => $id, 'status' => UserStatus::ACTIVE]);
}
/**
* @inheritdoc
*/
public static function findIdentityByAccessToken($token, $type = null)
{
throw new NotSupportedException('"findIdentityByAccessToken" is not implemented.');
}
/**
* Finds user by username
*
* @param string $username
* @return static|null
*/
public static function findByUsername($username)
{
return static::findOne(['username' => $username, 'status' => UserStatus::ACTIVE]);
}
/**
* Finds user by password reset token
*
* @param string $token password reset token
* @return static|null
*/
public static function findByPasswordResetToken($token)
{
if (!static::isPasswordResetTokenValid($token)) {
return null;
}
return static::findOne([
'password_reset_token' => $token,
'status' => UserStatus::ACTIVE,
]);
}
/**
* Finds out if password reset token is valid
*
* @param string $token password reset token
* @return boolean
*/
public static function isPasswordResetTokenValid($token)
{
if (empty($token)) {
return false;
}
$expire = Yii::$app->params['user.passwordResetTokenExpire'];
$parts = explode('_', $token);
$timestamp = (int) end($parts);
return $timestamp + $expire >= time();
}
/**
* @inheritdoc
*/
public function getId()
{
return $this->getPrimaryKey();
}
/**
* @inheritdoc
*/
public function getAuthKey()
{
return $this->auth_key;
}
/**
* @inheritdoc
*/
public function validateAuthKey($authKey)
{
return $this->getAuthKey() === $authKey;
}
/**
* Validates password
*
* @param string $password password to validate
* @return boolean if password provided is valid for current user
*/
public function validatePassword($password)
{
return Yii::$app->security->validatePassword($password, $this->password_hash);
}
/**
* Generates password hash from password and sets it to the model
*
* @param string $password
*/
public function setPassword($password)
{
$this->password_hash = Yii::$app->security->generatePasswordHash($password);
}
/**
* Generates "remember me" authentication key
*/
public function generateAuthKey()
{
$this->auth_key = Yii::$app->security->generateRandomString();
}
/**
* Generates new password reset token
*/
public function generatePasswordResetToken()
{
$this->password_reset_token = Yii::$app->security->generateRandomString() . '_' . time();
}
/**
* Removes password reset token
*/
public function removePasswordResetToken()
{
$this->password_reset_token = null;
}
public static function getDb()
{
return Configs::userDb();
}
public function getTanggal($tanggal) // fungsi atau method untuk mengubah hari, tanggal ke format indonesia
{
$BulanIndo = array("", "Januari", "Februari", "Maret", "April", "Mei", "Juni", "Juli", "Agustus", "September", "Oktober", "November", "Desember");
$HariIndo = array("Minggu", "Senin", "Selasa", "Rabu", "Kamis", "Jumat", "Sabtu");
$sepparator = '-';
$parts = explode($sepparator, $tanggal);
//$hari = $HariIndo[date("w", mktime(0, 0, 0, $parts[1], $parts[2], $parts[0]))]; //mendapatkan hari indonesia
$tgl = substr($tanggal, 8, 2); // memisahkan format tanggal menggunakan substring
$bulan = substr($tanggal, 5, 2); // memisahkan format bulan menggunakan substring
$tahun = substr($tanggal, 0, 4); // memisahkan format tahun menggunakan substring
//$result = $hari .", " .$tgl . " " . $BulanIndo[(int)$bulan] . " ". $tahun;
$result = $tgl . " " . $BulanIndo[(int)$bulan] . " " . $tahun;
return ($result);
}
}