language;
}
$langAlias = "{$alias}".$langAliasNew;
$query->leftJoin([ $langAlias=> VendorLang::tableName()],
"$langAlias.vendor_id = $alias.vendor_id")
->andWhere(["$langAlias.language_code" => $language])
->addSelect([
"$langAlias.vendor_name",
"$langAlias.vendor_image_path",
"$langAlias.vendor_description"
]);
}
/**
* @return array
*/
public function behaviors()
{
$behaviors = parent::behaviors();
$behaviors[] = [
'class' => AttributeKeyGeneratorBehaviour::class,
'attributes' => [
'vendor_key'
]
];
return $behaviors;
}
/**
* Finds an identity by the given ID.
* @param string|int $id the ID to be looked for
* @return IdentityInterface the identity object that matches the given ID.
* Null should be returned if such an identity cannot be found
* or the identity is not in an active state (disabled, deleted, etc.)
*/
public static function findIdentity($id)
{
$vendor = static::findOne(['user_id' => $id, 'status' => self::ACTIVE]);
return $vendor;
}
/**
* Finds an identity by the given token.
* @param mixed $token the token to be looked for
* @param mixed $type the type of the token. The value of this parameter depends on the implementation.
* For example, [[\yii\filters\auth\HttpBearerAuth]] will set this parameter to be `yii\filters\auth\HttpBearerAuth`.
* @return IdentityInterface the identity object that matches the given token.
* @throws \OutOfBoundsException
* @throws \BadMethodCallException
* Null should be returned if such an identity cannot be found
* or the identity is not in an active state (disabled, deleted, etc.)
*/
public static function findIdentityByAccessToken($token, $type = null)
{
$id = null;
$jwtObj = Jwt::getInstance();
if( $jwtObj->isValid($token) ){
$id = $jwtObj->getPrivateClaim($token);
}
return self::findOne($id);
}
/**
* Finds user by user_name
*
* @param string $user_name
* @return static|null
*/
/**
* @param $username
* @return array|null|\yii\db\ActiveRecord
*/
public static function findByUsername($username)
{
return static::find()
->where( ['vendor_email' => $username])
->andWhere(['vendor_status' => self::STATUS_ACTIVE])
->limit(1)
->one();
}
/**
* 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,
'vendor_status' => self::STATUS_ACTIVE,
]);
}
/**
* Finds out if password reset token is valid
*
* @param string $token password reset token
* @return bool
*/
public static function isPasswordResetTokenValid($token)
{
if (empty($token)) {
return false;
}
$timestamp = (int) substr($token, strrpos($token, '_') + 1);
$expire = Yii::$app->params['user.passwordResetTokenExpire'];
return $timestamp + $expire >= time();
}
/**
* Returns an ID that can uniquely identify a user identity.
* @return string|int an ID that uniquely identifies a user identity.
*/
public function getId()
{
return $this->getPrimaryKey();
}
/**
* Returns a key that can be used to check the validity of a given identity ID.
*
* The key should be unique for each individual user, and should be persistent
* so that it can be used to check the validity of the user identity.
*
* The space of such keys should be big enough to defeat potential identity attacks.
*
* This is required if [[User::enableAutoLogin]] is enabled.
* @return string a key that is used to check the validity of a given identity ID.
* @see validateAuthKey()
*/
public function getAuthKey()
{
return $this->auth_key;
}
/**
* Validates the given auth key.
*
* This is required if [[User::enableAutoLogin]] is enabled.
* @param string $authKey the given auth key
* @return bool whether the given auth key is valid.
* @see getAuthKey()
*/
public function validateAuthKey($authKey)
{
return $this->getAuthKey() === $authKey;
}
/**
* Validates password
*
* @param string $password password to validate
* @return bool if password provided is valid for current user
* @throws \yii\base\InvalidParamException
*/
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
* @throws \yii\base\Exception
*/
public function setPassword($password)
{
$this->password_hash = Yii::$app->security->generatePasswordHash($password);
}
/**
* Generates secret password hash from password and sets it to the model
*
* @param string $password
* @throws \yii\base\Exception
*/
public function setSecretPassword($secret_password)
{
$this->secret_password_hash = Yii::$app->security->generatePasswordHash($secret_password);
}
/**
* Generates "remember me" authentication key
* @throws \yii\base\Exception
*/
public function generateAuthKey()
{
$this->auth_key = Yii::$app->security->generateRandomString();
}
/**
* Generates new password reset token
* @throws \yii\base\Exception
*/
public function generatePasswordResetToken()
{
$this->password_reset_token = Yii::$app->security->generateRandomString() . '_' . time();
}
/**
* Removes password reset token
*/
public function removePasswordResetToken()
{
$this->password_reset_token = null;
}
/**
* @param int $option
* @return string
*/
public static function getPaymentOptionList($option = 3)
{
$option = explode(",", $option);
$paymentOption = '';
if(isset($_GET['type']) && $_GET['type'] != 2){
if(in_array(Order::PAYMENT_OPTION_COD, $option)){
$paymentOption .= '';
}
}
if(in_array(Order::PAYMENT_OPTION_WALLET, $option)) {
$paymentOption .= '';
}
if(in_array(Order::PAYMENT_OPTION_ONLINE, $option)) {
$paymentOption .= '';
}
if(in_array(Order::PAYMENT_OPTION_MADA, $option)) {
$paymentOption .= '';
}
if(in_array(Order::PAYMENT_OPTION_STC, $option)) {
$paymentOption .= '';
}
// default:
// $paymentOption = '';
return $paymentOption;
}
}