public function actionGetRegion() { $areaCode = \yii::$app->request->get('area_code'); $depth = \yii::$app->request->get('dep'); $data = []; if (!empty($areaCode) && !empty($depth)) { $model = new Area(); $data = $model->FindAreaByCode($areaCode, $depth); } $arr['regions'] = $data; $arr['type'] = $depth; $arr['target'] = !empty($_REQUEST['target']) ? stripslashes(trim($_REQUEST['target'])) : ''; $arr['target'] = htmlspecialchars($arr['target']); exit(Json::encode($arr)); }
protected function findModel($id) { if (($model = Area::findOne($id)) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }
/** * 获得地区名称 * @return string */ public static function getAreaNameById($id) { $areaLists = \Yii::$app->cache->get('cache_area'); if (!$areaLists) { $area = Area::find()->where('1=1')->orderBy('id asc')->all(); foreach ($area as $one) { $areaLists[$one->areaID] = $one->area; } \Yii::$app->cache->set('cache_area', $areaLists); } return $areaLists[$id]; }
/** * 初始化与系统地址有关的文件缓冲 */ public static function initSysaddress() { $sysaddress = array(); //配置ID与地区匹配缓冲 $province = Province::find()->where('1=1')->orderBy('id asc')->all(); $city = City::find()->where('1=1')->orderBy('father asc,id asc')->all(); $area = Area::find()->where('1=1')->orderBy('father asc,id asc')->all(); foreach ($province as $value) { $sysaddress['province'][$value->provinceID] = $value->province; } foreach ($city as $value) { $sysaddress['city'][$value->cityID] = $value->city; } foreach ($area as $value) { $sysaddress['area'][$value->areaID] = $value->area; } //配置多级联动操作相关缓冲 $sysaddress['province_option'] = ''; foreach ($province as $value) { $sysaddress['province_option'] .= '<option value="' . $value->provinceID . '">' . $value->province . '</option>'; } $sysaddress['province_option'] = '<select name="province" class="qys_common_provice contactField requiredField">' . $sysaddress['province_option'] . '</select>'; #获得所有城市列表并按照省份排序 #先从缓冲获得数据 $i = 0; $city_list_fit = ''; foreach ($city as $value) { if ($value->father !== $i) { $city_list_fit .= '</select><select name="city" class="qys_common_city_' . $value->father . ' contactField requiredField">'; $i = $value->father; } $city_list_fit .= '<option value="' . $value->cityID . '">' . $value->city . '</option>'; } $city_list_fit .= '</select>'; $city_list_fit = substr($city_list_fit, 9); $sysaddress['city_option'] = $city_list_fit; #获得所有城市列表并按照省份排序 #先从缓冲获得数据 $i = 0; $area_list_fit = ''; foreach ($area as $value) { if ($value->father !== $i) { $area_list_fit .= '</select><select name="area" class="qys_common_area_' . $value->father . ' contactField requiredField">'; $i = $value->father; } $area_list_fit .= '<option value="' . $value->areaID . '">' . $value->area . '</option>'; } $area_list_fit .= '</select>'; $area_list_fit = substr($area_list_fit, 9); $sysaddress['area_option'] = $area_list_fit; \Yii::$app->cache->set('sys_address', $sysaddress); }
/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = Area::find(); $dataProvider = new ActiveDataProvider(['query' => $query]); $this->load($params); if (!$this->validate()) { // uncomment the following line if you do not want to return any records when validation fails // $query->where('0=1'); return $dataProvider; } $query->andFilterWhere(['id' => $this->id]); $query->andFilterWhere(['like', 'location', $this->location])->andFilterWhere(['like', 'city', $this->city]); return $dataProvider; }
public function getShipingAreaList($shipping_id, $page = 1, $pageSize = 10) { $q = (new yii\db\Query())->select('*')->from(self::tableName()); if ($shipping_id) { $q->where(['id' => $shipping_id]); } $pages = new Pagination(['totalCount' => $q->count(), 'defaultPageSize' => $pageSize]); $result = $q->offset($pages->offset)->limit($pages->limit)->all(); $list = []; foreach ($result as $key => $row) { $sql = "SELECT r.area_name FROM " . AreaRegion::tableName() . " AS a, " . Area::tableName() . " AS r " . " WHERE a.region_area = r.area_code " . " AND a.shipping_area_id = {$shipping_id}"; $regions = UtilD::getCol(\Yii::$app->getDb()->createCommand($sql)->queryAll()); $row['shipping_area_regions'] = empty($regions) ? '<a href="' . Url::toRoute(['/shipping-area/region', 'id' => $row['shipping_area_id']]) . '" style="color:red">' . \Yii::t('shipping', 'empty_regions') . '</a>' : $regions; $list[] = $row; } return $list; }
<div class="station-index"> <h4><?php echo Html::encode($this->title); ?> </h4> <?php echo GridView::widget(['dataProvider' => $dataProvider, 'columns' => [['class' => 'yii\\grid\\SerialColumn', 'options' => ['width' => '6%']], 'code', 'name', ['attribute' => 'center_id', 'format' => 'text', 'value' => function ($model) { $center = Center::findOne($model->center_id); if ($center) { return $center->name; } return null; }], ['attribute' => 'area_id', 'format' => 'text', 'value' => function ($model) { $area = Area::findOne($model->area_id); if ($area) { return $area->name; } return null; }], ['attribute' => 'status', 'format' => 'html', 'value' => function ($model) { if ($model->status == Station::STATUS_CONNECTED) { $html = Show::decorateString($model->getStatus($model->status), 'good'); } if ($model->status == Station::STATUS_LOST) { $html = Show::decorateString($model->getStatus($model->status), 'bad'); } return $html; }], ['class' => 'yii\\grid\\ActionColumn', 'options' => ['width' => '10%']]]]); ?>
public function actionIndex() { // default time duration $timePoints = Convert::currentTimePoints(); $getBy = Yii::$app->request->get('get_by'); if ($getBy == 'week') { $timePoints = Convert::currentWeekTimePoints(); } else { if ($getBy == 'month') { $timePoints = Convert::currentMonthTimePoints(); } } $whereClause = ['sst.sensor_id' => Sensor::ID_SECURITY]; // get station ids by role $role = new Role(); if (!$role->isAdministrator) { $position = $role->getPosition(); $stationIds = Station::getByRole($position, Yii::$app->user->id); $whereClause['s.id'] = $stationIds; } // get data $query = new Query(); $stations = $query->select('s.area_id, s.status AS station_status, sst.value AS sensor_value, count(w.id) AS total_warning, max(w.warning_time) AS last_warning_time')->from('station s')->leftJoin('sensor_status sst', 'sst.station_id = s.id')->leftJoin('warning w', 'w.station_id = s.id')->where($whereClause)->groupBy('s.id')->all(); // data $parseData = []; $data = []; // get areas $areas = Area::find()->all(); $parseData['areas'] = $areas; if (!empty($areas)) { $notHave = []; foreach ($areas as $area) { $have = 0; $data[$area['id']]['has_warning'] = 0; $data[$area['id']]['no_warning'] = 0; $data[$area['id']]['security_on'] = 0; $data[$area['id']]['security_off'] = 0; $data[$area['id']]['connected'] = 0; $data[$area['id']]['lost_connect'] = 0; $data[$area['id']]['last_warning_time'] = 0; // security and connect stations if (!empty($stations)) { foreach ($stations as $station) { if ($station['area_id'] == $area['id']) { $have = 1; // warnings if ($station['total_warning'] > 0 && $station['last_warning_time'] >= $timePoints['start'] && $station['last_warning_time'] <= $timePoints['end']) { $data[$area['id']]['has_warning']++; $data[$area['id']]['last_warning_time'] = $station['last_warning_time'] > $data[$area['id']]['last_warning_time'] ? $station['last_warning_time'] : $data[$area['id']]['last_warning_time']; } else { $data[$area['id']]['no_warning']++; } // status if ($station['station_status'] == Station::STATUS_CONNECTED) { $data[$area['id']]['connected']++; } else { if ($station['station_status'] == Station::STATUS_LOST) { $data[$area['id']]['lost_connect']++; } } // security mode if ($station['sensor_value'] == Sensor::SECURITY_ON) { $data[$area['id']]['security_on']++; } else { if ($station['sensor_value'] == Sensor::SECURITY_OFF) { $data[$area['id']]['security_off']++; } } } } } if ($have == 0) { $notHave[] = $area['id']; } } if (!empty($notHave)) { foreach ($notHave as $not) { unset($data[$not]); } } } $parseData['data'] = $data; return $this->render('station', $parseData); }
?> </h3> <p class="action"> <?php echo Html::a('会员列表', ['index'], ['class' => 'btn btn-success']); ?> </p> </div> <?php Pjax::begin(); ?> <?php echo GridView::widget(['dataProvider' => $dataProvider, 'columns' => ['consignee', ['header' => Html::a('地址', 'javascript:;'), 'content' => function ($model) { $area = Area::find()->where(['id' => [$model->province, $model->city, $model->district]])->asArray()->all(); $str = ''; foreach ($area as $val) { $str .= $val['name'] . ' '; } if ($model->default == 1) { $str .= '<span style="color: red">[默认]</span>'; } $str .= '<br/>' . $model->address; return $str; }], ['header' => Html::a('联系方式', 'javascript:;'), 'content' => function ($model) { $data = '手机:' . $model->mobile . '<br/>邮编:' . $model->zipcode; return $data; }]]]); ?> <?php
public function getDistrictArea() { return $this->hasOne(Area::className(), ['area_id' => 'district']); }
public function getArea() { return $this->hasOne(Area::className(), ['id' => 'area_id']); }
/** * @return \yii\db\ActiveQuery */ public function getLocation0() { return $this->hasOne(Area::className(), ['location' => 'location']); }
?> <p>(in kg)</p> <?php echo $form->field($model2, 'weight')->textInput(); ?> <?php echo $form->field($model2, 'religion')->textInput(['maxlength' => true]); ?> <h2>Academic Background</h2> <?php echo $form->field($model3, 'location')->textInput(['maxlength' => true]); ?> <?php echo $form->field($model3, 'location')->dropDownList(ArrayHelper::map(Area::find()->all(), 'id', 'location'), ['prompt' => 'Select HS location']); ?> <?php echo $form->field($model3, 'type')->dropDownList(['MAPSA' => 'MAPSA', 'Public School' => 'Public School'], ['prompt' => '']); ?> <?php echo $form->field($model3, 'hs_name')->textInput(['maxlength' => true]); ?> <?php echo $form->field($model3, 'section')->textInput(); ?> <?php
/** * @return \yii\db\ActiveQuery */ public function getAreas() { return $this->hasMany(Area::className(), ['cityid' => 'id']); }
protected function findModel($id) { // session $role = new Role(); if (!$role->isAdministrator) { $position = $role->getPosition(); $stationIds = Station::getByRole($position, Yii::$app->user->id); if (!empty($stationIds) && !in_array($id, $stationIds)) { $this->permissionDeny(); } } if (($model = Station::findOne($id)) !== null) { // find area & center $model->area = Area::findOne($model->area_id); $model->center = Center::findOne($model->center_id); // get equipment $equipments = EquipmentStatus::findAll(['station_id' => $id]); if (!empty($equipments)) { foreach ($equipments as $equipment) { $model->equipment[] = $equipment->equipment_id; } } // get power equipment $powerEquipments = PowerStatus::findAll(['station_id' => $id]); if (!empty($powerEquipments)) { foreach ($powerEquipments as $equipment) { $model->power_equipment[] = $equipment->item_id; } } // get dc $dcEquips = DcEquipmentStatus::findByStation($id); if (!empty($dcEquips)) { foreach ($dcEquips as $dcEquip) { $model->dc_equip_ids[] = $dcEquip['equipment_id']; $model->dc_equip_status[] = ['equipment_id' => $dcEquip['equipment_id'], 'name' => $dcEquip['name'], 'amperage' => $dcEquip['amperage'], 'voltage' => $dcEquip['voltage'], 'unit_voltage' => $dcEquip['unit_voltage'], 'temperature' => $dcEquip['temperature'], 'unit_amperage' => $dcEquip['unit_amperage'], 'status' => $dcEquip['status']]; } } // get sensor status $query = new Query(); $sensorStatus = $query->select('sst.*, s.type, s.unit_type, s.name')->from('sensor_status sst')->leftJoin('sensor s', 's.id = sst.sensor_id')->where(['sst.station_id' => $id])->andWhere(['s.active' => Sensor::STATUS_ACTIVE])->all(); if (!empty($sensorStatus)) { foreach ($sensorStatus as $sst) { $model->sensor_status[] = ['type' => $sst['type'], 'sensor_id' => $sst['sensor_id'], 'name' => $sst['name'], 'unit' => $sst['unit_type'], 'value' => $sst['value'], 'status' => $sst['status']]; } } return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }
public function actionEdit() { $request = \Yii::$app->request; $id = $request->get('id'); if ($id < 1) { exit; } if ($postData = $request->post()) { $postData['info']['mate'] = trim($postData['info']['mate']); $postData['info']['mate'] = str_replace("\t", "", $postData['info']['mate']); $postData['user_id'] = $id; $postData['info']['age'] = strtotime($postData['info']['age']); $user = User::getInstance()->editUser($postData); if ($user['id'] > 0) { return $this->__success('修改成功'); } else { return $this->__error('修改失败'); } } $user = User::getInstance()->getUserById($id); $user['info'] = json_decode($user['info']); $user['auth'] = json_decode($user['auth']); $this->assign('id', $id); $this->assign('user', $user); $this->assign('sport', Config::getInstance()->getListByType(1)); $this->assign('movie', Config::getInstance()->getListByType(2)); $this->assign('food', Config::getInstance()->getListByType(3)); $this->assign('travel', Area::getInstance()->getWentTravelList()); $photoList = UserPhoto::getInstance()->getPhotoList($id, 0, 12); $photoList = json_encode($photoList); $this->assign('photoList', $photoList); return $this->render(); }
/** * get catList * @author Cangzhou Wu<*****@*****.**> * @param $cat_id * @param bool $city city list flag * @return array */ public function getList($cat_id, $city = true) { $cities = Area::find()->where(['parent_id' => $cat_id])->all(); $catList = []; if ($city) { foreach ($cities as $s) { $catList[] = ['id' => $s->area_id, 'name' => $s->name]; } } else { foreach ($cities as $s) { $catList['out'][] = ['id' => $s->area_id, 'name' => $s->name]; } $catList['selected'] = $s->area_id; } return $catList; }
function getSSQ($s, $shi, $q) { $list1 = \common\models\Area::getInstance()->getTravelListById($s); $list2 = \common\models\Area::getInstance()->getTravelListById($shi); $list3 = \common\models\Area::getInstance()->getTravelListById($q); $str = ''; if (is_array($list1) && count($list1) > 0) { $str = $list1[0]['name']; if (is_array($list2) && count($list2) > 0) { $str .= '-' . $list2[0]['name']; if (is_array($list3) && count($list3) > 0) { $str .= '-' . $list3[0]['name']; } } } return $str; }
<?php /** * Created by PhpStorm. * User: JFog * Date: 7/16/2015 * Time: 12:33 AM */ use common\components\helpers\Show; use common\components\helpers\Convert; use common\models\Area; use common\models\Center; use common\models\Station; $areaList = Area::find()->all(); $centerList = Center::find()->all(); $query = Station::find()->select('id, name')->where([]); if (isset($_GET['area']) && $_GET['area'] > 0) { $query->andWhere(['area_id' => $_GET['area']]); } if (isset($_GET['center']) && $_GET['center'] > 0) { $query->andWhere(['center_id' => $_GET['center']]); } $collections = $query->all(); $stationList[] = ['id' => '0', 'name' => 'Chọn trạm']; if (!empty($collections)) { foreach ($collections as $col) { $stationList[] = ['id' => $col['id'], 'name' => $col['name']]; } } //print '<pre>'; print_r($stationList); die; ?>
/** * 获取去过的地方或者想去的地方的地区列表 */ public function actionGetTravelList() { $list = Area::getInstance()->getTravelListById($this->get['area_id']); $this->renderAjax(['status' => 1, 'data' => $list]); }