Commit d967f25f by Junaid Rahman pv

modified website module

parent 9defc564
...@@ -46,9 +46,6 @@ $config = [ ...@@ -46,9 +46,6 @@ $config = [
], ],
'location' => [ 'location' => [
'class' => 'backend\modules\location\Module', 'class' => 'backend\modules\location\Module',
],
'website' => [
'class' => 'backend\modules\website\Module',
] ]
], ],
......
<?php <?php
namespace backend\modules\website\controllers; namespace backend\controllers;
use Yii; use Yii;
use common\models\website; use common\models\website;
use backend\modules\website\models\search\WebsiteSearch; use backend\models\search\WebsiteSearch;
use yii\web\Controller; use yii\web\Controller;
use yii\web\NotFoundHttpException; use yii\web\NotFoundHttpException;
use yii\filters\VerbFilter; use yii\filters\VerbFilter;
...@@ -14,6 +14,8 @@ use yii\filters\VerbFilter; ...@@ -14,6 +14,8 @@ use yii\filters\VerbFilter;
*/ */
class WebsiteController extends Controller class WebsiteController extends Controller
{ {
public function behaviors() public function behaviors()
{ {
return [ return [
...@@ -61,9 +63,14 @@ class WebsiteController extends Controller ...@@ -61,9 +63,14 @@ class WebsiteController extends Controller
public function actionCreate() public function actionCreate()
{ {
$model = new website(); $model = new website();
$searchModel = new WebsiteSearch();
$dataProvider = $searchModel->search(Yii::$app->request->queryParams);
if ($model->load(Yii::$app->request->post()) && $model->save()) { if ($model->load(Yii::$app->request->post()) && $model->save()) {
return $this->redirect(['view', 'id' => $model->id]); return $this->redirect('index', [
'searchModel' => $searchModel,
'dataProvider' => $dataProvider,
]);
} else { } else {
return $this->render('create', [ return $this->render('create', [
'model' => $model, 'model' => $model,
......
<?php <?php
namespace backend\modules\website\models\search; namespace backend\models\search;
use Yii; use Yii;
use yii\base\Model; use yii\base\Model;
......
<?php
namespace backend\modules\website;
/**
* website module definition class
*/
class Module extends \yii\base\Module
{
/**
* @inheritdoc
*/
public $controllerNamespace = 'backend\modules\website\controllers';
/**
* @inheritdoc
*/
public function init()
{
parent::init();
// custom initialization code goes here
}
}
<?php
namespace backend\modules\website\controllers;
use yii\web\Controller;
/**
* Default controller for the `website` module
*/
class DefaultController extends Controller
{
/**
* Renders the index view for the module
* @return string
*/
public function actionIndex()
{
return $this->render('index');
}
}
<div class="website-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>
...@@ -210,7 +210,7 @@ $bundle = BackendAsset::register($this); ...@@ -210,7 +210,7 @@ $bundle = BackendAsset::register($this);
[ [
'label' => Yii::t('backend', 'Website'), 'label' => Yii::t('backend', 'Website'),
'icon' => '<i class="fa fa-globe"></i>', 'icon' => '<i class="fa fa-globe"></i>',
'url' => ['/website/website'], 'url' => ['/website'],
'visible' => Yii::$app->user->can('administrator') 'visible' => Yii::$app->user->can('administrator')
], ],
[ [
......
...@@ -4,7 +4,7 @@ use yii\helpers\Html; ...@@ -4,7 +4,7 @@ use yii\helpers\Html;
use yii\grid\GridView; use yii\grid\GridView;
/* @var $this yii\web\View */ /* @var $this yii\web\View */
/* @var $searchModel backend\modules\website\models\search\WebsiteSearch */ /* @var $searchModel backend\models\search\WebsiteSearch */
/* @var $dataProvider yii\data\ActiveDataProvider */ /* @var $dataProvider yii\data\ActiveDataProvider */
$this->title = Yii::t('backend', 'Websites'); $this->title = Yii::t('backend', 'Websites');
......
...@@ -12,28 +12,25 @@ class m160907_100248_website extends Migration ...@@ -12,28 +12,25 @@ class m160907_100248_website extends Migration
} }
$this->createTable('{{%website}}', [ $this->createTable('{{%website}}', [
'id' => $this->primaryKey(), 'id' => $this->primaryKey(),
'business_id' => $this->integer(), 'business_id' => $this->integer(),
'theme_id' => $this->integer(), 'theme_id' => $this->integer(),
'domain_name' => $this->string(255)->notNull(), 'domain_name' => $this->string(255)->notNull(),
'expiry_date' => $this->string(11)->notNull(),
'status' => $this->smallInteger(6), 'status' => $this->smallInteger(6),
'expiry_date' => $this->integer(11),
'created_at' => $this->integer(11), 'created_at' => $this->integer(11),
'updated_at' => $this->integer(11), 'updated_at' => $this->integer(11),
], $tableOptions); ], $tableOptions);
$this->createIndex('idx_domain_name', '{{%website}}', 'domain_name'); $this->createIndex('idx_domain_name', '{{%website}}', 'domain_name');
$this->addForeignKey('fk_theme_id', '{{%website}}', 'theme_id', '{{%theme}}', 'id', 'RESTRICT', $this->addForeignKey('fk_website_theme', '{{%website}}', 'theme_id', '{{%theme}}', 'id', 'RESTRICT', 'RESTRICT');
'RESTRICT');
} }
public function safeDown() public function safeDown()
{ {
$this->dropForeignKey('fk_theme_id', '{{%website}}'); $this->dropForeignKey('fk_website_theme', '{{%website}}');
$this->dropIndex('idx_domain_name', '{{%website}}'); $this->dropIndex('idx_domain_name', '{{%website}}');
......
...@@ -4,6 +4,7 @@ namespace common\models; ...@@ -4,6 +4,7 @@ namespace common\models;
use Yii; use Yii;
use yii\behaviors\TimestampBehavior; use yii\behaviors\TimestampBehavior;
use MongoDB\BSON\UTCDatetime;
/** /**
* This is the model class for table "{{%website}}". * This is the model class for table "{{%website}}".
...@@ -49,10 +50,16 @@ class Website extends \yii\db\ActiveRecord ...@@ -49,10 +50,16 @@ class Website extends \yii\db\ActiveRecord
public function rules() public function rules()
{ {
return [ return [
[['business_id', 'theme_id', 'status', 'expiry_date', 'created_at', 'updated_at'], 'integer'], [['business_id', 'theme_id', 'status', 'expiry_date','created_at', 'updated_at'], 'integer'],
[['domain_name'], 'required'], [['domain_name'], 'required'],
[['domain_name'], 'string', 'max' => 255], [['domain_name'], 'string', 'max' => 255],
[['theme_id'], 'exist', 'skipOnError' => true, 'targetClass' => Theme::className(), 'targetAttribute' => ['theme_id' => 'id']], [
['theme_id'],
'exist',
'skipOnError' => true,
'targetClass' => Theme::className(),
'targetAttribute' => ['theme_id' => 'id']
],
]; ];
} }
...@@ -63,8 +70,8 @@ class Website extends \yii\db\ActiveRecord ...@@ -63,8 +70,8 @@ class Website extends \yii\db\ActiveRecord
{ {
return [ return [
'id' => Yii::t('common', 'ID'), 'id' => Yii::t('common', 'ID'),
'business_id' => Yii::t('common', 'Business ID'), 'business_id' => Yii::t('common', 'Business'),
'theme_id' => Yii::t('common', 'Theme ID'), 'theme_id' => Yii::t('common', 'Theme'),
'domain_name' => Yii::t('common', 'Domain Name'), 'domain_name' => Yii::t('common', 'Domain Name'),
'status' => Yii::t('common', 'Status'), 'status' => Yii::t('common', 'Status'),
'expiry_date' => Yii::t('common', 'Expiry Date'), 'expiry_date' => Yii::t('common', 'Expiry Date'),
...@@ -101,4 +108,15 @@ class Website extends \yii\db\ActiveRecord ...@@ -101,4 +108,15 @@ class Website extends \yii\db\ActiveRecord
self::STATUS_IN_ACTIVE => Yii::t('common', 'In Active'), self::STATUS_IN_ACTIVE => Yii::t('common', 'In Active'),
]; ];
} }
public function beforeSave($insert)
{
if (parent::beforeSave($insert)) {
$expiry_date = date('Y-m-d', strtotime('+1 years'));
$this->expiry_date = strtotime($expiry_date);
return true;
} else {
return false;
}
}
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment