update folder location

This commit is contained in:
Antonio Ramirez
2017-01-11 21:31:42 +01:00
parent 1cb60f0740
commit 13255a5117
167 changed files with 4770 additions and 8 deletions

View File

@ -0,0 +1,74 @@
<?php
/*
* This file is part of the 2amigos/yii2-usuario project.
*
* (c) 2amigOS! <http://2amigos.us/>
*
* For the full copyright and license information, please view
* the LICENSE file that was distributed with this source code.
*/
namespace Da\User\Search;
use Da\User\Traits\AuthManagerAwareTrait;
use Da\User\Traits\ContainerAwareTrait;
use yii\base\Model;
use yii\data\ArrayDataProvider;
use yii\db\Query;
abstract class AbstractAuthItemSearch extends Model
{
use AuthManagerAwareTrait;
use ContainerAwareTrait;
/**
* @var string
*/
public $name;
/**
* @var string
*/
public $description;
/**
* @var string
*/
public $rule_name;
/**
* @return int
*/
abstract public function getType();
/**
* @return array
*/
public function scenarios()
{
return [
'default' => ['name', 'description', 'rule_name'],
];
}
public function search($params = [])
{
/** @var ArrayDataProvider $dataProvider */
$dataProvider = $this->make(ArrayDataProvider::class);
$query = (new Query())
->select(['name', 'description', 'rule_name'])
->andWhere(['type' => $this->getType()])
->from($this->getAuthManager()->itemTable);
if ($this->load($params) && $this->validate()) {
$query
->andFilterWhere(['like', 'name', $this->name])
->andFilterWhere(['like', 'description', $this->description])
->andFilterWhere(['like', 'rule_name', $this->rule_name]);
}
$dataProvider->allModels = $query->all($this->getAuthManager()->db);
return $dataProvider;
}
}

View File

@ -0,0 +1,25 @@
<?php
/*
* This file is part of the 2amigos/yii2-usuario project.
*
* (c) 2amigOS! <http://2amigos.us/>
*
* For the full copyright and license information, please view
* the LICENSE file that was distributed with this source code.
*/
namespace Da\User\Search;
use yii\rbac\Item;
class PermissionSearch extends AbstractAuthItemSearch
{
/**
* {@inheritdoc}
*/
public function getType()
{
return Item::TYPE_PERMISSION;
}
}

View File

@ -0,0 +1,25 @@
<?php
/*
* This file is part of the 2amigos/yii2-usuario project.
*
* (c) 2amigOS! <http://2amigos.us/>
*
* For the full copyright and license information, please view
* the LICENSE file that was distributed with this source code.
*/
namespace Da\User\Search;
use yii\rbac\Item;
class RoleSearch extends AbstractAuthItemSearch
{
/**
* {@inheritdoc}
*/
public function getType()
{
return Item::TYPE_ROLE;
}
}

View File

@ -0,0 +1,107 @@
<?php
/*
* This file is part of the 2amigos/yii2-usuario project.
*
* (c) 2amigOS! <http://2amigos.us/>
*
* For the full copyright and license information, please view
* the LICENSE file that was distributed with this source code.
*/
namespace Da\User\Search;
use Da\User\Query\UserQuery;
use Yii;
use yii\base\Model;
use yii\data\ActiveDataProvider;
class UserSearch extends Model
{
/**
* @var string
*/
public $username;
/**
* @var string
*/
public $email;
/**
* @var int
*/
public $created_at;
/**
* @var string
*/
public $registration_ip;
/**
* @var UserQuery
*/
protected $query;
/**
* UserSearch constructor.
*
* @param UserQuery $query
* @param array $config
*/
public function __construct(UserQuery $query, $config = [])
{
$this->query = $query;
parent::__construct($config);
}
/**
* @return array
*/
public function rules()
{
return [
'safeFields' => [['username', 'email', 'registration_ip', 'created_at'], 'safe'],
'createdDefault' => ['created_at', 'default', 'value' => null],
];
}
/**
* @return array
*/
public function attributeLabels()
{
return [
'username' => Yii::t('usuario', 'Username'),
'email' => Yii::t('usuario', 'Email'),
'created_at' => Yii::t('usuario', 'Registration time'),
'registration_ip' => Yii::t('usuario', 'Registration ip'),
];
}
/**
* @param $params
*
* @return ActiveDataProvider
*/
public function search($params)
{
$query = $this->query;
$dataProvider = new ActiveDataProvider([
'query' => $query,
]);
if (!($this->load($params) && $this->validate())) {
return $dataProvider;
}
if ($this->created_at !== null) {
$date = strtotime($this->created_at);
$query->andFilterWhere(['between', 'created_at', $date, $date + 3600 * 24]);
}
$query
->andFilterWhere(['like', 'username', $this->username])
->andFilterWhere(['like', 'email', $this->email])
->andFilterWhere(['registration_ip' => $this->registration_ip]);
return $dataProvider;
}
}