style: Remove espaços em branco

parent e7b99107
......@@ -25,9 +25,9 @@ use vendor\yiisoft\validators\Validator\validateUserBirthDate;
class SistemaTabUsuarios extends \yii\db\ActiveRecord implements IdentityInterface
{
use \common\models\traits\ModelSearch;
public $strSearchModel = '\app\common\models\sistema\SistemaTabUsuariosSearch';
const STATUS_DELETED = 0;
const STATUS_INACTIVE = 2;
const STATUS_SUSPENDEND = 5;
......@@ -63,7 +63,7 @@ class SistemaTabUsuarios extends \yii\db\ActiveRecord implements IdentityInterf
$scenarios[self::SCENARIO_REGISTER] = ['txt_nome', 'txt_email', 'username', 'num_cpf', 'txt_cargo', 'dte_nascimento', 'num_registro_profissional', 'cod_area', 'cod_nivel', 'txt_cep', 'cod_chefia', 'txt_logradouro', 'txt_bairro', 'txt_cidade', 'txt_uf', 'password_reset_token', ];
$scenarios[self::SCENARIO_UPDATE] = [ 'txt_nome', 'txt_email', 'username', 'num_cpf', 'txt_cargo', 'dte_nascimento', 'num_registro_profissional', 'cod_area', 'cod_nivel', 'cod_chefia', 'txt_cep', 'txt_logradouro', 'txt_bairro', 'txt_cidade', 'txt_uf', 'password_reset_token', 'oldPassword','passwordConfirm','password',];
$scenarios[self::SCENARIO_UPDATEADM] = ['txt_nome', 'txt_email', 'username', 'num_cpf', 'txt_cargo', 'num_registro_profissional', 'cod_area', 'cod_nivel', 'cod_chefia', 'txt_logradouro', 'txt_bairro', 'txt_cidade', 'txt_uf', 'password_reset_token',];
return $scenarios;
}
/**
......@@ -73,7 +73,7 @@ class SistemaTabUsuarios extends \yii\db\ActiveRecord implements IdentityInterf
{
return 'sistema.tab_usuarios';
}
/**
* @inheritdoc
*/
......@@ -83,7 +83,7 @@ class SistemaTabUsuarios extends \yii\db\ActiveRecord implements IdentityInterf
TimestampBehavior::className(),
];
}
/**
* @inheritdoc
*/
......@@ -107,32 +107,32 @@ class SistemaTabUsuarios extends \yii\db\ActiveRecord implements IdentityInterf
// UNIQUE
[
['num_cpf','txt_email','username', 'txt_login_usuario',],
'unique',
'unique',
'message' => 'Campo único já cadastrado.',
'on' => [self::SCENARIO_REGISTER, self::SCENARIO_UPDATE, self::SCENARIO_UPDATEADM]
],
// FKS
// [
// 'cod_area',
// 'exist',
// 'exist',
// 'message' => 'Código de área inválido',
// 'targetClass' => 'SistemaOpcAreas'
// ],
// [
// 'cod_chefia',
// 'exist',
// 'cod_chefia',
// 'exist',
// 'message' => 'Código de área inválido',
// // 'targetClass' => '\common\models\sistema\SistemaTabUsuarios',
// 'targetAttribute' => 'cod_usuario',
// ],
// [
// 'cod_nivel',
// 'exist',
// 'cod_nivel',
// 'exist',
// 'message' => 'Código de nível inválido',
// 'targetClass' => '\common\models\sistema\SistemaOpcNivel'
// ],
[
'txt_email',
'txt_email',
'exist',
'targetClass' => '\common\models\sistema\SistemaTabUsuarios',
'filter' => ['bln_ativo' => true],
......@@ -164,16 +164,16 @@ class SistemaTabUsuarios extends \yii\db\ActiveRecord implements IdentityInterf
],
[
[
'txt_login_usuario', 'txt_nome', 'num_cpf', 'txt_cargo', 'num_registro_profissional',
'txt_email', 'auth_key', 'username', 'password_reset_token', 'txt_logradouro', 'txt_cidade',
'txt_bairro', 'txt_uf', 'txt_cep', 'txt_preferencias',
],
'filter',
'txt_login_usuario', 'txt_nome', 'num_cpf', 'txt_cargo', 'num_registro_profissional',
'txt_email', 'auth_key', 'username', 'password_reset_token', 'txt_logradouro', 'txt_cidade',
'txt_bairro', 'txt_uf', 'txt_cep', 'txt_preferencias',
],
'filter',
'filter' => 'trim'
],
// EMAIL
[
'txt_email',
'txt_email',
'email',
'on' => [self::SCENARIO_REGISTER,self::SCENARIO_UPDATE,self::SCENARIO_UPDATEADM]
],
......@@ -193,90 +193,90 @@ class SistemaTabUsuarios extends \yii\db\ActiveRecord implements IdentityInterf
// return ($.inArray(valArea,['1','2','3','4']) != -1);
// }
// ",
// ],
// ],
// INTEGER
[
['cod_area', 'cod_endereco', 'cod_nivel','status', 'created_at', 'updated_at'],
['cod_area', 'cod_endereco', 'cod_nivel','status', 'created_at', 'updated_at'],
'integer',
'message' => 'Campo deve ser um número inteiro',
'on' => [self::SCENARIO_REGISTER,self::SCENARIO_UPDATE,self::SCENARIO_UPDATEADM]
],
// STRINGS
[
['txt_login_usuario', 'oldPassword', 'txt_senha_usuario', 'txt_nome', 'num_cpf', 'txt_cargo', 'num_registro_profissional', 'txt_email', 'auth_key', 'username', 'password_hash', 'password_reset_token', 'txt_logradouro', 'txt_cidade', 'txt_bairro', 'txt_uf', 'txt_cep', ],
['txt_login_usuario', 'oldPassword', 'txt_senha_usuario', 'txt_nome', 'num_cpf', 'txt_cargo', 'num_registro_profissional', 'txt_email', 'auth_key', 'username', 'password_hash', 'password_reset_token', 'txt_logradouro', 'txt_cidade', 'txt_bairro', 'txt_uf', 'txt_cep', ],
'string' ,
'on' => [self::SCENARIO_REGISTER,self::SCENARIO_UPDATE,self::SCENARIO_UPDATEADM]
],
[
['password','passwordConfirm'],
'string',
'min' => 6,
'string',
'min' => 6,
'message' => 'A senha deve ter ao menos 6 caracteres',
'on' => [self::SCENARIO_REGISTER,self::SCENARIO_UPDATE]
],
[
['txt_login_usuario', 'num_registro_profissional'],
'string',
['txt_login_usuario', 'num_registro_profissional'],
'string',
'max' => 30,
'message' => 'O campo pode ter no máximo 30 caracteres.',
'on' => [self::SCENARIO_REGISTER,self::SCENARIO_UPDATE,self::SCENARIO_UPDATEADM]
],
[
['auth_key'],
'string',
['auth_key'],
'string',
'max' => 32,
'message' => 'O campo pode ter no máximo 32 caracteres',
],
[
['txt_nome', 'txt_email', 'txt_bairro', 'txt_uf'],
'string',
['txt_nome', 'txt_email', 'txt_bairro', 'txt_uf'],
'string',
'max' => 150,
'message' => 'O campo pode ter no máximo 150 caracteres',
],
[
['num_cpf'],
'string',
['num_cpf'],
'string',
'max' => 14,
'message' => 'O campo pode ter no máximo 14 caracteres',
// Verificar como mudar a mensagem global para regra MAX de uma STRING
//'message' => 'O cargo pode ter no máximo {max} caracteres.',
],
[
['txt_cargo'],
'string',
['txt_cargo'],
'string',
'max' => 50,
'message' => 'O campo pode ter no máximo 50 caracteres',
],
[
['txt_cep'],
'string',
['txt_cep'],
'string',
'max' => 10,
'message' => 'O campo pode ter no máximo 50 caracteres',
],
[
['username', 'img_foto', 'txt_logradouro', 'txt_cidade',],
'string',
'min' => 2,
['username', 'img_foto', 'txt_logradouro', 'txt_cidade',],
'string',
'min' => 2,
'max' => 255,
'message' => 'O campo deve ter no mínimo 2 e no máximo 255 caracteres',
],
// VALORES PADRÃO
[
'status',
'status',
'default',
'value' => self::STATUS_ACTIVE,
],
// RANGE
[
'status',
'in',
'status',
'in',
'range' => [self::STATUS_ACTIVE, self::STATUS_DELETED]
],
// FILE
[
'file',
'file',
'skipOnEmpty' => true,
'file',
'file',
'skipOnEmpty' => true,
'extensions' => 'png, jpg'
],
[
......@@ -293,27 +293,27 @@ class SistemaTabUsuarios extends \yii\db\ActiveRecord implements IdentityInterf
'passwordConfirm',
'validateConfirmPassword',
'on' => self::SCENARIO_UPDATE,
'skipOnEmpty' => false,
'skipOnEmpty' => false,
'skipOnError' => false
],
];
}
public function validateUpdateSenha($attribute, $params) {
if ( ! $this->validatePassword($this->$attribute)) {
$this->addError($attribute,"A senha atual inválida informada é inválida.");
}
}
public function validateConfirmPassword($attribute, $params) {
if (
(trim($this->password) || trim($this->passwordConfirm)) &&
(strcmp($this->password, $this->passwordConfirm) != 0)
) {
$this->addError($attribute,"A nova senha e a sua confirmação são não coincidem.");
$this->addError($attribute,"A nova senha e a sua confirmação são não coincidem.");
}
}
public function validateEmail($attribute, $params) {
list($user, $dominio) = explode('@', $this->$attribute);
if (
......@@ -326,7 +326,7 @@ class SistemaTabUsuarios extends \yii\db\ActiveRecord implements IdentityInterf
$this->addError($attribute,"O email deve ser do MDR (@mdr.gov.br).");
}
}
/**
* @inheritdoc
*/
......@@ -417,7 +417,7 @@ class SistemaTabUsuarios extends \yii\db\ActiveRecord implements IdentityInterf
'dte_cadastro',
'dte_nascimento',
];
return $arrFields;
}
......@@ -470,7 +470,7 @@ class SistemaTabUsuarios extends \yii\db\ActiveRecord implements IdentityInterf
'cod_area',
];
}
public function getSistemaOpcNivel()
{
return $this->hasOne(
......@@ -478,7 +478,7 @@ class SistemaTabUsuarios extends \yii\db\ActiveRecord implements IdentityInterf
['cod_nivel' => 'cod_nivel']
);
}
public function getDeleteColumn(){
if ($this->bln_ativo) {
$btn = "
......@@ -598,36 +598,36 @@ class SistemaTabUsuarios extends \yii\db\ActiveRecord implements IdentityInterf
{
return $this->hasMany(SistemaTabUsuarios::className(), ['cod_chefia' => 'cod_usuario']);
}
public function getMonitoresChefia() {
if (Yii::$app->user->identity) {
return Yii::$app->db->createCommand("
WITH RECURSIVE nivelChefia(cod_usuario,username,nivel, chefe) AS (
-- Ancora
SELECT
SELECT
tab_usuarios.cod_usuario,
tab_usuarios.username,
1 AS \"nivel\",
1 AS \"nivel\",
NULL::text as chefe
FROM sistema.tab_usuarios
FROM sistema.tab_usuarios
WHERE true
AND bln_ativo IS TRUE
AND username = '". Yii::$app->user->identity->username ."'
-- AND cod_chefia IS NULL
UNION ALL
-- Parte RECURSIVA
SELECT DISTINCT
SELECT DISTINCT
c.cod_usuario,
c.username,
m.nivel + 1 AS \"nivel\",
m.username::text
FROM sistema.tab_usuarios c
FROM sistema.tab_usuarios c
INNER JOIN nivelChefia m ON m.cod_usuario = c.cod_chefia
WHERE c.bln_ativo IS TRUE
)
SELECT DISTINCT
SELECT DISTINCT
cc.cod_usuario
--,cc.nivel
--,cc.username
......@@ -640,7 +640,7 @@ class SistemaTabUsuarios extends \yii\db\ActiveRecord implements IdentityInterf
}
return [];
}
public static function getUser() {
$ret = null;
if (Yii::$app->user->identity) {
......@@ -648,7 +648,7 @@ class SistemaTabUsuarios extends \yii\db\ActiveRecord implements IdentityInterf
}
return $ret;
}
public function getPreferencias () {
//return json_decode(json_encode(['a'=>'b']), true);
$this->txt_preferencias = (is_array($this->txt_preferencias))
......@@ -656,7 +656,7 @@ class SistemaTabUsuarios extends \yii\db\ActiveRecord implements IdentityInterf
: json_decode($this->txt_preferencias, true);
return ($this->txt_preferencias) ? : [];
}
public static function setPreferencia ($attr, $val) {
if ($objUser = self::getUser()) {
$arrPref = $objUser->getPreferencias();
......@@ -664,7 +664,7 @@ class SistemaTabUsuarios extends \yii\db\ActiveRecord implements IdentityInterf
$objUser->txt_preferencias = json_encode($arrPref);
//die_r($objUser->getDirtyAttributes());
return $objUser->save(false, ['txt_preferencias']);
}
}
// Salvamos também na sessão
if (isset($_SESSION)) {
$_SESSION[$attr] = $val;
......@@ -680,7 +680,7 @@ class SistemaTabUsuarios extends \yii\db\ActiveRecord implements IdentityInterf
$objUser->txt_preferencias = json_encode($arrPref);
//die_r($objUser->getDirtyAttributes());
return $objUser->save(false, ['txt_preferencias']);
}
}
// Salvamos também na sessão
if (isset($_SESSION)) {
$_SESSION[$key][$attr] = $val;
......@@ -688,7 +688,7 @@ class SistemaTabUsuarios extends \yii\db\ActiveRecord implements IdentityInterf
}
return false;
}
public static function getPreferencia ($attr) {
if ($objUser = self::getUser()) {
$arrPref = $objUser->getPreferencias();
......@@ -738,14 +738,14 @@ class SistemaTabUsuarios extends \yii\db\ActiveRecord implements IdentityInterf
}
return null;
}
public static function isAdmin() {
return (
Yii::$app->user->identity &&
Yii::$app->user->identity &&
(Yii::$app->user->identity->cod_nivel == 9)
);
}
/**
* @return \yii\db\ActiveQuery
*/
......@@ -761,7 +761,7 @@ class SistemaTabUsuarios extends \yii\db\ActiveRecord implements IdentityInterf
{
return TabNotificacoes::find()->where(['monitor' => $this->txt_login_usuario, 'bln_lido'=>false])->all();
}
/**
* @return \yii\db\ActiveQuery
*/
......@@ -769,7 +769,7 @@ class SistemaTabUsuarios extends \yii\db\ActiveRecord implements IdentityInterf
{
return $this->hasMany(TabMensagens::className(), ['cod_usuario' => 'cod_usuario', 'bln_lido'=>false]);
}
/**
* @return \yii\db\ActiveQuery
*/
......@@ -777,7 +777,7 @@ class SistemaTabUsuarios extends \yii\db\ActiveRecord implements IdentityInterf
{
return TabMensagens::find()->where( ['cod_usuario' => $this->cod_usuario, 'bln_lido'=>false])->count();
}
/**
* @return \yii\db\ActiveQuery
*/
......@@ -824,7 +824,7 @@ class SistemaTabUsuarios extends \yii\db\ActiveRecord implements IdentityInterf
public static function findIdentity($id)
{
return static::findOne([
'cod_usuario' => $id,
'cod_usuario' => $id,
'bln_ativo' => true,
]);
}
......@@ -846,7 +846,7 @@ class SistemaTabUsuarios extends \yii\db\ActiveRecord implements IdentityInterf
public static function findByUsername($username)
{
return static::findOne([
'username' => $username,
'username' => $username,
'bln_ativo' => true,
]);
}
......@@ -879,13 +879,13 @@ class SistemaTabUsuarios extends \yii\db\ActiveRecord implements IdentityInterf
if (empty($token)) {
return false;
}
$expire = Yii::$app->params['user.passwordResetTokenExpire'];
$parts = explode('_', $token);
$timestamp = (int) end($parts);
return $timestamp + $expire >= time();
}
/**
* @inheritdoc
*/
......@@ -934,7 +934,7 @@ class SistemaTabUsuarios extends \yii\db\ActiveRecord implements IdentityInterf
// SACI
$this->txt_senha_usuario = md5($password);
}
/**
* Generates "remember me" authentication key
*/
......@@ -974,9 +974,9 @@ class SistemaTabUsuarios extends \yii\db\ActiveRecord implements IdentityInterf
return Yii::$app->mailer
->compose(
[
'html' => 'passwordResetToken-html',
'html' => 'passwordResetToken-html',
'text' => 'passwordResetToken-text'
],
],
['user' => $user]
)
->setFrom(Yii::$app->params['supportEmail'])
......@@ -985,12 +985,12 @@ class SistemaTabUsuarios extends \yii\db\ActiveRecord implements IdentityInterf
->send();
}
}
return false;
}
//Envia email para a equipe de suporte: usuarios.saci@cidades.gov.br
public function sendEmailSuporte($title,$msg){
public function sendEmailSuporte($title,$msg){
$emailSuporte = 'cgmi-suporte@cidades.gov.br';
//$emailSuporte = 'josecarlos.fernandes@jointecnologia.com.br';
......@@ -1023,11 +1023,11 @@ class SistemaTabUsuarios extends \yii\db\ActiveRecord implements IdentityInterf
$this->created_at = date('U');
$this->updated_at = date('U');
$this->bln_ativo = 1;
if ($this->validate()) {
$this->removePasswordResetToken();
$this->setPassword($this->password);
if ($this->save(false)) {
$msg = '<h3>Novo usuário CADASTRADO</h3><br/>'.
'<b>Nome: </b>'.$this->txt_nome. '<br/>'.
......@@ -1045,7 +1045,7 @@ class SistemaTabUsuarios extends \yii\db\ActiveRecord implements IdentityInterf
return $this->getErrors();
}
}
public function atualizar()
{
// Valor padrao
......@@ -1080,7 +1080,7 @@ class SistemaTabUsuarios extends \yii\db\ActiveRecord implements IdentityInterf
return $dsc_name;
}
public function getDscByCod($attr, $val) {
if (strpos($attr, 'bln_') !== false) {
$val = ($val)? 'Sim' : 'Não';
} else {
......@@ -1106,7 +1106,7 @@ class SistemaTabUsuarios extends \yii\db\ActiveRecord implements IdentityInterf
$attr= 'cod_usuario';
$all = SistemaTabUsuarios::find()
->where([
'cod_nivel' => [4,5],
'cod_nivel' => [4,5],
'bln_ativo' => true,
]);
break;
......@@ -1119,19 +1119,19 @@ class SistemaTabUsuarios extends \yii\db\ActiveRecord implements IdentityInterf
return $all;
}
public function generateSelectFilters(){
$selectFilters = '<select id="select-filters">
<option value="">Escolha um filtro...</option>';
$arrSelect = SistemaTabUsuarios::getPreferencia("savedFilters");
if (isset($arrSelect)){
foreach ($arrSelect as $key => $arr){
$selectFilters.= "<option value='$key'>{$arr['name']}</option>";
}
}
$selectFilters.= '</select>';
return $selectFilters;
public function generateSelectFilters(){
$selectFilters = '<select id="select-filters">
<option value="">Escolha um filtro...</option>';
$arrSelect = SistemaTabUsuarios::getPreferencia("savedFilters");
if (isset($arrSelect)){
foreach ($arrSelect as $key => $arr){
$selectFilters.= "<option value='$key'>{$arr['name']}</option>";
}
}
$selectFilters.= '</select>';
return $selectFilters;
}
public function returnFilterSearchStr($filterName){
......@@ -1145,7 +1145,7 @@ class SistemaTabUsuarios extends \yii\db\ActiveRecord implements IdentityInterf
'dte_cadastro'
];
}
public function getSpecificPageSummary($col){
switch ($col){
case 'monitoraContratos':
......@@ -1158,7 +1158,7 @@ class SistemaTabUsuarios extends \yii\db\ActiveRecord implements IdentityInterf
break;
}
}
public function getSpecificArrColumns(){
return [
'specific' => [
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment