public static function store()
 {
     $params = $_POST;
     $hospital = new Hospital(array('name' => $params['name'], 'open_time' => $params['open_time'], 'close_time' => $params['close_time']));
     $errors = $hospital->errors();
     if (count($errors) > 0) {
         flash()->error(':(', 'Something was a little off...');
         Redirect::to('/hospitals/create', array('errors' => $errors, 'attributes' => $params));
     }
     $hospital->save();
     for ($i = 1; $i <= 24; $i++) {
         $hour = new Hour(array('at' => $i, 'hospital_id' => $hospital->id, 'importance_id' => $params['importance_id']));
         $hour->save();
     }
     Redirect::to('/hospitals#' . $hospital->id);
 }
示例#2
0
 /**
  * Creates a new model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  */
 public function actionCreate($id = '')
 {
     if ($id) {
         $model = $this->loadModel($id);
     } else {
         $model = new Hospital();
     }
     // Uncomment the following line if AJAX validation is needed
     // $this->performAjaxValidation($model);
     if (isset($_POST['Hospital'])) {
         $model->attributes = $_POST['Hospital'];
         if ($model->save()) {
             $this->redirect(array('view', 'id' => $model->uid));
         }
     }
     $this->render('create', array('model' => $model));
 }
示例#3
0
 public function excelAction($path)
 {
     //phalcon向数据库导入的时候有点小问题,有default值的列需要赋值,不然这列的default值不会写入数据库
     include '../app/classes/PHPExcel.php';
     $this->view->disable();
     $obj = new PHPExcel();
     $name = '/home/sify/' . $path;
     $type = PHPExcel_IOFactory::identify($name);
     $reader = PHPExcel_IOFactory::createReader($type);
     $obj = $reader->load($name);
     //导入hospital子表
     $sheet = $obj->getSheetByName('hospital');
     for ($j = 2; $j <= $sheet->getHighestRow(); $j++) {
         $hospital = new Hospital();
         $hospital->id = $sheet->getCell('A' . $j)->getValue();
         $hospital->name = (string) $sheet->getCell('B' . $j)->getValue();
         $hospital->intro = (string) $sheet->getCell('C' . $j)->getValue();
         $hospital->cityid = $sheet->getCell('D' . $j)->getValue();
         $hospital->street = (string) $sheet->getCell('E' . $j)->getValue();
         $hospital->tele = (string) $sheet->getCell('F' . $j)->getValue();
         $hospital->level = (string) $sheet->getCell('G' . $j)->getValue();
         $hospital->notice = (string) $sheet->getCell('H' . $j)->getValue();
         $hospital->img = '/img/hospital/default.img';
         $hospital->save();
     }
     //导入department子表
     $sheet = $obj->getSheetByName('department');
     for ($j = 2; $j <= $sheet->getHighestRow(); $j++) {
         $department = new Department();
         $department->id = $sheet->getCell('A' . $j)->getValue();
         $department->h_id = $sheet->getCell('B' . $j)->getValue();
         $department->type = (string) $sheet->getCell('C' . $j)->getValue();
         $department->intro = (string) $sheet->getCell('D' . $j)->getValue();
         $department->name = (string) $sheet->getCell('E' . $j)->getValue();
         $department->dcount = 0;
         $department->save();
     }
     //导入doctor子表
     $sheet = $obj->getSheetByName('doctor');
     for ($j = 2; $j <= $sheet->getHighestRow(); $j++) {
         $doctor = new Doctor();
         $doctor->id = $sheet->getCell('A' . $j)->getValue();
         $doctor->name = (string) $sheet->getCell('B' . $j)->getValue();
         $doctor->de_id = $sheet->getCell('C' . $j)->getValue();
         $doctor->post = (string) $sheet->getCell('D' . $j)->getValue();
         $doctor->intro = (string) $sheet->getCell('E' . $j)->getValue();
         $doctor->specialty = (string) $sheet->getCell('F' . $j)->getValue();
         $doctor->fee = $sheet->getCell('G' . $j)->getValue();
         $doctor->img = '/img/doctor/default.img';
         $doctor->save();
     }
     //导入available子表
     $sheet = $obj->getSheetByName('available');
     for ($j = 2; $j <= $sheet->getHighestRow(); $j++) {
         $available = new Available();
         $available->id = $sheet->getCell('A' . $j)->getValue();
         $available->do_id = $sheet->getCell('B' . $j)->getValue();
         $available->date = $sheet->getCell('C' . $j)->getFormattedValue();
         $available->time = $sheet->getCell('D' . $j)->getValue();
         $available->save();
     }
     echo '数据导入成功!';
 }
 public function actionUpload()
 {
     $folder = $_SERVER['DOCUMENT_ROOT'] . Yii::app()->request->baseUrl . '/upload/';
     // folder for uploaded files
     $file = $folder . basename($_FILES['uploadfile']['name']);
     if (move_uploaded_file($_FILES['uploadfile']['tmp_name'], $file)) {
         $row = 0;
         if (($handle = fopen($file, "r")) !== FALSE) {
             while (($data = fgetcsv($handle, 1000, ",")) !== FALSE) {
                 if ($row > 0) {
                     $model = Hospital::model()->findByPk((int) $data[0]);
                     if ($model === null) {
                         $model = new Hospital();
                     }
                     $model->addressbookid = (int) $data[0];
                     $model->fullname = $data[1];
                     $model->ishospital = 1;
                     $model->recordstatus = (int) $data[2];
                     try {
                         if (!$model->save()) {
                             $this->messages = $this->messages . Catalogsys::model()->getcatalog(' upload error at ' . $data[0]);
                         }
                     } catch (Exception $e) {
                         $this->messages = $this->messages . $e->getMessage();
                     }
                 }
                 $row++;
             }
         } else {
             $this->messages = $this->messages . ' memory or harddisk full';
         }
         fclose($handle);
     } else {
         $this->messages = $this->messages . ' check your directory permission';
     }
     if ($this->messages == '') {
         $this->messages = 'success';
     }
     echo $this->messages;
 }