/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = LogUpload::find(); $dataProvider = new ActiveDataProvider(['query' => $query, 'sort' => ['defaultOrder' => ['id' => SORT_DESC]]]); if (!($this->load($params) && $this->validate())) { return $dataProvider; } $query->andFilterWhere(['id' => $this->id, 'userId' => $this->userCreate, 'type' => $this->type]); $query->andFilterWhere(['like', 'title', $this->title])->andFilterWhere(['like', 'filename', $this->filename])->andFilterWhere(['like', 'fileori', $this->fileori])->andFilterWhere(['like', 'warning', $this->warning])->andFilterWhere(['like', 'updateDate', $this->updateDate])->andFilterWhere(['like', 'createDate', $this->createDate])->andFilterWhere(['like', 'params', $this->params]); return $dataProvider; }
public function actionParsingLog($id) { $mod = LogUpload::findOne($id); $type = $mod->type; $keys = \yii\helpers\Json::decode($mod->keys); $values = \yii\helpers\Json::decode($mod->values); $modelAttribute = new Setting(); $not = Util::excelNot(); foreach ($values as $value) { if ($type == LogUpload::TYPE_INSERT) { $model = new Setting(); } else { $model = Setting::findOne($value['id']); } foreach ($keys as $v) { $model->{$v} = $value[$v]; } $e = 0; if ($model->save()) { $model = NULL; $pos = NULL; } else { $error[] = \yii\helpers\Json::encode($model->getErrors()); $e = 1; } } if ($error) { foreach ($error as $err) { if ($err) { $er[] = $err; $e += 1; } } if ($e) { $mod->warning = \yii\helpers\Json::encode($er); $mod->save(); echo '<pre>'; print_r($er); } } }
public function actionSample() { //$objPHPExcel = new \PHPExcel(); $template = Yii::$app->util->templateExcel(); $model = new LogUpload(); $date = date('YmdHis'); $name = $date . LogUpload; //$attributes = $model->attributeLabels(); $models = LogUpload::find()->all(); $excelChar = Yii::$app->util->excelChar(); $not = Yii::$app->util->excelNot(); foreach ($model->attributeLabels() as $k => $v) { if (!in_array($k, $not)) { $attributes[$k] = $v; } } $objReader = \PHPExcel_IOFactory::createReader('Excel5'); $objPHPExcel = $objReader->load(Yii::getAlias($template)); return $this->render('sample', ['models' => $models, 'attributes' => $attributes, 'excelChar' => $excelChar, 'not' => $not, 'name' => $name, 'objPHPExcel' => $objPHPExcel]); }
public function actionParsingLog($id) { $mod = LogUpload::findOne($id); $type = $mod->type; $params = \yii\helpers\Json::decode($mod->params); $values = \yii\helpers\Json::decode($mod->values); $modelAttribute = new Setting(); $not = Util::excelNot(); foreach ($modelAttribute->attributeLabels() as $k => $v) { if (!in_array($k, $not)) { $attr[] = $k; } } foreach ($values as $value) { if ($type == LogUpload::TYPE_INSERT) { $model = new Setting(); } else { $model = Setting::findOne($value['id']); } foreach ($attr as $at) { if (isset($value[$at])) { if ($value[$at]) { $model->{$at} = trim($value[$at]); } } } $e = 0; if ($model->save()) { $model = NULL; $pos = NULL; } else { $error[] = \yii\helpers\Json::encode($model->getErrors()); $e = 1; } } if ($error) { foreach ($error as $err) { if ($err) { $er[] = $err; $e += 1; } } if ($e) { $mod->warning = \yii\helpers\Json::encode($er); $mod->save(); echo '<pre>'; print_r($er); } } }