/** * 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 a new Categoria model. * If creation is successful, the browser will be redirected to the 'view' page. * @return mixed */ public function actionCreate() { $model = new Categoria(); if ($model->load(Yii::$app->request->post()) && $model->save()) { return $this->redirect(['view', 'id' => $model->id]); } else { return $this->render('create', ['model' => $model]); } }