Commit 9defc564 by Junaid Rahman pv

created website module

parent aa00fd2b
......@@ -46,6 +46,9 @@ $config = [
],
'location' => [
'class' => 'backend\modules\location\Module',
],
'website' => [
'class' => 'backend\modules\website\Module',
]
],
......
......@@ -137,42 +137,29 @@ use common\widgets\PlacePicker\PlacePicker;
</div>
<div class="row">
<div class="col-md-4">
<?= $form->field($model, 'latitude')->textInput(['maxlength' => true, 'id' => 'latitude']) ?>
</div>
<div class="col-md-4">
<?= $form->field($model, 'longitude')->textInput(['maxlength' => true, 'id' => 'longitude']) ?>
</div>
</div>
<div class="row">
<div class="col-md-8">
<?= PlacePicker::widget([
'model' => $model,
'name' => 'map',
'latitudeFieldId' => 'latitude',
'longitudeFieldId' => 'longitude'
]) ?>
</div>
</div>
<div class="row">
<div class="col-md-4">
<?= $form->field($model, 'latitude')->textInput(['maxlength' => true, 'id' => 'latitude']) ?>
</div>
<div class="col-md-4">
<?= $form->field($model, 'longitude')->textInput(['maxlength' => true, 'id' => 'longitude']) ?>
</div>
</div>
<div class="row">
<div class="col-md-4">
<?= $form->field($model, 'status')->dropDownList($model::statuses()) ?>
</div>
</div>
<div class="form-group">
<?= Html::submitButton($model->isNewRecord ? Yii::t('backend', 'Create') : Yii::t('backend',
'Update'), ['class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary']) ?>
</div>
<?php ActiveForm::end(); ?>
......
<?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');
}
}
<?php
namespace backend\modules\website\controllers;
use Yii;
use common\models\website;
use backend\modules\website\models\search\WebsiteSearch;
use yii\web\Controller;
use yii\web\NotFoundHttpException;
use yii\filters\VerbFilter;
/**
* WebsiteController implements the CRUD actions for website model.
*/
class WebsiteController extends Controller
{
public function behaviors()
{
return [
'verbs' => [
'class' => VerbFilter::className(),
'actions' => [
'delete' => ['post'],
],
],
];
}
/**
* Lists all website models.
* @return mixed
*/
public function actionIndex()
{
$searchModel = new WebsiteSearch();
$dataProvider = $searchModel->search(Yii::$app->request->queryParams);
return $this->render('index', [
'searchModel' => $searchModel,
'dataProvider' => $dataProvider,
]);
}
/**
* Displays a single website model.
* @param integer $id
* @return mixed
*/
public function actionView($id)
{
return $this->render('view', [
'model' => $this->findModel($id),
]);
}
/**
* Creates a new website model.
* If creation is successful, the browser will be redirected to the 'view' page.
* @return mixed
*/
public function actionCreate()
{
$model = new website();
if ($model->load(Yii::$app->request->post()) && $model->save()) {
return $this->redirect(['view', 'id' => $model->id]);
} else {
return $this->render('create', [
'model' => $model,
]);
}
}
/**
* Updates an existing website model.
* If update is successful, the browser will be redirected to the 'view' page.
* @param integer $id
* @return mixed
*/
public function actionUpdate($id)
{
$model = $this->findModel($id);
if ($model->load(Yii::$app->request->post()) && $model->save()) {
return $this->redirect(['view', 'id' => $model->id]);
} else {
return $this->render('update', [
'model' => $model,
]);
}
}
/**
* Deletes an existing website model.
* If deletion is successful, the browser will be redirected to the 'index' page.
* @param integer $id
* @return mixed
*/
public function actionDelete($id)
{
$this->findModel($id)->delete();
return $this->redirect(['index']);
}
/**
* Finds the website model based on its primary key value.
* If the model is not found, a 404 HTTP exception will be thrown.
* @param integer $id
* @return website the loaded model
* @throws NotFoundHttpException if the model cannot be found
*/
protected function findModel($id)
{
if (($model = website::findOne($id)) !== null) {
return $model;
} else {
throw new NotFoundHttpException('The requested page does not exist.');
}
}
}
<?php
namespace backend\modules\website\models\search;
use Yii;
use yii\base\Model;
use yii\data\ActiveDataProvider;
use common\models\website;
/**
* WebsiteSearch represents the model behind the search form about `common\models\website`.
*/
class WebsiteSearch extends website
{
/**
* @inheritdoc
*/
public function rules()
{
return [
[['id', 'business_id', 'theme_id', 'status', 'expiry_date', 'created_at', 'updated_at'], 'integer'],
[['domain_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 = website::find();
$dataProvider = new ActiveDataProvider([
'query' => $query,
]);
if (!($this->load($params) && $this->validate())) {
return $dataProvider;
}
$query->andFilterWhere([
'id' => $this->id,
'business_id' => $this->business_id,
'theme_id' => $this->theme_id,
'status' => $this->status,
'expiry_date' => $this->expiry_date,
'created_at' => $this->created_at,
'updated_at' => $this->updated_at,
]);
$query->andFilterWhere(['like', 'domain_name', $this->domain_name]);
return $dataProvider;
}
}
<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>
<?php
use yii\helpers\Html;
use yii\bootstrap\ActiveForm;
/* @var $this yii\web\View */
/* @var $model common\models\website */
/* @var $form yii\bootstrap\ActiveForm */
?>
<div class="website-form">
<?php $form = ActiveForm::begin(); ?>
<?= $form->errorSummary($model); ?>
<div class="row">
<div class="col-md-4">
<?= $form->field($model, 'business_id')->textInput() ?>
</div>
</div>
<div class="row">
<div class="col-md-4">
<?= $form->field($model, 'theme_id')->textInput() ?>
</div>
</div>
<div class="row">
<div class="col-md-4">
<?= $form->field($model, 'domain_name')->textInput(['maxlength' => true]) ?>
</div>
</div>
<div class="row">
<div class="col-md-4">
<?= $form->field($model, 'status')->dropDownList($model::statuses()) ?>
</div>
</div>
<div class="form-group">
<?= Html::submitButton($model->isNewRecord ? Yii::t('backend', 'Create') : Yii::t('backend', 'Update'),
['class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary']) ?>
</div>
<?php ActiveForm::end(); ?>
</div>
<?php
use yii\helpers\Html;
use yii\bootstrap\ActiveForm;
/* @var $this yii\web\View */
/* @var $model backend\modules\website\models\search\WebsiteSearch */
/* @var $form yii\bootstrap\ActiveForm */
?>
<div class="website-search">
<?php $form = ActiveForm::begin([
'action' => ['index'],
'method' => 'get',
]); ?>
<?= $form->field($model, 'id') ?>
<?= $form->field($model, 'business_id') ?>
<?= $form->field($model, 'theme_id') ?>
<?= $form->field($model, 'domain_name') ?>
<?= $form->field($model, 'status') ?>
<?php // echo $form->field($model, 'expiry_date') ?>
<?php // echo $form->field($model, 'created_at') ?>
<?php // echo $form->field($model, 'updated_at') ?>
<div class="form-group">
<?= Html::submitButton(Yii::t('backend', 'Search'), ['class' => 'btn btn-primary']) ?>
<?= Html::resetButton(Yii::t('backend', 'Reset'), ['class' => 'btn btn-default']) ?>
</div>
<?php ActiveForm::end(); ?>
</div>
<?php
use yii\helpers\Html;
/* @var $this yii\web\View */
/* @var $model common\models\website */
$this->title = Yii::t('backend', 'Create {modelClass}', [
'modelClass' => 'Website',
]);
$this->params['breadcrumbs'][] = ['label' => Yii::t('backend', 'Websites'), 'url' => ['index']];
$this->params['breadcrumbs'][] = $this->title;
?>
<div class="website-create">
<?= $this->render('_form', [
'model' => $model,
]) ?>
</div>
<?php
use yii\helpers\Html;
use yii\grid\GridView;
/* @var $this yii\web\View */
/* @var $searchModel backend\modules\website\models\search\WebsiteSearch */
/* @var $dataProvider yii\data\ActiveDataProvider */
$this->title = Yii::t('backend', 'Websites');
$this->params['breadcrumbs'][] = $this->title;
?>
<div class="website-index">
<?php // echo $this->render('_search', ['model' => $searchModel]); ?>
<p>
<?= Html::a(Yii::t('backend', 'Create {modelClass}', [
'modelClass' => 'Website',
]), ['create'], ['class' => 'btn btn-success']) ?>
</p>
<?= GridView::widget([
'dataProvider' => $dataProvider,
'filterModel' => $searchModel,
'columns' => [
['class' => 'yii\grid\SerialColumn'],
//'id',
'business_id',
'theme_id',
'domain_name',
[
'class'=>\common\grid\EnumColumn::className(),
'attribute'=>'status',
'enum'=>[
Yii::t('backend', 'In Active'),
Yii::t('backend', 'Active')
],
],
'expiry_date:datetime',
// 'created_at',
// 'updated_at',
['class' => 'yii\grid\ActionColumn',
'template' => '{update}{delete}'],
],
]); ?>
</div>
<?php
use yii\helpers\Html;
/* @var $this yii\web\View */
/* @var $model common\models\website */
$this->title = Yii::t('backend', 'Update {modelClass}: ', [
'modelClass' => 'Website',
]) . ' ' . $model->id;
$this->params['breadcrumbs'][] = ['label' => Yii::t('backend', 'Websites'), 'url' => ['index']];
$this->params['breadcrumbs'][] = ['label' => $model->id, 'url' => ['view', 'id' => $model->id]];
$this->params['breadcrumbs'][] = Yii::t('backend', 'Update');
?>
<div class="website-update">
<?= $this->render('_form', [
'model' => $model,
]) ?>
</div>
<?php
use yii\helpers\Html;
use yii\widgets\DetailView;
/* @var $this yii\web\View */
/* @var $model common\models\website */
$this->title = $model->id;
$this->params['breadcrumbs'][] = ['label' => Yii::t('backend', 'Websites'), 'url' => ['index']];
$this->params['breadcrumbs'][] = $this->title;
?>
<div class="website-view">
<p>
<?= Html::a(Yii::t('backend', 'Update'), ['update', 'id' => $model->id], ['class' => 'btn btn-primary']) ?>
<?= Html::a(Yii::t('backend', 'Delete'), ['delete', 'id' => $model->id], [
'class' => 'btn btn-danger',
'data' => [
'confirm' => Yii::t('backend', 'Are you sure you want to delete this item?'),
'method' => 'post',
],
]) ?>
</p>
<?= DetailView::widget([
'model' => $model,
'attributes' => [
'id',
'business_id',
'theme_id',
'domain_name',
'status',
'expiry_date',
'created_at',
'updated_at',
],
]) ?>
</div>
......@@ -208,6 +208,12 @@ $bundle = BackendAsset::register($this);
'visible' => Yii::$app->user->can('administrator')
],
[
'label' => Yii::t('backend', 'Website'),
'icon' => '<i class="fa fa-globe"></i>',
'url' => ['/website/website'],
'visible' => Yii::$app->user->can('administrator')
],
[
'label' => Yii::t('backend', 'Location'),
'icon' => '<i class="fa fa-map"></i>',
'url' => '#',
......
......@@ -38,7 +38,8 @@ class m160831_092919_business extends Migration
$this->createIndex('idx_business_domain_name', '{{%business}}', 'domain_name');
$this->createIndex('idx_business_email', '{{%business}}', 'email');
$this->addForeignKey('fk_category_id', '{{%business}}', 'category_id', '{{%category}}', 'id', 'RESTRICT', 'RESTRICT');
$this->addForeignKey('fk_category_id', '{{%business}}', 'category_id', '{{%category}}', 'id', 'RESTRICT',
'RESTRICT');
$this->addForeignKey('fk_district_id', '{{%business}}', 'district_id', '{{%district}}', 'id', 'RESTRICT', 'RESTRICT');
}
......
<?php
use yii\db\Migration;
class m160907_100248_website extends Migration
{
public function safeUp()
{
$tableOptions = null;
if ($this->db->driverName === 'mysql') {
$tableOptions = 'CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE=InnoDB';
}
$this->createTable('{{%website}}', [
'id' => $this->primaryKey(),
'business_id' => $this->integer(),
'theme_id' => $this->integer(),
'domain_name' => $this->string(255)->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');
}
public function safeDown()
{
$this->dropForeignKey('fk_theme_id', '{{%website}}');
$this->dropIndex('idx_domain_name', '{{%website}}');
$this->dropTable('{{%website}}');
}
}
<?php
namespace common\models;
use Yii;
use yii\behaviors\TimestampBehavior;
/**
* This is the model class for table "{{%website}}".
*
* @property integer $id
* @property integer $business_id
* @property integer $theme_id
* @property string $domain_name
* @property integer $status
* @property integer $expiry_date
* @property integer $created_at
* @property integer $updated_at
*
* @property Theme $theme
*/
class Website extends \yii\db\ActiveRecord
{
const STATUS_ACTIVE = 1;
const STATUS_IN_ACTIVE = 0;
/**
* @inheritdoc
*/
public static function tableName()
{
return '{{%website}}';
}
public function behaviors()
{
return [
[
'class' => TimestampBehavior::className(),
'createdAtAttribute' => 'created_at',
'updatedAtAttribute' => 'updated_at'
]
];
}
/**
* @inheritdoc
*/
public function rules()
{
return [
[['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']],
];
}
/**
* @inheritdoc
*/
public function attributeLabels()
{
return [
'id' => Yii::t('common', 'ID'),
'business_id' => Yii::t('common', 'Business ID'),
'theme_id' => Yii::t('common', 'Theme ID'),
'domain_name' => Yii::t('common', 'Domain Name'),
'status' => Yii::t('common', 'Status'),
'expiry_date' => Yii::t('common', 'Expiry Date'),
'created_at' => Yii::t('common', 'Created At'),
'updated_at' => Yii::t('common', 'Updated At'),
];
}
/**
* @return \yii\db\ActiveQuery
*/
public function getTheme()
{
return $this->hasOne(Theme::className(), ['id' => 'theme_id']);
}
/**
* @inheritdoc
* @return \common\models\query\WebsiteQuery the active query used by this AR class.
*/
public static function find()
{
return new \common\models\query\WebsiteQuery(get_called_class());
}
/**
* @return array
* status drop down list used in view
*/
public static function statuses()
{
return [
self::STATUS_ACTIVE => Yii::t('common', 'Active'),
self::STATUS_IN_ACTIVE => Yii::t('common', 'In Active'),
];
}
}
<?php
namespace common\models\query;
/**
* This is the ActiveQuery class for [[\common\models\Website]].
*
* @see \common\models\Website
*/
class WebsiteQuery extends \yii\db\ActiveQuery
{
/*public function active()
{
return $this->andWhere('[[status]]=1');
}*/
/**
* @inheritdoc
* @return \common\models\Website[]|array
*/
public function all($db = null)
{
return parent::all($db);
}
/**
* @inheritdoc
* @return \common\models\Website|array|null
*/
public function one($db = null)
{
return parent::one($db);
}
}
......@@ -6,26 +6,46 @@ use yii\helpers\Html;
use yii\helpers\Json;
use yii\helpers\ArrayHelper;
/*
* this widget can be used when a user have to tel his location details,
* this widget will display the google map and it provides search place option
*/
class PlacePicker extends InputWidget
{
/*
* @var string , variable to store the id of latitude input field
*/
public $latitudeFieldId;
/*
* @var string , variable to store the id of longitude input field
*/
public $longitudeFieldId;
/*
* @var string , variable to store the name of map canvas input field
*/
public $name;
/*
* array, which binds all client options in to single array
*/
public $clientOptions = [];
/*
* @var num, this variable is used to generate random number
* which can be used for generating unique place search field
*/
public $randNumber;
public function init()
{
MapAsset::register($this->view);
parent::init();
$randNumber = rand(1,100);
$randNumber = rand(1, 100);
$this->clientOptions = ArrayHelper::merge(
[
'latitudeFieldId' => $this->latitudeFieldId,
'longitudeFieldId' => $this->longitudeFieldId,
'mapName' => $this->name,
'searchTextField' => 'searchTextField'.$randNumber
'searchTextField' => 'searchTextField' . $randNumber
],
$this->clientOptions
......
......@@ -4,17 +4,20 @@
(function ($) {
jQuery.fn.yiiMapKit = function (options) {
var inputLatitude = options.latitudeFieldId,
inputLongitude = options.longitudeFieldId,
map_canvas = options.mapName,
searchTextField = options.searchTextField,
image = 'http://www.google.com/intl/en_us/mapfiles/ms/micons/red-dot.png';
var methods = {
init: function () {
var inputLatitude = options.latitudeFieldId;
var inputLongitude = options.longitudeFieldId;
var map_canvas = options.mapName;
var searchTextField = options.searchTextField;
var lat = $('#'+inputLatitude).val(),
lng = $('#'+inputLongitude).val(),
image = 'http://www.google.com/intl/en_us/mapfiles/ms/micons/red-dot.png';
if (!lat && !lng) {
var lat = $('#' + inputLatitude).val(),
lng = $('#' + inputLongitude).val();
if
(!lat && !lng)
{
lat = 10.5113798;
lng = 76.1532094;
}
......@@ -62,12 +65,12 @@
map.setZoom(17);
}
moveMarker(place.name, place.geometry.location);
$('#'+inputLatitude).val(place.geometry.location.lat());
$('#'+inputLongitude).val(place.geometry.location.lng());
$('#' + inputLatitude).val(place.geometry.location.lat());
$('#' + inputLongitude).val(place.geometry.location.lng());
});
google.maps.event.addListener(map, 'click', function (event) {
$('#'+inputLatitude).val(event.latLng.lat());
$('#'+inputLongitude).val(event.latLng.lng());
$('#' + inputLatitude).val(event.latLng.lat());
$('#' + inputLongitude).val(event.latLng.lng());
infowindow.close();
var geocoder = new google.maps.Geocoder();
geocoder.geocode({
......@@ -81,25 +84,25 @@
placeName = results[0].address_components[0].long_name,
latlng = new google.maps.LatLng(lat, lng);
moveMarker(placeName, latlng);
$("#"+searchTextField).val(results[0].formatted_address);
$("#" + searchTextField).val(results[0].formatted_address);
}
});
});
google.maps.event.addListener(marker, 'click', function (event) {
$('#'+inputLatitude).val(event.latLng.lat());
$('#'+inputLongitude).val(event.latLng.lng());
$('#' + inputLatitude).val(event.latLng.lat());
$('#' + inputLongitude).val(event.latLng.lng());
infowindow.close();
});
google.maps.event.addListener(marker, 'dragend', function (event) {
$('#'+inputLatitude).val(event.latLng.lat());
$('#'+inputLongitude).val(event.latLng.lng());
$('#' + inputLatitude).val(event.latLng.lat());
$('#' + inputLongitude).val(event.latLng.lng());
infowindow.close();
});
$('#'+inputLatitude).bind('input', function () {
$('#' + inputLatitude).bind('input', function () {
methods.init();
infowindow.close();
});
$('#'+inputLongitude).bind('input', function () {
$('#' + inputLongitude).bind('input', function () {
methods.init();
infowindow.close();
});
......@@ -113,9 +116,7 @@
};
methods.init.apply(this);
return this;
};
})(jQuery);
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