コード例 #1
0
ファイル: ParcerController.php プロジェクト: emisdb/gena_0
 private function readsimple($thefile, $model)
 {
     TmpXml::model()->deleteAll('user='******'user='******'user='******'ALTER TABLE tmp_xml AUTO_INCREMENT = 1;')->execute();
     //            $connection->createCommand('ALTER TABLE tmp_docd AUTO_INCREMENT = 1;')->execute();
     $ii = 0;
     $jj = 0;
     $result = false;
     //			$data=array();
     if (file_exists($thefile)) {
         if (($handle = fopen($thefile, "r")) === FALSE) {
             return 'empty';
         }
         while (($cols = fgetcsv($handle, 1000, ";")) !== FALSE) {
             $ii++;
             if ($ii >= $model->n_str && $ii <= $model->n_fin) {
                 if ($jj == 0) {
                     $jj = 1;
                 }
                 $data = new TmpDocd();
                 $xml = new TmpXml();
                 $data->cnom = $jj;
                 $data->ckey = $jj;
                 $data->user = Yii::app()->user->uid;
                 $xml->user = Yii::app()->user->uid;
                 $xml->ckey = $jj++;
                 $tmp = trim($cols[$model->n_nom - 1]);
                 $tmp = iconv('windows-1251', 'UTF-8', $tmp . "");
                 $tmp = str_replace('""', '"', $tmp);
                 $tmp = preg_replace("/^\"(.*)\"\$/sim", "\$1", $tmp);
                 $xml->cname = $tmp;
                 $tmp = trim($cols[$model->n_art - 1]);
                 $xml->cgr = $tmp;
                 $xml->save();
                 $tmp = trim($cols[$model->n_price - 1]);
                 //									echo $tmp."/";
                 $tmp = str_replace(',', '.', $tmp);
                 //									echo $tmp."/";
                 $price = filter_var($tmp, FILTER_SANITIZE_NUMBER_FLOAT, FILTER_FLAG_ALLOW_FRACTION);
                 $tmp = trim($cols[$model->n_quant - 1]);
                 //									echo $tmp."/";
                 $tmp = str_replace(',', '.', $tmp);
                 //									echo $tmp."/";
                 $sum = filter_var($tmp, FILTER_SANITIZE_NUMBER_FLOAT, FILTER_FLAG_ALLOW_FRACTION);
                 //									echo ":".$price.":".$sum."<hr>";
                 $data->bpri = $price;
                 $data->bsum = $sum;
                 if ($price != 0) {
                     $data->bqua = round($sum / $price, 4);
                 }
                 $data->save();
             }
         }
     }
     return jj;
 }
コード例 #2
0
ファイル: TmpXmlController.php プロジェクト: emisdb/tffin
 /**
  * Returns the data model based on the primary key given in the GET variable.
  * If the data model is not found, an HTTP exception will be raised.
  * @param integer $id the ID of the model to be loaded
  * @return TmpXml the loaded model
  * @throws CHttpException
  */
 public function loadModel($id)
 {
     $model = TmpXml::model()->findByPk($id);
     if ($model === null) {
         throw new CHttpException(404, 'The requested page does not exist.');
     }
     return $model;
 }