/** * Renders the index view for the module * @return string */ public function actionIndex() { $new = new Registro(); $searchModel = new RegistroSearch(); $dataProvider = $searchModel->searchActive(Yii::$app->request->queryParams); if ($new->load(Yii::$app->request->post())) { $new->save(); } $cadenas = ArrayHelper::map(Cadena::find()->where(['status' => 'active'])->orderBy('titulo')->all(), 'id', 'titulo'); $almacenes = ArrayHelper::map(Almacen::find()->where(['status' => 'active'])->orderBy('identificador')->all(), 'id', 'identificador'); $categorias = ArrayHelper::map(Categoria::find()->where(['status' => 'active'])->orderBy('titulo')->all(), 'id', 'titulo'); return $this->render('index', ['new' => $new, 'cadenas' => $cadenas, 'almacenes' => $almacenes, 'categorias' => $categorias, 'searchModel' => $searchModel, 'dataProvider' => $dataProvider]); }
/** * This command echoes what you have entered as the message. * @param string $message the message to be echoed. */ public function actionStart() { $registros = Registro::find()->all(); foreach ($registros as $r) { //La cadena es la primera palabra $words = explode(' ', $r->almacen); $regcadena = $words[0]; $cadena = Cadena::find()->where(['titulo' => $regcadena])->one(); if (!$cadena) { $cadena = new Cadena(); $cadena->titulo = $regcadena; $cadena->detachBehavior('blameable'); $cadena->created_by = 1; $cadena->save(); } $regalmacen = ""; if (count($words) > 1) { $regalmacen = implode(' ', array_slice($words, 1, count($words) - 1)); $almacen = Almacen::find()->where(['identificador' => $regalmacen, 'cadena_id' => $cadena->id])->one(); } else { $almacen = null; } if (!$almacen) { $almacen = new Almacen(); $almacen->cadena_id = $cadena->id; $almacen->identificador = $regalmacen; $almacen->detachBehavior('blameable'); $almacen->created_by = 1; $almacen->save(); } $regcategoria = $r->categoria; $categoria = Categoria::find()->where(['titulo' => $r->categoria])->one(); if (!$categoria) { $categoria = new Categoria(); $categoria->titulo = $regcategoria; $categoria->descripcion = $r->elemento; $categoria->detachBehavior('blameable'); $categoria->created_by = 1; $categoria->save(); } elseif (strpos($categoria->descripcion, $r->elemento) === false) { $o = explode(', ', $categoria->descripcion); $o[] = $r->elemento; $categoria->descripcion = implode(', ', $o); $categoria->save(); } $r->cadena_id = $cadena->id; $r->almacen_id = $almacen->id; $r->categoria_id = $categoria->id; $r->save(); } }
/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = Categoria::find(); $dataProvider = new ActiveDataProvider(['query' => $query]); $this->load($params); if (!$this->validate()) { // uncomment the following line if you do not want to return any records when validation fails // $query->where('0=1'); return $dataProvider; } $query->andFilterWhere(['id' => $this->id, 'created_at' => $this->created_at, 'updated_at' => $this->updated_at, 'created_by' => $this->created_by, 'updated_by' => $this->updated_by]); $query->andFilterWhere(['like', 'titulo', $this->titulo])->andFilterWhere(['like', 'descripcion', $this->descripcion])->andFilterWhere(['like', 'status', $this->status]); return $dataProvider; }