Merge pull request #41 from apuc/sum_and_calendar

Sum and calendar
This commit is contained in:
kavalar 2020-05-22 16:43:51 +03:00 committed by GitHub
commit 38069c57d4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 62 additions and 62 deletions

View File

@ -111,64 +111,6 @@ class UserCard extends \common\models\UserCard
parent::afterSave($insert, $changedAttributes); // TODO: Change the autogenerated stub parent::afterSave($insert, $changedAttributes); // TODO: Change the autogenerated stub
} }
public static function generateUser($email, $status)
{
$user = new User();
$auth_key = Yii::$app->security->generateRandomString();
$password = Yii::$app->security->generateRandomString(12);
$password_hash = Yii::$app->security->generatePasswordHash($password);
$user->username = $email;
$user->auth_key = $auth_key;
$user->password_hash = $password_hash;
$user->email = $email;
if ($status == 1) $user->status = 10;
$user->save();
$auth = Yii::$app->authManager;
$authorRole = $auth->getRole('user');
$auth->assign($authorRole, $user->id);
$log = "Логин: " . $email . " Пароль: " . $password . " | ";
file_put_contents("log.txt", $log, FILE_APPEND | LOCK_EX);
return $user->id;
}
public static function genereateLinlkOnUser($user_card, $user_id)
{
$user_card->id_user = $user_id;
$user_card->save();
}
public static function generateUserForUserCard($card_id = null)
{
$userCardQuery = UserCard::find();
$card_id ? $userCardQuery->where(['id' => $card_id]) : $userCardQuery->where(['id_user' => NULL]);
$user_card_array = $userCardQuery->all();
$user_array = User::find()->all();
foreach ($user_card_array as $user_card_value) {
foreach ($user_array as $user_value)
if ($user_card_value->email == $user_value->email) {
$user_id = $user_value->id;
break;
} else $user_id = NULL;
if ($user_id) {
UserCard::genereateLinlkOnUser($user_card_value, $user_id);
} else {
$user_id = UserCard::generateUser($user_card_value->email, $user_card_value->status);
UserCard::genereateLinlkOnUser($user_card_value, $user_id);
}
}
if ($user_card_array) return "data generated successfully";
else return "no data to generate";
}
public static function getParameter($params, $key) public static function getParameter($params, $key)
{ {
try { try {

View File

@ -4,7 +4,6 @@ use common\classes\Debug;
use kartik\select2\Select2; use kartik\select2\Select2;
use mihaildev\elfinder\InputFile; use mihaildev\elfinder\InputFile;
use unclead\multipleinput\MultipleInput; use unclead\multipleinput\MultipleInput;
use unclead\multipleinput\examples\models\ExampleModel;
use yii\helpers\Html; use yii\helpers\Html;
use yii\widgets\ActiveForm; use yii\widgets\ActiveForm;
@ -53,7 +52,7 @@ use yii\widgets\ActiveForm;
'language' => 'ru', 'language' => 'ru',
'controller' => 'elfinder', 'controller' => 'elfinder',
// вставляем название контроллера, по умолчанию равен elfinder // вставляем название контроллера, по умолчанию равен elfinder
'filter' => ['image', 'application/zip', 'application/pdf', 'application/msword', 'application/vnd.openxmlformats-officedocument.wordprocessingml.document'], //'filter' => ['image', 'application/zip', 'application/csv', 'application/pdf', 'application/msword', 'application/vnd.openxmlformats-officedocument.wordprocessingml.document'],
// фильтр файлов, можно задать массив фильтров https://github.com/Studio-42/elFinder/wiki/Client-con.. // фильтр файлов, можно задать массив фильтров https://github.com/Studio-42/elFinder/wiki/Client-con..
'name' => 'UserCard[resume]', 'name' => 'UserCard[resume]',
'id' => 'usercard-resume', 'id' => 'usercard-resume',

View File

@ -65,7 +65,7 @@ class UserCard extends \yii\db\ActiveRecord
public function rules() public function rules()
{ {
return [ return [
[['fio', 'status', 'gender'], 'required'], [['fio', 'status', 'gender', 'email'], 'required'],
[['gender', 'status', 'position_id', 'id_user'], 'integer'], [['gender', 'status', 'position_id', 'id_user'], 'integer'],
[['dob', 'created_at', 'updated_at', 'deleted_at'], 'safe'], [['dob', 'created_at', 'updated_at', 'deleted_at'], 'safe'],
[['fio', 'passport', 'photo', 'email', 'resume', 'city'], 'string', 'max' => 255], [['fio', 'passport', 'photo', 'email', 'resume', 'city'], 'string', 'max' => 255],
@ -162,4 +162,62 @@ class UserCard extends \yii\db\ActiveRecord
{ {
return ArrayHelper::map(self::find()->all(), 'id', 'fio'); return ArrayHelper::map(self::find()->all(), 'id', 'fio');
} }
public static function generateUserForUserCard($card_id = null)
{
$userCardQuery = self::find();
$card_id ? $userCardQuery->where(['id' => $card_id]) : $userCardQuery->where(['id_user' => NULL]);
$user_card_array = $userCardQuery->all();
$user_array = User::find()->all();
foreach ($user_card_array as $user_card_value) {
foreach ($user_array as $user_value)
if ($user_card_value->email == $user_value->email) {
$user_id = $user_value->id;
break;
} else $user_id = NULL;
if ($user_id) {
UserCard::genereateLinlkOnUser($user_card_value, $user_id);
} else {
$user_id = UserCard::generateUser($user_card_value->email, $user_card_value->status);
UserCard::genereateLinlkOnUser($user_card_value, $user_id);
}
}
if ($user_card_array) return "data generated successfully";
else return "no data to generate";
}
public static function generateUser($email, $status)
{
$user = new User();
$auth_key = Yii::$app->security->generateRandomString();
$password = Yii::$app->security->generateRandomString(12);
$password_hash = Yii::$app->security->generatePasswordHash($password);
$user->username = $email;
$user->auth_key = $auth_key;
$user->password_hash = $password_hash;
$user->email = $email;
if ($status == 1) $user->status = 10;
$user->save();
$auth = Yii::$app->authManager;
$authorRole = $auth->getRole('user');
$auth->assign($authorRole, $user->id);
$log = "Логин: " . $email . " Пароль: " . $password . " | ";
file_put_contents("log.txt", $log, FILE_APPEND | LOCK_EX);
return $user->id;
}
public static function genereateLinlkOnUser($user_card, $user_id)
{
$user_card->id_user = $user_id;
$user_card->save();
}
} }

View File

@ -4,7 +4,7 @@
namespace console\controllers; namespace console\controllers;
use backend\modules\card\models\UserCard; use common\models\UserCard;
use Yii; use Yii;
use yii\console\Controller; use yii\console\Controller;

1
log.txt Normal file
View File

@ -0,0 +1 @@
Логин: test6@test.com Пароль: 6YKuWYVRyJ2I |