public function actionEdit($id = null)
 {
     $model = new PrefilteredPages();
     $model->loadDefaultValues();
     if ($id !== null) {
         $model = PrefilteredPages::findOne($id);
     }
     $static_values_properties = [];
     $property_groups_ids_for_object = (new Query())->select('id')->from(PropertyGroup::tableName())->where(['object_id' => Object::getForClass(Product::className())->id])->column();
     $properties = Property::find()->andWhere(['in', 'property_group_id', $property_groups_ids_for_object])->all();
     foreach ($properties as $prop) {
         /** @var Property $prop */
         $static_values_properties[$prop->id] = ['property' => $prop, 'static_values_select' => PropertyStaticValues::getSelectForPropertyId($prop->id), 'has_static_values' => $prop->has_static_values === 1];
     }
     $post = \Yii::$app->request->post();
     if ($model->load($post) && $model->validate()) {
         $save_result = $model->save();
         if ($save_result) {
             Yii::$app->session->setFlash('info', Yii::t('app', 'Object saved'));
             $returnUrl = Yii::$app->request->get('returnUrl', ['index', 'id' => $model->id]);
             switch (Yii::$app->request->post('action', 'save')) {
                 case 'next':
                     return $this->redirect(['edit', 'returnUrl' => $returnUrl]);
                 case 'back':
                     return $this->redirect($returnUrl);
                 default:
                     return $this->redirect(Url::toRoute(['edit', 'id' => $model->id, 'returnUrl' => $returnUrl]));
             }
             //return $this->redirect(['/backend/prefiltered-pages/edit', 'id' => $model->id]);
         } else {
             \Yii::$app->session->setFlash('error', Yii::t('app', 'Cannot update data'));
         }
     }
     return $this->render('prefiltered-page-form', ['model' => $model, 'static_values_properties' => $static_values_properties]);
 }
 public function actionEdit($id = null)
 {
     $model = new DynamicContent();
     $model->loadDefaultValues();
     if ($id !== null) {
         $model = DynamicContent::findOne($id);
     }
     $static_values_properties = [];
     if (isset($_GET['DynamicContent'])) {
         if (isset($_GET['DynamicContent']['object_id'])) {
             $model->object_id = intval($_GET['DynamicContent']['object_id']);
         }
     }
     $property_groups_ids_for_object = (new Query())->select('id')->from(PropertyGroup::tableName())->where([])->column();
     $properties = Property::find()->where(['has_static_values' => 1, 'has_slugs_in_values' => 1])->andWhere(['in', 'property_group_id', $property_groups_ids_for_object])->all();
     foreach ($properties as $prop) {
         $static_values_properties[$prop->id] = ['has_static_values' => true, 'property' => $prop, 'static_values_select' => PropertyStaticValues::getSelectForPropertyId($prop->id)];
     }
     $post = \Yii::$app->request->post();
     if (isset($_GET['DynamicContent'])) {
         $post = $_GET;
     }
     if ($model->load($post) && $model->validate() && !isset($_GET['DynamicContent'])) {
         $save_result = $model->save();
         if ($save_result) {
             return $this->redirectUser($model->id);
         } else {
             \Yii::$app->session->setFlash('error', Yii::t('app', 'Cannot update data'));
         }
     }
     return $this->render('dynamic-content-form', ['model' => $model, 'static_values_properties' => $static_values_properties]);
 }
 /**
  * Update the specified resource in storage.
  *
  * @param  \Illuminate\Http\Request $request
  * @param  int $id
  * @return \Illuminate\Http\Response
  */
 public function update(Request $request, $id)
 {
     $model = Property::find($id);
     $model->DataSourceId = $request->input("DataSourceId");
     $model->DataId = $request->input("DataId");
     $model->ReferenceUrl = $request->input("ReferenceUrl");
     $model->PhotoUrls = $request->input("PhotoUrls");
     $model->MLSNumber = $request->input("MLSNumber");
     $model->Status = $request->input("Status");
     $model->StatusEnum = $request->input("StatusEnum");
     $model->SaleType = $request->input("SaleType");
     $model->SaleTypeEnum = $request->input("SaleTypeEnum");
     $model->PropertyType = $request->input("PropertyType");
     $model->PropertyTypeEnum = $request->input("PropertyTypeEnum");
     $model->ListPrice = $request->input("ListPrice");
     $model->SalePrice = $request->input("SalePrice");
     $model->State = $request->input("State");
     $model->County = $request->input("County");
     $model->City = $request->input("City");
     $model->Address = $request->input("Address");
     $model->PostalCode = $request->input("PostalCode");
     $model->Area = $request->input("Area");
     $model->CrossStreets = $request->input("CrossStreets");
     $model->Location = $request->input("Location");
     $model->Description = $request->input("Description");
     $model->YearBuilt = $request->input("YearBuilt");
     $model->LotSqFt = $request->input("LotSqFt");
     $model->StructureSqFt = $request->input("StructureSqFt");
     $model->Bedrooms = $request->input("Bedrooms");
     $model->BathsFull = $request->input("BathsFull");
     $model->BathsHalf = $request->input("BathsHalf");
     //        PropertyBiz::update($model);
     $model->save();
     return Redirect::to('properties');
 }
 public function up()
 {
     $this->insert('{{%theme_active_widgets}}', ['part_id' => 5, 'widget_id' => 5, 'variation_id' => 2]);
     $propertyId1 = \app\models\Property::find()->where(['key' => 'tip_pamyati'])->select('id')->scalar();
     $propertyId2 = \app\models\Property::find()->where(['key' => 'tip_ekrana'])->select('id')->scalar();
     $this->insert('{{%filter_sets}}', ['category_id' => 3, 'sort_order' => 2, 'property_id' => $propertyId2]);
     $this->insert('{{%filter_sets}}', ['category_id' => 3, 'sort_order' => 1, 'property_id' => $propertyId1]);
 }
示例#5
0
 /**
  *
  * @return Response
  */
 public function show($id)
 {
     $owner = Owner::findOrFail($id);
     $owner->Properties = $owner->Properties;
     foreach ($owner->Properties as $property) {
         $allTransactions = Property::find($property->id)->allTransactions();
         $property->transactions = $allTransactions;
     }
     return \Response::json(['success' => true, 'message' => 'Owners Loaded.', 'data' => $owner]);
 }
示例#6
0
 /**
  * @return mixed
  */
 public function store()
 {
     $input = \Request::all();
     $validator = \Validator::make($input, ['property_id' => 'required', 'unit_name' => 'required|max:255']);
     if ($validator->fails()) {
         \App::abort(400, $validator->messages()->first());
     }
     $unit = new Unit($input);
     $property = Property::find($input['property_id']);
     $unit = $property->Units()->save($unit);
     return \Response::json(['success' => true, 'message' => 'Unit Created.', 'data' => $unit]);
 }
示例#7
0
 private function prepareProperties()
 {
     $props = Property::getDb()->cache(function ($db) {
         return Property::find()->select('id, name, property_handler_id, key, property_group_id, has_static_values, is_eav, handler_additional_params')->all();
     }, 86400, new TagDependency(['tags' => [ActiveRecordHelper::getCommonTag(Property::className())]]));
     foreach ($props as $one) {
         $additionalParams = Json::decode($one['handler_additional_params']);
         if (false === empty($additionalParams['use_in_file'])) {
             if (1 == $one['is_eav'] && false === isset(self::$ymlEavProperties[$one['id']])) {
                 self::$ymlEavProperties[$one['id']] = ['name' => $one['name'], 'unit' => empty($additionalParams['unit']) ? '' : $additionalParams['unit'], 'key' => $one['key'], 'group_id' => $one['property_group_id'], 'handler_id' => $one['property_handler_id']];
             } else {
                 if (1 == $one['has_static_values'] && false === isset(self::$ymlStaticProperties[$one['id']])) {
                     self::$ymlStaticProperties[$one['id']] = ['name' => $one['name'], 'unit' => empty($additionalParams['unit']) ? '' : $additionalParams['unit']];
                 }
             }
         }
     }
 }
 public function up()
 {
     $objects = \app\models\Object::find()->asArray()->all();
     foreach ($objects as $object) {
         if ($object['name'] == 'Submission') {
             continue;
         } else {
             if ($object['name'] == 'Form') {
                 $submissionObject = \app\models\Object::findOne(['name' => 'Submission']);
                 $this->addColumn($object['eav_table_name'], 'property_group_id', 'INT UNSIGNED NOT NULL AFTER `object_model_id`');
                 $this->addColumn($submissionObject->eav_table_name, 'property_group_id', 'INT UNSIGNED NOT NULL AFTER `object_model_id`');
                 $groups = \app\models\PropertyGroup::find()->where(['object_id' => $object['id']])->asArray()->all();
                 foreach ($groups as $group) {
                     $forms = \app\models\ObjectPropertyGroup::find()->select('object_model_id')->where(['property_group_id' => $group['id']])->asArray()->all();
                     $formIDs = [];
                     foreach ($forms as $formID) {
                         if (!in_array($formID['object_model_id'], $formIDs)) {
                             $formIDs[] = $formID['object_model_id'];
                         }
                     }
                     $submissionIDs = \app\models\Submission::find()->select('id')->where(['form_id' => $formIDs])->asArray()->all();
                     $subIDs = [];
                     foreach ($submissionIDs as $submission) {
                         $subIDs[] = $submission['id'];
                     }
                     $properties = \app\models\Property::find()->select(['id', 'key'])->where(['property_group_id' => $group['id'], 'is_eav' => 1])->asArray()->all();
                     foreach ($properties as $property) {
                         $this->update($submissionObject->eav_table_name, ['property_group_id' => $group['id']], ['key' => $property['key']]);
                     }
                 }
             } else {
                 $this->addColumn($object['eav_table_name'], 'property_group_id', 'INT UNSIGNED NOT NULL AFTER `object_model_id`');
                 $groups = \app\models\PropertyGroup::find()->where(['object_id' => $object['id']])->asArray()->all();
                 foreach ($groups as $group) {
                     $properties = \app\models\Property::find()->select(['id', 'key'])->where(['property_group_id' => $group['id'], 'is_eav' => 1])->asArray()->all();
                     foreach ($properties as $property) {
                         $this->update($object['eav_table_name'], ['property_group_id' => $group['id']], ['key' => $property['key']]);
                     }
                 }
             }
         }
     }
 }
示例#9
0
 protected static function getRelation($model, $relationName, $default_value = '')
 {
     $result = $default_value;
     $relation = self::$modelSetting->{$relationName};
     if ($relation['type'] === 'field' && !empty($relation['key'])) {
         try {
             $result = $model->{$relation['key']};
         } catch (Exception $e) {
         }
     } elseif ($relation['type'] === 'property' && !empty($relation['key'])) {
         try {
             $propertyKey = Property::find()->select('key')->where(['id' => $relation['key']])->asArray()->scalar();
             $result = $model->property($propertyKey);
         } catch (Exception $e) {
         }
     } elseif ($relation['type'] === 'relation' && !empty($relation['key']) && !empty($relation['value'])) {
         $relModel = $model->{$relation['key']}();
         $result = $relModel->{$relation}['value'];
     }
     return $result;
 }
示例#10
0
 public function actionRemoveAllGroups()
 {
     $items = Yii::$app->request->post('items', []);
     if (!empty($items)) {
         $items = PropertyGroup::find()->where(['in', 'id', $items])->all();
         foreach ($items as $item) {
             $properties = Property::find()->where(['property_group_id' => $item->id])->all();
             foreach ($properties as $prop) {
                 $prop->delete();
             }
             $item->delete();
         }
     }
     return $this->redirect(['index']);
 }
示例#11
0
 /**
  * loopnet.com需要美国ip才能访问,所以使用代理服务器
  * 免费代理:http://www.xicidaili.com/wt/
  * @param $url
  * @return mixed
  * @throws FunFangException
  */
 public static function parseLoopnetProperty($url)
 {
     if (!$url) {
         return null;
     }
     $dataSourceId = 1000;
     $html = new \simple_html_dom();
     $httpClient = new GuzzleHttp\Client();
     try {
         $content = $httpClient->get($url, ['proxy' => 'tcp://108.61.218.68:8888', 'timeout' => 30])->getBody()->getContents();
     } catch (GuzzleHttp\Exception\RequestException $e) {
         throw new FunFangException("访问 {$url} 时出错!" . $e->getMessage());
     }
     $html->load($content);
     //对该页面进行简单的检查,判断是否有DataId
     $dataIdWrapper = $html->find('.property-timestamp', 0);
     if (!$dataIdWrapper) {
         throw new FunFangException('您输入的URL可能不正确,解析失败!');
     }
     $dataId = $dataIdWrapper->find('td', 0)->plaintext;
     $dataId = str_replace(' ', '', $dataId);
     $dataId = str_replace('ListingID:', '', $dataId);
     if (!$dataId) {
         throw new FunFangException('未找到房源ID!');
     }
     //先从数据库中查找
     if ($dataId) {
         $record = Property::where('DataSourceId', $dataSourceId)->where('DataId', $dataId)->first();
         if ($record) {
             return $record;
         }
     }
     //如果数据库中没有记录,从html中解析并保存到数据库
     //只采集特定类型房源
     $record = new Property();
     $record->DataSourceId = $dataSourceId;
     $record->DataId = trim($dataId);
     $record->ReferenceUrl = $url;
     $propertyTds = $html->find('.property-data', 0)->find('td');
     for ($i = 0; $i < count($propertyTds); $i = $i + 2) {
         $dataType = trim($propertyTds[$i]->plaintext);
         $dataValue = trim($propertyTds[$i + 1]->plaintext);
         if (StringUtil::equalsIgnoreCase('Price', $dataType)) {
             //价格
             $record->ListPrice = str_replace(',', '', str_replace('$', '', $dataValue));
         } else {
             if (StringUtil::equalsIgnoreCase('Property Type', $dataType)) {
                 //房产类型
                 //指定采集的房源类型
                 $specTypes = ['Multifamily', 'Office', 'Industrial', 'Land', 'Residential Income'];
                 if (!in_array($dataValue, $specTypes)) {
                     throw new FunFangException('暂不采集该类型的房源!');
                 }
                 $propertyTypeEnum = Util::getPropertyTypeEnum($dataValue);
                 if ($propertyTypeEnum) {
                     $record->PropertyType = $propertyTypeEnum['name'];
                     $record->PropertyTypeEnum = $propertyTypeEnum['value'];
                 }
             } else {
                 if (StringUtil::equalsIgnoreCase('Lot Size', $dataType)) {
                     //土地面积
                     $lotSqFt = str_ireplace('AC', '', $dataValue);
                     $lotSqFt = str_replace(' ', '', $lotSqFt);
                     $lotSqFt = $lotSqFt * 43560;
                     $record->LotSqFt = $lotSqFt;
                 } else {
                     if (StringUtil::equalsIgnoreCase('Building Size', $dataType)) {
                         //建筑面积
                         $structureSqFt = str_ireplace('SF', '', $dataValue);
                         $structureSqFt = str_ireplace(' ', '', $structureSqFt);
                         $structureSqFt = str_ireplace(',', '', $structureSqFt);
                         $record->StructureSqFt = $structureSqFt;
                     }
                 }
             }
         }
     }
     $addressStr = $html->find('.basic-info', 0)->find('h1', 0)->plaintext;
     $addressStr = str_replace('·', '', $addressStr);
     $addressRes = $httpClient->get('http://maps.googleapis.com/maps/api/geocode/json?address=' . $addressStr);
     $addressJson = json_decode($addressRes->getBody()->getContents());
     if ($addressJson->status == 'OK') {
         $addressObj = GoogleGeoHelper::getAddress($addressJson->results);
     }
     if ($addressObj) {
         $record->State = $addressObj->state;
         $record->County = $addressObj->county;
         $record->City = $addressObj->city;
         $record->Address = "{$addressObj->streetNumber} {$addressObj->street}";
         $record->PostalCode = $addressObj->postalCode;
         //$record->Location = DB::raw("GeomFromText('POINT($addressObj->lng $addressObj->lat)')");
         $record->Location = "{$addressObj->lng},{$addressObj->lat}";
     }
     $record->Description = $html->find('.description', 0)->find('.row', 1)->plaintext;
     //描述
     $photos = $html->find('.carousel-wrapper', 0)->find('.carousel-inner', 0)->find('img');
     //照片
     $photoUrls = [];
     foreach ($photos as $photo) {
         if ($photo->src) {
             array_push($photoUrls, $photo->src);
         } else {
             array_push($photoUrls, $photo->getAttribute('lazy-src'));
         }
     }
     $record->PhotoUrls = implode(',', $photoUrls);
     $record->save();
     $html->clear();
     $newRecord = Property::find($record->Id);
     return $newRecord;
 }
示例#12
0
 public function postAddRoom(Request $request)
 {
     if (Session::get('member')->property_id != null) {
         if (Session::get('member')->type > 1) {
             return redirect()->back()->withErrors(['คุณไม่มีสิทธิ์เข้าใช้งานส่วนนี้'])->withInput();
         }
     }
     $messages = ['code.required' => 'กรุณาใส่รหัสห้อง', 'name.required' => 'กรุณาใส่ชื่อห้อง', 'price.required' => 'กรุณาใส่ราคาห้อง', 'description.required' => 'กรุณาอธิบายห้องของคุณ'];
     $validator = Validator::make($request->all(), ['code' => 'required', 'name' => 'required', 'price' => 'required', 'description' => 'required'], $messages);
     if ($validator->fails()) {
         return redirect()->back()->withErrors($validator)->withInput();
     }
     $property = \App\Models\Property::find(Session::get('property')->id);
     $room = new \App\Models\Room();
     $room->code = $request->code;
     $room->name = $request->name;
     $room->price = $request->price;
     $room->description = $request->description;
     $property->rooms()->save($room);
     return redirect('/property/add-room');
 }
示例#13
0
/*
 * As you can see this is just a simple yii2 view file with several additional variables available
 *
 * For content rendering use $this->blocks!
 */
/**
 * @var \app\components\WebView $this
 * @var $breadcrumbs array
 * @var $model \app\modules\page\models\Page
 */
$this->params['breadcrumbs'] = $breadcrumbs;
use yii\helpers\Html;
// we need id of property that is related to todays-deals
// in production it is better to fill it statically in your template for better performance
$propertyId = \app\models\Property::getDb()->cache(function ($db) {
    return \app\models\Property::find()->where(['key' => 'todays_deals'])->select('id')->scalar($db);
}, 86400, new \yii\caching\TagDependency(['tags' => [\devgroup\TagDependencyHelper\ActiveRecordHelper::getCommonTag(\app\models\Property::className())]]));
?>

<div class="container rows-padding-top-bottom-20">
    <div class="row">
        <div class="col-md-12">
            <h1 class="text-center">
                <?php 
echo isset($this->blocks['h1']) ? $this->blocks['h1'] : Yii::t('app', 'Today\'s deals');
?>
            </h1>
            <!-- here we use ProductsWidget to show the same products as in Today's deal prefiltered page -->
            <?php 
if (intval($propertyId) > 0) {
    ?>
示例#14
0
 public function view($id)
 {
     $property = Property::find($id);
     $images = Image::where('propertyId', $property->id)->get();
     return view('property.view')->with('name', Auth::user()->name)->with('propertyName', $property->name)->with('propertyLocation', $property->location)->with('images', $images);
 }