Пример #1
0
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = Conocimiento::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(['idPerfil' => $this->idPerfil, 'idAreaConocimiento' => $this->idAreaConocimiento]);
     return $dataProvider;
 }
Пример #2
0
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = Conocimiento::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_conocimiento' => $this->id_conocimiento, 'nivel' => $this->nivel]);
     $query->andFilterWhere(['like', 'nombre', $this->nombre])->andFilterWhere(['like', 'descripcion', $this->descripcion]);
     return $dataProvider;
 }
Пример #3
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getConocimientos()
 {
     return $this->hasMany(Conocimiento::className(), ['idPerfil' => 'id']);
 }
Пример #4
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getConocimientos()
 {
     return $this->hasMany(Conocimiento::className(), ['NombreConocimientoid' => 'id']);
 }
Пример #5
0
 public function getDescripcion()
 {
     $conocimiento = Conocimiento::find()->where(['Usuarioid_usuario' => $this->id_usuario])->one();
     if (Direccion::find()->where(['Usuarioid_usuario' => $this->id_usuario])->exists()) {
         return $conocimiento->nivel;
     } else {
         return 'Este dato no se encuentra registrado';
     }
 }
 /**
  * Finds the Conocimiento model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param integer $idPerfil
  * @param integer $idAreaConocimiento
  * @return Conocimiento the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($idPerfil, $idAreaConocimiento)
 {
     if (($model = Conocimiento::findOne(['idPerfil' => $idPerfil, 'idAreaConocimiento' => $idAreaConocimiento])) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }
Пример #7
0
 /**
  * Finds the Conocimiento model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param integer $id
  * @return Conocimiento the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = Conocimiento::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }
Пример #8
0
 /**
  * Updates an existing Usuario model.
  * If update is successful, the browser will be redirected to the 'view' page.
  * @param integer $id
  * @return mixed
  */
 public function actionUpdate($id)
 {
     $user = new Usuario();
     $user = $this->findModel($id);
     $modelsConocimientos = $user->conocimientos;
     $modelsConocimientos = Conocimiento::find()->where(['id_conocimiento' => $user->id_usuario])->all();
     $institucion = ArrayHelper::map(Institucion::find()->all(), 'id_institucion', 'nombre');
     $cont = Contacto::find()->where(['id_contacto' => $user->id_usuario])->one();
     $dir = Direccion::find()->where(['id_direccion' => $user->id_usuario])->one();
     $repr = Representante::find()->where(['id_representante' => $user->id_usuario])->one();
     if ($user->load(Yii::$app->request->post()) && $cont->load(Yii::$app->request->post()) && $dir->load(Yii::$app->request->post()) && $repr->load(Yii::$app->request->post())) {
         $oldIDs = ArrayHelper::map($modelsConocimientos, 'id', 'id');
         $modelsConocimientos = Model::createMultiple(Conocimiento::classname(), $modelsConocimientos);
         Model::loadMultiple($modelsConocimientos, Yii::$app->request->post());
         $deletedIDs = array_diff($oldIDs, array_filter(ArrayHelper::map($modelsConocimientos, 'id_conocimiento', 'id_conocimiento')));
         if (Yii::$app->request->isAjax) {
             Yii::$app->response->format = Response::FORMAT_JSON;
             return ArrayHelper::merge(ActiveForm::validateMultiple($modelsConocimientos), ActiveForm::validate($user));
         }
         // validate all models
         $valid = $user->validate();
         $valid = Model::validateMultiple($modelsConocimientos) && $valid;
         if ($valid) {
             $transaction = \Yii::$app->db->beginTransaction();
             try {
                 if ($flag = $user->save(false)) {
                     if (!empty($deletedIDs)) {
                         Conocimiento::deleteAll(['id' => $deletedIDs]);
                     }
                     foreach ($modelsConocimientos as $modelConocimientos) {
                         $modelConocimientos->Usuarioid_usuario = $user->id_usuario;
                         if (!($flag = $modelConocimientos->save(false))) {
                             $transaction->rollBack();
                             break;
                         }
                     }
                 }
                 if ($flag) {
                     $transaction->commit();
                     return $this->redirect(['view', 'id' => $user->id_usuario]);
                 }
             } catch (Exception $e) {
                 $transaction->rollBack();
             }
         }
         if ($repr->save() && $cont->save() && $dir->save()) {
             return $this->redirect(['view', 'id' => $user->id_usuario]);
         } else {
             return $this->redirect(['index', 'id' => $user->id_usuario]);
         }
     } else {
         return $this->render('update', ['user' => $user, 'cont' => $cont, 'dir' => $dir, 'repr' => $repr, 'institucion' => $institucion, 'modelsConocimientos' => empty($modelsConocimientos) ? [new Conocimiento()] : $modelsConocimientos]);
     }
 }