Commit 13cf417b by dianc

Merge remote-tracking branch 'origin/development' into development

parents 45d0743a 687b4661
......@@ -3,6 +3,7 @@
use yii\helpers\Html;
use yii\widgets\ActiveForm;
use common\widgets\PlacePicker\PlacePicker;
use trntv\filekit\widget\Upload;
/* @var $this yii\web\View */
/* @var $model common\models\Business */
......@@ -111,14 +112,13 @@ use common\widgets\PlacePicker\PlacePicker;
<div class="row">
<div class="col-md-4">
<?= $form->field($model, 'logo_base_url')->textInput(['maxlength' => true]) ?>
</div>
</div>
<div class="row">
<div class="col-md-4">
<?= $form->field($model, 'logo_path')->textInput(['maxlength' => true]) ?>
<?= $form->field($model, 'logo')->widget(
Upload::className(),
[
'url' => ['/file-storage/upload'],
'maxFileSize' => 5000000, // 5 MiB
]);
?>
</div>
</div>
......
......@@ -5,6 +5,7 @@ namespace common\models;
use Yii;
use yii\behaviors\SluggableBehavior;
use yii\behaviors\TimestampBehavior;
use trntv\filekit\behaviors\UploadBehavior;
/**
* This is the model class for table "{{%business}}".
......@@ -40,6 +41,11 @@ class Business extends \yii\db\ActiveRecord
const STATUS_IN_ACTIVE = 0;
/**
* @var array
*/
public $logo;
/**
* @inheritdoc
*/
public static function tableName()
......@@ -63,6 +69,12 @@ class Business extends \yii\db\ActiveRecord
'class' => TimestampBehavior::className(),
'createdAtAttribute' => 'created_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
[['landmark'], 'string', 'max' => 500],
[['contact_no'], 'string', 'max' => 150],
[['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;
use Yii;
use yii\behaviors\TimestampBehavior;
use MongoDB\BSON\UTCDatetime;
/**
* This is the model class for table "{{%website}}".
......@@ -50,7 +49,7 @@ 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],
[
......@@ -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)
{
if (parent::beforeSave($insert)) {
//setting expiry date to 1 year
$expiry_date = date('Y-m-d', strtotime('+1 years'));
$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;
} else {
return false;
......
<?php
namespace frontend\controllers;
use common\models\Website;
use Yii;
use frontend\models\ContactForm;
use yii\web\Controller;
use yii\httpclient\Client;
use yii\db\Query;
/**
* Site controller
......@@ -33,18 +35,16 @@ class SiteController extends Controller
public function actionIndex()
{
$domain = $_SERVER['HTTP_HOST'];
$website = Website::find()->where(['domain_name' =>$domain])->one();
$businessId = $website->business_id;
$client = new Client();
$response = $client->createRequest()
->setMethod('get')
->setUrl('http://libromi.com/api/v1/business/view')
->setData(['id' => '3997'])
->setData(['id' => $businessId])
->send();
// echo '<pre>';
// var_dump($response);
// echo '</pre>';
// exit;
$data = $response->isOk ? $response->data : [];
return $this->render('index', ['data' => $data]);
}
......
<?php
/* @var $this yii\web\View */
/* @var $data array*/
$this->title = Yii::$app->name;
?>
<div class="site-index">
<?php
print_r($data);
?>
<?php echo 'Name :'.$data['name']; ?>
<br>
<?php echo 'Email :'.$data['email']; ?>
</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