當前位置: 首頁>>代碼示例>>PHP>>正文


PHP DataModel::create方法代碼示例

本文整理匯總了PHP中DataModel::create方法的典型用法代碼示例。如果您正苦於以下問題:PHP DataModel::create方法的具體用法?PHP DataModel::create怎麽用?PHP DataModel::create使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在DataModel的用法示例。


在下文中一共展示了DataModel::create方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: upload

 public function upload()
 {
     $attrModel = new AttributesModel();
     $configArr = (array) $attrModel->getConfig();
     if ($configArr['beginRow'] == 0) {
         Tool::alertBackNoRefresh('請先設置上傳文件的數據格式:)');
         return;
     }
     $allAttr = $attrModel->getAttributes();
     $allAttrArray = array();
     foreach ($allAttr as $attr) {
         $allAttrArray[] = $attr->attributeName;
     }
     $attributes = array_values(array_slice($configArr, 4, 57));
     $attributesFlip = array_flip($attributes);
     /*print_r($attributesFlip);
       echo '<hr/>';*/
     $sheetNumArr = explode('-', $configArr['dataSheetNum']);
     foreach ($sheetNumArr as $key => &$sheetNum) {
         if (trim($sheetNum)) {
             $sheetNum = trim($sheetNum) - 1;
         } else {
             unset($sheetNumArr[$key]);
         }
     }
     if (isset($_POST['send'])) {
         $beginTime = microtime(true);
         $fileName = $_FILES['excel']['name'];
         $explodeArr = explode('.', $fileName);
         $extensionName = $explodeArr[count($explodeArr) - 1];
         $inputFileName = $_FILES['excel']['tmp_name'];
         require '../Extension/PHPExcel_1.8.0/Classes/PHPExcel.php';
         require '../Extension/PHPExcel_1.8.0/Classes/PHPExcel/Writer/Excel2007.php';
         require '../Extension/PHPExcel_1.8.0/Classes/PHPExcel/Writer/Excel5.php';
         $inputFileType = PHPExcel_IOFactory::identify($inputFileName);
         if ($inputFileType != 'Excel2007' && $inputFileType != 'Excel5') {
             Tool::alertBackNoRefresh('上傳文件格式不正確:(');
             return;
         }
         $objReader = PHPExcel_IOFactory::createReader($inputFileType);
         $PHPExcel = $objReader->load($inputFileName);
         //根據自己的數據表的大小修改
         $arr = array('A' => 1, 'B' => 2, 'C' => 3, 'D' => 4, 'E' => 5, 'F' => 6, 'G' => 7, 'H' => 8, 'I' => 9, 'J' => 10, 'K' => 11, 'L' => 12, 'M' => 13, 'N' => 14, 'O' => 15, 'P' => 16, 'Q' => 17, 'R' => 18, 'S' => 19, 'T' => 20, 'U' => 21, 'V' => 22, 'W' => 23, 'X' => 24, 'Y' => 25, 'Z' => 26, 'AA' => 27, 'AB' => 28, 'AC' => 29, 'AD' => 30, 'AE' => 31, 'AF' => 32, 'AG' => 33, 'AH' => 34, 'AI' => 35, 'AJ' => 36, 'AK' => 37, 'AL' => 38, 'AM' => 39, 'AN' => 40, 'AO' => 41, 'AP' => 42, 'AQ' => 43, 'AR' => 44, 'AS' => '45', 'AT' => 46, 'AU' => 47, 'AV' => 48, 'AW' => 49, 'AX' => 50, 'AY' => 51, 'AZ' => 52, 'BA' => 53, 'BB' => 54, 'BC' => 55, 'BD' => 56, 'BE' => 57);
         $sexArr = array('男' => 1, '女' => 0);
         $BMIArr = array('肥胖' => 0, '超重' => 1, '低體重' => 2, '正常' => 3);
         $otherArr = array('不及格' => 0, '及格' => 1, '良好' => 2, '優秀' => 3);
         $year = $_POST['year'];
         $year = str_replace('-', '_', $year);
         $tableName = 'tice_data_' . $year;
         $model = new DataModel();
         $model->dbName = 'tice';
         $model->tableName = $tableName;
         if (!$model->tableExist()) {
             $model->createTable();
         }
         $model = new DataModel();
         foreach ($allAttrArray as $attr) {
             $model->{$attr} = 0;
         }
         $user = new UserModel();
         $totalEmptyErrorArr = array();
         $totalInsertErrorArr = array();
         //檢查插入失敗數據的二維數組
         $emptyErrorArr = array();
         //檢查不完整的數據的二維數組
         $sqlParams = array();
         $affectedRows = 0;
         foreach ($sheetNumArr as $i) {
             $currentSheet = $PHPExcel->getSheet($i);
             //獲得工作表,從0開始
             $highestRow = $currentSheet->getHighestRow();
             // 取得總行數
             $highestColumn = $currentSheet->getHighestColumn();
             //取得總列數 比如 ‘AJ'列這樣子
             //                echo $currentSheet->getTitle() . ' ' . $highestRow . '<br/>'; // 得到當前工作表的名字
             //讀取一個工作表的數據 每次讀取一行,再在行中循環每列的數值
             for ($row = $configArr['beginRow']; $row <= $highestRow; $row++) {
                 $listRow = array();
                 for ($column = self::BEGIN_COL; $column <= $arr[$highestColumn]; $column++) {
                     $val = $currentSheet->getCellByColumnAndRow($column, $row)->getValue();
                     $listRow[] = $val;
                     $listRow['row'] = $row;
                 }
                 //                    print_r($listRow);
                 //檢查數據的完整性
                 if (!self::checkDataComplete($configArr['schoolType'], $listRow, $attributesFlip)) {
                     $empty = array();
                     $empty['sheetName'] = $currentSheet->getTitle();
                     $empty['row'] = $row;
                     $emptyErrorArr[] = $empty;
                     unset($empty);
                 }
                 $model->tableName = $tableName;
                 $listRow[$attributesFlip['sex']] = $sexArr[trim($listRow[$attributesFlip['sex']])];
                 $listRow[$attributesFlip['BMIGrade']] = $BMIArr[trim($listRow[$attributesFlip['BMIGrade']])];
                 $listRow[$attributesFlip['FVCGrade']] = $otherArr[trim($listRow[$attributesFlip['FVCGrade']])];
                 $listRow[$attributesFlip['_50mGrade']] = $otherArr[trim($listRow[$attributesFlip['_50mGrade']])];
                 $listRow[$attributesFlip['SARGrade']] = $otherArr[trim($listRow[$attributesFlip['SARGrade']])];
                 $listRow[$attributesFlip['SLJGrade']] = $otherArr[trim($listRow[$attributesFlip['SLJGrade']])];
                 $listRow[$attributesFlip['ChinUpGrade']] = $otherArr[trim($listRow[$attributesFlip['ChinUpGrade']])];
//.........這裏部分代碼省略.........
開發者ID:denglitong,項目名稱:tice,代碼行數:101,代碼來源:DataController.class.php


注:本文中的DataModel::create方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。