Commit d967f25f by Junaid Rahman pv

modified website module

parent 9defc564
......@@ -46,9 +46,6 @@ $config = [
],
'location' => [
'class' => 'backend\modules\location\Module',
],
'website' => [
'class' => 'backend\modules\website\Module',
]
],
......
<?php
namespace backend\modules\website\controllers;
namespace backend\controllers;
use Yii;
use common\models\website;
use backend\modules\website\models\search\WebsiteSearch;
use backend\models\search\WebsiteSearch;
use yii\web\Controller;
use yii\web\NotFoundHttpException;
use yii\filters\VerbFilter;
......@@ -14,6 +14,8 @@ use yii\filters\VerbFilter;
*/
class WebsiteController extends Controller
{
public function behaviors()
{
return [
......@@ -61,9 +63,14 @@ class WebsiteController extends Controller
public function actionCreate()
{
$model = new website();
$searchModel = new WebsiteSearch();
$dataProvider = $searchModel->search(Yii::$app->request->queryParams);
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 {
return $this->render('create', [
'model' => $model,
......
<?php
namespace backend\modules\website\models\search;
namespace backend\models\search;
use Yii;
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);
[
'label' => Yii::t('backend', 'Website'),
'icon' => '<i class="fa fa-globe"></i>',
'url' => ['/website/website'],
'url' => ['/website'],
'visible' => Yii::$app->user->can('administrator')
],
[
......
......@@ -4,7 +4,7 @@ use yii\helpers\Html;
use yii\grid\GridView;
/* @var $this yii\web\View */
/* @var $searchModel backend\modules\website\models\search\WebsiteSearch */
/* @var $searchModel backend\models\search\WebsiteSearch */
/* @var $dataProvider yii\data\ActiveDataProvider */
$this->title = Yii::t('backend', 'Websites');
......
......@@ -12,28 +12,25 @@ class m160907_100248_website extends Migration
}
$this->createTable('{{%website}}', [
'id' => $this->primaryKey(),
'business_id' => $this->integer(),
'theme_id' => $this->integer(),
'domain_name' => $this->string(255)->notNull(),
'expiry_date' => $this->string(11)->notNull(),
'status' => $this->smallInteger(6),
'expiry_date' => $this->integer(11),
'created_at' => $this->integer(11),
'updated_at' => $this->integer(11),
], $tableOptions);
$this->createIndex('idx_domain_name', '{{%website}}', 'domain_name');
$this->addForeignKey('fk_theme_id', '{{%website}}', 'theme_id', '{{%theme}}', 'id', 'RESTRICT',
'RESTRICT');
$this->addForeignKey('fk_website_theme', '{{%website}}', 'theme_id', '{{%theme}}', 'id', 'RESTRICT', 'RESTRICT');
}
public function safeDown()
{
$this->dropForeignKey('fk_theme_id', '{{%website}}');
$this->dropForeignKey('fk_website_theme', '{{%website}}');
$this->dropIndex('idx_domain_name', '{{%website}}');
......
......@@ -4,6 +4,7 @@ namespace common\models;
use Yii;
use yii\behaviors\TimestampBehavior;
use MongoDB\BSON\UTCDatetime;
/**
* This is the model class for table "{{%website}}".
......@@ -49,10 +50,16 @@ class Website extends \yii\db\ActiveRecord
public function rules()
{
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'], '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
{
return [
'id' => Yii::t('common', 'ID'),
'business_id' => Yii::t('common', 'Business ID'),
'theme_id' => Yii::t('common', 'Theme ID'),
'business_id' => Yii::t('common', 'Business'),
'theme_id' => Yii::t('common', 'Theme'),
'domain_name' => Yii::t('common', 'Domain Name'),
'status' => Yii::t('common', 'Status'),
'expiry_date' => Yii::t('common', 'Expiry Date'),
......@@ -101,4 +108,15 @@ class Website extends \yii\db\ActiveRecord
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