first commit
This commit is contained in:
4
backend/Dockerfile
Executable file
4
backend/Dockerfile
Executable 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/backend/web|g' /etc/apache2/sites-available/000-default.conf
|
23
backend/assets/AppAsset.php
Executable file
23
backend/assets/AppAsset.php
Executable file
@ -0,0 +1,23 @@
|
||||
<?php
|
||||
|
||||
namespace backend\assets;
|
||||
|
||||
use yii\web\AssetBundle;
|
||||
|
||||
/**
|
||||
* Main backend 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
backend/codeception.yml
Executable file
15
backend/codeception.yml
Executable file
@ -0,0 +1,15 @@
|
||||
namespace: backend\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
backend/config/.gitignore
vendored
Executable file
4
backend/config/.gitignore
vendored
Executable file
@ -0,0 +1,4 @@
|
||||
codeception-local.php
|
||||
main-local.php
|
||||
params-local.php
|
||||
test-local.php
|
1
backend/config/bootstrap.php
Executable file
1
backend/config/bootstrap.php
Executable file
@ -0,0 +1 @@
|
||||
<?php
|
58
backend/config/main.php
Executable file
58
backend/config/main.php
Executable file
@ -0,0 +1,58 @@
|
||||
<?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 [
|
||||
'homeUrl' => '/secure',
|
||||
'id' => 'app-backend',
|
||||
'basePath' => dirname(__DIR__),
|
||||
'controllerNamespace' => 'backend\controllers',
|
||||
'bootstrap' => ['log'],
|
||||
'modules' => [
|
||||
'news' => [
|
||||
'class' => 'backend\modules\news\News',
|
||||
],
|
||||
|
||||
'profile' => [
|
||||
'class' => 'app\modules\profile\Profile',
|
||||
],
|
||||
],
|
||||
'components' => [
|
||||
'request' => [
|
||||
'csrfParam' => '_csrf-backend',
|
||||
'baseUrl' => '/secure',
|
||||
],
|
||||
'user' => [
|
||||
'identityClass' => 'common\models\User',
|
||||
'enableAutoLogin' => true,
|
||||
'identityCookie' => ['name' => '_identity-backend', 'httpOnly' => true],
|
||||
],
|
||||
'session' => [
|
||||
// this is the name of the session cookie used for login on the backend
|
||||
'name' => 'advanced-backend',
|
||||
],
|
||||
'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,
|
||||
];
|
4
backend/config/params.php
Executable file
4
backend/config/params.php
Executable file
@ -0,0 +1,4 @@
|
||||
<?php
|
||||
return [
|
||||
'adminEmail' => 'admin@example.com',
|
||||
];
|
15
backend/config/test.php
Executable file
15
backend/config/test.php
Executable file
@ -0,0 +1,15 @@
|
||||
<?php
|
||||
return [
|
||||
'id' => 'app-backend-tests',
|
||||
'components' => [
|
||||
'assetManager' => [
|
||||
'basePath' => __DIR__ . '/../web/assets',
|
||||
],
|
||||
'urlManager' => [
|
||||
'showScriptName' => true,
|
||||
],
|
||||
'request' => [
|
||||
'cookieValidationKey' => 'test',
|
||||
],
|
||||
],
|
||||
];
|
105
backend/controllers/SiteController.php
Executable file
105
backend/controllers/SiteController.php
Executable file
@ -0,0 +1,105 @@
|
||||
<?php
|
||||
|
||||
namespace backend\controllers;
|
||||
|
||||
use common\models\LoginForm;
|
||||
use Yii;
|
||||
use yii\filters\VerbFilter;
|
||||
use yii\filters\AccessControl;
|
||||
use yii\web\Controller;
|
||||
use yii\web\Response;
|
||||
use function PHPUnit\Framework\directoryExists;
|
||||
|
||||
/**
|
||||
* Site controller
|
||||
*/
|
||||
class SiteController extends Controller
|
||||
{
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function behaviors()
|
||||
{
|
||||
return [
|
||||
'access' => [
|
||||
'class' => AccessControl::class,
|
||||
'rules' => [
|
||||
[
|
||||
'actions' => ['login', 'error'],
|
||||
'allow' => true,
|
||||
],
|
||||
[
|
||||
'actions' => ['logout', 'index'],
|
||||
'allow' => true,
|
||||
'roles' => ['@'],
|
||||
],
|
||||
],
|
||||
],
|
||||
'verbs' => [
|
||||
'class' => VerbFilter::class,
|
||||
'actions' => [
|
||||
'logout' => ['post'],
|
||||
],
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function actions()
|
||||
{
|
||||
return [
|
||||
'error' => [
|
||||
'class' => \yii\web\ErrorAction::class,
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Displays homepage.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function actionIndex()
|
||||
{
|
||||
return $this->render('index');
|
||||
}
|
||||
|
||||
/**
|
||||
* Login action.
|
||||
*
|
||||
* @return string|Response
|
||||
*/
|
||||
public function actionLogin()
|
||||
{
|
||||
if (!Yii::$app->user->isGuest) {
|
||||
return $this->goHome();
|
||||
}
|
||||
|
||||
$this->layout = 'blank';
|
||||
|
||||
$model = new LoginForm();
|
||||
if ($model->load(Yii::$app->request->post()) && $model->login()) {
|
||||
return $this->goBack();
|
||||
}
|
||||
|
||||
$model->password = '';
|
||||
|
||||
return $this->render('login', [
|
||||
'model' => $model,
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Logout action.
|
||||
*
|
||||
* @return Response
|
||||
*/
|
||||
public function actionLogout()
|
||||
{
|
||||
Yii::$app->user->logout();
|
||||
|
||||
return $this->goHome();
|
||||
}
|
||||
}
|
1
backend/models/.gitkeep
Executable file
1
backend/models/.gitkeep
Executable file
@ -0,0 +1 @@
|
||||
*
|
24
backend/modules/news/News.php
Executable file
24
backend/modules/news/News.php
Executable file
@ -0,0 +1,24 @@
|
||||
<?php
|
||||
|
||||
namespace backend\modules\news;
|
||||
|
||||
/**
|
||||
* news module definition class
|
||||
*/
|
||||
class News extends \yii\base\Module
|
||||
{
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public $controllerNamespace = 'app\modules\news\controllers';
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function init()
|
||||
{
|
||||
parent::init();
|
||||
|
||||
// custom initialization code goes here
|
||||
}
|
||||
}
|
53
backend/modules/news/controllers/DefaultController.php
Executable file
53
backend/modules/news/controllers/DefaultController.php
Executable file
@ -0,0 +1,53 @@
|
||||
<?php
|
||||
|
||||
namespace app\modules\news\controllers;
|
||||
|
||||
use yii\filters\AccessControl;
|
||||
use yii\filters\VerbFilter;
|
||||
use yii\web\Controller;
|
||||
|
||||
/**
|
||||
* Default controller for the `news` module
|
||||
*/
|
||||
class DefaultController extends Controller
|
||||
{
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function behaviors()
|
||||
{
|
||||
return array_merge(
|
||||
parent::behaviors(),
|
||||
[
|
||||
'access' => [
|
||||
'class' => AccessControl::class,
|
||||
'rules' => [
|
||||
[
|
||||
'actions' => ['login', 'error'],
|
||||
'allow' => true,
|
||||
],
|
||||
[
|
||||
'actions' => ['logout', 'index'],
|
||||
'allow' => true,
|
||||
'roles' => ['@'],
|
||||
],
|
||||
],
|
||||
],
|
||||
'verbs' => [
|
||||
'class' => VerbFilter::className(),
|
||||
'actions' => [
|
||||
'delete' => ['POST'],
|
||||
],
|
||||
],
|
||||
]
|
||||
);
|
||||
}
|
||||
/**
|
||||
* Renders the index view for the module
|
||||
* @return string
|
||||
*/
|
||||
public function actionIndex()
|
||||
{
|
||||
return $this->render('index');
|
||||
}
|
||||
}
|
148
backend/modules/news/controllers/NewsController.php
Executable file
148
backend/modules/news/controllers/NewsController.php
Executable file
@ -0,0 +1,148 @@
|
||||
<?php
|
||||
|
||||
namespace app\modules\news\controllers;
|
||||
|
||||
use common\models\News;
|
||||
use app\modules\news\models\NewsSearch;
|
||||
use yii\filters\AccessControl;
|
||||
use yii\web\Controller;
|
||||
use yii\web\NotFoundHttpException;
|
||||
use yii\filters\VerbFilter;
|
||||
|
||||
/**
|
||||
* NewsController implements the CRUD actions for News model.
|
||||
*/
|
||||
class NewsController extends Controller
|
||||
{
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function behaviors()
|
||||
{
|
||||
return array_merge(
|
||||
parent::behaviors(),
|
||||
[
|
||||
'access' => [
|
||||
'class' => AccessControl::class,
|
||||
'rules' => [
|
||||
[
|
||||
'actions' => ['login', 'error'],
|
||||
'allow' => true,
|
||||
],
|
||||
[
|
||||
'allow' => true,
|
||||
'roles' => ['@'],
|
||||
],
|
||||
],
|
||||
],
|
||||
'verbs' => [
|
||||
'class' => VerbFilter::className(),
|
||||
'actions' => [
|
||||
'delete' => ['POST'],
|
||||
],
|
||||
],
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Lists all News models.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function actionIndex()
|
||||
{
|
||||
$searchModel = new NewsSearch();
|
||||
$dataProvider = $searchModel->search($this->request->queryParams);
|
||||
|
||||
return $this->render('index', [
|
||||
'searchModel' => $searchModel,
|
||||
'dataProvider' => $dataProvider,
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Displays a single News 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 News model.
|
||||
* If creation is successful, the browser will be redirected to the 'view' page.
|
||||
* @return string|\yii\web\Response
|
||||
*/
|
||||
public function actionCreate()
|
||||
{
|
||||
$model = new News();
|
||||
|
||||
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,
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates an existing News 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($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 News 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 News 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 News the loaded model
|
||||
* @throws NotFoundHttpException if the model cannot be found
|
||||
*/
|
||||
protected function findModel($id)
|
||||
{
|
||||
if (($model = News::findOne(['id' => $id])) !== null) {
|
||||
return $model;
|
||||
}
|
||||
|
||||
throw new NotFoundHttpException('The requested page does not exist.');
|
||||
}
|
||||
}
|
70
backend/modules/news/models/NewsSearch.php
Executable file
70
backend/modules/news/models/NewsSearch.php
Executable file
@ -0,0 +1,70 @@
|
||||
<?php
|
||||
|
||||
namespace app\modules\news\models;
|
||||
|
||||
use yii\base\Model;
|
||||
use yii\data\ActiveDataProvider;
|
||||
use common\models\News;
|
||||
|
||||
/**
|
||||
* NewsSearch represents the model behind the search form of `common\models\News`.
|
||||
*/
|
||||
class NewsSearch extends News
|
||||
{
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function rules()
|
||||
{
|
||||
return [
|
||||
[['id'], 'integer'],
|
||||
[['title', 'text', 'slug'], '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 = News::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,
|
||||
]);
|
||||
|
||||
$query->andFilterWhere(['like', 'title', $this->title])
|
||||
->andFilterWhere(['like', 'text', $this->text])
|
||||
->andFilterWhere(['like', 'slug', $this->slug]);
|
||||
|
||||
return $dataProvider;
|
||||
}
|
||||
}
|
12
backend/modules/news/views/default/index.php
Executable file
12
backend/modules/news/views/default/index.php
Executable file
@ -0,0 +1,12 @@
|
||||
<div class="news-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>
|
31
backend/modules/news/views/news/_form.php
Executable file
31
backend/modules/news/views/news/_form.php
Executable file
@ -0,0 +1,31 @@
|
||||
<?php
|
||||
|
||||
use yii\helpers\Html;
|
||||
use yii\widgets\ActiveForm;
|
||||
|
||||
/** @var yii\web\View $this */
|
||||
/** @var common\models\News[] $model */
|
||||
/** @var yii\widgets\ActiveForm $form */
|
||||
?>
|
||||
|
||||
<div class="news-form">
|
||||
|
||||
<?php $form = ActiveForm::begin(['options' => ['enctype' => 'multipart/form-data']]); ?>
|
||||
|
||||
<?= $form->field($model, 'title')->textInput(['maxlength' => true]) ?>
|
||||
|
||||
<?= $form->field($model, 'text')->widget(\asmoday74\ckeditor5\EditorClassic::class, [
|
||||
'clientOptions' => [
|
||||
'language' => 'en',
|
||||
]
|
||||
]) ?>
|
||||
|
||||
<?= $form->field($model, 'slug')->textInput(['maxlength' => true]) ?>
|
||||
|
||||
<div class="form-group">
|
||||
<?= Html::submitButton('Save', ['class' => 'btn btn-success']) ?>
|
||||
</div>
|
||||
|
||||
<?php ActiveForm::end(); ?>
|
||||
|
||||
</div>
|
33
backend/modules/news/views/news/_search.php
Executable file
33
backend/modules/news/views/news/_search.php
Executable file
@ -0,0 +1,33 @@
|
||||
<?php
|
||||
|
||||
use yii\helpers\Html;
|
||||
use yii\widgets\ActiveForm;
|
||||
|
||||
/** @var yii\web\View $this */
|
||||
/** @var app\modules\news\models\NewsSearch $model */
|
||||
/** @var yii\widgets\ActiveForm $form */
|
||||
?>
|
||||
|
||||
<div class="news-search">
|
||||
|
||||
<?php $form = ActiveForm::begin([
|
||||
'action' => ['index'],
|
||||
'method' => 'get',
|
||||
]); ?>
|
||||
|
||||
<?= $form->field($model, 'id') ?>
|
||||
|
||||
<?= $form->field($model, 'title') ?>
|
||||
|
||||
<?= $form->field($model, 'text') ?>
|
||||
|
||||
<?= $form->field($model, 'slug') ?>
|
||||
|
||||
<div class="form-group">
|
||||
<?= Html::submitButton('Search', ['class' => 'btn btn-primary']) ?>
|
||||
<?= Html::resetButton('Reset', ['class' => 'btn btn-outline-secondary']) ?>
|
||||
</div>
|
||||
|
||||
<?php ActiveForm::end(); ?>
|
||||
|
||||
</div>
|
20
backend/modules/news/views/news/create.php
Executable file
20
backend/modules/news/views/news/create.php
Executable file
@ -0,0 +1,20 @@
|
||||
<?php
|
||||
|
||||
use yii\helpers\Html;
|
||||
|
||||
/** @var yii\web\View $this */
|
||||
/** @var common\models\News $model */
|
||||
|
||||
$this->title = 'Create News';
|
||||
$this->params['breadcrumbs'][] = ['label' => 'News', 'url' => ['index']];
|
||||
$this->params['breadcrumbs'][] = $this->title;
|
||||
?>
|
||||
<div class="news-create">
|
||||
|
||||
<h1><?= Html::encode($this->title) ?></h1>
|
||||
|
||||
<?= $this->render('_form', [
|
||||
'model' => $model,
|
||||
]) ?>
|
||||
|
||||
</div>
|
46
backend/modules/news/views/news/index.php
Executable file
46
backend/modules/news/views/news/index.php
Executable file
@ -0,0 +1,46 @@
|
||||
<?php
|
||||
|
||||
use common\models\News;
|
||||
use yii\helpers\Html;
|
||||
use yii\helpers\Url;
|
||||
use yii\grid\ActionColumn;
|
||||
use yii\grid\GridView;
|
||||
|
||||
/** @var yii\web\View $this */
|
||||
/** @var app\modules\news\models\NewsSearch $searchModel */
|
||||
/** @var yii\data\ActiveDataProvider $dataProvider */
|
||||
|
||||
$this->title = 'News';
|
||||
$this->params['breadcrumbs'][] = $this->title;
|
||||
?>
|
||||
<div class="news-index">
|
||||
|
||||
<h1><?= Html::encode($this->title) ?></h1>
|
||||
|
||||
<p>
|
||||
<?= Html::a('Create News', ['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',
|
||||
'title',
|
||||
'text:ntext',
|
||||
'slug',
|
||||
[
|
||||
'class' => ActionColumn::className(),
|
||||
'urlCreator' => function ($action, News $model, $key, $index, $column) {
|
||||
return Url::toRoute([$action, 'id' => $model->id]);
|
||||
}
|
||||
],
|
||||
],
|
||||
]); ?>
|
||||
|
||||
|
||||
</div>
|
21
backend/modules/news/views/news/update.php
Executable file
21
backend/modules/news/views/news/update.php
Executable file
@ -0,0 +1,21 @@
|
||||
<?php
|
||||
|
||||
use yii\helpers\Html;
|
||||
|
||||
/** @var yii\web\View $this */
|
||||
/** @var common\models\News $model */
|
||||
|
||||
$this->title = 'Update News: ' . $model->title;
|
||||
$this->params['breadcrumbs'][] = ['label' => 'News', 'url' => ['index']];
|
||||
$this->params['breadcrumbs'][] = ['label' => $model->title, 'url' => ['view', 'id' => $model->id]];
|
||||
$this->params['breadcrumbs'][] = 'Update';
|
||||
?>
|
||||
<div class="news-update">
|
||||
|
||||
<h1><?= Html::encode($this->title) ?></h1>
|
||||
|
||||
<?= $this->render('_form', [
|
||||
'model' => $model,
|
||||
]) ?>
|
||||
|
||||
</div>
|
39
backend/modules/news/views/news/view.php
Executable file
39
backend/modules/news/views/news/view.php
Executable file
@ -0,0 +1,39 @@
|
||||
<?php
|
||||
|
||||
use yii\helpers\Html;
|
||||
use yii\widgets\DetailView;
|
||||
|
||||
/** @var yii\web\View $this */
|
||||
/** @var common\models\News $model */
|
||||
|
||||
$this->title = $model->title;
|
||||
$this->params['breadcrumbs'][] = ['label' => 'News', 'url' => ['index']];
|
||||
$this->params['breadcrumbs'][] = $this->title;
|
||||
\yii\web\YiiAsset::register($this);
|
||||
?>
|
||||
<div class="news-view">
|
||||
|
||||
<h1><?= Html::encode($this->title) ?></h1>
|
||||
|
||||
<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',
|
||||
'text:ntext',
|
||||
'slug',
|
||||
],
|
||||
]) ?>
|
||||
|
||||
</div>
|
24
backend/modules/profile/Profile.php
Executable file
24
backend/modules/profile/Profile.php
Executable file
@ -0,0 +1,24 @@
|
||||
<?php
|
||||
|
||||
namespace app\modules\profile;
|
||||
|
||||
/**
|
||||
* profile module definition class
|
||||
*/
|
||||
class Profile extends \yii\base\Module
|
||||
{
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public $controllerNamespace = 'app\modules\profile\controllers';
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function init()
|
||||
{
|
||||
parent::init();
|
||||
|
||||
// custom initialization code goes here
|
||||
}
|
||||
}
|
20
backend/modules/profile/controllers/DefaultController.php
Executable file
20
backend/modules/profile/controllers/DefaultController.php
Executable file
@ -0,0 +1,20 @@
|
||||
<?php
|
||||
|
||||
namespace app\modules\profile\controllers;
|
||||
|
||||
use yii\web\Controller;
|
||||
|
||||
/**
|
||||
* Default controller for the `profile` module
|
||||
*/
|
||||
class DefaultController extends Controller
|
||||
{
|
||||
/**
|
||||
* Renders the index view for the module
|
||||
* @return string
|
||||
*/
|
||||
public function actionIndex()
|
||||
{
|
||||
return $this->render('index');
|
||||
}
|
||||
}
|
166
backend/modules/profile/controllers/ProfileController.php
Executable file
166
backend/modules/profile/controllers/ProfileController.php
Executable file
@ -0,0 +1,166 @@
|
||||
<?php
|
||||
|
||||
namespace app\modules\profile\controllers;
|
||||
|
||||
use app\modules\profile\models\ProfileSearch;
|
||||
use common\models\Profile;
|
||||
use common\services\UserService;
|
||||
use yii\filters\AccessControl;
|
||||
use yii\filters\VerbFilter;
|
||||
use yii\web\Controller;
|
||||
use yii\web\NotFoundHttpException;
|
||||
|
||||
/**
|
||||
* ProfileController implements the CRUD actions for Profile model.
|
||||
*/
|
||||
class ProfileController extends Controller
|
||||
{
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function behaviors()
|
||||
{
|
||||
return array_merge(
|
||||
parent::behaviors(),
|
||||
[
|
||||
'verbs' => [
|
||||
'class' => VerbFilter::className(),
|
||||
'actions' => [
|
||||
'delete' => ['POST'],
|
||||
],
|
||||
],
|
||||
'access' => [
|
||||
'class' => AccessControl::class,
|
||||
'rules' => [
|
||||
[
|
||||
'actions' => ['login', 'error'],
|
||||
'allow' => true,
|
||||
],
|
||||
[
|
||||
'allow' => true,
|
||||
'roles' => ['@'],
|
||||
],
|
||||
],
|
||||
],
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Lists all Profile models.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function actionIndex()
|
||||
{
|
||||
$searchModel = new ProfileSearch();
|
||||
$dataProvider = $searchModel->search($this->request->queryParams);
|
||||
|
||||
return $this->render('index', [
|
||||
'searchModel' => $searchModel,
|
||||
'dataProvider' => $dataProvider,
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Displays a single Profile 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 Profile model.
|
||||
* If creation is successful, the browser will be redirected to the 'view' page.
|
||||
* @return string|\yii\web\Response
|
||||
*/
|
||||
public function actionCreate()
|
||||
{
|
||||
$model = new Profile();
|
||||
$service = UserService::run();
|
||||
$texts = $service->newTexts();
|
||||
$users = $service->getAllUsers();
|
||||
if ($this->request->isPost) {
|
||||
if ($service->saveProfile($this->request->post(), $model)) {
|
||||
$service->saveTexts($this->request->post('Text'), $model->id, $texts);
|
||||
|
||||
return $this->redirect(['view', 'id' => $model->id]);
|
||||
}
|
||||
}
|
||||
|
||||
return $this->render('create', [
|
||||
'model' => $model,
|
||||
'users' => $users,
|
||||
'texts' => $texts
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates an existing Profile 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($id)
|
||||
{
|
||||
$model = $this->findModel($id);
|
||||
$service = UserService::run();
|
||||
$texts = $service->getTexts($id);
|
||||
$users = $service->getAllUsers();
|
||||
|
||||
if ($this->request->isPost) {
|
||||
if ($service->saveProfile($this->request->post(), $model)) {
|
||||
$service->saveTexts($this->request->post('Text'), $model->id, $texts);
|
||||
|
||||
return $this->redirect(['view', 'id' => $model->id]);
|
||||
}
|
||||
}
|
||||
|
||||
return $this->render('update', [
|
||||
'model' => $model,
|
||||
'users' => $users,
|
||||
'texts' => $texts
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Deletes an existing Profile 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)
|
||||
{
|
||||
$model = $this->findModel($id);
|
||||
foreach ($model->texts as $text) {
|
||||
$text->delete();
|
||||
}
|
||||
$model->delete();
|
||||
|
||||
return $this->redirect(['index']);
|
||||
}
|
||||
|
||||
/**
|
||||
* Finds the Profile 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 Profile the loaded model
|
||||
* @throws NotFoundHttpException if the model cannot be found
|
||||
*/
|
||||
protected function findModel($id)
|
||||
{
|
||||
if (($model = Profile::findOne(['id' => $id])) !== null) {
|
||||
return $model;
|
||||
}
|
||||
|
||||
throw new NotFoundHttpException('The requested page does not exist.');
|
||||
}
|
||||
}
|
71
backend/modules/profile/models/ProfileSearch.php
Executable file
71
backend/modules/profile/models/ProfileSearch.php
Executable file
@ -0,0 +1,71 @@
|
||||
<?php
|
||||
|
||||
namespace app\modules\profile\models;
|
||||
|
||||
use yii\base\Model;
|
||||
use yii\data\ActiveDataProvider;
|
||||
use common\models\Profile;
|
||||
|
||||
/**
|
||||
* ProfileSearch represents the model behind the search form of `common\models\Profile`.
|
||||
*/
|
||||
class ProfileSearch extends Profile
|
||||
{
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function rules()
|
||||
{
|
||||
return [
|
||||
[['id', 'user_id', 'activity'], 'integer'],
|
||||
[['created_at', 'image'], '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 = Profile::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,
|
||||
'user_id' => $this->user_id,
|
||||
'created_at' => $this->created_at,
|
||||
'activity' => $this->activity,
|
||||
]);
|
||||
|
||||
$query->andFilterWhere(['like', 'image', $this->image]);
|
||||
|
||||
return $dataProvider;
|
||||
}
|
||||
}
|
12
backend/modules/profile/views/default/index.php
Executable file
12
backend/modules/profile/views/default/index.php
Executable file
@ -0,0 +1,12 @@
|
||||
<div class="profile-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>
|
40
backend/modules/profile/views/profile/_form.php
Executable file
40
backend/modules/profile/views/profile/_form.php
Executable file
@ -0,0 +1,40 @@
|
||||
<?php
|
||||
|
||||
use yii\helpers\ArrayHelper;
|
||||
use yii\helpers\Html;
|
||||
use yii\widgets\ActiveForm;
|
||||
|
||||
/** @var yii\web\View $this */
|
||||
/** @var common\models\Profile $model */
|
||||
/** @var common\models\User[] $users */
|
||||
/** @var common\models\Text[] $texts */
|
||||
/** @var yii\widgets\ActiveForm $form */
|
||||
?>
|
||||
|
||||
<div class="profile-form">
|
||||
|
||||
<?php $form = ActiveForm::begin(); ?>
|
||||
|
||||
<?= $form->field($model, 'user_id')->dropDownList(ArrayHelper::map($users, 'id', 'username')) ?>
|
||||
|
||||
<?= $form->field($model, 'file')->fileInput() ?>
|
||||
|
||||
<?= $form->field($model, 'activity')->checkbox() ?>
|
||||
|
||||
<?php
|
||||
if (!empty($texts)):
|
||||
foreach ($texts as $i => $text): ?>
|
||||
|
||||
<?= $form->field($text, 'title[' . $text['language'] . ']')->textInput(['maxlength' => true, 'value' => $text->title])->label($text['language'] . ' заголовок') ?>
|
||||
|
||||
<?= $form->field($text, 'text[' . $text['language'] . ']')->textarea(['value' => $text->title])->label($text['language'] . ' текст') ?>
|
||||
|
||||
<?php endforeach; endif; ?>
|
||||
|
||||
<div class="form-group">
|
||||
<?= Html::submitButton('Save', ['class' => 'btn btn-success']) ?>
|
||||
</div>
|
||||
|
||||
<?php ActiveForm::end(); ?>
|
||||
|
||||
</div>
|
35
backend/modules/profile/views/profile/_search.php
Executable file
35
backend/modules/profile/views/profile/_search.php
Executable file
@ -0,0 +1,35 @@
|
||||
<?php
|
||||
|
||||
use yii\helpers\Html;
|
||||
use yii\widgets\ActiveForm;
|
||||
|
||||
/** @var yii\web\View $this */
|
||||
/** @var app\modules\profile\models\ProfileSearch $model */
|
||||
/** @var yii\widgets\ActiveForm $form */
|
||||
?>
|
||||
|
||||
<div class="profile-search">
|
||||
|
||||
<?php $form = ActiveForm::begin([
|
||||
'action' => ['index'],
|
||||
'method' => 'get',
|
||||
]); ?>
|
||||
|
||||
<?= $form->field($model, 'id') ?>
|
||||
|
||||
<?= $form->field($model, 'user_id') ?>
|
||||
|
||||
<?= $form->field($model, 'created_at') ?>
|
||||
|
||||
<?= $form->field($model, 'image') ?>
|
||||
|
||||
<?= $form->field($model, 'activity') ?>
|
||||
|
||||
<div class="form-group">
|
||||
<?= Html::submitButton('Search', ['class' => 'btn btn-primary']) ?>
|
||||
<?= Html::resetButton('Reset', ['class' => 'btn btn-outline-secondary']) ?>
|
||||
</div>
|
||||
|
||||
<?php ActiveForm::end(); ?>
|
||||
|
||||
</div>
|
24
backend/modules/profile/views/profile/create.php
Executable file
24
backend/modules/profile/views/profile/create.php
Executable file
@ -0,0 +1,24 @@
|
||||
<?php
|
||||
|
||||
use yii\helpers\Html;
|
||||
|
||||
/** @var yii\web\View $this */
|
||||
/** @var common\models\Profile $model */
|
||||
/** @var common\models\User[] $users */
|
||||
/** @var common\models\Text[] $texts */
|
||||
|
||||
$this->title = 'Create Profile';
|
||||
$this->params['breadcrumbs'][] = ['label' => 'Profiles', 'url' => ['index']];
|
||||
$this->params['breadcrumbs'][] = $this->title;
|
||||
?>
|
||||
<div class="profile-create">
|
||||
|
||||
<h1><?= Html::encode($this->title) ?></h1>
|
||||
|
||||
<?= $this->render('_form', [
|
||||
'model' => $model,
|
||||
'users' => $users,
|
||||
'texts' => $texts
|
||||
]) ?>
|
||||
|
||||
</div>
|
57
backend/modules/profile/views/profile/index.php
Executable file
57
backend/modules/profile/views/profile/index.php
Executable file
@ -0,0 +1,57 @@
|
||||
<?php
|
||||
|
||||
use common\models\Profile;
|
||||
use yii\helpers\Html;
|
||||
use yii\helpers\Url;
|
||||
use yii\grid\ActionColumn;
|
||||
use yii\grid\GridView;
|
||||
|
||||
/** @var yii\web\View $this */
|
||||
/** @var app\modules\profile\models\ProfileSearch $searchModel */
|
||||
/** @var yii\data\ActiveDataProvider $dataProvider */
|
||||
|
||||
$this->title = 'Profiles';
|
||||
$this->params['breadcrumbs'][] = $this->title;
|
||||
?>
|
||||
<div class="profile-index">
|
||||
|
||||
<h1><?= Html::encode($this->title) ?></h1>
|
||||
|
||||
<p>
|
||||
<?= Html::a('Create Profile', ['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',
|
||||
'created_at',
|
||||
[
|
||||
'attribute' => 'user_id',
|
||||
'value' => function($model){return $model->user->username;},
|
||||
],
|
||||
[
|
||||
'attribute' => 'image',
|
||||
'value' => function($model){return '/uploads/' . $model->image;},
|
||||
'format' => ['image', ['width' => 100, 'height' => 100]],
|
||||
],
|
||||
[
|
||||
'attribute' => 'activity',
|
||||
'value' => function($model){return $model->getStatusLabel();},
|
||||
],
|
||||
[
|
||||
'class' => ActionColumn::className(),
|
||||
'urlCreator' => function ($action, Profile $model, $key, $index, $column) {
|
||||
return Url::toRoute([$action, 'id' => $model->id]);
|
||||
}
|
||||
],
|
||||
],
|
||||
]); ?>
|
||||
|
||||
|
||||
</div>
|
25
backend/modules/profile/views/profile/update.php
Executable file
25
backend/modules/profile/views/profile/update.php
Executable file
@ -0,0 +1,25 @@
|
||||
<?php
|
||||
|
||||
use yii\helpers\Html;
|
||||
|
||||
/** @var yii\web\View $this */
|
||||
/** @var common\models\Profile $model */
|
||||
/** @var common\models\User[] $users */
|
||||
/** @var common\models\Text[] $texts */
|
||||
|
||||
$this->title = 'Update Profile: ' . $model->id;
|
||||
$this->params['breadcrumbs'][] = ['label' => 'Profiles', 'url' => ['index']];
|
||||
$this->params['breadcrumbs'][] = ['label' => $model->id, 'url' => ['view', 'id' => $model->id]];
|
||||
$this->params['breadcrumbs'][] = 'Update';
|
||||
?>
|
||||
<div class="profile-update">
|
||||
|
||||
<h1><?= Html::encode($this->title) ?></h1>
|
||||
|
||||
<?= $this->render('_form', [
|
||||
'model' => $model,
|
||||
'users' => $users,
|
||||
'texts' => $texts
|
||||
]) ?>
|
||||
|
||||
</div>
|
50
backend/modules/profile/views/profile/view.php
Executable file
50
backend/modules/profile/views/profile/view.php
Executable file
@ -0,0 +1,50 @@
|
||||
<?php
|
||||
|
||||
use yii\helpers\Html;
|
||||
use yii\widgets\DetailView;
|
||||
|
||||
/** @var yii\web\View $this */
|
||||
/** @var common\models\Profile $model */
|
||||
|
||||
$this->title = $model->id;
|
||||
$this->params['breadcrumbs'][] = ['label' => 'Profiles', 'url' => ['index']];
|
||||
$this->params['breadcrumbs'][] = $this->title;
|
||||
\yii\web\YiiAsset::register($this);
|
||||
?>
|
||||
<div class="profile-view">
|
||||
|
||||
<h1><?= Html::encode($this->title) ?></h1>
|
||||
|
||||
<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',
|
||||
[
|
||||
'attribute' => 'user_id',
|
||||
'value' => function($model){return $model->user->username;},
|
||||
],
|
||||
'created_at',
|
||||
[
|
||||
'attribute' => 'image',
|
||||
'value' => function($model){return '/uploads/' . $model->image;},
|
||||
'format' => ['image', ['width' => 100, 'height' => 100]],
|
||||
],
|
||||
[
|
||||
'attribute' => 'activity',
|
||||
'value' => function($model){return $model->getStatusLabel();},
|
||||
],
|
||||
],
|
||||
]) ?>
|
||||
|
||||
</div>
|
2
backend/runtime/.gitignore
vendored
Executable file
2
backend/runtime/.gitignore
vendored
Executable file
@ -0,0 +1,2 @@
|
||||
*
|
||||
!.gitignore
|
10
backend/tests/_bootstrap.php
Executable file
10
backend/tests/_bootstrap.php
Executable 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';
|
0
backend/tests/_data/.gitignore
vendored
Executable file
0
backend/tests/_data/.gitignore
vendored
Executable file
13
backend/tests/_data/login_data.php
Executable file
13
backend/tests/_data/login_data.php
Executable file
@ -0,0 +1,13 @@
|
||||
<?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',
|
||||
],
|
||||
];
|
2
backend/tests/_output/.gitignore
vendored
Executable file
2
backend/tests/_output/.gitignore
vendored
Executable file
@ -0,0 +1,2 @@
|
||||
*
|
||||
!.gitignore
|
1
backend/tests/_support/.gitignore
vendored
Executable file
1
backend/tests/_support/.gitignore
vendored
Executable file
@ -0,0 +1 @@
|
||||
_generated
|
26
backend/tests/_support/FunctionalTester.php
Executable file
26
backend/tests/_support/FunctionalTester.php
Executable file
@ -0,0 +1,26 @@
|
||||
<?php
|
||||
|
||||
namespace backend\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;
|
||||
/**
|
||||
* Define custom actions here
|
||||
*/
|
||||
}
|
26
backend/tests/_support/UnitTester.php
Executable file
26
backend/tests/_support/UnitTester.php
Executable file
@ -0,0 +1,26 @@
|
||||
<?php
|
||||
|
||||
namespace backend\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
|
||||
*/
|
||||
}
|
5
backend/tests/functional.suite.yml
Executable file
5
backend/tests/functional.suite.yml
Executable file
@ -0,0 +1,5 @@
|
||||
suite_namespace: backend\tests\functional
|
||||
actor: FunctionalTester
|
||||
modules:
|
||||
enabled:
|
||||
- Yii2
|
44
backend/tests/functional/LoginCest.php
Executable file
44
backend/tests/functional/LoginCest.php
Executable file
@ -0,0 +1,44 @@
|
||||
<?php
|
||||
|
||||
namespace backend\tests\functional;
|
||||
|
||||
use backend\tests\FunctionalTester;
|
||||
use common\fixtures\UserFixture;
|
||||
|
||||
/**
|
||||
* Class LoginCest
|
||||
*/
|
||||
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'
|
||||
]
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param FunctionalTester $I
|
||||
*/
|
||||
public function loginUser(FunctionalTester $I)
|
||||
{
|
||||
$I->amOnRoute('/site/login');
|
||||
$I->fillField('Username', 'erau');
|
||||
$I->fillField('Password', 'password_0');
|
||||
$I->click('login-button');
|
||||
|
||||
$I->see('Logout (erau)', 'form button[type=submit]');
|
||||
$I->dontSeeLink('Login');
|
||||
$I->dontSeeLink('Signup');
|
||||
}
|
||||
}
|
16
backend/tests/functional/_bootstrap.php
Executable file
16
backend/tests/functional/_bootstrap.php
Executable 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');
|
||||
* ```
|
||||
*/
|
2
backend/tests/unit.suite.yml
Executable file
2
backend/tests/unit.suite.yml
Executable file
@ -0,0 +1,2 @@
|
||||
suite_namespace: backend\tests\unit
|
||||
actor: UnitTester
|
16
backend/tests/unit/_bootstrap.php
Executable file
16
backend/tests/unit/_bootstrap.php
Executable 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');
|
||||
* ```
|
||||
*/
|
33
backend/views/layouts/blank.php
Executable file
33
backend/views/layouts/blank.php
Executable file
@ -0,0 +1,33 @@
|
||||
<?php
|
||||
|
||||
/** @var yii\web\View $this */
|
||||
/** @var string $content */
|
||||
|
||||
use backend\assets\AppAsset;
|
||||
use yii\helpers\Html;
|
||||
|
||||
AppAsset::register($this);
|
||||
?>
|
||||
<?php $this->beginPage() ?>
|
||||
<!DOCTYPE html>
|
||||
<html lang="<?= Yii::$app->language ?>" class="h-100">
|
||||
<head>
|
||||
<meta charset="<?= Yii::$app->charset ?>">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
|
||||
<?php $this->registerCsrfMetaTags() ?>
|
||||
<title><?= Html::encode($this->title) ?></title>
|
||||
<?php $this->head() ?>
|
||||
</head>
|
||||
<body class="d-flex flex-column h-100">
|
||||
<?php $this->beginBody() ?>
|
||||
|
||||
<main role="main">
|
||||
<div class="container">
|
||||
<?= $content ?>
|
||||
</div>
|
||||
</main>
|
||||
|
||||
<?php $this->endBody() ?>
|
||||
</body>
|
||||
</html>
|
||||
<?php $this->endPage();
|
83
backend/views/layouts/main.php
Executable file
83
backend/views/layouts/main.php
Executable file
@ -0,0 +1,83 @@
|
||||
<?php
|
||||
|
||||
/** @var \yii\web\View $this */
|
||||
/** @var string $content */
|
||||
|
||||
use backend\assets\AppAsset;
|
||||
use common\widgets\Alert;
|
||||
use yii\bootstrap5\Breadcrumbs;
|
||||
use yii\bootstrap5\Html;
|
||||
use yii\bootstrap5\Nav;
|
||||
use yii\bootstrap5\NavBar;
|
||||
|
||||
AppAsset::register($this);
|
||||
?>
|
||||
<?php $this->beginPage() ?>
|
||||
<!DOCTYPE html>
|
||||
<html lang="<?= Yii::$app->language ?>" class="h-100">
|
||||
<head>
|
||||
<meta charset="<?= Yii::$app->charset ?>">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
|
||||
<?php $this->registerCsrfMetaTags() ?>
|
||||
<title><?= Html::encode($this->title) ?></title>
|
||||
<?php $this->head() ?>
|
||||
</head>
|
||||
<body class="d-flex flex-column h-100">
|
||||
<?php $this->beginBody() ?>
|
||||
|
||||
<header>
|
||||
<?php
|
||||
NavBar::begin([
|
||||
'brandLabel' => Yii::$app->name,
|
||||
'brandUrl' => Yii::$app->homeUrl,
|
||||
'options' => [
|
||||
'class' => 'navbar navbar-expand-md navbar-dark bg-dark fixed-top',
|
||||
],
|
||||
]);
|
||||
$menuItems = [
|
||||
['label' => 'Home', 'url' => ['/site/index']],
|
||||
['label' => 'Круд новостей', 'url' => ['/news/news']],
|
||||
['label' => 'Круд профилей', 'url' => ['/profile/profile']],
|
||||
];
|
||||
if (Yii::$app->user->isGuest) {
|
||||
$menuItems[] = ['label' => 'Login', 'url' => ['/site/login']];
|
||||
}
|
||||
echo Nav::widget([
|
||||
'options' => ['class' => 'navbar-nav me-auto mb-2 mb-md-0'],
|
||||
'items' => $menuItems,
|
||||
]);
|
||||
if (Yii::$app->user->isGuest) {
|
||||
echo Html::tag('div',Html::a('Login',['/site/login'],['class' => ['btn btn-link login text-decoration-none']]),['class' => ['d-flex']]);
|
||||
} else {
|
||||
echo Html::beginForm(['/site/logout'], 'post', ['class' => 'd-flex'])
|
||||
. Html::submitButton(
|
||||
'Logout (' . Yii::$app->user->identity->username . ')',
|
||||
['class' => 'btn btn-link logout text-decoration-none']
|
||||
)
|
||||
. Html::endForm();
|
||||
}
|
||||
NavBar::end();
|
||||
?>
|
||||
</header>
|
||||
|
||||
<main role="main" class="flex-shrink-0">
|
||||
<div class="container">
|
||||
<?= Breadcrumbs::widget([
|
||||
'links' => isset($this->params['breadcrumbs']) ? $this->params['breadcrumbs'] : [],
|
||||
]) ?>
|
||||
<?= Alert::widget() ?>
|
||||
<?= $content ?>
|
||||
</div>
|
||||
</main>
|
||||
|
||||
<footer class="footer mt-auto py-3 text-muted">
|
||||
<div class="container">
|
||||
<p class="float-start">© <?= Html::encode(Yii::$app->name) ?> <?= date('Y') ?></p>
|
||||
<p class="float-end"><?= Yii::powered() ?></p>
|
||||
</div>
|
||||
</footer>
|
||||
|
||||
<?php $this->endBody() ?>
|
||||
</body>
|
||||
</html>
|
||||
<?php $this->endPage();
|
27
backend/views/site/error.php
Executable file
27
backend/views/site/error.php
Executable file
@ -0,0 +1,27 @@
|
||||
<?php
|
||||
|
||||
/** @var yii\web\View $this */
|
||||
/** @var string $name */
|
||||
/** @var string $message */
|
||||
/** @var Exception $exception*/
|
||||
|
||||
use yii\helpers\Html;
|
||||
|
||||
$this->title = $name;
|
||||
?>
|
||||
<div class="site-error">
|
||||
|
||||
<h1><?= Html::encode($this->title) ?></h1>
|
||||
|
||||
<div class="alert alert-danger">
|
||||
<?= nl2br(Html::encode($message)) ?>
|
||||
</div>
|
||||
|
||||
<p>
|
||||
The above error occurred while the Web server was processing your request.
|
||||
</p>
|
||||
<p>
|
||||
Please contact us if you think this is a server error. Thank you.
|
||||
</p>
|
||||
|
||||
</div>
|
53
backend/views/site/index.php
Executable file
53
backend/views/site/index.php
Executable file
@ -0,0 +1,53 @@
|
||||
<?php
|
||||
|
||||
/** @var yii\web\View $this */
|
||||
|
||||
$this->title = 'My Yii Application';
|
||||
?>
|
||||
<div class="site-index">
|
||||
|
||||
<div class="jumbotron text-center bg-transparent">
|
||||
<h1 class="display-4">Congratulations!</h1>
|
||||
|
||||
<p class="lead">You have successfully created your Yii-powered application.</p>
|
||||
|
||||
<p><a class="btn btn-lg btn-success" href="http://www.yiiframework.com">Get started with Yii</a></p>
|
||||
</div>
|
||||
|
||||
<div class="body-content">
|
||||
|
||||
<div class="row">
|
||||
<div class="col-lg-4">
|
||||
<h2>Heading</h2>
|
||||
|
||||
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et
|
||||
dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip
|
||||
ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu
|
||||
fugiat nulla pariatur.</p>
|
||||
|
||||
<p><a class="btn btn-outline-secondary" href="http://www.yiiframework.com/doc/">Yii Documentation »</a></p>
|
||||
</div>
|
||||
<div class="col-lg-4">
|
||||
<h2>Heading</h2>
|
||||
|
||||
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et
|
||||
dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip
|
||||
ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu
|
||||
fugiat nulla pariatur.</p>
|
||||
|
||||
<p><a class="btn btn-outline-secondary" href="http://www.yiiframework.com/forum/">Yii Forum »</a></p>
|
||||
</div>
|
||||
<div class="col-lg-4">
|
||||
<h2>Heading</h2>
|
||||
|
||||
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et
|
||||
dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip
|
||||
ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu
|
||||
fugiat nulla pariatur.</p>
|
||||
|
||||
<p><a class="btn btn-outline-secondary" href="http://www.yiiframework.com/extensions/">Yii Extensions »</a></p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
</div>
|
32
backend/views/site/login.php
Executable file
32
backend/views/site/login.php
Executable file
@ -0,0 +1,32 @@
|
||||
<?php
|
||||
|
||||
/** @var yii\web\View $this */
|
||||
/** @var yii\bootstrap5\ActiveForm $form */
|
||||
/** @var \common\models\LoginForm $model */
|
||||
|
||||
use yii\bootstrap5\ActiveForm;
|
||||
use yii\bootstrap5\Html;
|
||||
|
||||
$this->title = 'Login';
|
||||
?>
|
||||
<div class="site-login">
|
||||
<div class="mt-5 offset-lg-3 col-lg-6">
|
||||
<h1><?= Html::encode($this->title) ?></h1>
|
||||
|
||||
<p>Please fill out the following fields to login:</p>
|
||||
|
||||
<?php $form = ActiveForm::begin(['id' => 'login-form']); ?>
|
||||
|
||||
<?= $form->field($model, 'username')->textInput(['autofocus' => true]) ?>
|
||||
|
||||
<?= $form->field($model, 'password')->passwordInput() ?>
|
||||
|
||||
<?= $form->field($model, 'rememberMe')->checkbox() ?>
|
||||
|
||||
<div class="form-group">
|
||||
<?= Html::submitButton('Login', ['class' => 'btn btn-primary btn-block', 'name' => 'login-button']) ?>
|
||||
</div>
|
||||
|
||||
<?php ActiveForm::end(); ?>
|
||||
</div>
|
||||
</div>
|
2
backend/web/assets/.gitignore
vendored
Executable file
2
backend/web/assets/.gitignore
vendored
Executable file
@ -0,0 +1,2 @@
|
||||
*
|
||||
!.gitignore
|
90
backend/web/css/site.css
Executable file
90
backend/web/css/site.css
Executable file
@ -0,0 +1,90 @@
|
||||
main > .container {
|
||||
padding: 70px 15px 20px;
|
||||
}
|
||||
|
||||
.footer {
|
||||
background-color: #f5f5f5;
|
||||
font-size: .9em;
|
||||
height: 60px;
|
||||
}
|
||||
|
||||
.footer > .container {
|
||||
padding-right: 15px;
|
||||
padding-left: 15px;
|
||||
}
|
||||
|
||||
.not-set {
|
||||
color: #c55;
|
||||
font-style: italic;
|
||||
}
|
||||
|
||||
/* add sorting icons to gridview sort links */
|
||||
a.asc:after, a.desc:after {
|
||||
content: '';
|
||||
left: 3px;
|
||||
display: inline-block;
|
||||
width: 0;
|
||||
height: 0;
|
||||
border: solid 5px transparent;
|
||||
margin: 4px 4px 2px 4px;
|
||||
background: transparent;
|
||||
}
|
||||
|
||||
a.asc:after {
|
||||
border-bottom: solid 7px #212529;
|
||||
border-top-width: 0;
|
||||
}
|
||||
|
||||
a.desc:after {
|
||||
border-top: solid 7px #212529;
|
||||
border-bottom-width: 0;
|
||||
}
|
||||
|
||||
.grid-view th,
|
||||
.grid-view td:last-child {
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
.grid-view .filters input,
|
||||
.grid-view .filters select {
|
||||
min-width: 50px;
|
||||
}
|
||||
|
||||
.hint-block {
|
||||
display: block;
|
||||
margin-top: 5px;
|
||||
color: #999;
|
||||
}
|
||||
|
||||
.error-summary {
|
||||
color: #a94442;
|
||||
background: #fdf7f7;
|
||||
border-left: 3px solid #eed3d7;
|
||||
padding: 10px 20px;
|
||||
margin: 0 0 15px 0;
|
||||
}
|
||||
|
||||
/* align the logout "link" (button in form) of the navbar */
|
||||
.nav li > form > button.logout {
|
||||
padding-top: 7px;
|
||||
color: rgba(255, 255, 255, 0.5);
|
||||
}
|
||||
|
||||
@media(max-width:767px) {
|
||||
.nav li > form > button.logout {
|
||||
display:block;
|
||||
text-align: left;
|
||||
width: 100%;
|
||||
padding: 10px 0;
|
||||
}
|
||||
}
|
||||
|
||||
.nav > li > form > button.logout:focus,
|
||||
.nav > li > form > button.logout:hover {
|
||||
text-decoration: none;
|
||||
color: rgba(255, 255, 255, 0.75);
|
||||
}
|
||||
|
||||
.nav > li > form > button.logout:focus {
|
||||
outline: none;
|
||||
}
|
BIN
backend/web/favicon.ico
Executable file
BIN
backend/web/favicon.ico
Executable file
Binary file not shown.
After Width: | Height: | Size: 318 B |
Reference in New Issue
Block a user