/**
  * Crear categorias de notificaciones
  */
 public function actionCategoriasInit()
 {
     foreach ($this->categorias_notificaciones as $categoria) {
         if (!NotificacionesTipo::find()->where(['tipo' => $categoria['tipo']])->exists()) {
             $model = new NotificacionesTipo();
             $model->nombre = $categoria['nombre'];
             $model->estado = $categoria['estado'];
             $model->tipo = $categoria['tipo'];
             if (!$model->save()) {
                 $this->stdout("No se ha podido crear la categoria '" . $categoria['nombre'] . "'\n", Console::FG_RED);
                 return;
             }
         }
     }
     $this->stdout("Se han creado todas las categorias de notificaciones\n", Console::FG_GREEN);
     return;
 }
Example #2
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getTipos()
 {
     return $this->hasOne(NotificacionesTipo::className(), ['id' => 'tipo']);
 }
 /**
  * Obtiene el id del tipo de notificacion
  * @return int
  */
 private function obtenerTipo()
 {
     return NotificacionesTipo::findOne(['tipo' => $this->tipo])->id;
 }