create project

This commit is contained in:
2024-04-24 18:02:58 +03:00
commit 17df2ce6a9
276 changed files with 15932 additions and 0 deletions

4
frontend/Dockerfile Normal file
View File

@ -0,0 +1,4 @@
FROM yiisoftware/yii2-php:8.1-apache
# Change document root for Apache
RUN sed -i -e 's|/app/web|/app/frontend/web|g' /etc/apache2/sites-available/000-default.conf

View File

@ -0,0 +1,23 @@
<?php
namespace frontend\assets;
use yii\web\AssetBundle;
/**
* Main frontend application asset bundle.
*/
class AppAsset extends AssetBundle
{
public $basePath = '@webroot';
public $baseUrl = '@web';
public $css = [
'css/site.css',
];
public $js = [
];
public $depends = [
'yii\web\YiiAsset',
'yii\bootstrap5\BootstrapAsset',
];
}

15
frontend/codeception.yml Normal file
View File

@ -0,0 +1,15 @@
namespace: frontend\tests
actor_suffix: Tester
paths:
tests: tests
output: tests/_output
data: tests/_data
support: tests/_support
bootstrap: _bootstrap.php
settings:
colors: true
memory_limit: 1024M
modules:
config:
Yii2:
configFile: 'config/codeception-local.php'

4
frontend/config/.gitignore vendored Normal file
View File

@ -0,0 +1,4 @@
codeception-local.php
main-local.php
params-local.php
test-local.php

View File

@ -0,0 +1 @@
<?php

67
frontend/config/main.php Normal file
View File

@ -0,0 +1,67 @@
<?php
$params = array_merge(
require __DIR__ . '/../../common/config/params.php',
require __DIR__ . '/../../common/config/params-local.php',
require __DIR__ . '/params.php',
require __DIR__ . '/params-local.php'
);
return [
'id' => 'app-frontend',
'basePath' => dirname(__DIR__),
'bootstrap' => ['log'],
'controllerNamespace' => 'frontend\controllers',
'modules' => [
'company' => [
'class' => 'frontend\modules\company\Company',
],
'product' => [
'class' => 'frontend\modules\product\Product',
],
'addresses' => [
'class' => 'frontend\modules\addresses\Addresses',
],
'check' => [
'class' => 'frontend\modules\check\Check',
],
'product_category' => [
'class' => 'frontend\modules\product_category\ProductCategory',
],
],
'components' => [
'request' => [
'csrfParam' => '_csrf-frontend',
],
'user' => [
'identityClass' => 'common\models\User',
'enableAutoLogin' => true,
'identityCookie' => ['name' => '_identity-frontend', 'httpOnly' => true],
],
'session' => [
// this is the name of the session cookie used for login on the frontend
'name' => 'advanced-frontend',
],
'view' => [
],
'log' => [
'traceLevel' => YII_DEBUG ? 3 : 0,
'targets' => [
[
'class' => \yii\log\FileTarget::class,
'levels' => ['error', 'warning'],
],
],
],
'errorHandler' => [
'errorAction' => 'site/error',
],
'urlManager' => [
'enablePrettyUrl' => true,
'showScriptName' => false,
'rules' => [
],
],
],
'params' => $params,
];

View File

@ -0,0 +1,4 @@
<?php
return [
'adminEmail' => 'admin@example.com',
];

18
frontend/config/test.php Normal file
View File

@ -0,0 +1,18 @@
<?php
return [
'id' => 'app-frontend-tests',
'components' => [
'assetManager' => [
'basePath' => __DIR__ . '/../web/assets',
],
'urlManager' => [
'showScriptName' => true,
],
'request' => [
'cookieValidationKey' => 'test',
],
'mailer' => [
'messageClass' => \yii\symfonymailer\Message::class
]
],
];

View File

@ -0,0 +1,265 @@
<?php
namespace frontend\controllers;
use common\classes\Debug;
use common\models\User;
use frontend\models\ResendVerificationEmailForm;
use frontend\models\VerifyEmailForm;
use Yii;
use yii\base\InvalidArgumentException;
use yii\web\BadRequestHttpException;
use yii\web\Controller;
use yii\filters\VerbFilter;
use yii\filters\AccessControl;
use common\models\LoginForm;
use frontend\models\PasswordResetRequestForm;
use frontend\models\ResetPasswordForm;
use frontend\models\SignupForm;
use frontend\models\ContactForm;
/**
* Site controller
*/
class SiteController extends Controller
{
/**
* {@inheritdoc}
*/
public function behaviors()
{
return [
'access' => [
'class' => AccessControl::class,
'only' => ['logout', 'signup'],
'rules' => [
[
'actions' => ['signup'],
'allow' => true,
'roles' => ['?'],
],
[
'actions' => ['logout'],
'allow' => true,
'roles' => ['@'],
],
],
],
'verbs' => [
'class' => VerbFilter::class,
'actions' => [
'logout' => ['post'],
],
],
];
}
/**
* {@inheritdoc}
*/
public function actions()
{
return [
'error' => [
'class' => \yii\web\ErrorAction::class,
],
'captcha' => [
'class' => \yii\captcha\CaptchaAction::class,
'fixedVerifyCode' => YII_ENV_TEST ? 'testme' : null,
],
];
}
/**
* Displays homepage.
*
* @return mixed
*/
public function actionIndex()
{
return $this->render('index');
}
/**
* Logs in a user.
*
* @return mixed
*/
public function actionLogin()
{
$this->layout = 'main-login';
if (!Yii::$app->user->isGuest) {
return $this->goHome();
}
$model = new LoginForm();
if ($model->load(Yii::$app->request->post()) && $model->login()) {
return $this->goBack();
}
$model->password = '';
return $this->render('login', [
'model' => $model,
]);
}
/**
* Logs out the current user.
*
* @return mixed
*/
public function actionLogout()
{
Yii::$app->user->logout();
return $this->goHome();
}
/**
* Displays contact page.
*
* @return mixed
*/
public function actionContact()
{
$model = new ContactForm();
if ($model->load(Yii::$app->request->post()) && $model->validate()) {
if ($model->sendEmail(Yii::$app->params['adminEmail'])) {
Yii::$app->session->setFlash('success', 'Thank you for contacting us. We will respond to you as soon as possible.');
} else {
Yii::$app->session->setFlash('error', 'There was an error sending your message.');
}
return $this->refresh();
}
return $this->render('contact', [
'model' => $model,
]);
}
/**
* Displays about page.
*
* @return mixed
*/
public function actionAbout()
{
return $this->render('about');
}
/**
* Signs user up.
*
* @return mixed
*/
public function actionSignup()
{
$this->layout = 'main-login';
$model = new SignupForm();
if ($model->load(Yii::$app->request->post()) && $model->signup()) {
Yii::$app->session->setFlash('success', 'Спасиюо за регистрацию');
return $this->goHome();
}
return $this->render('signup', [
'model' => $model,
]);
}
/**
* Requests password reset.
*
* @return mixed
*/
public function actionRequestPasswordReset()
{
$model = new PasswordResetRequestForm();
if ($model->load(Yii::$app->request->post()) && $model->validate()) {
if ($model->sendEmail()) {
Yii::$app->session->setFlash('success', 'Check your email for further instructions.');
return $this->goHome();
}
Yii::$app->session->setFlash('error', 'Sorry, we are unable to reset password for the provided email address.');
}
return $this->render('requestPasswordResetToken', [
'model' => $model,
]);
}
/**
* Resets password.
*
* @param string $token
* @return mixed
* @throws BadRequestHttpException
*/
public function actionResetPassword($token)
{
try {
$model = new ResetPasswordForm($token);
} catch (InvalidArgumentException $e) {
throw new BadRequestHttpException($e->getMessage());
}
if ($model->load(Yii::$app->request->post()) && $model->validate() && $model->resetPassword()) {
Yii::$app->session->setFlash('success', 'New password saved.');
return $this->goHome();
}
return $this->render('resetPassword', [
'model' => $model,
]);
}
/**
* Verify email address
*
* @param string $token
* @throws BadRequestHttpException
* @return yii\web\Response
*/
public function actionVerifyEmail($token)
{
try {
$model = new VerifyEmailForm($token);
} catch (InvalidArgumentException $e) {
throw new BadRequestHttpException($e->getMessage());
}
if (($user = $model->verifyEmail()) && Yii::$app->user->login($user)) {
Yii::$app->session->setFlash('success', 'Your email has been confirmed!');
return $this->goHome();
}
Yii::$app->session->setFlash('error', 'Sorry, we are unable to verify your account with provided token.');
return $this->goHome();
}
/**
* Resend verification email
*
* @return mixed
*/
public function actionResendVerificationEmail()
{
$model = new ResendVerificationEmailForm();
if ($model->load(Yii::$app->request->post()) && $model->validate()) {
if ($model->sendEmail()) {
Yii::$app->session->setFlash('success', 'Check your email for further instructions.');
return $this->goHome();
}
Yii::$app->session->setFlash('error', 'Sorry, we are unable to resend verification email for the provided email address.');
}
return $this->render('resendVerificationEmail', [
'model' => $model
]);
}
}

View File

@ -0,0 +1,61 @@
<?php
namespace frontend\models;
use Yii;
use yii\base\Model;
/**
* ContactForm is the model behind the contact form.
*/
class ContactForm extends Model
{
public $name;
public $email;
public $subject;
public $body;
public $verifyCode;
/**
* {@inheritdoc}
*/
public function rules()
{
return [
// name, email, subject and body are required
[['name', 'email', 'subject', 'body'], 'required'],
// email has to be a valid email address
['email', 'email'],
// verifyCode needs to be entered correctly
['verifyCode', 'captcha'],
];
}
/**
* {@inheritdoc}
*/
public function attributeLabels()
{
return [
'verifyCode' => 'Verification Code',
];
}
/**
* Sends an email to the specified email address using the information collected by this model.
*
* @param string $email the target email address
* @return bool whether the email was sent
*/
public function sendEmail($email)
{
return Yii::$app->mailer->compose()
->setTo($email)
->setFrom([Yii::$app->params['senderEmail'] => Yii::$app->params['senderName']])
->setReplyTo([$this->email => $this->name])
->setSubject($this->subject)
->setTextBody($this->body)
->send();
}
}

View File

@ -0,0 +1,69 @@
<?php
namespace frontend\models;
use Yii;
use yii\base\Model;
use common\models\User;
/**
* Password reset request form
*/
class PasswordResetRequestForm extends Model
{
public $email;
/**
* {@inheritdoc}
*/
public function rules()
{
return [
['email', 'trim'],
['email', 'required'],
['email', 'email'],
['email', 'exist',
'targetClass' => '\common\models\User',
'filter' => ['status' => User::STATUS_ACTIVE],
'message' => 'There is no user with this email address.'
],
];
}
/**
* Sends an email with a link, for resetting the password.
*
* @return bool whether the email was send
*/
public function sendEmail()
{
/* @var $user User */
$user = User::findOne([
'status' => User::STATUS_ACTIVE,
'email' => $this->email,
]);
if (!$user) {
return false;
}
if (!User::isPasswordResetTokenValid($user->password_reset_token)) {
$user->generatePasswordResetToken();
if (!$user->save()) {
return false;
}
}
return Yii::$app
->mailer
->compose(
['html' => 'passwordResetToken-html', 'text' => 'passwordResetToken-text'],
['user' => $user]
)
->setFrom([Yii::$app->params['supportEmail'] => Yii::$app->name . ' robot'])
->setTo($this->email)
->setSubject('Password reset for ' . Yii::$app->name)
->send();
}
}

View File

@ -0,0 +1,61 @@
<?php
namespace frontend\models;
use Yii;
use common\models\User;
use yii\base\Model;
class ResendVerificationEmailForm extends Model
{
/**
* @var string
*/
public $email;
/**
* {@inheritdoc}
*/
public function rules()
{
return [
['email', 'trim'],
['email', 'required'],
['email', 'email'],
['email', 'exist',
'targetClass' => '\common\models\User',
'filter' => ['status' => User::STATUS_INACTIVE],
'message' => 'There is no user with this email address.'
],
];
}
/**
* Sends confirmation email to user
*
* @return bool whether the email was sent
*/
public function sendEmail()
{
$user = User::findOne([
'email' => $this->email,
'status' => User::STATUS_INACTIVE
]);
if ($user === null) {
return false;
}
return Yii::$app
->mailer
->compose(
['html' => 'emailVerify-html', 'text' => 'emailVerify-text'],
['user' => $user]
)
->setFrom([Yii::$app->params['supportEmail'] => Yii::$app->name . ' robot'])
->setTo($this->email)
->setSubject('Account registration at ' . Yii::$app->name)
->send();
}
}

View File

@ -0,0 +1,67 @@
<?php
namespace frontend\models;
use yii\base\InvalidArgumentException;
use yii\base\Model;
use Yii;
use common\models\User;
/**
* Password reset form
*/
class ResetPasswordForm extends Model
{
public $password;
/**
* @var \common\models\User
*/
private $_user;
/**
* Creates a form model given a token.
*
* @param string $token
* @param array $config name-value pairs that will be used to initialize the object properties
* @throws InvalidArgumentException if token is empty or not valid
*/
public function __construct($token, $config = [])
{
if (empty($token) || !is_string($token)) {
throw new InvalidArgumentException('Password reset token cannot be blank.');
}
$this->_user = User::findByPasswordResetToken($token);
if (!$this->_user) {
throw new InvalidArgumentException('Wrong password reset token.');
}
parent::__construct($config);
}
/**
* {@inheritdoc}
*/
public function rules()
{
return [
['password', 'required'],
['password', 'string', 'min' => Yii::$app->params['user.passwordMinLength']],
];
}
/**
* Resets password.
*
* @return bool if password was reset.
*/
public function resetPassword()
{
$user = $this->_user;
$user->setPassword($this->password);
$user->removePasswordResetToken();
$user->generateAuthKey();
return $user->save(false);
}
}

View File

@ -0,0 +1,80 @@
<?php
namespace frontend\models;
use Yii;
use yii\base\Model;
use common\models\User;
/**
* Signup form
*/
class SignupForm extends Model
{
public $username;
public $email;
public $password;
/**
* {@inheritdoc}
*/
public function rules()
{
return [
['username', 'trim'],
['username', 'required'],
['username', 'unique', 'targetClass' => '\common\models\User', 'message' => 'This username has already been taken.'],
['username', 'string', 'min' => 2, 'max' => 255],
['email', 'trim'],
['email', 'required'],
['email', 'email'],
['email', 'string', 'max' => 255],
['email', 'unique', 'targetClass' => '\common\models\User', 'message' => 'This email address has already been taken.'],
['password', 'required'],
['password', 'string', 'min' => Yii::$app->params['user.passwordMinLength']],
];
}
/**
* Signs user up.
*
* @return bool whether the creating new account was successful and email was sent
*/
public function signup()
{
if (!$this->validate()) {
return null;
}
$user = new User();
$user->username = $this->username;
$user->email = $this->email;
$user->setPassword($this->password);
$user->generateAuthKey();
$user->generateEmailVerificationToken();
return $user->save() && $this->sendEmail($user);
}
/**
* Sends confirmation email to user
* @param User $user user model to with email should be send
* @return bool whether the email was sent
*/
protected function sendEmail($user)
{
return Yii::$app
->mailer
->compose(
['html' => 'emailVerify-html', 'text' => 'emailVerify-text'],
['user' => $user]
)
->setFrom([Yii::$app->params['supportEmail'] => Yii::$app->name . ' robot'])
->setTo($this->email)
->setSubject('Account registration at ' . Yii::$app->name)
->send();
}
}

View File

@ -0,0 +1,52 @@
<?php
namespace frontend\models;
use common\models\User;
use yii\base\InvalidArgumentException;
use yii\base\Model;
class VerifyEmailForm extends Model
{
/**
* @var string
*/
public $token;
/**
* @var User
*/
private $_user;
/**
* Creates a form model with given token.
*
* @param string $token
* @param array $config name-value pairs that will be used to initialize the object properties
* @throws InvalidArgumentException if token is empty or not valid
*/
public function __construct($token, array $config = [])
{
if (empty($token) || !is_string($token)) {
throw new InvalidArgumentException('Verify email token cannot be blank.');
}
$this->_user = User::findByVerificationToken($token);
if (!$this->_user) {
throw new InvalidArgumentException('Wrong verify email token.');
}
parent::__construct($config);
}
/**
* Verify email
*
* @return User|null the saved model or null if saving fails
*/
public function verifyEmail()
{
$user = $this->_user;
$user->status = User::STATUS_ACTIVE;
return $user->save(false) ? $user : null;
}
}

View File

@ -0,0 +1,24 @@
<?php
namespace frontend\modules\addresses;
/**
* addresses module definition class
*/
class Addresses extends \yii\base\Module
{
/**
* {@inheritdoc}
*/
public $controllerNamespace = 'frontend\modules\addresses\controllers';
/**
* {@inheritdoc}
*/
public function init()
{
parent::init();
// custom initialization code goes here
}
}

View File

@ -0,0 +1,140 @@
<?php
namespace frontend\modules\addresses\controllers;
use common\services\CompanyService;
use Yii;
use frontend\modules\addresses\models\Addresses;
use frontend\modules\addresses\models\AddressesSearch;
use yii\web\Controller;
use yii\web\NotFoundHttpException;
use yii\filters\VerbFilter;
/**
* AddressesController implements the CRUD actions for Addresses model.
*/
class AddressesController extends Controller
{
public CompanyService $companyService;
public function init()
{
parent::init();
$this->companyService = new CompanyService();
}
/**
* {@inheritdoc}
*/
public function behaviors()
{
return [
'verbs' => [
'class' => VerbFilter::className(),
'actions' => [
'delete' => ['POST'],
],
],
];
}
/**
* Lists all Addresses models.
* @return mixed
*/
public function actionIndex()
{
$searchModel = new AddressesSearch();
$dataProvider = $searchModel->search(Yii::$app->request->queryParams);
return $this->render('index', [
'searchModel' => $searchModel,
'dataProvider' => $dataProvider,
'companyService' => $this->companyService,
]);
}
/**
* Displays a single Addresses model.
* @param int $id ID
* @return mixed
* @throws NotFoundHttpException if the model cannot be found
*/
public function actionView($id)
{
return $this->render('view', [
'model' => $this->findModel($id),
'companyService' => $this->companyService,
]);
}
/**
* Creates a new Addresses model.
* If creation is successful, the browser will be redirected to the 'view' page.
* @return mixed
*/
public function actionCreate()
{
$model = new Addresses();
if ($model->load(Yii::$app->request->post()) && $model->save()) {
return $this->redirect(['view', 'id' => $model->id]);
}
return $this->render('create', [
'model' => $model,
'companyService' => $this->companyService,
]);
}
/**
* Updates an existing Addresses model.
* If update is successful, the browser will be redirected to the 'view' page.
* @param int $id ID
* @return mixed
* @throws NotFoundHttpException if the model cannot be found
*/
public function actionUpdate($id)
{
$model = $this->findModel($id);
if ($model->load(Yii::$app->request->post()) && $model->save()) {
return $this->redirect(['view', 'id' => $model->id]);
}
return $this->render('update', [
'model' => $model,
'companyService' => $this->companyService
]);
}
/**
* Deletes an existing Addresses model.
* If deletion is successful, the browser will be redirected to the 'index' page.
* @param int $id ID
* @return mixed
* @throws NotFoundHttpException if the model cannot be found
*/
public function actionDelete($id)
{
$this->findModel($id)->delete();
return $this->redirect(['index']);
}
/**
* Finds the Addresses model based on its primary key value.
* If the model is not found, a 404 HTTP exception will be thrown.
* @param int $id ID
* @return Addresses the loaded model
* @throws NotFoundHttpException if the model cannot be found
*/
protected function findModel($id)
{
if (($model = Addresses::findOne($id)) !== null) {
return $model;
}
throw new NotFoundHttpException('The requested page does not exist.');
}
}

View File

@ -0,0 +1,20 @@
<?php
namespace frontend\modules\addresses\controllers;
use yii\web\Controller;
/**
* Default controller for the `addresses` module
*/
class DefaultController extends Controller
{
/**
* Renders the index view for the module
* @return string
*/
public function actionIndex()
{
return $this->render('index');
}
}

View File

@ -0,0 +1,8 @@
<?php
namespace frontend\modules\addresses\models;
class Addresses extends \common\models\Addresses
{
}

View File

@ -0,0 +1,70 @@
<?php
namespace frontend\modules\addresses\models;
use yii\base\Model;
use yii\data\ActiveDataProvider;
use frontend\modules\addresses\models\Addresses;
/**
* AddressesSearch represents the model behind the search form of `frontend\modules\addresses\models\Addresses`.
*/
class AddressesSearch extends Addresses
{
/**
* {@inheritdoc}
*/
public function rules()
{
return [
[['id', 'company_id'], 'integer'],
[['address', 'name'], 'safe'],
];
}
/**
* {@inheritdoc}
*/
public function scenarios()
{
// bypass scenarios() implementation in the parent class
return Model::scenarios();
}
/**
* Creates data provider instance with search query applied
*
* @param array $params
*
* @return ActiveDataProvider
*/
public function search($params)
{
$query = Addresses::find();
// add conditions that should always apply here
$dataProvider = new ActiveDataProvider([
'query' => $query,
]);
$this->load($params);
if (!$this->validate()) {
// uncomment the following line if you do not want to return any records when validation fails
// $query->where('0=1');
return $dataProvider;
}
// grid filtering conditions
$query->andFilterWhere([
'id' => $this->id,
'company_id' => $this->company_id,
]);
$query->andFilterWhere(['like', 'address', $this->address])
->andFilterWhere(['like', 'name', $this->name]);
return $dataProvider;
}
}

View File

@ -0,0 +1,29 @@
<?php
use common\services\CompanyService;
use yii\helpers\Html;
use yii\bootstrap4\ActiveForm;
/* @var $this yii\web\View */
/* @var $model frontend\modules\addresses\models\Addresses */
/* @var $form yii\bootstrap4\ActiveForm */
/* @var $companyService CompanyService */
?>
<div class="addresses-form">
<?php $form = ActiveForm::begin(); ?>
<?= $form->field($model, 'address')->textInput(['maxlength' => true]) ?>
<?= $form->field($model, 'company_id')->dropDownList($companyService->getCompaniesByUserArr()) ?>
<?= $form->field($model, 'name')->textInput(['maxlength' => true]) ?>
<div class="form-group">
<?= Html::submitButton('Сохранить', ['class' => 'btn btn-success']) ?>
</div>
<?php ActiveForm::end(); ?>
</div>

View File

@ -0,0 +1,36 @@
<?php
use yii\helpers\Html;
use yii\widgets\ActiveForm;
/* @var $this yii\web\View */
/* @var $model frontend\modules\addresses\models\AddressesSearch */
/* @var $form yii\widgets\ActiveForm */
?>
<div class="row mt-2">
<div class="col-md-12">
<?php $form = ActiveForm::begin([
'action' => ['index'],
'method' => 'get',
]); ?>
<?= $form->field($model, 'id') ?>
<?= $form->field($model, 'address') ?>
<?= $form->field($model, 'company_id') ?>
<?= $form->field($model, 'name') ?>
<div class="form-group">
<?= Html::submitButton('Search', ['class' => 'btn btn-primary']) ?>
<?= Html::resetButton('Reset', ['class' => 'btn btn-outline-secondary']) ?>
</div>
<?php ActiveForm::end(); ?>
</div>
<!--.col-md-12-->
</div>

View File

@ -0,0 +1,30 @@
<?php
use common\services\CompanyService;
use yii\helpers\Html;
/* @var $this yii\web\View */
/* @var $model frontend\modules\addresses\models\Addresses */
/* @var $companyService CompanyService */
$this->title = 'Добавить отделение';
$this->params['breadcrumbs'][] = ['label' => 'Отделения', 'url' => ['index']];
$this->params['breadcrumbs'][] = $this->title;
?>
<div class="container-fluid">
<div class="card">
<div class="card-body">
<div class="row">
<div class="col-md-12">
<?=$this->render('_form', [
'model' => $model,
'companyService' => $companyService,
]) ?>
</div>
</div>
</div>
<!--.card-body-->
</div>
<!--.card-->
</div>

View File

@ -0,0 +1,62 @@
<?php
use common\services\CompanyService;
use yii\helpers\Html;
use yii\grid\GridView;
/* @var $this yii\web\View */
/* @var $searchModel frontend\modules\addresses\models\AddressesSearch */
/* @var $dataProvider yii\data\ActiveDataProvider */
/* @var $companyService CompanyService */
$this->title = 'Отделения';
$this->params['breadcrumbs'][] = $this->title;
?>
<div class="container-fluid">
<div class="row">
<div class="col-md-12">
<div class="card">
<div class="card-body">
<div class="row mb-2">
<div class="col-md-12">
<?= Html::a('Добавить', ['create'], ['class' => 'btn btn-success']) ?>
</div>
</div>
<?php // echo $this->render('_search', ['model' => $searchModel]); ?>
<?= GridView::widget([
'dataProvider' => $dataProvider,
'filterModel' => $searchModel,
'columns' => [
['class' => 'yii\grid\SerialColumn'],
'id',
'address',
[
'attribute' => 'company_id',
'value' => function($model) use ($companyService){
return $companyService->getCompany($model->company_id)->name ?? null;
}
],
'name',
['class' => 'hail812\adminlte3\yii\grid\ActionColumn'],
],
'summaryOptions' => ['class' => 'summary mb-2'],
'pager' => [
'class' => 'yii\bootstrap4\LinkPager',
]
]); ?>
</div>
<!--.card-body-->
</div>
<!--.card-->
</div>
<!--.col-md-12-->
</div>
<!--.row-->
</div>

View File

@ -0,0 +1,30 @@
<?php
/* @var $this yii\web\View */
/* @var $model frontend\modules\addresses\models\Addresses */
/* @var $companyService CompanyService */
use common\services\CompanyService;
$this->title = 'Update Addresses: ' . $model->name;
$this->params['breadcrumbs'][] = ['label' => 'Addresses', 'url' => ['index']];
$this->params['breadcrumbs'][] = ['label' => $model->name, 'url' => ['view', 'id' => $model->id]];
$this->params['breadcrumbs'][] = 'Update';
?>
<div class="container-fluid">
<div class="card">
<div class="card-body">
<div class="row">
<div class="col-md-12">
<?=$this->render('_form', [
'model' => $model,
'companyService' => $companyService,
]) ?>
</div>
</div>
</div>
<!--.card-body-->
</div>
<!--.card-->
</div>

View File

@ -0,0 +1,53 @@
<?php
use common\services\CompanyService;
use yii\helpers\Html;
use yii\widgets\DetailView;
/* @var $this yii\web\View */
/* @var $model frontend\modules\addresses\models\Addresses */
/* @var $companyService CompanyService */
$this->title = $model->name;
$this->params['breadcrumbs'][] = ['label' => 'Addresses', 'url' => ['index']];
$this->params['breadcrumbs'][] = $this->title;
\yii\web\YiiAsset::register($this);
?>
<div class="container-fluid">
<div class="card">
<div class="card-body">
<div class="row">
<div class="col-md-12">
<p>
<?= Html::a('Список', ['index'], ['class' => 'btn btn-primary']) ?>
<?= Html::a('Редактировать', ['update', 'id' => $model->id], ['class' => 'btn btn-primary']) ?>
<?= Html::a('Удалить', ['delete', 'id' => $model->id], [
'class' => 'btn btn-danger',
'data' => [
'confirm' => 'Are you sure you want to delete this item?',
'method' => 'post',
],
]) ?>
</p>
<?= DetailView::widget([
'model' => $model,
'attributes' => [
'id',
'address',
[
'attribute' => 'company_id',
'value' => $companyService->getCompany($model->company_id)->name ?? null,
],
'name',
],
]) ?>
</div>
<!--.col-md-12-->
</div>
<!--.row-->
</div>
<!--.card-body-->
</div>
<!--.card-->
</div>

View File

@ -0,0 +1,12 @@
<div class="addresses-default-index">
<h1><?= $this->context->action->uniqueId ?></h1>
<p>
This is the view content for action "<?= $this->context->action->id ?>".
The action belongs to the controller "<?= get_class($this->context) ?>"
in the "<?= $this->context->module->id ?>" module.
</p>
<p>
You may customize this page by editing the following file:<br>
<code><?= __FILE__ ?></code>
</p>
</div>

View File

@ -0,0 +1,24 @@
<?php
namespace frontend\modules\check;
/**
* check module definition class
*/
class Check extends \yii\base\Module
{
/**
* {@inheritdoc}
*/
public $controllerNamespace = 'frontend\modules\check\controllers';
/**
* {@inheritdoc}
*/
public function init()
{
parent::init();
// custom initialization code goes here
}
}

View File

@ -0,0 +1,127 @@
<?php
namespace frontend\modules\check\controllers;
use Yii;
use frontend\modules\check\models\Check;
use frontend\modules\check\models\CheckSearch;
use yii\web\Controller;
use yii\web\NotFoundHttpException;
use yii\filters\VerbFilter;
/**
* CheckController implements the CRUD actions for Check model.
*/
class CheckController extends Controller
{
/**
* {@inheritdoc}
*/
public function behaviors()
{
return [
'verbs' => [
'class' => VerbFilter::className(),
'actions' => [
'delete' => ['POST'],
],
],
];
}
/**
* Lists all Check models.
* @return mixed
*/
public function actionIndex()
{
$searchModel = new CheckSearch();
$dataProvider = $searchModel->search(Yii::$app->request->queryParams);
return $this->render('index', [
'searchModel' => $searchModel,
'dataProvider' => $dataProvider,
]);
}
/**
* Displays a single Check model.
* @param int $id ID
* @return mixed
* @throws NotFoundHttpException if the model cannot be found
*/
public function actionView($id)
{
return $this->render('view', [
'model' => $this->findModel($id),
]);
}
/**
* Creates a new Check model.
* If creation is successful, the browser will be redirected to the 'view' page.
* @return mixed
*/
public function actionCreate()
{
$model = new Check();
if ($model->load(Yii::$app->request->post()) && $model->save()) {
return $this->redirect(['view', 'id' => $model->id]);
}
return $this->render('create', [
'model' => $model,
]);
}
/**
* Updates an existing Check model.
* If update is successful, the browser will be redirected to the 'view' page.
* @param int $id ID
* @return mixed
* @throws NotFoundHttpException if the model cannot be found
*/
public function actionUpdate($id)
{
$model = $this->findModel($id);
if ($model->load(Yii::$app->request->post()) && $model->save()) {
return $this->redirect(['view', 'id' => $model->id]);
}
return $this->render('update', [
'model' => $model,
]);
}
/**
* Deletes an existing Check model.
* If deletion is successful, the browser will be redirected to the 'index' page.
* @param int $id ID
* @return mixed
* @throws NotFoundHttpException if the model cannot be found
*/
public function actionDelete($id)
{
$this->findModel($id)->delete();
return $this->redirect(['index']);
}
/**
* Finds the Check model based on its primary key value.
* If the model is not found, a 404 HTTP exception will be thrown.
* @param int $id ID
* @return Check the loaded model
* @throws NotFoundHttpException if the model cannot be found
*/
protected function findModel($id)
{
if (($model = Check::findOne($id)) !== null) {
return $model;
}
throw new NotFoundHttpException('The requested page does not exist.');
}
}

View File

@ -0,0 +1,20 @@
<?php
namespace frontend\modules\check\controllers;
use yii\web\Controller;
/**
* Default controller for the `check` module
*/
class DefaultController extends Controller
{
/**
* Renders the index view for the module
* @return string
*/
public function actionIndex()
{
return $this->render('index');
}
}

View File

@ -0,0 +1,8 @@
<?php
namespace frontend\modules\check\models;
class Check extends \common\models\Check
{
}

View File

@ -0,0 +1,72 @@
<?php
namespace frontend\modules\check\models;
use yii\base\Model;
use yii\data\ActiveDataProvider;
use frontend\modules\check\models\Check;
/**
* CheckSearch represents the model behind the search form of `frontend\modules\check\models\Check`.
*/
class CheckSearch extends Check
{
/**
* {@inheritdoc}
*/
public function rules()
{
return [
[['id', 'company_id', 'addresses_id', 'status'], 'integer'],
[['number', 'additional'], 'safe'],
];
}
/**
* {@inheritdoc}
*/
public function scenarios()
{
// bypass scenarios() implementation in the parent class
return Model::scenarios();
}
/**
* Creates data provider instance with search query applied
*
* @param array $params
*
* @return ActiveDataProvider
*/
public function search($params)
{
$query = Check::find();
// add conditions that should always apply here
$dataProvider = new ActiveDataProvider([
'query' => $query,
]);
$this->load($params);
if (!$this->validate()) {
// uncomment the following line if you do not want to return any records when validation fails
// $query->where('0=1');
return $dataProvider;
}
// grid filtering conditions
$query->andFilterWhere([
'id' => $this->id,
'company_id' => $this->company_id,
'addresses_id' => $this->addresses_id,
'status' => $this->status,
]);
$query->andFilterWhere(['like', 'number', $this->number])
->andFilterWhere(['like', 'additional', $this->additional]);
return $dataProvider;
}
}

View File

@ -0,0 +1,27 @@
<?php
use yii\helpers\Html;
use yii\bootstrap4\ActiveForm;
/* @var $this yii\web\View */
/* @var $model frontend\modules\check\models\Check */
/* @var $form yii\bootstrap4\ActiveForm */
$companyService = new \common\services\CompanyService();
?>
<div class="check-form">
<?php $form = ActiveForm::begin(); ?>
<?= $form->field($model, 'addresses_id')->dropDownList($companyService->getAddressesByUserArr()) ?>
<?= $form->field($model, 'status')->dropDownList(\common\models\Check::getStatus()) ?>
<div class="form-group">
<?= Html::submitButton('Save', ['class' => 'btn btn-success']) ?>
</div>
<?php ActiveForm::end(); ?>
</div>

View File

@ -0,0 +1,40 @@
<?php
use yii\helpers\Html;
use yii\widgets\ActiveForm;
/* @var $this yii\web\View */
/* @var $model frontend\modules\check\models\CheckSearch */
/* @var $form yii\widgets\ActiveForm */
?>
<div class="row mt-2">
<div class="col-md-12">
<?php $form = ActiveForm::begin([
'action' => ['index'],
'method' => 'get',
]); ?>
<?= $form->field($model, 'id') ?>
<?= $form->field($model, 'number') ?>
<?= $form->field($model, 'company_id') ?>
<?= $form->field($model, 'additional') ?>
<?= $form->field($model, 'addresses_id') ?>
<?php // echo $form->field($model, 'status') ?>
<div class="form-group">
<?= Html::submitButton('Search', ['class' => 'btn btn-primary']) ?>
<?= Html::resetButton('Reset', ['class' => 'btn btn-outline-secondary']) ?>
</div>
<?php ActiveForm::end(); ?>
</div>
<!--.col-md-12-->
</div>

View File

@ -0,0 +1,27 @@
<?php
use yii\helpers\Html;
/* @var $this yii\web\View */
/* @var $model frontend\modules\check\models\Check */
$this->title = 'Создать чек';
$this->params['breadcrumbs'][] = ['label' => 'Чеки', 'url' => ['index']];
$this->params['breadcrumbs'][] = $this->title;
?>
<div class="container-fluid">
<div class="card">
<div class="card-body">
<div class="row">
<div class="col-md-12">
<?=$this->render('_form', [
'model' => $model
]) ?>
</div>
</div>
</div>
<!--.card-body-->
</div>
<!--.card-->
</div>

View File

@ -0,0 +1,58 @@
<?php
use yii\helpers\Html;
use yii\grid\GridView;
/* @var $this yii\web\View */
/* @var $searchModel frontend\modules\check\models\CheckSearch */
/* @var $dataProvider yii\data\ActiveDataProvider */
$this->title = 'Чеки';
$this->params['breadcrumbs'][] = $this->title;
?>
<div class="container-fluid">
<div class="row">
<div class="col-md-12">
<div class="card">
<div class="card-body">
<div class="row mb-2">
<div class="col-md-12">
<?= Html::a('Создать чек', ['create'], ['class' => 'btn btn-success']) ?>
</div>
</div>
<?php // echo $this->render('_search', ['model' => $searchModel]); ?>
<?= GridView::widget([
'dataProvider' => $dataProvider,
'filterModel' => $searchModel,
'columns' => [
['class' => 'yii\grid\SerialColumn'],
// 'id',
'title',
'number',
'company_id',
'additional:ntext',
//'addresses_id',
//'status',
['class' => 'hail812\adminlte3\yii\grid\ActionColumn'],
],
'summaryOptions' => ['class' => 'summary mb-2'],
'pager' => [
'class' => 'yii\bootstrap4\LinkPager',
]
]); ?>
</div>
<!--.card-body-->
</div>
<!--.card-->
</div>
<!--.col-md-12-->
</div>
<!--.row-->
</div>

View File

@ -0,0 +1,26 @@
<?php
/* @var $this yii\web\View */
/* @var $model frontend\modules\check\models\Check */
$this->title = 'Update Check: ' . $model->id;
$this->params['breadcrumbs'][] = ['label' => 'Checks', 'url' => ['index']];
$this->params['breadcrumbs'][] = ['label' => $model->id, 'url' => ['view', 'id' => $model->id]];
$this->params['breadcrumbs'][] = 'Update';
?>
<div class="container-fluid">
<div class="card">
<div class="card-body">
<div class="row">
<div class="col-md-12">
<?=$this->render('_form', [
'model' => $model
]) ?>
</div>
</div>
</div>
<!--.card-body-->
</div>
<!--.card-->
</div>

View File

@ -0,0 +1,49 @@
<?php
use yii\helpers\Html;
use yii\widgets\DetailView;
/* @var $this yii\web\View */
/* @var $model frontend\modules\check\models\Check */
$this->title = $model->id;
$this->params['breadcrumbs'][] = ['label' => 'Checks', 'url' => ['index']];
$this->params['breadcrumbs'][] = $this->title;
\yii\web\YiiAsset::register($this);
?>
<div class="container-fluid">
<div class="card">
<div class="card-body">
<div class="row">
<div class="col-md-12">
<p>
<?= Html::a('Update', ['update', 'id' => $model->id], ['class' => 'btn btn-primary']) ?>
<?= Html::a('Delete', ['delete', 'id' => $model->id], [
'class' => 'btn btn-danger',
'data' => [
'confirm' => 'Are you sure you want to delete this item?',
'method' => 'post',
],
]) ?>
</p>
<?= DetailView::widget([
'model' => $model,
'attributes' => [
'id',
'number',
'company_id',
'additional:ntext',
'addresses_id',
'status',
],
]) ?>
</div>
<!--.col-md-12-->
</div>
<!--.row-->
</div>
<!--.card-body-->
</div>
<!--.card-->
</div>

View File

@ -0,0 +1,12 @@
<div class="check-default-index">
<h1><?= $this->context->action->uniqueId ?></h1>
<p>
This is the view content for action "<?= $this->context->action->id ?>".
The action belongs to the controller "<?= get_class($this->context) ?>"
in the "<?= $this->context->module->id ?>" module.
</p>
<p>
You may customize this page by editing the following file:<br>
<code><?= __FILE__ ?></code>
</p>
</div>

View File

@ -0,0 +1,24 @@
<?php
namespace frontend\modules\company;
/**
* company module definition class
*/
class Company extends \yii\base\Module
{
/**
* {@inheritdoc}
*/
public $controllerNamespace = 'frontend\modules\company\controllers';
/**
* {@inheritdoc}
*/
public function init()
{
parent::init();
// custom initialization code goes here
}
}

View File

@ -0,0 +1,154 @@
<?php
namespace frontend\modules\company\controllers;
use common\services\CompanyService;
use frontend\modules\company\models\Company;
use frontend\modules\company\models\CompanySearch;
use yii\web\Controller;
use yii\web\NotFoundHttpException;
use yii\filters\VerbFilter;
/**
* CompanyController implements the CRUD actions for Company model.
*/
class CompanyController extends Controller
{
public CompanyService $service;
public function init()
{
parent::init();
$this->service = new CompanyService();
}
/**
* @inheritDoc
*/
public function behaviors()
{
return array_merge(
parent::behaviors(),
[
'verbs' => [
'class' => VerbFilter::className(),
'actions' => [
'delete' => ['POST'],
],
],
'access' => [
'class' => \yii\filters\AccessControl::className(),
'rules' => [
[
'allow' => true,
'roles' => ['@'],
],
],
],
]
);
}
/**
* Lists all Company models.
*
* @return string
*/
public function actionIndex()
{
$searchModel = new CompanySearch();
$dataProvider = $searchModel->search($this->request->queryParams);
return $this->render('index', [
'searchModel' => $searchModel,
'dataProvider' => $dataProvider,
]);
}
/**
* Displays a single Company model.
* @param int $id ID
* @return string
* @throws NotFoundHttpException if the model cannot be found
*/
public function actionView($id)
{
return $this->render('view', [
'model' => $this->findModel($id),
]);
}
/**
* Creates a new Company model.
* If creation is successful, the browser will be redirected to the 'view' page.
* @return string|\yii\web\Response
*/
public function actionCreate()
{
$model = new Company();
$model->user_id = \Yii::$app->user->id;
if ($this->request->isPost) {
if ($model->load($this->request->post()) && $model->save()) {
return $this->redirect(['view', 'id' => $model->id]);
}
} else {
$model->loadDefaultValues();
}
return $this->render('create', [
'model' => $model,
'companies' => $this->service->getCompaniesByUserArr(),
]);
}
/**
* Updates an existing Company model.
* If update is successful, the browser will be redirected to the 'view' page.
* @param int $id ID
* @return string|\yii\web\Response
* @throws NotFoundHttpException if the model cannot be found
*/
public function actionUpdate(int $id)
{
$model = $this->findModel($id);
if ($this->request->isPost && $model->load($this->request->post()) && $model->save()) {
return $this->redirect(['view', 'id' => $model->id]);
}
return $this->render('update', [
'model' => $model,
]);
}
/**
* Deletes an existing Company model.
* If deletion is successful, the browser will be redirected to the 'index' page.
* @param int $id ID
* @return \yii\web\Response
* @throws NotFoundHttpException if the model cannot be found
*/
public function actionDelete($id)
{
$this->findModel($id)->delete();
return $this->redirect(['index']);
}
/**
* Finds the Company model based on its primary key value.
* If the model is not found, a 404 HTTP exception will be thrown.
* @param int $id ID
* @return Company the loaded model
* @throws NotFoundHttpException if the model cannot be found
*/
protected function findModel($id)
{
if (($model = Company::findOne(['id' => $id])) !== null) {
return $model;
}
throw new NotFoundHttpException('The requested page does not exist.');
}
}

View File

@ -0,0 +1,20 @@
<?php
namespace frontend\modules\company\controllers;
use yii\web\Controller;
/**
* Default controller for the `company` module
*/
class DefaultController extends Controller
{
/**
* Renders the index view for the module
* @return string
*/
public function actionIndex()
{
return $this->render('index');
}
}

View File

@ -0,0 +1,8 @@
<?php
namespace frontend\modules\company\models;
class Company extends \common\models\Company
{
}

View File

@ -0,0 +1,77 @@
<?php
namespace frontend\modules\company\models;
use yii\base\Model;
use yii\data\ActiveDataProvider;
use frontend\modules\company\models\Company;
/**
* CompanySearch represents the model behind the search form of `frontend\modules\company\models\Company`.
*/
class CompanySearch extends Company
{
/**
* {@inheritdoc}
*/
public function rules()
{
return [
[['id', 'inn', 'created_at', 'updated_at', 'status'], 'integer'],
[['name', 'address'], 'safe'],
];
}
/**
* {@inheritdoc}
*/
public function scenarios()
{
// bypass scenarios() implementation in the parent class
return Model::scenarios();
}
/**
* Creates data provider instance with search query applied
*
* @param array $params
*
* @return ActiveDataProvider
*/
public function search($params)
{
$query = Company::find();
// add conditions that should always apply here
$dataProvider = new ActiveDataProvider([
'query' => $query,
]);
$this->load($params);
if (!$this->validate()) {
// uncomment the following line if you do not want to return any records when validation fails
// $query->where('0=1');
return $dataProvider;
}
$query->where(['user_id' => \Yii::$app->user->id]);
// grid filtering conditions
$query->andFilterWhere([
'id' => $this->id,
'inn' => $this->inn,
'created_at' => $this->created_at,
'updated_at' => $this->updated_at,
'status' => $this->status,
]);
$query->andFilterWhere(['like', 'name', $this->name])
->andFilterWhere(['like', 'address', $this->address]);
$query->orderBy("id DESC");
return $dataProvider;
}
}

View File

@ -0,0 +1,29 @@
<?php
use yii\helpers\Html;
use yii\widgets\ActiveForm;
/** @var yii\web\View $this */
/** @var frontend\modules\company\models\Company $model */
/** @var yii\widgets\ActiveForm $form */
?>
<div class="company-form">
<?php $form = ActiveForm::begin(); ?>
<?= $form->field($model, 'inn')->textInput() ?>
<?= $form->field($model, 'name')->textInput(['maxlength' => true]) ?>
<?= $form->field($model, 'address')->textInput(['maxlength' => true]) ?>
<?= $form->field($model, 'status')->dropDownList(\common\models\Company::getStatus()) ?>
<div class="form-group">
<?= Html::submitButton('Сохранить', ['class' => 'btn btn-success']) ?>
</div>
<?php ActiveForm::end(); ?>
</div>

View File

@ -0,0 +1,39 @@
<?php
use yii\helpers\Html;
use yii\widgets\ActiveForm;
/** @var yii\web\View $this */
/** @var frontend\modules\company\models\CompanySearch $model */
/** @var yii\widgets\ActiveForm $form */
?>
<div class="company-search">
<?php $form = ActiveForm::begin([
'action' => ['index'],
'method' => 'get',
]); ?>
<?= $form->field($model, 'id') ?>
<?= $form->field($model, 'inn') ?>
<?= $form->field($model, 'name') ?>
<?= $form->field($model, 'address') ?>
<?= $form->field($model, 'created_at') ?>
<?php // echo $form->field($model, 'updated_at') ?>
<?php // echo $form->field($model, 'status') ?>
<div class="form-group">
<?= Html::submitButton('Search', ['class' => 'btn btn-primary']) ?>
<?= Html::resetButton('Reset', ['class' => 'btn btn-outline-secondary']) ?>
</div>
<?php ActiveForm::end(); ?>
</div>

View File

@ -0,0 +1,18 @@
<?php
use yii\helpers\Html;
/** @var yii\web\View $this */
/** @var frontend\modules\company\models\Company $model */
$this->title = 'Добавить';
$this->params['breadcrumbs'][] = ['label' => 'Компании', 'url' => ['index']];
$this->params['breadcrumbs'][] = $this->title;
?>
<div class="company-create">
<?= $this->render('_form', [
'model' => $model,
]) ?>
</div>

View File

@ -0,0 +1,47 @@
<?php
use frontend\modules\company\models\Company;
use yii\helpers\Html;
use yii\helpers\Url;
use yii\grid\ActionColumn;
use yii\grid\GridView;
/** @var yii\web\View $this */
/** @var frontend\modules\company\models\CompanySearch $searchModel */
/** @var yii\data\ActiveDataProvider $dataProvider */
$this->title = 'Компании';
$this->params['breadcrumbs'][] = $this->title;
?>
<div class="company-index">
<p>
<?= Html::a('Создать', ['create'], ['class' => 'btn btn-success']) ?>
</p>
<?php // echo $this->render('_search', ['model' => $searchModel]); ?>
<?= GridView::widget([
'dataProvider' => $dataProvider,
'filterModel' => $searchModel,
'columns' => [
['class' => 'yii\grid\SerialColumn'],
'id',
'inn',
'name',
'address',
'created_at',
//'updated_at',
//'status',
[
'class' => ActionColumn::className(),
'urlCreator' => function ($action, Company $model, $key, $index, $column) {
return Url::toRoute([$action, 'id' => $model->id]);
}
],
],
]); ?>
</div>

View File

@ -0,0 +1,19 @@
<?php
use yii\helpers\Html;
/** @var yii\web\View $this */
/** @var frontend\modules\company\models\Company $model */
$this->title = 'Редактировать: ' . $model->name;
$this->params['breadcrumbs'][] = ['label' => 'Компании', 'url' => ['index']];
$this->params['breadcrumbs'][] = ['label' => $model->name, 'url' => ['view', 'id' => $model->id]];
$this->params['breadcrumbs'][] = 'Редактировать';
?>
<div class="company-update">
<?= $this->render('_form', [
'model' => $model,
]) ?>
</div>

View File

@ -0,0 +1,41 @@
<?php
use yii\helpers\Html;
use yii\widgets\DetailView;
/** @var yii\web\View $this */
/** @var frontend\modules\company\models\Company $model */
$this->title = $model->name;
$this->params['breadcrumbs'][] = ['label' => 'Компании', 'url' => ['index']];
$this->params['breadcrumbs'][] = $this->title;
\yii\web\YiiAsset::register($this);
?>
<div class="company-view">
<p>
<?= Html::a('Список', ['index'], ['class' => 'btn btn-primary']) ?>
<?= Html::a('Редактировать', ['update', 'id' => $model->id], ['class' => 'btn btn-primary']) ?>
<?= Html::a('Удалить', ['delete', 'id' => $model->id], [
'class' => 'btn btn-danger',
'data' => [
'confirm' => 'Are you sure you want to delete this item?',
'method' => 'post',
],
]) ?>
</p>
<?= DetailView::widget([
'model' => $model,
'attributes' => [
'id',
'inn',
'name',
'address',
'created_at',
'updated_at',
'status',
],
]) ?>
</div>

View File

@ -0,0 +1,12 @@
<div class="company-default-index">
<h1><?= $this->context->action->uniqueId ?></h1>
<p>
This is the view content for action "<?= $this->context->action->id ?>".
The action belongs to the controller "<?= get_class($this->context) ?>"
in the "<?= $this->context->module->id ?>" module.
</p>
<p>
You may customize this page by editing the following file:<br>
<code><?= __FILE__ ?></code>
</p>
</div>

View File

@ -0,0 +1,24 @@
<?php
namespace frontend\modules\product;
/**
* product module definition class
*/
class Product extends \yii\base\Module
{
/**
* {@inheritdoc}
*/
public $controllerNamespace = 'frontend\modules\product\controllers';
/**
* {@inheritdoc}
*/
public function init()
{
parent::init();
// custom initialization code goes here
}
}

View File

@ -0,0 +1,20 @@
<?php
namespace frontend\modules\product\controllers;
use yii\web\Controller;
/**
* Default controller for the `product` module
*/
class DefaultController extends Controller
{
/**
* Renders the index view for the module
* @return string
*/
public function actionIndex()
{
return $this->render('index');
}
}

View File

@ -0,0 +1,139 @@
<?php
namespace frontend\modules\product\controllers;
use common\services\CompanyService;
use Yii;
use frontend\modules\product\models\Product;
use frontend\modules\product\models\ProductSearch;
use yii\web\Controller;
use yii\web\NotFoundHttpException;
use yii\filters\VerbFilter;
/**
* ProductController implements the CRUD actions for Product model.
*/
class ProductController extends Controller
{
public CompanyService $companyService;
public function init()
{
parent::init();
$this->companyService = new CompanyService();
}
/**
* {@inheritdoc}
*/
public function behaviors()
{
return [
'verbs' => [
'class' => VerbFilter::className(),
'actions' => [
'delete' => ['POST'],
],
],
];
}
/**
* Lists all Product models.
* @return mixed
*/
public function actionIndex()
{
$searchModel = new ProductSearch();
$dataProvider = $searchModel->search(Yii::$app->request->queryParams);
return $this->render('index', [
'searchModel' => $searchModel,
'dataProvider' => $dataProvider,
]);
}
/**
* Displays a single Product model.
* @param int $id ID
* @return mixed
* @throws NotFoundHttpException if the model cannot be found
*/
public function actionView($id)
{
return $this->render('view', [
'model' => $this->findModel($id),
'companyService' => $this->companyService,
]);
}
/**
* Creates a new Product model.
* If creation is successful, the browser will be redirected to the 'view' page.
* @return mixed
*/
public function actionCreate()
{
$model = new Product();
if ($model->load(Yii::$app->request->post()) && $model->save()) {
return $this->redirect(['view', 'id' => $model->id]);
}
return $this->render('create', [
'model' => $model,
'companies' => $this->companyService->getCompaniesByUserArr(),
]);
}
/**
* Updates an existing Product model.
* If update is successful, the browser will be redirected to the 'view' page.
* @param int $id ID
* @return mixed
* @throws NotFoundHttpException if the model cannot be found
*/
public function actionUpdate($id)
{
$model = $this->findModel($id);
if ($model->load(Yii::$app->request->post()) && $model->save()) {
return $this->redirect(['view', 'id' => $model->id]);
}
return $this->render('update', [
'model' => $model,
'companies' => $this->companyService->getCompaniesByUserArr(),
]);
}
/**
* Deletes an existing Product model.
* If deletion is successful, the browser will be redirected to the 'index' page.
* @param int $id ID
* @return mixed
* @throws NotFoundHttpException if the model cannot be found
*/
public function actionDelete($id)
{
$this->findModel($id)->delete();
return $this->redirect(['index']);
}
/**
* Finds the Product model based on its primary key value.
* If the model is not found, a 404 HTTP exception will be thrown.
* @param int $id ID
* @return Product the loaded model
* @throws NotFoundHttpException if the model cannot be found
*/
protected function findModel($id)
{
if (($model = Product::findOne($id)) !== null) {
return $model;
}
throw new NotFoundHttpException('The requested page does not exist.');
}
}

View File

@ -0,0 +1,8 @@
<?php
namespace frontend\modules\product\models;
class Product extends \common\models\Product
{
}

View File

@ -0,0 +1,73 @@
<?php
namespace frontend\modules\product\models;
use yii\base\Model;
use yii\data\ActiveDataProvider;
use frontend\modules\product\models\Product;
/**
* ProductSearch represents the model behind the search form of `frontend\modules\product\models\Product`.
*/
class ProductSearch extends Product
{
/**
* {@inheritdoc}
*/
public function rules()
{
return [
[['id', 'company_id', 'type', 'price', 'status'], 'integer'],
[['title', 'article'], 'safe'],
];
}
/**
* {@inheritdoc}
*/
public function scenarios()
{
// bypass scenarios() implementation in the parent class
return Model::scenarios();
}
/**
* Creates data provider instance with search query applied
*
* @param array $params
*
* @return ActiveDataProvider
*/
public function search($params)
{
$query = Product::find();
// add conditions that should always apply here
$dataProvider = new ActiveDataProvider([
'query' => $query,
]);
$this->load($params);
if (!$this->validate()) {
// uncomment the following line if you do not want to return any records when validation fails
// $query->where('0=1');
return $dataProvider;
}
// grid filtering conditions
$query->andFilterWhere([
'id' => $this->id,
'company_id' => $this->company_id,
'type' => $this->type,
'price' => $this->price,
'status' => $this->status,
]);
$query->andFilterWhere(['like', 'title', $this->title])
->andFilterWhere(['like', 'article', $this->article]);
return $dataProvider;
}
}

View File

@ -0,0 +1,12 @@
<div class="product-default-index">
<h1><?= $this->context->action->uniqueId ?></h1>
<p>
This is the view content for action "<?= $this->context->action->id ?>".
The action belongs to the controller "<?= get_class($this->context) ?>"
in the "<?= $this->context->module->id ?>" module.
</p>
<p>
You may customize this page by editing the following file:<br>
<code><?= __FILE__ ?></code>
</p>
</div>

View File

@ -0,0 +1,34 @@
<?php
use yii\helpers\Html;
use yii\bootstrap4\ActiveForm;
/* @var $this yii\web\View */
/* @var $model frontend\modules\product\models\Product */
/* @var $form yii\bootstrap4\ActiveForm */
/* @var $companies array */
?>
<div class="product-form">
<?php $form = ActiveForm::begin(); ?>
<?= $form->field($model, 'title')->textInput(['maxlength' => true]) ?>
<?= $form->field($model, 'article')->textInput(['maxlength' => true]) ?>
<?= $form->field($model, 'company_id')->dropDownList($companies) ?>
<?= $form->field($model, 'type')->dropDownList(\common\models\Product::getType()) ?>
<?= $form->field($model, 'price')->textInput() ?>
<?= $form->field($model, 'status')->dropDownList(\common\models\Product::getStatus(), ['prompt' => 'Выберите статус']) ?>
<div class="form-group">
<?= Html::submitButton('Сохранить', ['class' => 'btn btn-success']) ?>
</div>
<?php ActiveForm::end(); ?>
</div>

View File

@ -0,0 +1,42 @@
<?php
use yii\helpers\Html;
use yii\widgets\ActiveForm;
/* @var $this yii\web\View */
/* @var $model frontend\modules\product\models\ProductSearch */
/* @var $form yii\widgets\ActiveForm */
?>
<div class="row mt-2">
<div class="col-md-12">
<?php $form = ActiveForm::begin([
'action' => ['index'],
'method' => 'get',
]); ?>
<?= $form->field($model, 'id') ?>
<?= $form->field($model, 'title') ?>
<?= $form->field($model, 'article') ?>
<?= $form->field($model, 'company_id') ?>
<?= $form->field($model, 'type') ?>
<?php // echo $form->field($model, 'price') ?>
<?php // echo $form->field($model, 'status') ?>
<div class="form-group">
<?= Html::submitButton('Search', ['class' => 'btn btn-primary']) ?>
<?= Html::resetButton('Reset', ['class' => 'btn btn-outline-secondary']) ?>
</div>
<?php ActiveForm::end(); ?>
</div>
<!--.col-md-12-->
</div>

View File

@ -0,0 +1,29 @@
<?php
use yii\helpers\Html;
/* @var $this yii\web\View */
/* @var $model frontend\modules\product\models\Product */
/* @var $companies array */
$this->title = 'Добавить продукт';
$this->params['breadcrumbs'][] = ['label' => 'Продукты', 'url' => ['index']];
$this->params['breadcrumbs'][] = $this->title;
?>
<div class="container-fluid">
<div class="card">
<div class="card-body">
<div class="row">
<div class="col-md-12">
<?=$this->render('_form', [
'model' => $model,
'companies' => $companies,
]) ?>
</div>
</div>
</div>
<!--.card-body-->
</div>
<!--.card-->
</div>

View File

@ -0,0 +1,58 @@
<?php
use yii\helpers\Html;
use yii\grid\GridView;
/* @var $this yii\web\View */
/* @var $searchModel frontend\modules\product\models\ProductSearch */
/* @var $dataProvider yii\data\ActiveDataProvider */
$this->title = 'Товары';
$this->params['breadcrumbs'][] = $this->title;
?>
<div class="container-fluid">
<div class="row">
<div class="col-md-12">
<div class="card">
<div class="card-body">
<div class="row mb-2">
<div class="col-md-12">
<?= Html::a('Добавть', ['create'], ['class' => 'btn btn-success']) ?>
</div>
</div>
<?php // echo $this->render('_search', ['model' => $searchModel]); ?>
<?= GridView::widget([
'dataProvider' => $dataProvider,
'filterModel' => $searchModel,
'columns' => [
['class' => 'yii\grid\SerialColumn'],
//'id',
'title',
'article',
//'company_id',
//'type',
//'price',
//'status',
['class' => 'hail812\adminlte3\yii\grid\ActionColumn'],
],
'summaryOptions' => ['class' => 'summary mb-2'],
'pager' => [
'class' => 'yii\bootstrap4\LinkPager',
]
]); ?>
</div>
<!--.card-body-->
</div>
<!--.card-->
</div>
<!--.col-md-12-->
</div>
<!--.row-->
</div>

View File

@ -0,0 +1,28 @@
<?php
/* @var $this yii\web\View */
/* @var $model frontend\modules\product\models\Product */
/* @var $companies array */
$this->title = 'Редактировать: ' . $model->title;
$this->params['breadcrumbs'][] = ['label' => 'Товары', 'url' => ['index']];
$this->params['breadcrumbs'][] = ['label' => $model->title, 'url' => ['view', 'id' => $model->id]];
$this->params['breadcrumbs'][] = 'Редактировать';
?>
<div class="container-fluid">
<div class="card">
<div class="card-body">
<div class="row">
<div class="col-md-12">
<?=$this->render('_form', [
'model' => $model,
'companies' => $companies,
]) ?>
</div>
</div>
</div>
<!--.card-body-->
</div>
<!--.card-->
</div>

View File

@ -0,0 +1,62 @@
<?php
use common\services\CompanyService;
use yii\helpers\Html;
use yii\widgets\DetailView;
/* @var $this yii\web\View */
/* @var $model frontend\modules\product\models\Product */
/* @var $companyService CompanyService */
$this->title = $model->title;
$this->params['breadcrumbs'][] = ['label' => 'Продукты', 'url' => ['index']];
$this->params['breadcrumbs'][] = $this->title;
\yii\web\YiiAsset::register($this);
?>
<div class="container-fluid">
<div class="card">
<div class="card-body">
<div class="row">
<div class="col-md-12">
<p>
<?= Html::a('Список', ['index'], ['class' => 'btn btn-primary']) ?>
<?= Html::a('Редактировать', ['update', 'id' => $model->id], ['class' => 'btn btn-primary']) ?>
<?= Html::a('Удалить', ['delete', 'id' => $model->id], [
'class' => 'btn btn-danger',
'data' => [
'confirm' => 'Are you sure you want to delete this item?',
'method' => 'post',
],
]) ?>
</p>
<?= DetailView::widget([
'model' => $model,
'attributes' => [
'id',
'title',
'article',
[
'attribute' => 'company_id',
'value' => $companyService->getCompany($model->company_id)->name ?? null
],
[
'attribute' => 'type',
'value' => \common\models\Product::getType()[$model->type]
],
'price',
[
'attribute' => 'status',
'value' => \common\models\Product::getStatus()[$model->status]
],
],
]) ?>
</div>
<!--.col-md-12-->
</div>
<!--.row-->
</div>
<!--.card-body-->
</div>
<!--.card-->
</div>

View File

@ -0,0 +1,24 @@
<?php
namespace frontend\modules\product_category;
/**
* product_category module definition class
*/
class ProductCategory extends \yii\base\Module
{
/**
* {@inheritdoc}
*/
public $controllerNamespace = 'frontend\modules\product_category\controllers';
/**
* {@inheritdoc}
*/
public function init()
{
parent::init();
// custom initialization code goes here
}
}

View File

@ -0,0 +1,20 @@
<?php
namespace frontend\modules\product_category\controllers;
use yii\web\Controller;
/**
* Default controller for the `product_category` module
*/
class DefaultController extends Controller
{
/**
* Renders the index view for the module
* @return string
*/
public function actionIndex()
{
return $this->render('index');
}
}

View File

@ -0,0 +1,132 @@
<?php
namespace frontend\modules\product_category\controllers;
use common\classes\Debug;
use common\models\User;
use Yii;
use frontend\modules\product_category\models\ProductCategory;
use frontend\modules\product_category\models\ProductCategorySearch;
use yii\helpers\ArrayHelper;
use yii\web\Controller;
use yii\web\NotFoundHttpException;
use yii\filters\VerbFilter;
/**
* ProductCategoryController implements the CRUD actions for ProductCategory model.
*/
class ProductCategoryController extends Controller
{
/**
* {@inheritdoc}
*/
public function behaviors()
{
return [
'verbs' => [
'class' => VerbFilter::className(),
'actions' => [
'delete' => ['POST'],
],
],
];
}
/**
* Lists all ProductCategory models.
* @return mixed
*/
public function actionIndex()
{
$searchModel = new ProductCategorySearch();
$dataProvider = $searchModel->search(Yii::$app->request->queryParams);
return $this->render('index', [
'searchModel' => $searchModel,
'dataProvider' => $dataProvider,
]);
}
/**
* Displays a single ProductCategory model.
* @param int $id ID
* @return mixed
* @throws NotFoundHttpException if the model cannot be found
*/
public function actionView($id)
{
return $this->render('view', [
'model' => $this->findModel($id),
]);
}
/**
* Creates a new ProductCategory model.
* If creation is successful, the browser will be redirected to the 'view' page.
* @return mixed
*/
public function actionCreate()
{
$model = new ProductCategory();
$user = User::findOne(Yii::$app->user->id);
if ($model->load(Yii::$app->request->post()) && $model->save()) {
return $this->redirect(['view', 'id' => $model->id]);
}
return $this->render('create', [
'model' => $model,
'user' => $user,
]);
}
/**
* Updates an existing ProductCategory model.
* If update is successful, the browser will be redirected to the 'view' page.
* @param int $id ID
* @return mixed
* @throws NotFoundHttpException if the model cannot be found
*/
public function actionUpdate($id)
{
$model = $this->findModel($id);
if ($model->load(Yii::$app->request->post()) && $model->save()) {
return $this->redirect(['view', 'id' => $model->id]);
}
return $this->render('update', [
'model' => $model,
]);
}
/**
* Deletes an existing ProductCategory model.
* If deletion is successful, the browser will be redirected to the 'index' page.
* @param int $id ID
* @return mixed
* @throws NotFoundHttpException if the model cannot be found
*/
public function actionDelete($id)
{
$this->findModel($id)->delete();
return $this->redirect(['index']);
}
/**
* Finds the ProductCategory model based on its primary key value.
* If the model is not found, a 404 HTTP exception will be thrown.
* @param int $id ID
* @return ProductCategory the loaded model
* @throws NotFoundHttpException if the model cannot be found
*/
protected function findModel($id)
{
if (($model = ProductCategory::findOne($id)) !== null) {
return $model;
}
throw new NotFoundHttpException('The requested page does not exist.');
}
}

View File

@ -0,0 +1,8 @@
<?php
namespace frontend\modules\product_category\models;
class ProductCategory extends \common\models\ProductCategory
{
}

View File

@ -0,0 +1,71 @@
<?php
namespace frontend\modules\product_category\models;
use yii\base\Model;
use yii\data\ActiveDataProvider;
use frontend\modules\product_category\models\ProductCategory;
/**
* ProductCategorySearch represents the model behind the search form of `frontend\modules\product_category\models\ProductCategory`.
*/
class ProductCategorySearch extends ProductCategory
{
/**
* {@inheritdoc}
*/
public function rules()
{
return [
[['id', 'parent_id', 'company_id', 'status'], 'integer'],
[['title'], 'safe'],
];
}
/**
* {@inheritdoc}
*/
public function scenarios()
{
// bypass scenarios() implementation in the parent class
return Model::scenarios();
}
/**
* Creates data provider instance with search query applied
*
* @param array $params
*
* @return ActiveDataProvider
*/
public function search($params)
{
$query = ProductCategory::find();
// add conditions that should always apply here
$dataProvider = new ActiveDataProvider([
'query' => $query,
]);
$this->load($params);
if (!$this->validate()) {
// uncomment the following line if you do not want to return any records when validation fails
// $query->where('0=1');
return $dataProvider;
}
// grid filtering conditions
$query->andFilterWhere([
'id' => $this->id,
'parent_id' => $this->parent_id,
'company_id' => $this->company_id,
'status' => $this->status,
]);
$query->andFilterWhere(['like', 'title', $this->title]);
return $dataProvider;
}
}

View File

@ -0,0 +1,12 @@
<div class="product_category-default-index">
<h1><?= $this->context->action->uniqueId ?></h1>
<p>
This is the view content for action "<?= $this->context->action->id ?>".
The action belongs to the controller "<?= get_class($this->context) ?>"
in the "<?= $this->context->module->id ?>" module.
</p>
<p>
You may customize this page by editing the following file:<br>
<code><?= __FILE__ ?></code>
</p>
</div>

View File

@ -0,0 +1,32 @@
<?php
use common\models\User;
use yii\helpers\ArrayHelper;
use yii\helpers\Html;
use yii\bootstrap4\ActiveForm;
/* @var $this yii\web\View */
/* @var $model frontend\modules\product_category\models\ProductCategory */
/* @var $form yii\bootstrap4\ActiveForm */
/* @var $user User */
?>
<div class="product-category-form">
<?php $form = ActiveForm::begin(); ?>
<?= $form->field($model, 'title')->textInput(['maxlength' => true]) ?>
<?= $form->field($model, 'company_id')->dropDownList(ArrayHelper::map($user->getMyCompany()->asArray()->all(), 'id', 'name')) ?>
<?= $form->field($model, 'parent_id')->textInput() ?>
<?= $form->field($model, 'status')->dropDownList(\common\models\ProductCategory::getStatus()) ?>
<div class="form-group">
<?= Html::submitButton('Save', ['class' => 'btn btn-success']) ?>
</div>
<?php ActiveForm::end(); ?>
</div>

View File

@ -0,0 +1,38 @@
<?php
use yii\helpers\Html;
use yii\widgets\ActiveForm;
/* @var $this yii\web\View */
/* @var $model frontend\modules\product_category\models\ProductCategorySearch */
/* @var $form yii\widgets\ActiveForm */
?>
<div class="row mt-2">
<div class="col-md-12">
<?php $form = ActiveForm::begin([
'action' => ['index'],
'method' => 'get',
]); ?>
<?= $form->field($model, 'id') ?>
<?= $form->field($model, 'title') ?>
<?= $form->field($model, 'parent_id') ?>
<?= $form->field($model, 'company_id') ?>
<?= $form->field($model, 'status') ?>
<div class="form-group">
<?= Html::submitButton('Search', ['class' => 'btn btn-primary']) ?>
<?= Html::resetButton('Reset', ['class' => 'btn btn-outline-secondary']) ?>
</div>
<?php ActiveForm::end(); ?>
</div>
<!--.col-md-12-->
</div>

View File

@ -0,0 +1,30 @@
<?php
use common\models\User;
use yii\helpers\Html;
/* @var $this yii\web\View */
/* @var $model frontend\modules\product_category\models\ProductCategory */
/* @var $user User */
$this->title = 'Добавить категорию';
$this->params['breadcrumbs'][] = ['label' => 'Категории товаров', 'url' => ['index']];
$this->params['breadcrumbs'][] = $this->title;
?>
<div class="container-fluid">
<div class="card">
<div class="card-body">
<div class="row">
<div class="col-md-12">
<?=$this->render('_form', [
'model' => $model,
'user' => $user,
]) ?>
</div>
</div>
</div>
<!--.card-body-->
</div>
<!--.card-->
</div>

View File

@ -0,0 +1,56 @@
<?php
use yii\helpers\Html;
use yii\grid\GridView;
/* @var $this yii\web\View */
/* @var $searchModel frontend\modules\product_category\models\ProductCategorySearch */
/* @var $dataProvider yii\data\ActiveDataProvider */
$this->title = 'Категории товаров';
$this->params['breadcrumbs'][] = $this->title;
?>
<div class="container-fluid">
<div class="row">
<div class="col-md-12">
<div class="card">
<div class="card-body">
<div class="row mb-2">
<div class="col-md-12">
<?= Html::a('Создать', ['create'], ['class' => 'btn btn-success']) ?>
</div>
</div>
<?php // echo $this->render('_search', ['model' => $searchModel]); ?>
<?= GridView::widget([
'dataProvider' => $dataProvider,
'filterModel' => $searchModel,
'columns' => [
['class' => 'yii\grid\SerialColumn'],
'id',
'title',
//'parent_id',
'company_id',
'status',
['class' => 'hail812\adminlte3\yii\grid\ActionColumn'],
],
'summaryOptions' => ['class' => 'summary mb-2'],
'pager' => [
'class' => 'yii\bootstrap4\LinkPager',
]
]); ?>
</div>
<!--.card-body-->
</div>
<!--.card-->
</div>
<!--.col-md-12-->
</div>
<!--.row-->
</div>

View File

@ -0,0 +1,30 @@
<?php
use common\models\User;
/* @var $this yii\web\View */
/* @var $model frontend\modules\product_category\models\ProductCategory */
/* @var $user User */
$this->title = 'Update Product Category: ' . $model->title;
$this->params['breadcrumbs'][] = ['label' => 'Product Categories', 'url' => ['index']];
$this->params['breadcrumbs'][] = ['label' => $model->title, 'url' => ['view', 'id' => $model->id]];
$this->params['breadcrumbs'][] = 'Update';
?>
<div class="container-fluid">
<div class="card">
<div class="card-body">
<div class="row">
<div class="col-md-12">
<?=$this->render('_form', [
'model' => $model,
'user' => $user,
]) ?>
</div>
</div>
</div>
<!--.card-body-->
</div>
<!--.card-->
</div>

View File

@ -0,0 +1,48 @@
<?php
use yii\helpers\Html;
use yii\widgets\DetailView;
/* @var $this yii\web\View */
/* @var $model frontend\modules\product_category\models\ProductCategory */
$this->title = $model->title;
$this->params['breadcrumbs'][] = ['label' => 'Product Categories', 'url' => ['index']];
$this->params['breadcrumbs'][] = $this->title;
\yii\web\YiiAsset::register($this);
?>
<div class="container-fluid">
<div class="card">
<div class="card-body">
<div class="row">
<div class="col-md-12">
<p>
<?= Html::a('Update', ['update', 'id' => $model->id], ['class' => 'btn btn-primary']) ?>
<?= Html::a('Delete', ['delete', 'id' => $model->id], [
'class' => 'btn btn-danger',
'data' => [
'confirm' => 'Are you sure you want to delete this item?',
'method' => 'post',
],
]) ?>
</p>
<?= DetailView::widget([
'model' => $model,
'attributes' => [
'id',
'title',
'parent_id',
'company_id',
'status',
],
]) ?>
</div>
<!--.col-md-12-->
</div>
<!--.row-->
</div>
<!--.card-body-->
</div>
<!--.card-->
</div>

2
frontend/runtime/.gitignore vendored Normal file
View File

@ -0,0 +1,2 @@
*
!.gitignore

View File

@ -0,0 +1,10 @@
<?php
defined('YII_DEBUG') or define('YII_DEBUG', true);
defined('YII_ENV') or define('YII_ENV', 'test');
defined('YII_APP_BASE_PATH') or define('YII_APP_BASE_PATH', __DIR__.'/../../');
require_once YII_APP_BASE_PATH . '/vendor/autoload.php';
require_once YII_APP_BASE_PATH . '/vendor/yiisoft/yii2/Yii.php';
require_once YII_APP_BASE_PATH . '/common/config/bootstrap.php';
require_once __DIR__ . '/../config/bootstrap.php';

View File

@ -0,0 +1,25 @@
<?php
return [
[
'username' => 'erau',
'auth_key' => 'tUu1qHcde0diwUol3xeI-18MuHkkprQI',
// password_0
'password_hash' => '$2y$13$nJ1WDlBaGcbCdbNC5.5l4.sgy.OMEKCqtDQOdQ2OWpgiKRWYyzzne',
'password_reset_token' => 'RkD_Jw0_8HEedzLk7MM-ZKEFfYR7VbMr_1392559490',
'created_at' => '1392559490',
'updated_at' => '1392559490',
'email' => 'sfriesen@jenkins.info',
],
[
'username' => 'test.test',
'auth_key' => 'O87GkY3_UfmMHYkyezZ7QLfmkKNsllzT',
// Test1234
'password_hash' => 'O87GkY3_UfmMHYkyezZ7QLfmkKNsllzT',
'email' => 'test@mail.com',
'status' => '9',
'created_at' => '1548675330',
'updated_at' => '1548675330',
'verification_token' => '4ch0qbfhvWwkcuWqjN8SWRq72SOw1KYT_1548675330',
],
];

View File

@ -0,0 +1,45 @@
<?php
return [
[
'username' => 'okirlin',
'auth_key' => 'iwTNae9t34OmnK6l4vT4IeaTk-YWI2Rv',
'password_hash' => '$2y$13$CXT0Rkle1EMJ/c1l5bylL.EylfmQ39O5JlHJVFpNn618OUS1HwaIi',
'password_reset_token' => 't5GU9NwpuGYSfb7FEZMAxqtuz2PkEvv_' . time(),
'created_at' => '1391885313',
'updated_at' => '1391885313',
'email' => 'brady.renner@rutherford.com',
],
[
'username' => 'troy.becker',
'auth_key' => 'EdKfXrx88weFMV0vIxuTMWKgfK2tS3Lp',
'password_hash' => '$2y$13$g5nv41Px7VBqhS3hVsVN2.MKfgT3jFdkXEsMC4rQJLfaMa7VaJqL2',
'password_reset_token' => '4BSNyiZNAuxjs5Mty990c47sVrgllIi_' . time(),
'created_at' => '1391885313',
'updated_at' => '1391885313',
'email' => 'nicolas.dianna@hotmail.com',
'status' => '0',
],
[
'username' => 'test.test',
'auth_key' => 'O87GkY3_UfmMHYkyezZ7QLfmkKNsllzT',
//Test1234
'password_hash' => '$2y$13$d17z0w/wKC4LFwtzBcmx6up4jErQuandJqhzKGKczfWuiEhLBtQBK',
'email' => 'test@mail.com',
'status' => '9',
'created_at' => '1548675330',
'updated_at' => '1548675330',
'verification_token' => '4ch0qbfhvWwkcuWqjN8SWRq72SOw1KYT_1548675330',
],
[
'username' => 'test2.test',
'auth_key' => '4XXdVqi3rDpa_a6JH6zqVreFxUPcUPvJ',
//Test1234
'password_hash' => '$2y$13$d17z0w/wKC4LFwtzBcmx6up4jErQuandJqhzKGKczfWuiEhLBtQBK',
'email' => 'test2@mail.com',
'status' => '10',
'created_at' => '1548675330',
'updated_at' => '1548675330',
'verification_token' => 'already_used_token_1548675330',
],
];

2
frontend/tests/_output/.gitignore vendored Normal file
View File

@ -0,0 +1,2 @@
*
!.gitignore

1
frontend/tests/_support/.gitignore vendored Normal file
View File

@ -0,0 +1 @@
_generated

View File

@ -0,0 +1,34 @@
<?php
namespace frontend\tests;
/**
* Inherited Methods
* @method void wantToTest($text)
* @method void wantTo($text)
* @method void execute($callable)
* @method void expectTo($prediction)
* @method void verify($prediction)
* @method void amGoingTo($argumentation)
* @method void am($role)
* @method void lookForwardTo($achieveValue)
* @method void comment($description)
* @method \Codeception\Lib\Friend haveFriend($name, $actorClass = NULL)
*
* @SuppressWarnings(PHPMD)
*/
class FunctionalTester extends \Codeception\Actor
{
use _generated\FunctionalTesterActions;
public function seeValidationError($message)
{
$this->see($message, '.invalid-feedback');
}
public function dontSeeValidationError($message)
{
$this->dontSee($message, '.invalid-feedback');
}
}

View File

@ -0,0 +1,26 @@
<?php
namespace frontend\tests;
/**
* Inherited Methods
* @method void wantToTest($text)
* @method void wantTo($text)
* @method void execute($callable)
* @method void expectTo($prediction)
* @method void verify($prediction)
* @method void amGoingTo($argumentation)
* @method void am($role)
* @method void lookForwardTo($achieveValue)
* @method void comment($description)
* @method \Codeception\Lib\Friend haveFriend($name, $actorClass = NULL)
*
* @SuppressWarnings(PHPMD)
*/
class UnitTester extends \Codeception\Actor
{
use _generated\UnitTesterActions;
/**
* Define custom actions here
*/
}

View File

@ -0,0 +1,9 @@
suite_namespace: frontend\tests\acceptance
actor: AcceptanceTester
modules:
enabled:
- WebDriver:
url: http://localhost:8080
browser: firefox
- Yii2:
part: init

View File

@ -0,0 +1,21 @@
<?php
namespace frontend\tests\acceptance;
use frontend\tests\AcceptanceTester;
use yii\helpers\Url;
class HomeCest
{
public function checkHome(AcceptanceTester $I)
{
$I->amOnRoute(Url::toRoute('/site/index'));
$I->see('My Application');
$I->seeLink('About');
$I->click('About');
$I->wait(2); // wait for page to be opened
$I->see('This is the About page.');
}
}

View File

@ -0,0 +1,16 @@
<?php
/**
* Here you can initialize variables via \Codeception\Util\Fixtures class
* to store data in global array and use it in Cepts.
*
* ```php
* // Here _bootstrap.php
* \Codeception\Util\Fixtures::add('user1', ['name' => 'davert']);
* ```
*
* In Cept
*
* ```php
* \Codeception\Util\Fixtures::get('user1');
* ```
*/

View File

@ -0,0 +1,7 @@
suite_namespace: frontend\tests\functional
actor: FunctionalTester
modules:
enabled:
- Filesystem
- Yii2
- Asserts

View File

@ -0,0 +1,14 @@
<?php
namespace frontend\tests\functional;
use frontend\tests\FunctionalTester;
class AboutCest
{
public function checkAbout(FunctionalTester $I)
{
$I->amOnRoute('site/about');
$I->see('About', 'h1');
}
}

View File

@ -0,0 +1,60 @@
<?php
namespace frontend\tests\functional;
use frontend\tests\FunctionalTester;
/* @var $scenario \Codeception\Scenario */
class ContactCest
{
public function _before(FunctionalTester $I)
{
$I->amOnRoute('site/contact');
}
public function checkContact(FunctionalTester $I)
{
$I->see('Contact', 'h1');
}
public function checkContactSubmitNoData(FunctionalTester $I)
{
$I->submitForm('#contact-form', []);
$I->see('Contact', 'h1');
$I->seeValidationError('Name cannot be blank');
$I->seeValidationError('Email cannot be blank');
$I->seeValidationError('Subject cannot be blank');
$I->seeValidationError('Body cannot be blank');
$I->seeValidationError('The verification code is incorrect');
}
public function checkContactSubmitNotCorrectEmail(FunctionalTester $I)
{
$I->submitForm('#contact-form', [
'ContactForm[name]' => 'tester',
'ContactForm[email]' => 'tester.email',
'ContactForm[subject]' => 'test subject',
'ContactForm[body]' => 'test content',
'ContactForm[verifyCode]' => 'testme',
]);
$I->seeValidationError('Email is not a valid email address.');
$I->dontSeeValidationError('Name cannot be blank');
$I->dontSeeValidationError('Subject cannot be blank');
$I->dontSeeValidationError('Body cannot be blank');
$I->dontSeeValidationError('The verification code is incorrect');
}
public function checkContactSubmitCorrectData(FunctionalTester $I)
{
$I->submitForm('#contact-form', [
'ContactForm[name]' => 'tester',
'ContactForm[email]' => 'tester@example.com',
'ContactForm[subject]' => 'test subject',
'ContactForm[body]' => 'test content',
'ContactForm[verifyCode]' => 'testme',
]);
$I->seeEmailIsSent();
$I->see('Thank you for contacting us. We will respond to you as soon as possible.');
}
}

View File

@ -0,0 +1,17 @@
<?php
namespace frontend\tests\functional;
use frontend\tests\FunctionalTester;
class HomeCest
{
public function checkOpen(FunctionalTester $I)
{
$I->amOnRoute(\Yii::$app->homeUrl);
$I->see('My Application');
$I->seeLink('About');
$I->click('About');
$I->see('This is the About page.');
}
}

View File

@ -0,0 +1,66 @@
<?php
namespace frontend\tests\functional;
use frontend\tests\FunctionalTester;
use common\fixtures\UserFixture;
class LoginCest
{
/**
* Load fixtures before db transaction begin
* Called in _before()
* @see \Codeception\Module\Yii2::_before()
* @see \Codeception\Module\Yii2::loadFixtures()
* @return array
*/
public function _fixtures()
{
return [
'user' => [
'class' => UserFixture::class,
'dataFile' => codecept_data_dir() . 'login_data.php',
],
];
}
public function _before(FunctionalTester $I)
{
$I->amOnRoute('site/login');
}
protected function formParams($login, $password)
{
return [
'LoginForm[username]' => $login,
'LoginForm[password]' => $password,
];
}
public function checkEmpty(FunctionalTester $I)
{
$I->submitForm('#login-form', $this->formParams('', ''));
$I->seeValidationError('Username cannot be blank.');
$I->seeValidationError('Password cannot be blank.');
}
public function checkWrongPassword(FunctionalTester $I)
{
$I->submitForm('#login-form', $this->formParams('admin', 'wrong'));
$I->seeValidationError('Incorrect username or password.');
}
public function checkInactiveAccount(FunctionalTester $I)
{
$I->submitForm('#login-form', $this->formParams('test.test', 'Test1234'));
$I->seeValidationError('Incorrect username or password');
}
public function checkValidLogin(FunctionalTester $I)
{
$I->submitForm('#login-form', $this->formParams('erau', 'password_0'));
$I->see('Logout (erau)', 'form button[type=submit]');
$I->dontSeeLink('Login');
$I->dontSeeLink('Signup');
}
}

View File

@ -0,0 +1,83 @@
<?php
namespace frontend\tests\functional;
use common\fixtures\UserFixture;
use frontend\tests\FunctionalTester;
class ResendVerificationEmailCest
{
protected $formId = '#resend-verification-email-form';
/**
* Load fixtures before db transaction begin
* Called in _before()
* @see \Codeception\Module\Yii2::_before()
* @see \Codeception\Module\Yii2::loadFixtures()
* @return array
*/
public function _fixtures()
{
return [
'user' => [
'class' => UserFixture::class,
'dataFile' => codecept_data_dir() . 'user.php',
],
];
}
public function _before(FunctionalTester $I)
{
$I->amOnRoute('/site/resend-verification-email');
}
protected function formParams($email)
{
return [
'ResendVerificationEmailForm[email]' => $email
];
}
public function checkPage(FunctionalTester $I)
{
$I->see('Resend verification email', 'h1');
$I->see('Please fill out your email. A verification email will be sent there.');
}
public function checkEmptyField(FunctionalTester $I)
{
$I->submitForm($this->formId, $this->formParams(''));
$I->seeValidationError('Email cannot be blank.');
}
public function checkWrongEmailFormat(FunctionalTester $I)
{
$I->submitForm($this->formId, $this->formParams('abcd.com'));
$I->seeValidationError('Email is not a valid email address.');
}
public function checkWrongEmail(FunctionalTester $I)
{
$I->submitForm($this->formId, $this->formParams('wrong@email.com'));
$I->seeValidationError('There is no user with this email address.');
}
public function checkAlreadyVerifiedEmail(FunctionalTester $I)
{
$I->submitForm($this->formId, $this->formParams('test2@mail.com'));
$I->seeValidationError('There is no user with this email address.');
}
public function checkSendSuccessfully(FunctionalTester $I)
{
$I->submitForm($this->formId, $this->formParams('test@mail.com'));
$I->canSeeEmailIsSent();
$I->seeRecord('common\models\User', [
'email' => 'test@mail.com',
'username' => 'test.test',
'status' => \common\models\User::STATUS_INACTIVE
]);
$I->see('Check your email for further instructions.');
}
}

View File

@ -0,0 +1,59 @@
<?php
namespace frontend\tests\functional;
use frontend\tests\FunctionalTester;
class SignupCest
{
protected $formId = '#form-signup';
public function _before(FunctionalTester $I)
{
$I->amOnRoute('site/signup');
}
public function signupWithEmptyFields(FunctionalTester $I)
{
$I->see('Signup', 'h1');
$I->see('Please fill out the following fields to signup:');
$I->submitForm($this->formId, []);
$I->seeValidationError('Username cannot be blank.');
$I->seeValidationError('Email cannot be blank.');
$I->seeValidationError('Password cannot be blank.');
}
public function signupWithWrongEmail(FunctionalTester $I)
{
$I->submitForm(
$this->formId, [
'SignupForm[username]' => 'tester',
'SignupForm[email]' => 'ttttt',
'SignupForm[password]' => 'tester_password',
]
);
$I->dontSee('Username cannot be blank.', '.invalid-feedback');
$I->dontSee('Password cannot be blank.', '.invalid-feedback');
$I->see('Email is not a valid email address.', '.invalid-feedback');
}
public function signupSuccessfully(FunctionalTester $I)
{
$I->submitForm($this->formId, [
'SignupForm[username]' => 'tester',
'SignupForm[email]' => 'tester.email@example.com',
'SignupForm[password]' => 'tester_password',
]);
$I->seeRecord('common\models\User', [
'username' => 'tester',
'email' => 'tester.email@example.com',
'status' => \common\models\User::STATUS_INACTIVE
]);
$I->seeEmailIsSent();
$I->see('Thank you for registration. Please check your inbox for verification email.');
}
}

View File

@ -0,0 +1,68 @@
<?php
namespace frontend\tests\functional;
use common\fixtures\UserFixture;
use frontend\tests\FunctionalTester;
class VerifyEmailCest
{
/**
* Load fixtures before db transaction begin
* Called in _before()
* @see \Codeception\Module\Yii2::_before()
* @see \Codeception\Module\Yii2::loadFixtures()
* @return array
*/
public function _fixtures()
{
return [
'user' => [
'class' => UserFixture::class,
'dataFile' => codecept_data_dir() . 'user.php',
],
];
}
public function checkEmptyToken(FunctionalTester $I)
{
$I->amOnRoute('site/verify-email', ['token' => '']);
$I->canSee('Bad Request', 'h1');
$I->canSee('Verify email token cannot be blank.');
}
public function checkInvalidToken(FunctionalTester $I)
{
$I->amOnRoute('site/verify-email', ['token' => 'wrong_token']);
$I->canSee('Bad Request', 'h1');
$I->canSee('Wrong verify email token.');
}
public function checkNoToken(FunctionalTester $I)
{
$I->amOnRoute('site/verify-email');
$I->canSee('Bad Request', 'h1');
$I->canSee('Missing required parameters: token');
}
public function checkAlreadyActivatedToken(FunctionalTester $I)
{
$I->amOnRoute('site/verify-email', ['token' => 'already_used_token_1548675330']);
$I->canSee('Bad Request', 'h1');
$I->canSee('Wrong verify email token.');
}
public function checkSuccessVerification(FunctionalTester $I)
{
$I->amOnRoute('site/verify-email', ['token' => '4ch0qbfhvWwkcuWqjN8SWRq72SOw1KYT_1548675330']);
$I->canSee('Your email has been confirmed!');
$I->canSee('Congratulations!', 'h1');
$I->see('Logout (test.test)', 'form button[type=submit]');
$I->seeRecord('common\models\User', [
'username' => 'test.test',
'email' => 'test@mail.com',
'status' => \common\models\User::STATUS_ACTIVE
]);
}
}

View File

@ -0,0 +1,16 @@
<?php
/**
* Here you can initialize variables via \Codeception\Util\Fixtures class
* to store data in global array and use it in Cests.
*
* ```php
* // Here _bootstrap.php
* \Codeception\Util\Fixtures::add('user1', ['name' => 'davert']);
* ```
*
* In Cests
*
* ```php
* \Codeception\Util\Fixtures::get('user1');
* ```
*/

View File

@ -0,0 +1,7 @@
suite_namespace: frontend\tests\unit
actor: UnitTester
modules:
enabled:
- Yii2:
part: [orm, email, fixtures]
- Asserts

View File

@ -0,0 +1,16 @@
<?php
/**
* Here you can initialize variables via \Codeception\Util\Fixtures class
* to store data in global array and use it in Tests.
*
* ```php
* // Here _bootstrap.php
* \Codeception\Util\Fixtures::add('user1', ['name' => 'davert']);
* ```
*
* In Tests
*
* ```php
* \Codeception\Util\Fixtures::get('user1');
* ```
*/

View File

@ -0,0 +1,35 @@
<?php
namespace frontend\tests\unit\models;
use frontend\models\ContactForm;
use yii\mail\MessageInterface;
class ContactFormTest extends \Codeception\Test\Unit
{
public function testSendEmail()
{
$model = new ContactForm();
$model->attributes = [
'name' => 'Tester',
'email' => 'tester@example.com',
'subject' => 'very important letter subject',
'body' => 'body of current message',
];
verify($model->sendEmail('admin@example.com'))->notEmpty();
// using Yii2 module actions to check email was sent
$this->tester->seeEmailIsSent();
/** @var MessageInterface $emailMessage */
$emailMessage = $this->tester->grabLastSentEmail();
verify($emailMessage)->instanceOf('yii\mail\MessageInterface');
verify($emailMessage->getTo())->arrayHasKey('admin@example.com');
verify($emailMessage->getFrom())->arrayHasKey('noreply@example.com');
verify($emailMessage->getReplyTo())->arrayHasKey('tester@example.com');
verify($emailMessage->getSubject())->equals('very important letter subject');
verify($emailMessage->toString())->stringContainsString('body of current message');
}
}

View File

@ -0,0 +1,59 @@
<?php
namespace frontend\tests\unit\models;
use Yii;
use frontend\models\PasswordResetRequestForm;
use common\fixtures\UserFixture as UserFixture;
use common\models\User;
class PasswordResetRequestFormTest extends \Codeception\Test\Unit
{
/**
* @var \frontend\tests\UnitTester
*/
protected $tester;
public function _before()
{
$this->tester->haveFixtures([
'user' => [
'class' => UserFixture::class,
'dataFile' => codecept_data_dir() . 'user.php'
]
]);
}
public function testSendMessageWithWrongEmailAddress()
{
$model = new PasswordResetRequestForm();
$model->email = 'not-existing-email@example.com';
verify($model->sendEmail())->false();
}
public function testNotSendEmailsToInactiveUser()
{
$user = $this->tester->grabFixture('user', 1);
$model = new PasswordResetRequestForm();
$model->email = $user['email'];
verify($model->sendEmail())->false();
}
public function testSendEmailSuccessfully()
{
$userFixture = $this->tester->grabFixture('user', 0);
$model = new PasswordResetRequestForm();
$model->email = $userFixture['email'];
$user = User::findOne(['password_reset_token' => $userFixture['password_reset_token']]);
verify($model->sendEmail())->notEmpty();
verify($user->password_reset_token)->notEmpty();
$emailMessage = $this->tester->grabLastSentEmail();
verify($emailMessage)->instanceOf('yii\mail\MessageInterface');
verify($emailMessage->getTo())->arrayHasKey($model->email);
verify($emailMessage->getFrom())->arrayHasKey(Yii::$app->params['supportEmail']);
}
}

View File

@ -0,0 +1,85 @@
<?php
namespace frontend\tests\unit\models;
use Codeception\Test\Unit;
use common\fixtures\UserFixture;
use frontend\models\ResendVerificationEmailForm;
class ResendVerificationEmailFormTest extends Unit
{
/**
* @var \frontend\tests\UnitTester
*/
protected $tester;
public function _before()
{
$this->tester->haveFixtures([
'user' => [
'class' => UserFixture::class,
'dataFile' => codecept_data_dir() . 'user.php'
]
]);
}
public function testWrongEmailAddress()
{
$model = new ResendVerificationEmailForm();
$model->attributes = [
'email' => 'aaa@bbb.cc'
];
verify($model->validate())->false();
verify($model->hasErrors())->true();
verify($model->getFirstError('email'))->equals('There is no user with this email address.');
}
public function testEmptyEmailAddress()
{
$model = new ResendVerificationEmailForm();
$model->attributes = [
'email' => ''
];
verify($model->validate())->false();
verify($model->hasErrors())->true();
verify($model->getFirstError('email'))->equals('Email cannot be blank.');
}
public function testResendToActiveUser()
{
$model = new ResendVerificationEmailForm();
$model->attributes = [
'email' => 'test2@mail.com'
];
verify($model->validate())->false();
verify($model->hasErrors())->true();
verify($model->getFirstError('email'))->equals('There is no user with this email address.');
}
public function testSuccessfullyResend()
{
$model = new ResendVerificationEmailForm();
$model->attributes = [
'email' => 'test@mail.com'
];
verify($model->validate())->true();
verify($model->hasErrors())->false();
verify($model->sendEmail())->true();
$this->tester->seeEmailIsSent();
$mail = $this->tester->grabLastSentEmail();
verify($mail)->instanceOf('yii\mail\MessageInterface');
verify($mail->getTo())->arrayHasKey('test@mail.com');
verify($mail->getFrom())->arrayHasKey(\Yii::$app->params['supportEmail']);
verify($mail->getSubject())->equals('Account registration at ' . \Yii::$app->name);
verify($mail->toString())->stringContainsString('4ch0qbfhvWwkcuWqjN8SWRq72SOw1KYT_1548675330');
}
}

Some files were not shown because too many files have changed in this diff Show More