Commit 5bf8bf66 by Junaid Rahman pv

modified business module and website module, added domain creation feature

parent d29c487c
...@@ -3,6 +3,7 @@ ...@@ -3,6 +3,7 @@
use yii\helpers\Html; use yii\helpers\Html;
use yii\widgets\ActiveForm; use yii\widgets\ActiveForm;
use common\widgets\PlacePicker\PlacePicker; use common\widgets\PlacePicker\PlacePicker;
use trntv\filekit\widget\Upload;
/* @var $this yii\web\View */ /* @var $this yii\web\View */
/* @var $model common\models\Business */ /* @var $model common\models\Business */
...@@ -111,14 +112,13 @@ use common\widgets\PlacePicker\PlacePicker; ...@@ -111,14 +112,13 @@ use common\widgets\PlacePicker\PlacePicker;
<div class="row"> <div class="row">
<div class="col-md-4"> <div class="col-md-4">
<?= $form->field($model, 'logo_base_url')->textInput(['maxlength' => true]) ?> <?= $form->field($model, 'logo')->widget(
Upload::className(),
</div> [
</div> 'url' => ['/file-storage/upload'],
<div class="row"> 'maxFileSize' => 5000000, // 5 MiB
<div class="col-md-4"> ]);
?>
<?= $form->field($model, 'logo_path')->textInput(['maxlength' => true]) ?>
</div> </div>
</div> </div>
......
...@@ -5,6 +5,7 @@ namespace common\models; ...@@ -5,6 +5,7 @@ namespace common\models;
use Yii; use Yii;
use yii\behaviors\SluggableBehavior; use yii\behaviors\SluggableBehavior;
use yii\behaviors\TimestampBehavior; use yii\behaviors\TimestampBehavior;
use trntv\filekit\behaviors\UploadBehavior;
/** /**
* This is the model class for table "{{%business}}". * This is the model class for table "{{%business}}".
...@@ -40,6 +41,11 @@ class Business extends \yii\db\ActiveRecord ...@@ -40,6 +41,11 @@ class Business extends \yii\db\ActiveRecord
const STATUS_IN_ACTIVE = 0; const STATUS_IN_ACTIVE = 0;
/** /**
* @var array
*/
public $logo;
/**
* @inheritdoc * @inheritdoc
*/ */
public static function tableName() public static function tableName()
...@@ -63,6 +69,12 @@ class Business extends \yii\db\ActiveRecord ...@@ -63,6 +69,12 @@ class Business extends \yii\db\ActiveRecord
'class' => TimestampBehavior::className(), 'class' => TimestampBehavior::className(),
'createdAtAttribute' => 'created_at', 'createdAtAttribute' => 'created_at',
'updatedAtAttribute' => 'updated_at' 'updatedAtAttribute' => 'updated_at'
],
[
'class' => UploadBehavior::className(),
'attribute' => 'logo',
'pathAttribute' => 'logo_path',
'baseUrlAttribute' => 'logo_base_url'
] ]
]; ];
} }
...@@ -79,8 +91,20 @@ class Business extends \yii\db\ActiveRecord ...@@ -79,8 +91,20 @@ class Business extends \yii\db\ActiveRecord
[['landmark'], 'string', 'max' => 500], [['landmark'], 'string', 'max' => 500],
[['contact_no'], 'string', 'max' => 150], [['contact_no'], 'string', 'max' => 150],
[['latitude', 'longitude'], 'string', 'max' => 30], [['latitude', 'longitude'], 'string', 'max' => 30],
[['category_id'], 'exist', 'skipOnError' => true, 'targetClass' => Category::className(), 'targetAttribute' => ['category_id' => 'id']], [
[['district_id'], 'exist', 'skipOnError' => true, 'targetClass' => District::className(), 'targetAttribute' => ['district_id' => 'id']], ['category_id'],
'exist',
'skipOnError' => true,
'targetClass' => Category::className(),
'targetAttribute' => ['category_id' => 'id']
],
[
['district_id'],
'exist',
'skipOnError' => true,
'targetClass' => District::className(),
'targetAttribute' => ['district_id' => 'id']
],
]; ];
} }
......
...@@ -4,7 +4,6 @@ namespace common\models; ...@@ -4,7 +4,6 @@ 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}}".
...@@ -50,7 +49,7 @@ class Website extends \yii\db\ActiveRecord ...@@ -50,7 +49,7 @@ 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],
[ [
...@@ -109,11 +108,44 @@ class Website extends \yii\db\ActiveRecord ...@@ -109,11 +108,44 @@ class Website extends \yii\db\ActiveRecord
]; ];
} }
public function beforeDelete()
{
if (parent::beforeDelete()) // TODO: Change the autogenerated stub
{
$file = 'C:/Windows/System32/drivers/etc/hosts';
$contents = file_get_contents($file);
$contents = str_replace($this->domain_name, '', $contents);
file_put_contents($file, $contents);
return true;
} else {
return false;
}
}
public function beforeSave($insert) public function beforeSave($insert)
{ {
if (parent::beforeSave($insert)) { if (parent::beforeSave($insert)) {
//setting expiry date to 1 year
$expiry_date = date('Y-m-d', strtotime('+1 years')); $expiry_date = date('Y-m-d', strtotime('+1 years'));
$this->expiry_date = strtotime($expiry_date); $this->expiry_date = strtotime($expiry_date);
//writing new domain to host file
$file = 'C:/Windows/System32/drivers/etc/hosts';
$content = file_get_contents($file);
$oldData = self::findOne($this->id);
if ($this->isNewRecord) {
$domain = ' ' . $this->domain_name;
$content .= $domain;
} else {
if ($oldData->domain_name != $this->domain_name) {
$oldDomain = $oldData->domain_name;
$newDomain = $this->domain_name;
$content = str_replace("$oldDomain", "$newDomain", $content);
}
}
file_put_contents($file, $content);
return true; return true;
} else { } else {
return false; return false;
......
<?php <?php
namespace frontend\controllers; namespace frontend\controllers;
use common\models\Website;
use Yii; use Yii;
use frontend\models\ContactForm; use frontend\models\ContactForm;
use yii\web\Controller; use yii\web\Controller;
use yii\httpclient\Client; use yii\httpclient\Client;
use yii\db\Query;
/** /**
* Site controller * Site controller
...@@ -33,14 +35,18 @@ class SiteController extends Controller ...@@ -33,14 +35,18 @@ class SiteController extends Controller
public function actionIndex() public function actionIndex()
{ {
$domain = $_SERVER['HTTP_HOST'];
$website = Website::find()->where(['domain_name' =>$domain])->one();
echo 'jhsda';
$businessId = $website->business_id;
$client = new Client(); $client = new Client();
$response = $client->createRequest() $response = $client->createRequest()
->setMethod('get') ->setMethod('get')
->setUrl('http://libromi.com/api/v1/business/view') ->setUrl('http://libromi.com/api/v1/business/view')
->setData(['id' => '3997']) ->setData(['id' => $businessId])
->send(); ->send();
// echo '<pre>'; // echo '<pre>';
// var_dump($response); // echo $businessId;
// echo '</pre>'; // echo '</pre>';
// exit; // exit;
$data = $response->isOk ? $response->data : []; $data = $response->isOk ? $response->data : [];
......
<?php <?php
/* @var $this yii\web\View */ /* @var $this yii\web\View */
/* @var $data array*/
$this->title = Yii::$app->name; $this->title = Yii::$app->name;
?> ?>
<div class="site-index"> <div class="site-index">
<?php <?php echo 'Name :'.$data['name']; ?>
print_r($data); <br>
?> <?php echo 'Email :'.$data['email']; ?>
</div> </div>
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