/** * 查询所有部门,返回object,缓存两小时、依赖部门数量变化 * @return \common\models\Department[] */ public static function findAllForObject() { $dependency = new DbDependency(['sql' => 'select count(*) from department']); $result = Department::getDb()->cache(function () { return Department::find()->all(); }, 2 * 3600, $dependency); return $result; }
/** * 查询科室下的对应疾病集 * @author gaoqing * @date 2016-04-08 * @param int $columns 在页面中,显示的列数 * @return array 科室下的对应疾病集 */ private static function getDepartmentDis($columns) { $departmentDis = array(); $department = new Department(); $disease = new Disease(); //get the first level departments $firstLevel = $department->getDepartmentLevel1(1); if (self::isNotNull($firstLevel)) { foreach ($firstLevel as $level1) { //select diseases that all belong current first level department $inner = array(); $inner['department'] = $level1; $size = count($firstLevel) * $columns; $inner['disease'] = $disease->getDiseaseByDepartment($level1['id'], 'class_level1', 0, $size); $departmentDis[] = $inner; } return $departmentDis; } return $departmentDis; }
/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = Department::find()->notDeleted(); $dataProvider = new ActiveDataProvider(['query' => $query]); $this->load($params); if (!$this->validate()) { // uncomment the following line if you do not want to any records when validation fails // $query->where('0=1'); return $dataProvider; } $query->andFilterWhere(['id' => $this->id, 'created_at' => $this->created_at, 'created_by' => $this->created_by, 'updated_at' => $this->updated_at, 'updated_by' => $this->updated_by, 'deleted' => $this->deleted]); $query->andFilterWhere(['like', 'name', $this->name]); return $dataProvider; }
/** 增加或更新用户 */ public function actionAddUpdate() { $request = Yii::$app->request; if ($request->isPost) { $userId = $request->post("userId"); if ($userId) { $addUserForm = AddUserForm::initWithIdOrRole($userId); } else { $addUserForm = AddUserForm::initWithIdOrRole(null, Users::ROLE_AAA); } $departments = Department::findAllForObject(); return $this->renderAjax('user-form', ['addUserForm' => $addUserForm, 'departments' => $departments]); } CommonFunctions::createAlertMessage("非法获取", "error"); return $this->redirect(['user-aaa/index']); }
public function getDepartment() { return $this->hasOne(Department::className(), ['departmentId' => 'departmentId']); }
/** * 疾病 sitemap * @author gaoqing * @date 2016-04-25 * @return array 响应信息 */ private function diseaseSitemap() { /** * <urlset> * <url> * <loc>http://jb.9939.com/article/2009/0327/1.shtml</loc> * <lastmod>2009-03-27</lastmod> * <changefreq>always</changefreq> * <priority>0.6</priority> * </url> * </urlset> */ $where = $this->_ownership; $sitemap = '<?xml version="1.0" encoding="UTF-8"?>'; $sitemap .= $this->_baidu ? '<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" xmlns:mobile="http://www.baidu.com/schemas/sitemap-mobile/1/">' : '<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">'; //判断jb还是wapjb $prefix = $where == 'pc' ? '' : 'wap_'; //1、生成 疾病 部分的 sitemap $diseases = Disease::find()->asArray()->all(); $sitemap .= $this->setSitemapURL($diseases, $prefix . 'disease'); //2、生成 症状 部分的 sitemap $symptoms = Symptom::find()->asArray()->all(); $sitemap .= $this->setSitemapURL($symptoms, $prefix . 'symptom'); //3、生成 科室 部分的 sitemap $departments = Department::find()->asArray()->all(); $sitemap .= $this->setSitemapURL($departments, $prefix . 'department'); //4、生成 部位 部分的 sitemap $parts = Part::find()->asArray()->all(); $sitemap .= $this->setSitemapURL($parts, $prefix . 'part'); $sitemap .= '</urlset>'; //5、生成 sitemap 文件 if ($where == 'pc') { $frontend = \Yii::getAlias("@frontend"); $frontDomain = \Yii::getAlias("@frontdomain"); } elseif ($where == 'wap') { $frontend = \Yii::getAlias("@wapjb"); $frontDomain = \Yii::getAlias("@mjb_domain"); } // $frontend = \Yii::getAlias("@frontend"); $sitemapFolder = 'sitemap'; $fileFolder = $frontend . '/web/' . $sitemapFolder; if (!file_exists($fileFolder) || !is_dir($fileFolder)) { mkdir($fileFolder, 0755); } $fileName = $this->_baidu ? 'diseasebaidusitemap.xml' : 'diseasesitemap.xml'; if (file_put_contents($fileFolder . '/' . $fileName, $sitemap)) { // $frontDomain = \Yii::getAlias("@frontdomain"); return ['flag' => 1, 'url' => $frontDomain . '/' . $sitemapFolder . '/' . $fileName, 'name' => $fileName]; } return []; }
/** * 症状首页可能疾病缓存数据 * lc 2016-4-15 * @param type $cacheKey 缓存的唯一标识 * @param type $parms 单条症状所有字段内容数组 * @param type $forceCache 是否强制缓存,默认不强制缓存 * @return type */ public static function cacheSymptomRelateDisease($cacheKey, $parms, $forceCache = false) { $symptomid = $parms['id']; $cache = \Yii::$app->cache_data_file; $key = $cacheKey . '_' . $symptomid; $data = $cache->get($key); if ($forceCache) { $data = false; } if (!isset($data) || empty($data)) { $relate = new Relate(); $disease = new Disease(); $department = new Department(); $diseaseList = $relate->getRelateDiseases($symptomid); //根据关联表查询出疾病id,该症状对应的疾病下的所有疾病信息 // print_r($diseaseList);exit; if (!empty($diseaseList)) { $diseaseId = []; foreach ($diseaseList as $k => $v) { $diseaseId[] = $v['diseaseid']; } $diseaseMap = $disease->batchGetDiseaseById($diseaseId); //该症状对应的疾病下的所有疾病信息 $symptomMap = $relate->batchGetSymptomsByDisid($diseaseId); //该症状对应的疾病下对应的所有相关症状 $diseaseIdStr = implode(',', $diseaseId); $departmentMap = $department->batchGetDepartmentsByDisid($diseaseIdStr); //该症状对应的疾病对应的所有科室 // print_r($departmentMap);exit; foreach ($symptomMap as $k => $v) { $disId = $v['diseaseid']; $symId = $v['symptomid']; foreach ($diseaseMap as $kk => $vv) { $pinyin = $vv['pinyin_initial']; if ($vv['id'] == $disId) { $tmp[$pinyin][] = $v; } } } $diseaseTmp['relDisease'] = $diseaseMap; $diseaseTmp['relSymptom'] = $tmp; $disTmp = ['diseaseMap' => $diseaseMap, 'symptomMap' => $symptomMap, 'departmentMap' => $departmentMap, 'diseaseTmp' => $diseaseTmp, 'diseaseId' => $diseaseId]; $cache->set($key, $disTmp); return $disTmp; } return array(); } else { return $data; } }
?> <?php echo $form->field($model, 'person_img')->fileInput(); ?> <?php echo $form->field($model, 'address')->textarea(['rows' => 6]); ?> <?php echo $form->field($model, 'tel')->textInput(['maxlength' => true]); ?> <?php echo $form->field($model, 'department_id')->dropDownList(ArrayHelper::map(Department::find()->all(), 'id', 'department')); ?> <div class="form-group"> <?php echo Html::submitButton($model->isNewRecord ? 'เพิ่ม' : 'แก้ไข', ['class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary']); ?> </div> <?php ActiveForm::end(); ?> </div>
/** * 所有科室名称对应的拼音 * lc 2016-4-7 * @return type */ public function getDepartmentPinyin() { $department = new Department(); $tmp = $department->getDepartmentListById(0); foreach ($tmp as $k => $v) { $ret[$v['name']] = $v['pinyin']; } return $ret; }
/** * 根据疾病的拼音简写,得到疾病的信息 * @author gaoqing * @date 2016-09-08 * @param String $pyInitial 疾病的拼音简写 * @param boolean $isRelDis 是否获取其 相关疾病 * @param boolean $isRelSym 是否获取其 典型症状 * @param boolean $isRelPart 是否获取其相关 部位 * @param boolean $isRelDep 是否获取其 就诊科室 * @return array 疾病的信息集 */ public static function getDiseasesByPinyin($pyInitial, $isRelDis = false, $isRelSym = false, $isRelPart = false, $isRelDep = false) { $disease = []; //1、得到疾病的疾病信息 $odisease = new Disease(); $disease = $odisease->getDiseasesByPinyin($pyInitial); if (self::isNotNull($disease)) { $disease['treat_method'] = self::explodeStr($disease['treatment']); $disease = self::replace($disease, '<br/>'); $disease['chuanranxing'] = '无'; if ($disease['chuanranflag'] == 1) { $disease['chuanranxing'] = '有'; } //2、获取科室信息 if ($isRelDep) { $treatDepNames = self::explodeStr($disease['treat_department']); $odepartment = new Department(); $disease['department'] = $odepartment->getDepsByName($treatDepNames); $disease['medicine'] = self::explodeStr($disease['medicine']); } //3、获取典型症状信息 if ($isRelSym) { $typicalSymptomNames = self::explodeStr($disease['typical_symptom']); $osymptom = new Symptom(); $disease['tsymptom'] = $osymptom->getSymptomsByName($typicalSymptomNames); } //4、得到疾病对应的所有部位 if ($isRelPart) { $disease['part'] = Relate::getPartsByDisid($disease['id']); } //5、得到相关疾病 if ($isRelDis) { $relDiseaseNames = self::explodeStr($disease['rel_disease']); $values = Disease::search(['name' => $relDiseaseNames]); if (self::isNotNull($values)) { $disease['reldis'] = $values['list']; } } } return $disease; }
/** * Updates an existing Hotel model. * If update is successful, the browser will be redirected to the 'view' page. * @param integer $id * @return mixed */ public function actionUpdate($id) { //$this->allowAccess(Hotel::checkAccess($id)); $model = $this->findModel($id); $languages = Lang::getAll(); $roomTypes = RoomType::getRoomTypes(); $department = Department::getAll(); $modelHotelDepartmentMapping = new HotelDepartmentMapping(); $modelHotelData = HotelData::getByHotelId($id); if (!$modelHotelData) { $modelHotelData = new HotelData(); } $availableRooms = HotelRoomTypeMapping::getRoomTypesIdByHotelId($id); $hotelDepartments = HotelDepartmentMapping::getByHotelId($id); $modelHotelRoomTypeMapping = new HotelRoomTypeMapping(); $countries = Country::getAllCountries(); $savePath = Yii::getAlias($model::FILE_PATH); $imageDataProvider = new ArrayDataProvider(['models' => Image::getImagesByHotelId($id)]); if ($model->load(Yii::$app->request->post())) { // $modelCity = City::getOrCreateByNameAndCountryId($_POST['Hotel']['cityName'], $model->country_id); // $model->city_id = $modelCity->id; if ($model->save()) { foreach ($_POST['HotelRoomTypeMapping']['room_type_id'] as $roomTypeId) { $hotelRoomTypeMappings = HotelRoomTypeMapping::getRoomTypeByHotelIdAndRoomTypeId($id, $roomTypeId); if (!$hotelRoomTypeMappings) { $modelHotelRoomTypeMapping = new HotelRoomTypeMapping(); $modelHotelRoomTypeMapping->setAttribute('hotel_id', $model->getAttribute('id')); $modelHotelRoomTypeMapping->setAttribute('room_type_id', $roomTypeId); $modelHotelRoomTypeMapping->save(); } elseif ($hotelRoomTypeMappings->getAttribute('deleted') === ActiveRecord::STATUS_DELETED) { $hotelRoomTypeMappings->setAttribute('deleted', ActiveRecord::STATUS_NOT_DELETED); $hotelRoomTypeMappings->save(); } } foreach ($languages as $key => $language) { $modelHotelData = HotelData::getByLanguageIdAndHotelId($language->local, $id); if ($modelHotelData) { $modelHotelData->setAttribute('lang_id', Yii::$app->request->post('HotelData')['lang_id'][$key]); $modelHotelData->setAttribute('description', Yii::$app->request->post('HotelData')['description'][$key]); $modelHotelData->setAttribute('location', Yii::$app->request->post('HotelData')['location'][$key]); $modelHotelData->setAttribute('price_information', Yii::$app->request->post('HotelData')['price_information'][$key]); $modelHotelData->setAttribute('other', Yii::$app->request->post('HotelData')['other'][$key]); $modelHotelData->save(); } else { $modelHotelData = new HotelData(); $modelHotelData->setAttribute('hotel_id', $id); $modelHotelData->setAttribute('lang_id', Yii::$app->request->post('HotelData')['lang_id'][$key]); $modelHotelData->setAttribute('description', Yii::$app->request->post('HotelData')['description'][$key]); $modelHotelData->setAttribute('location', Yii::$app->request->post('HotelData')['location'][$key]); $modelHotelData->setAttribute('price_information', Yii::$app->request->post('HotelData')['price_information'][$key]); $modelHotelData->setAttribute('other', Yii::$app->request->post('HotelData')['other'][$key]); $modelHotelData->save(); } } foreach ($availableRooms as $room) { if (!in_array($room, $_POST['HotelRoomTypeMapping']['room_type_id'])) { $hotelRoomTypeMapping = HotelRoomTypeMapping::getRoomTypeByHotelIdAndRoomTypeId($id, $room); $hotelRoomTypeMapping->setAttribute('deleted', ActiveRecord::STATUS_DELETED); $hotelRoomTypeMapping->save(); } } foreach ($_POST['HotelDepartmentMapping']['department_id'] as $departmentId) { $hotelDepartmentMapping = HotelDepartmentMapping::getByHotelIdAndDepartmentId($id, $departmentId); if (!$hotelDepartmentMapping) { $modelHotelDepartmentMapping = new HotelDepartmentMapping(); $modelHotelDepartmentMapping->setAttribute('hotel_id', $model->getAttribute('id')); $modelHotelDepartmentMapping->setAttribute('department_id', $departmentId); $modelHotelDepartmentMapping->save(); } elseif ($hotelDepartmentMapping->getAttribute('deleted') === ActiveRecord::STATUS_DELETED) { $hotelDepartmentMapping->setAttribute('deleted', ActiveRecord::STATUS_NOT_DELETED); $hotelDepartmentMapping->save(); } } foreach ($hotelDepartments as $department) { if (!in_array($department, $_POST['HotelDepartmentMapping']['department_id'])) { $modelHotelDepartmentMapping = HotelDepartmentMapping::getByHotelIdAndDepartmentId($id, $department); $modelHotelDepartmentMapping->setAttribute('deleted', ActiveRecord::STATUS_DELETED); $modelHotelDepartmentMapping->save(); } } $files = $model->loadFiles($model->fileAttribute); if ($files !== false) { foreach ($files as $file) { if ($file->saveAs($savePath . $file->name)) { $image = new Image(); $image->setAttribute('name', $file->name); $image->setAttribute('hotel_id', $id); $image->setAttribute('path', $model::FILE_PATH . $file->name); $image->save(); } } } if ($model->preview_image_id === 0 || $model->preview_image_id === null) { $model->setAttribute('preview_image_id', !empty($image) ? $image->id : $model::IMAGE_NOT_SET); $model->save(); } return $this->redirect(['view', 'id' => $model->id]); } } return $this->render('update', ['model' => $model, 'modelHotelData' => $modelHotelData, 'modelHotelRoomTypeMapping' => $modelHotelRoomTypeMapping, 'roomTypes' => $roomTypes, 'countries' => $countries, 'availableRooms' => $availableRooms, 'hotelDepartments' => $hotelDepartments, 'imageDataProvider' => $imageDataProvider, 'department' => $department, 'modelHotelDepartmentMapping' => $modelHotelDepartmentMapping, 'languages' => $languages]); }
?> <div class="box box-primary box-solid"> <div class="box-header"> <h3 class="box-title"><i class="fa fa-user"></i> <?php echo Html::encode($this->title); ?> </h3> </div> <div class="box-body"> <?php // echo $this->render('_search', ['model' => $searchModel]); ?> <p> <?php echo Html::a('เพิ่มบุคคลากร', ['create'], ['class' => 'btn btn-success']); ?> </p> <?php echo GridView::widget(['dataProvider' => $dataProvider, 'filterModel' => $searchModel, 'columns' => [['class' => 'yii\\grid\\SerialColumn'], ['attribute' => 'photo', 'format' => 'html', 'value' => function ($model) { return Html::img('uploads/person/' . $model->photo, ['class' => 'thumbnail', 'width' => 80, 'height' => 80, 'border' => 1]); }], 'user.username', 'user.email', 'firstname', 'lastname', 'tel', ['attribute' => 'department_id', 'value' => function ($model) { return $model->department->department; }, 'filter' => Html::activeDropDownList($searchModel, 'department_id', ArrayHelper::map(Department::find()->all(), 'id', 'department'), ['class' => 'form-control'])], ['class' => 'yii\\grid\\ActionColumn']]]); ?> </div> </div>
$this->registerJsFile('@web/js/grid/main.js', ['depends' => ['yii\\web\\JqueryAsset']]); ?> <div class="registration-index"> <?php $gridColumns = [['class' => '\\kartik\\grid\\SerialColumn'], ['class' => '\\kartik\\grid\\ActionColumn', 'template' => '{view} {update} {cancel} {delete}', 'buttons' => ['cancel' => function ($key, $model) { $customUrl = Yii::$app->getUrlManager()->createUrl(['registration/cancel-admin', 'id' => $model->id]); return Html::a('<span class="glyphicon glyphicon-ban-circle"></span>', $customUrl, ['title' => Yii::t('app', 'Cancel'), 'data-pjax' => '0', 'confirm' => Yii::t('app', 'Do you really want cancel registration?')]); }, 'delete' => function ($key, $model) { $customUrl = Yii::$app->getUrlManager()->createUrl(['registration/delete-admin', 'id' => $model->id]); return Html::a('<span class="glyphicon glyphicon-trash"></span>', $customUrl, ['title' => Yii::t('app', 'Delete'), 'data-pjax' => '0', 'confirm' => Yii::t('app', 'Do you really want delete registration?')]); }], 'header' => '<span class="glyphicon glyphicon-info-sign"></span>', 'headerOptions' => ['style' => 'min-width:50px;']], ['attribute' => 'status', 'value' => function ($data) { return array_key_exists($data->status, Registration::$reverseStatus) ? Registration::$reverseStatus[$data->status] : null; }, 'filterType' => GridView::FILTER_SELECT2, 'filterWidgetOptions' => ['data' => Registration::$statusNames + ['' => 'All']], 'headerOptions' => ['style' => 'min-width:115px;']], 'code', ['attribute' => 'title', 'value' => function ($data) { return Yii::t('general', $data->title); }, 'filterType' => GridView::FILTER_SELECT2, 'filterWidgetOptions' => ['data' => Registration::getTitles(), 'options' => ['prompt' => Yii::t('general', 'All')]], 'width' => '250px'], 'first_name', 'last_name', 'company', 'department', 'street', 'zip', 'city', ['attribute' => 'country_id', 'value' => function ($data) { return $data->country ? $data->country->name : null; }, 'filterType' => GridView::FILTER_SELECT2, 'filterWidgetOptions' => ['data' => Country::getMap(), 'options' => ['prompt' => Yii::t('general', 'All')]], 'headerOptions' => ['style' => 'min-width:150px;']], 'email:email', 'phone', ['attribute' => 'department_id', 'value' => function ($data) { return $data->departmentRel ? $data->departmentRel->name : null; }, 'filterType' => GridView::FILTER_SELECT2, 'filterWidgetOptions' => ['data' => Department::getMap(), 'options' => ['prompt' => Yii::t('general', 'All')]], 'width' => '250px'], ['attribute' => 'hotel_id', 'value' => function ($data) { return $data->hotel ? $data->hotel->name : null; }, 'filterType' => GridView::FILTER_SELECT2, 'filterWidgetOptions' => ['data' => Hotel::getMap(), 'options' => ['prompt' => Yii::t('general', 'All')]], 'headerOptions' => ['style' => 'min-width:155px;']], ['attribute' => 'check_in', 'format' => ['date', 'php:d/m/Y'], 'filterType' => GridView::FILTER_SELECT2, 'filterWidgetOptions' => ['data' => Registration::getCheckIn(), 'options' => ['prompt' => Yii::t('general', 'All')]], 'headerOptions' => ['style' => 'min-width:115px;']], ['attribute' => 'check_out', 'format' => ['date', 'php:d/m/Y'], 'filterType' => GridView::FILTER_SELECT2, 'filterWidgetOptions' => ['data' => Registration::getCheckOut(), 'options' => ['prompt' => Yii::t('general', 'All')]], 'headerOptions' => ['style' => 'min-width:115px;']], ['attribute' => 'room_type_id', 'value' => function ($data) { return $data->roomType ? $data->roomType->name : null; }, 'filterType' => GridView::FILTER_SELECT2, 'filterWidgetOptions' => ['data' => \common\models\RoomType::getMap(), 'options' => ['prompt' => Yii::t('general', 'All')]]], ['attribute' => 'room_rate', 'value' => function ($data) { return Registration::generateRoomRate($data->room_rate); }, 'format' => 'raw'], ['attribute' => 'special_request', 'hidden' => true], ['attribute' => 'updated_at', 'format' => ['date', 'php:h:i:s A d-m-Y']], ['attribute' => 'id', 'hiddenFromExport' => true, 'headerOptions' => ['style' => 'min-width:80px;']]]; // Generate a bootstrap responsive striped table with row highlighted on hover echo GridView::widget(['dataProvider' => $dataProvider, 'filterModel' => $searchModel, 'responsive' => true, 'hover' => true, 'columns' => $gridColumns, 'pjax' => true, 'resizableColumns' => false, 'toolbar' => [Html::a('<i class="glyphicon glyphicon-repeat"></i>', ['index'], ['data-pjax' => 0, 'class' => 'btn btn-default', 'title' => Yii::t('kvgrid', 'Reset Grid')]), '{export}', '{toggleData}'], 'toggleDataOptions' => ['default' => 'all'], 'panelBeforeTemplate' => '<div class="pull-right"><div class="btn-toolbar kv-grid-toolbar" role="toolbar"><span class="pager-mini">{pager}</span>{toolbar}</div></div>{before}<div class="clearfix"></div>', 'panelAfterTemplate' => '{after}<span class="pager-mini clearfix">{pager}</span>', 'panel' => ['type' => GridView::TYPE_PRIMARY, 'heading' => '<h3 class="panel-title"><i class="glyphicon glyphicon-user"></i> Registrations</h3>', 'before' => Html::a('<i class="glyphicon glyphicon-list-alt"></i> Hotel Rooming List', ['hotel-rooming'], ['class' => 'btn btn-primary']), 'footer' => false], 'exportConfig' => [GridView::EXCEL => [], GridView::CSV => ['config' => ['colDelimiter' => ';', 'rowDelimiter' => "\r\n"]], GridView::PDF => []], 'beforeHeader' => [['columns' => [['options' => ['colspan' => 3]], ['content' => 'Personal Data', 'options' => ['colspan' => 12, 'class' => 'text-center warning']], ['content' => 'Hotel Information', 'options' => ['colspan' => 6, 'class' => 'text-center warning']]], 'options' => ['class' => 'skip-export']]]]); ?> </div>
/** * 通过疾病id 获取 医生 * lc 2016-3-30 * @param type $diseaseid * @return type */ public function getDoctor($diseaseid, $offset = 0, $limit = 3) { require PROJECT_PATH . '/frontend/data/doctorid.php'; $doctorObj = new Doctor(); $departmentObj = new Department(); $department = $departmentObj->getDepartmentsByDisid($diseaseid); $uid = array_key_exists($department[0]['name'], $_DOCTORID) ? $_DOCTORID[$department[0]['name']] : $_DOCTORID['内科']; //科室名称获取医生id信息 $arruid = array_slice($uid, $offset, $limit); $uidstr = implode(',', $arruid); $doctor = $doctorObj->getDoctorById($uidstr); return $doctor; }
/** * Finds the Department model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * @param integer $id * @return Department the loaded model * @throws NotFoundHttpException if the model cannot be found */ protected function findModel($id) { if (($model = Department::findOne($id)) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }