/** * 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(); } }
/** * Updates an existing Almacen model. * If update is successful, the browser will be redirected to the 'view' page. * @param integer $id * @return mixed */ public function actionUpdate($id) { $model = $this->findModel($id); $cadenas = Cadena::find()->where('status = "active"')->orderBy('titulo')->all(); $cadenas = ArrayHelper::map($cadenas, 'id', 'titulo'); if ($model->load(Yii::$app->request->post()) && $model->save()) { return $this->redirect(['view', 'id' => $model->id]); } else { return $this->render('update', ['model' => $model, 'cadenas' => $cadenas]); } }
/** * 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]); }
/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = Cadena::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', 'pais_origen', $this->pais_origen])->andFilterWhere(['like', 'status', $this->status]); return $dataProvider; }
/** * Finds the Cadena model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * @param integer $id * @return Cadena the loaded model * @throws NotFoundHttpException if the model cannot be found */ protected function findModel($id) { if (($model = Cadena::findOne($id)) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }
/** * @return \yii\db\ActiveQuery */ public function getCadenaR() { return $this->hasOne(Cadena::className(), ['id' => 'cadena_id']); }