本文整理汇总了PHP中app\models\User::query方法的典型用法代码示例。如果您正苦于以下问题:PHP User::query方法的具体用法?PHP User::query怎么用?PHP User::query使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类app\models\User
的用法示例。
在下文中一共展示了User::query方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: up
public function up()
{
$rows = User::query(['not', ['email' => null]])->select('id,email')->all();
foreach ($rows as $row) {
$this->execute('update gs_users set `email`=\'' . strtolower($row['email']) . '\' where id=' . $row['id']);
}
}
示例2: actionMail
/**
* AJAX
* Создает подписку для авторизованного или неавторизованного пользователя
* Высылает письмо подтверждения email
*
* @return string json
* error
* 101, 'Такая почта уже зарегистрирована'
*/
public function actionMail()
{
$email = self::getParam('email');
$name = self::getParam('name');
$email = strtolower($email);
if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
return self::jsonErrorId(101, 'Не корректная почта');
}
if (User::query(['email' => $email])->exists()) {
return self::jsonErrorId(101, 'Такая почта уже зарегистрирована');
}
if (Yii::$app->user->isGuest) {
$fields = ['email' => $email, 'datetime_reg' => gmdate('YmdHis'), 'is_active' => 0, 'is_confirm' => 0, 'name_first' => $name];
foreach (Subscribe::$userFieldList as $field) {
$fields[$field] = 1;
}
$user = User::insert($fields);
} else {
/** @var \app\models\User $user */
$user = Yii::$app->user->identity;
$fields = ['email' => $email, 'datetime_reg' => gmdate('YmdHis'), 'is_active' => 0, 'is_confirm' => 0];
foreach (Subscribe::$userFieldList as $field) {
$fields[$field] = 1;
}
$user->update($fields);
}
$fields = RegistrationDispatcher::add($user->getId());
\cs\Application::mail($email, 'Подтверждение почты', 'subscribe_activate', ['url' => Url::to(['subscribe/activate', 'code' => $fields['code']], true), 'user' => $user, 'datetime' => \Yii::$app->formatter->asDatetime($fields['date_finish'])]);
return self::jsonSuccess();
}
示例3: add
/**
* Добавляет записи для рассылки в таблицу рассылки
*
* @param SiteContentInterface | \app\models\SubscribeItem $item тема письма
*/
public static function add($item)
{
if ($item instanceof SiteContentInterface) {
$subscribeItem = $item->getMailContent();
} else {
$subscribeItem = $item;
}
switch ($subscribeItem->type) {
case self::TYPE_NEWS:
$where = ['subscribe_is_news' => 1];
break;
case self::TYPE_SITE_UPDATE:
$where = ['subscribe_is_site_update' => 1];
break;
case self::TYPE_MANUAL:
$where = ['subscribe_is_tesla' => 1];
// $where = ['subscribe_is_test' => 1];
break;
}
$emailList = User::query($where)->select('email')->andWhere(['not', ['email' => null]])->andWhere(['not', ['email' => '']])->andWhere(['is_active' => 1])->column();
// VarDumper::dump(count($emailList),3,false);exit;
$rows = [];
foreach ($emailList as $email) {
$urlUnSubscribe = Url::to(['subscribe/unsubscribe', 'mail' => $email, 'type' => $subscribeItem->type, 'hash' => self::hashGenerate($email, $subscribeItem->type)], true);
SubscribeMailItem::insert(['text' => str_replace('{linkUnsubscribe}', $urlUnSubscribe, $subscribeItem->text), 'html' => str_replace('{linkUnsubscribe}', $urlUnSubscribe, $subscribeItem->html), 'subject' => $subscribeItem->subject, 'mail' => $email, 'date_insert' => time()]);
$rows[] = $email;
}
\Yii::info($rows, 'tg\\subscribe');
}
示例4: add
/**
* Добавляет записи для рассылки в таблицу рассылки
*
* @param SiteContentInterface | \app\models\SubscribeItem $item тема письма
*/
public static function add($item)
{
if ($item instanceof SiteContentInterface) {
$subscribeItem = $item->getMailContent();
} else {
$subscribeItem = $item;
}
switch ($subscribeItem->type) {
case self::TYPE_NEWS:
$where = ['subscribe_is_news' => 1];
break;
case self::TYPE_SITE_UPDATE:
$where = ['subscribe_is_site_update' => 1];
break;
case self::TYPE_MANUAL:
$where = ['subscribe_is_manual' => 1];
break;
}
$emailList = User::query($where)->select('email')->andWhere(['not', ['email' => null]])->andWhere(['is_active' => 1, 'is_confirm' => 1])->column();
$rows = [];
foreach ($emailList as $email) {
$urlUnSubscribe = Url::to(['subscribe/unsubscribe', 'mail' => $email, 'type' => $subscribeItem->type, 'hash' => self::hashGenerate($email, $subscribeItem->type)], true);
$rows[] = [str_replace('{linkUnsubscribe}', $urlUnSubscribe, $subscribeItem->text), str_replace('{linkUnsubscribe}', $urlUnSubscribe, $subscribeItem->html), $subscribeItem->subject, $email, time()];
}
\Yii::info(ArrayHelper::getColumn($rows, 3), 'gs\\subscribe');
if (count($rows) > 0) {
SubscribeMailItem::batchInsert(['text', 'html', 'subject', 'mail', 'date_insert'], $rows);
}
}
示例5: verify
public function verify($username, $login_token)
{
$user = User::query()->where(['username' => $user_name])->first(['id', 'login_token']);
if ($user->login_token === $login_token) {
return $user->id;
}
return false;
}
示例6: up
public function up()
{
$this->execute('ALTER TABLE galaxysss_4.cap_users ADD referal_link VARCHAR(20) NULL;');
$rows = \app\models\User::query()->select('id')->column();
foreach ($rows as $id) {
(new \yii\db\Query())->createCommand()->update('cap_users', ['referal_link' => \cs\services\Security::generateRandomString(20)], ['id' => $id])->execute();
}
}
示例7: show
public function show(UserAuth $user, $id)
{
$query = \App\Models\User::query();
if ($user != null && $user['id'] == $id) {
$query->select('id', 'username', 'first_name', 'last_name', 'email', 'phone');
} else {
$query->select(['id', 'username', 'first_name', 'last_name']);
}
return $query->find($id) ?: $this->notFoundJson();
}
示例8: validateEmail
public function validateEmail($attribute, $params)
{
if (!User::query(['email' => $this->email])->exists()) {
$this->addError($attribute, 'Такой пользователь не найден');
}
if (!User::query(['email' => $this->email, 'is_confirm' => 1])->exists()) {
$this->addError($attribute, 'Пользователь еще не подтвердил свой email');
}
if (!User::query(['email' => $this->email, 'is_active' => 1])->exists()) {
$this->addError($attribute, 'Пользователь заблокирован');
}
}
示例9: index
public function index()
{
$users = User::query()->orderBy('name', 'ASC')->get();
$movies = Movie::query()->orderBy('title', 'ASC')->get();
$prediction = new Prediction();
$predictionData = [];
$users->each(function ($user, $index) use($prediction, &$predictionData) {
$rateData = ["predictions" => $prediction->make($user), "ratedMovies" => $prediction->getRatedmovies()];
$predictionData[$user->id] = $rateData;
});
$data = ["users" => $users, "movies" => $movies, "predictionData" => $predictionData];
return view('prediction', $data);
}
示例10: postLogin
/**
* Login process
*/
public function postLogin()
{
//Form not valid
$validator = true;
//Error messages
$data['login_error_messages'] = [];
//Username
if (!isset($_POST['username']) || $_POST['username'] == '') {
//Set error message for login form username
$data['login_error_messages']['username'] = 'Username is required!';
//Validator is false
$validator = false;
}
if (!isset($_POST['password']) || $_POST['password'] == '') {
//Set error message for login form username
$data['login_error_messages']['password'] = 'Password is required!';
//Validator is false
$validator = false;
}
//If form is valid the continue processing
if ($validator) {
//Query to check username and password in database
//Create new haser object
$hasher = new Hash();
//Get credentials
$username = $_POST['username'];
$password = $hasher->make($_POST['password']);
//Create user model
$user = new User();
//Check username an password in database
$results = $user->query("SELECT * FROM users WHERE username = '" . $username . "' AND password = '" . $password . "'");
//Login is correct
if ($results !== false) {
//Login success
//Set the sessions data
$_SESSION['isLoggedIn'] = true;
$_SESSION['user_id'] = $results[0]['id'];
//Go back to home page
header('location:/blog');
} else {
//Login incorrect
$data['alert_login'] = 'Username or password is incorrect';
//Reload page
view('login-register', $data);
}
} else {
//Form is not valid
view('login-register', $data);
}
}
示例11: search
public function search($input)
{
$query = User::query();
$columns = Schema::getColumnListing('users');
$attributes = array();
foreach ($columns as $attribute) {
if (isset($input[$attribute]) and !empty($input[$attribute])) {
$query->where($attribute, $input[$attribute]);
$attributes[$attribute] = $input[$attribute];
} else {
$attributes[$attribute] = null;
}
}
return [$query->get(), $attributes];
}
示例12: handle
/**
* Execute the console command.
*
* @return mixed
*/
public function handle()
{
$benchmarck = new Benchmark();
$benchmarck->start();
$qtdCriar = $this->argument('qtd');
if (!is_numeric($qtdCriar)) {
$this->error('Parametro qtd deve ser um numero inteiro.');
return;
}
$qtdUsers = User::query()->count();
$until = $qtdUsers + $qtdCriar;
for ($qtdUsers; $qtdUsers < $until; $qtdUsers++) {
User::create(['name' => 'Usuário ' . ($qtdUsers + 1)]);
}
$this->info("Usuarios criados com sucesso!");
$this->info("Tem decorrido: " . $benchmarck->stop()->elapsedSeconds());
}
示例13: up
public function up()
{
foreach (\app\models\User::query(['referal_code' => null])->select('id')->column() as $id) {
$this->update(\app\models\User::TABLE, ['referal_code' => \cs\services\Security::generateRandomString(20)], ['id' => $id]);
}
}
示例14: runAction
/**
* @return Response
*/
public function runAction()
{
/** @var Criteria $query */
$query = User::query();
return $this->response($query);
}
示例15: actionStatistic
public function actionStatistic()
{
$data = User::query()->select(['datetime_reg'])->column();
$data2 = \app\services\Statistic::getIncrementDataAllGraphic($data, 'Y-m-d');
$new = [];
for ($i = 0; $i < count($data2['x']); $i++) {
if ($data2['x'][$i] > '2015-07-18') {
$new['x'][] = (new \DateTime($data2['x'][$i]))->format('d.m');
$new['y'][] = $data2['y'][$i];
}
}
$data2 = $new;
$data3 = GraphExporter::convert(['rows' => [User::query()->select(['COUNT(id) as `kurs`', 'DATE(datetime_reg) as `date`'])->groupBy('DATE(datetime_reg)')->all()], 'formatX' => 'd.m', 'start' => new \DateTime('2015-07-05'), 'isExcludeWeekend' => false]);
return $this->render(['lineArray' => $data3, 'lineArray2' => ['x' => $data2['x'], 'y' => [$data2['y']]]]);
}