Quellcode durchsuchen

Avances sincronización postgres

ElPoteito vor 3 Jahren
Ursprung
Commit
79f89a5adf

+ 127 - 7
commands/EventoController.php

@@ -4,19 +4,43 @@ namespace app\commands;
 
 use app\components\FirebaseHelper;
 use v1\models\Evento;
+use v1\models\EventoGrupo;
 use v1\models\Grupo;
+use v1\models\Usuario;
+use v1\models\UsuarioGrupo;
 use yii\console\Controller;
+use yii\db\Expression;
+use yii\helpers\Json;
 
 class EventoController extends Controller {
 
+  public function stdoutln($cadena) {
+    return $this->stdout($cadena."\n");
+  }
+
   public function actionSincronizar() {
     $firebase = new FirebaseHelper();
     $firestore = $firebase->firestore();
 
+    $refGrupos = $firestore->collection("grupos");
+    $refUsuarios = $firestore->collection("usuarios");
+
+    $grupos = [];
+    $usuarios = [];
+
+    foreach($refGrupos->documents() as $grupo) {
+      $grupos[$grupo->id()] = $grupo->data();
+    }
+
+    foreach($refUsuarios->documents() as $usuario) {
+      $usuarios[$usuario->id()] = $usuario->data();
+    }
+    
     $ultimaFecha = null;
     $limite = 1; // 1000;
     $continuar = true;
-    do {
+    // do {
+      $this->stdout("Sincronizando ...");
       $ref = $firestore->collection("eventos")
       //  ->where("sincronizado", "==", null)
         ->orderBy("timestamp", "ASC")
@@ -39,18 +63,114 @@ class EventoController extends Controller {
 
           $modelo->nombre = $data["nombre"];
           $modelo->descripcion = $data["descripcion"];
+          $modelo->ciudad = $data["ciudad"];
+          $fechaInicio = \DateTime::createFromFormat('Y-m-d\TH:i:s.u\Z', $data["fechaInicio"]);
+          if ($fechaInicio !== false) {
+            $modelo->fechaInicio = $fechaInicio->format(\DateTime::RFC3339_EXTENDED);
+          }
+          $fechaFinal = \DateTime::createFromFormat('Y-m-d\TH:i:s.u\Z', $data["fechaFinal"]);
+          if ($fechaFinal !== false) {
+            $modelo->fechaFinal = $fechaFinal->format(\DateTime::RFC3339_EXTENDED);
+          }
+          $modelo->fotoEvento = $data["fotoEvento"];
+          $modelo->url = $data["pathFirebase"];
+          if (isset($data["tag"])) {
+            $modelo->tag = $data["tag"];
+          }
+          $modelo->firebaseId = $doc->id();
+
+          if (!$modelo->save()) {
+            $this->stdoutln('Ocurrió un error al guardar un evento. '.Json::encode($modelo->getFirstErrors()));
+            continue;
+          }
+
+          foreach ($data["grupos"] as $grupoEvento) {
+            $grupoModelo = Grupo::findOne(["firebaseId" => $grupoEvento]);
+            if($grupoModelo === null && isset($grupos[$grupoEvento])) {
+              $grupoModelo = new Grupo();
+              $grupoModelo->creado = new Expression('now()');
+              $grupoModelo->nombre = $grupos[$grupoEvento]["nombre"];
+              $grupoModelo->descripcion = $grupos[$grupoEvento]["descripcion"];
+              $grupoModelo->firebaseId = $grupoEvento;
+
+              if (!$grupoModelo->save()) {
+                $this->stdoutln('Ocurrió un error al guardar un grupo. '.Json::encode($grupoModelo->getFirstErrors()));
+              }
 
-          // Mapear información de los modelos
+            }
+            if ($grupoModelo !== null) {
+              $eventoGrupo = new EventoGrupo();
+  
+              $eventoGrupo->idEvento = $modelo->id;
+              $eventoGrupo->idGrupo = $grupoModelo->id;
+  
+              if(!$eventoGrupo->save()) {
+                $this->stdoutln('Ocurrió un error al guardar un evento-grupo. '.Json::encode($eventoGrupo->getFirstErrors()));
+              }
+            }
+          }
+
+          foreach ($data["usuarios"] as $usuarioEvento) {
+            $usuarioModelo = Usuario::findOne(["uid" => $usuarioEvento["uid"]]);
+            if ($usuarioModelo === null && isset($usuarios[$usuarioEvento["uid"]])) {
+              $usuarioModelo = new Usuario();
+              $usuarioRef = $usuarios[$usuarioEvento["uid"]];
+              $usuarioModelo->nombre = $usuarioRef["nombre"];
+              if (isset($usuarioRef["correo"])) {
+                $usuarioModelo->email = $usuarioRef["correo"];
+              }
+              $usuarioModelo->telefono = $usuarioRef["telefono"];
+              $usuarioModelo->facebook = $usuarioRef["facebook"];
+              if (isset($usuarioRef["facebookVerificado"])) {
+                $usuarioModelo->facebookVerificado = $usuarioRef["facebookVerificado"];
+              }
+              $usuarioModelo->instagram = $usuarioRef["instagram"];
+              if (isset($usuarioRef["instagramVerificado"])) {
+                $usuarioModelo->instagramVerificado = $usuarioRef["instagramVerificado"];
+              }
+              $usuarioModelo->twitter = $usuarioRef["twitter"];
+              if (isset($usuarioRef["twitterVerificado"])) {
+                $usuarioModelo->twitterVerificado = $usuarioRef["twitterVerificado"];
+              }
+              $usuarioModelo->genero = $usuarioRef["genero"];
+              $usuarioModelo->verificado = $usuarioRef["verificado"];
+              $usuarioModelo->creado = new Expression('now()');
+
+              if(!$usuarioModelo->save()) {
+                $this->stdoutln('Ocurrió un error al guardar un usuario. '.Json::encode($usuarioModelo->getFirstErrors()));
+              }
+            }
+
+            if ($usuarioModelo !== null && isset($usuarios[$usuarioEvento["uid"]]) && isset($usuarios[$usuarioEvento["uid"]]["grupo"]) && isset($usuarios[$usuarioEvento["uid"]]["grupo"][0])) {
+              $modelGrupo = Grupo::findOne(['firebaseId' => $usuarios[$usuarioEvento["uid"]]["grupo"][0]]);
+
+              $usuarioGrupo = UsuarioGrupo::find()
+                ->andWhere(["idUsuario" => $usuarioModelo->id])
+                ->andWhere(["idGrupo" => $modelGrupo->id])
+                ->one();
+
+              if ($usuarioGrupo === null) {
+                $usuarioGrupo = new UsuarioGrupo();
+
+                $usuarioGrupo->idUsuario = $usuarioModelo->id;
+                $usuarioGrupo->idGrupo = $usuarioGrupo->id;
+
+                if(!$usuarioGrupo->save()) {
+                  $this->stdoutln('Ocurrió un error al guardar un usuario-grupo. '.Json::encode($usuarioGrupo->getFirstErrors()));
+                }
+              }
+            }
+          }
 
           $hoy = new \DateTime();
           $doc->reference()
             ->update([
               ["path" => "sincronizado", "value" => "OK"],
               ["path" => "sincronizadoFecha", "value" => $hoy->format("Y-m-d H:i:s")],
-              ["path" => "evidencias", "value" => $data["evidencias"]],
             ]);
+            $this->stdoutln("Sincronizado correcto");
         } catch(\Exception $e) {
-          $this->stdout("Exception: {$e->getMessage()}\n");
+          $this->stdoutln("Exception: {$e->getMessage()}\n");
           $doc->reference()
             ->update([
               ["path" => "sincronizado", "value" => "ERROR"],
@@ -61,11 +181,11 @@ class EventoController extends Controller {
       }
 
       # Si los registros procesados son menores al límite, terminar
-      if($c < $limite) {
+      /* if($c < $limite) {
         $continuar = false;
-      }
+      } */
 
-    } while($continuar);
+    // } while($continuar);
   }
 
 }

+ 2 - 1
composer.json

@@ -19,7 +19,8 @@
         "yiisoft/yii2-bootstrap4": "~2.0.0",
         "yiisoft/yii2-swiftmailer": "~2.0.0 || ~2.1.0",
         "firebase/php-jwt": "^5.4",
-        "kreait/firebase-php": "^6.2"
+        "kreait/firebase-php": "^6.2",
+        "google/cloud-firestore": "^1.27"
     },
     "require-dev": {
         "yiisoft/yii2-debug": "~2.1.0",

Datei-Diff unterdrückt, da er zu groß ist
+ 2836 - 1459
composer.lock


+ 1 - 1
config/db.php

@@ -2,7 +2,7 @@
 
 return [
     'class' => 'yii\db\Connection',
-    'dsn' => 'pgsql:host=localhost;dbname=yager',
+    'dsn' => 'pgsql:host=localhost;dbname=yager-local',
     'username' => 'yager',
     'password' => 'yager',
     'charset' => 'utf8',

+ 56 - 0
migrations/m230130_220056_redes.php

@@ -0,0 +1,56 @@
+<?php
+
+use yii\db\Migration;
+
+/**
+ * Class m230130_220056_redes
+ */
+class m230130_220056_redes extends Migration {
+  /**
+   * {@inheritdoc}
+   */
+  public function safeUp() {
+
+    $this->createTable('Red', [
+      'idEvento' => $this->integer(),
+      'key' => $this->string(50),
+      'url' => $this->string(500),
+      'redSocial' => $this->string(250)
+    ]);
+
+    $this->addPrimaryKey('RedPK', 'Red', ['idEvento', 'url']);
+    $this->addForeignKey('RedEventoFK', 'Red', 'idEvento', 'Evento', 'id');
+
+    $this->addColumn('Evento', 'ciudad', $this->string(100));
+
+    $this->createTable('EventoAccion', [
+      'idEvento' => $this->integer(),
+      'accion' => $this->string(10)
+    ]);
+
+    $this->addPrimaryKey('EventoAccionPK', 'EventoAccion', ['idEvento', 'accion']);
+    $this->addForeignKey('EventoAccionEventoFK', 'EventoAccion', 'idEvento', 'Evento', 'id');
+
+    $this->alterColumn('Usuario', 'email', $this->string(100));
+  }
+
+  /**
+   * {@inheritdoc}
+   */
+  public function safeDown() {
+
+    $this->alterColumn('Usuario', 'email', $this->string(100)->notNull());
+
+    $this->dropTable('EventoAccion');
+
+    $this->dropForeignKey('EventoAccionEventoFK', 'EventoAccion');
+    $this->dropPrimaryKey('EventoAccionPK', 'EventoAccion');
+
+    $this->dropColumn('Evento', 'ciudad');
+    
+    $this->dropForeignKey('RedEventoFK', 'Red');
+    $this->dropPrimaryKey('RedPK', 'Red');
+
+    $this->dropTable('Red');
+  }
+}

+ 86 - 63
models/Evento.php

@@ -19,78 +19,101 @@ use Yii;
  * @property string|null $modificado
  * @property string|null $eliminado
  * @property string|null $firebaseId
+ * @property string|null $ciudad
  *
+ * @property EventoAccion[] $eventoAccions
  * @property EventoGrupo[] $eventoGrupos
  * @property Grupo[] $grupos
+ * @property Red[] $reds
  * @property Resultado[] $resultados
  */
 class Evento extends \yii\db\ActiveRecord {
-	/**
-	 * {@inheritdoc}
-	 */
-	public static function tableName() {
-		return 'Evento';
-	}
+  /**
+   * {@inheritdoc}
+   */
+  public static function tableName() {
+    return 'Evento';
+  }
 
-	/**
-	 * {@inheritdoc}
-	 */
-	public function rules() {
-		return [
-			[['nombre', 'url'], 'required'],
-			[['descripcion', 'fotoEvento'], 'string'],
-			[['fechaInicio', 'fechaFinal', 'creado', 'modificado', 'eliminado'], 'safe'],
-			[['nombre'], 'string', 'max' => 255],
-			[['tag', 'firebaseId'], 'string', 'max' => 50],
-			[['url'], 'string', 'max' => 155],
-			[['tag'], 'unique'],
-		];
-	}
+  /**
+   * {@inheritdoc}
+   */
+  public function rules() {
+    return [
+      [['nombre', 'url'], 'required'],
+      [['descripcion', 'fotoEvento'], 'string'],
+      [['fechaInicio', 'fechaFinal', 'creado', 'modificado', 'eliminado'], 'safe'],
+      [['nombre'], 'string', 'max' => 255],
+      [['tag', 'firebaseId'], 'string', 'max' => 50],
+      [['url'], 'string', 'max' => 155],
+      [['ciudad'], 'string', 'max' => 100],
+      [['tag'], 'unique'],
+    ];
+  }
 
-	/**
-	 * {@inheritdoc}
-	 */
-	public function attributeLabels() {
-		return [
-			'id' => 'ID',
-			'nombre' => 'Nombre',
-			'descripcion' => 'Descripcion',
-			'fotoEvento' => 'Foto Evento',
-			'tag' => 'Tag',
-			'url' => 'Url',
-			'fechaInicio' => 'Fecha Inicio',
-			'fechaFinal' => 'Fecha Final',
-			'creado' => 'Creado',
-			'modificado' => 'Modificado',
-			'eliminado' => 'Eliminado',
-			'firebaseId' => 'Firebase ID',
-		];
-	}
+  /**
+   * {@inheritdoc}
+   */
+  public function attributeLabels() {
+    return [
+      'id' => 'ID',
+      'nombre' => 'Nombre',
+      'descripcion' => 'Descripcion',
+      'fotoEvento' => 'Foto Evento',
+      'tag' => 'Tag',
+      'url' => 'Url',
+      'fechaInicio' => 'Fecha Inicio',
+      'fechaFinal' => 'Fecha Final',
+      'creado' => 'Creado',
+      'modificado' => 'Modificado',
+      'eliminado' => 'Eliminado',
+      'firebaseId' => 'Firebase ID',
+      'ciudad' => 'Ciudad',
+    ];
+  }
 
-	/**
-	 * Gets query for [[eventoGrupos]].
-	 *
-	 * @return \yii\db\ActiveQuery
-	 */
-	public function getEventoGrupos() {
-		return $this->hasMany(EventoGrupo::className(), ['idEvento' => 'id']);
-	}
+  /**
+   * Gets query for [[eventoAcciones]].
+   *
+   * @return \yii\db\ActiveQuery
+   */
+  public function getEventoAcciones() {
+    return $this->hasMany(EventoAccion::class, ['idEvento' => 'id']);
+  }
 
-	/**
-	 * Gets query for [[grupos]].
-	 *
-	 * @return \yii\db\ActiveQuery
-	 */
-	public function getGrupos() {
-		return $this->hasMany(Grupo::className(), ['id' => 'idGrupo'])->viaTable('EventoGrupo', ['idEvento' => 'id']);
-	}
+  /**
+   * Gets query for [[eventoGrupos]].
+   *
+   * @return \yii\db\ActiveQuery
+   */
+  public function getEventoGrupos() {
+    return $this->hasMany(EventoGrupo::class, ['idEvento' => 'id']);
+  }
 
-	/**
-	 * Gets query for [[resultados]].
-	 *
-	 * @return \yii\db\ActiveQuery
-	 */
-	public function getResultados() {
-		return $this->hasMany(Resultado::className(), ['idEvento' => 'id']);
-	}
+  /**
+   * Gets query for [[grupos]].
+   *
+   * @return \yii\db\ActiveQuery
+   */
+  public function getGrupos() {
+    return $this->hasMany(Grupo::class, ['id' => 'idGrupo'])->viaTable('EventoGrupo', ['idEvento' => 'id']);
+  }
+
+  /**
+   * Gets query for [[redes]].
+   *
+   * @return \yii\db\ActiveQuery
+   */
+  public function getRedes() {
+    return $this->hasMany(Red::class, ['idEvento' => 'id']);
+  }
+
+  /**
+   * Gets query for [[resultados]].
+   *
+   * @return \yii\db\ActiveQuery
+   */
+  public function getResultados() {
+    return $this->hasMany(Resultado::class, ['idEvento' => 'id']);
+  }
 }

+ 55 - 0
models/EventoAccion.php

@@ -0,0 +1,55 @@
+<?php
+
+namespace app\models;
+
+use Yii;
+
+/**
+ * This is the model class for table "EventoAccion".
+ *
+ * @property int $idEvento
+ * @property string $accion
+ *
+ * @property Evento $evento
+ */
+class EventoAccion extends \yii\db\ActiveRecord {
+  /**
+   * {@inheritdoc}
+   */
+  public static function tableName() {
+    return 'EventoAccion';
+  }
+
+  /**
+   * {@inheritdoc}
+   */
+  public function rules() {
+    return [
+      [['idEvento', 'accion'], 'required'],
+      [['idEvento'], 'default', 'value' => null],
+      [['idEvento'], 'integer'],
+      [['accion'], 'string', 'max' => 10],
+      [['idEvento', 'accion'], 'unique', 'targetAttribute' => ['idEvento', 'accion']],
+      [['idEvento'], 'exist', 'skipOnError' => true, 'targetClass' => Evento::class, 'targetAttribute' => ['idEvento' => 'id']],
+    ];
+  }
+
+  /**
+   * {@inheritdoc}
+   */
+  public function attributeLabels() {
+    return [
+      'idEvento' => 'Id Evento',
+      'accion' => 'Accion',
+    ];
+  }
+
+  /**
+   * Gets query for [[evento]].
+   *
+   * @return \yii\db\ActiveQuery
+   */
+  public function getEvento() {
+    return $this->hasOne(Evento::class, ['id' => 'idEvento']);
+  }
+}

+ 61 - 0
models/Red.php

@@ -0,0 +1,61 @@
+<?php
+
+namespace app\models;
+
+use Yii;
+
+/**
+ * This is the model class for table "Red".
+ *
+ * @property int $idEvento
+ * @property string|null $key
+ * @property string $url
+ * @property string|null $redSocial
+ *
+ * @property Evento $evento
+ */
+class Red extends \yii\db\ActiveRecord {
+  /**
+   * {@inheritdoc}
+   */
+  public static function tableName() {
+    return 'Red';
+  }
+
+  /**
+   * {@inheritdoc}
+   */
+  public function rules() {
+    return [
+      [['idEvento', 'url'], 'required'],
+      [['idEvento'], 'default', 'value' => null],
+      [['idEvento'], 'integer'],
+      [['key'], 'string', 'max' => 50],
+      [['url'], 'string', 'max' => 500],
+      [['redSocial'], 'string', 'max' => 250],
+      [['idEvento', 'url'], 'unique', 'targetAttribute' => ['idEvento', 'url']],
+      [['idEvento'], 'exist', 'skipOnError' => true, 'targetClass' => Evento::class, 'targetAttribute' => ['idEvento' => 'id']],
+    ];
+  }
+
+  /**
+   * {@inheritdoc}
+   */
+  public function attributeLabels() {
+    return [
+      'idEvento' => 'Id Evento',
+      'key' => 'Key',
+      'url' => 'Url',
+      'redSocial' => 'Red Social',
+    ];
+  }
+
+  /**
+   * Gets query for [[evento]].
+   *
+   * @return \yii\db\ActiveQuery
+   */
+  public function getEvento() {
+    return $this->hasOne(Evento::class, ['id' => 'idEvento']);
+  }
+}

+ 1 - 1
models/Usuario.php

@@ -42,7 +42,7 @@ class Usuario extends \yii\db\ActiveRecord {
    */
   public function rules() {
     return [
-      [['email', 'nombre'], 'required'],
+      [['nombre'], 'required'],
       [['facebookVerificado', 'instagramVerificado', 'twitterVerificado'], 'boolean'],
       [['verificado', 'creado', 'modificado', 'eliminado'], 'safe'],
       [['uid', 'genero'], 'string', 'max' => 50],

+ 85 - 0
modules/v1/controllers/EventoAccionController.php

@@ -0,0 +1,85 @@
+<?php
+
+namespace v1\controllers;
+
+use common\data\Respuesta;
+use common\rest\AuthController;
+use yii\db\Expression;
+
+class EventoAccionController extends AuthController {
+
+  public $modelClass = "v1\models\EventoAccion";
+  public $modelName = "EventoAccion";
+
+  public function actionIndex() {
+    $id = intval($this->req->get("id", ""));
+    $q = trim($this->req->get("q", ""));
+
+    $query = $this->queryInicial;
+
+    if($id > 0) {
+      $query->andWhere(["id" => $id]);
+    }
+
+    if($q !== "") {
+      /*# Ejemplo de buscador
+      $query->andWhere([
+        "OR",
+        ["ilike", "nombre", $q],
+        ["ilike", "direccion", $q],
+      ]);
+      // */
+    }
+
+    return new Respuesta($query, $this->limite, $this->pagina, $this->ordenar);
+  }
+
+  public function actionGuardar() {
+    $id = intval($this->req->getBodyParam("id", null));
+    $modelo = null;
+
+    if($id > 0) {
+      $modelo = $this->modelClass::findOne($id);
+    }
+    if($modelo === null) {
+      $modelo = new $this->modelClass();
+      $modelo->creado = new Expression('now()');
+      $modelo->idUsuarioCreador = $this->usuario->id;
+    } else {
+      $modelo->modificado = new Expression('now()');
+    }
+
+    $modelo->load($this->req->getBodyParams(), '');
+    if (!$modelo->save()) {
+      return (new Respuesta($modelo))
+        ->mensaje("Hubo un problema al guardar el {$this->modelName}");
+    }
+
+    $modelo->refresh();
+    return (new Respuesta($modelo))
+      ->mensaje("{$this->modelName} guardado correctamente");
+  }
+
+  public function actionEliminar() {
+    $id = intval($this->req->getBodyParam("id", null));
+    $modelo = null;
+
+    if($id > 0) {
+      $modelo = $this->modelClass::findOne(["id" => $id]);
+    }
+    if($modelo === null) {
+      return (new Respuesta())
+        ->esError()
+        ->mensaje("{$this->modelName} no encontrado");
+    }
+    $modelo->eliminado = null;
+    if(!$modelo->save()) {
+      return (new Respuesta($modelo))
+        ->mensaje("No se pudo eliminar el {$this->modelName}");
+    }
+
+    return (new Respuesta())
+      ->mensaje("{$this->modelName} eliminado");
+  }
+
+}

+ 85 - 0
modules/v1/controllers/RedController.php

@@ -0,0 +1,85 @@
+<?php
+
+namespace v1\controllers;
+
+use common\data\Respuesta;
+use common\rest\AuthController;
+use yii\db\Expression;
+
+class RedController extends AuthController {
+
+  public $modelClass = "v1\models\Red";
+  public $modelName = "Red";
+
+  public function actionIndex() {
+    $id = intval($this->req->get("id", ""));
+    $q = trim($this->req->get("q", ""));
+
+    $query = $this->queryInicial;
+
+    if($id > 0) {
+      $query->andWhere(["id" => $id]);
+    }
+
+    if($q !== "") {
+      /*# Ejemplo de buscador
+      $query->andWhere([
+        "OR",
+        ["ilike", "nombre", $q],
+        ["ilike", "direccion", $q],
+      ]);
+      // */
+    }
+
+    return new Respuesta($query, $this->limite, $this->pagina, $this->ordenar);
+  }
+
+  public function actionGuardar() {
+    $id = intval($this->req->getBodyParam("id", null));
+    $modelo = null;
+
+    if($id > 0) {
+      $modelo = $this->modelClass::findOne($id);
+    }
+    if($modelo === null) {
+      $modelo = new $this->modelClass();
+      $modelo->creado = new Expression('now()');
+      $modelo->idUsuarioCreador = $this->usuario->id;
+    } else {
+      $modelo->modificado = new Expression('now()');
+    }
+
+    $modelo->load($this->req->getBodyParams(), '');
+    if (!$modelo->save()) {
+      return (new Respuesta($modelo))
+        ->mensaje("Hubo un problema al guardar el {$this->modelName}");
+    }
+
+    $modelo->refresh();
+    return (new Respuesta($modelo))
+      ->mensaje("{$this->modelName} guardado correctamente");
+  }
+
+  public function actionEliminar() {
+    $id = intval($this->req->getBodyParam("id", null));
+    $modelo = null;
+
+    if($id > 0) {
+      $modelo = $this->modelClass::findOne(["id" => $id]);
+    }
+    if($modelo === null) {
+      return (new Respuesta())
+        ->esError()
+        ->mensaje("{$this->modelName} no encontrado");
+    }
+    $modelo->eliminado = null;
+    if(!$modelo->save()) {
+      return (new Respuesta($modelo))
+        ->mensaje("No se pudo eliminar el {$this->modelName}");
+    }
+
+    return (new Respuesta())
+      ->mensaje("{$this->modelName} eliminado");
+  }
+
+}

+ 33 - 23
modules/v1/models/Evento.php

@@ -9,38 +9,48 @@ class Evento extends ModeloEvento {
   public function fields() {
     return [
       'id',
-			'nombre',
-			'descripcion',
-			'fotoEvento',
-			'tag',
-			'url',
-			'fechaInicio',
-			'fechaFinal',
-			'creado',
-			'modificado',
-			'eliminado',
-			'firebaseId'
+      'nombre',
+      'descripcion',
+      'fotoEvento',
+      'tag',
+      'url',
+      'fechaInicio',
+      'fechaFinal',
+      'creado',
+      'modificado',
+      'eliminado',
+      'firebaseId',
+      'ciudad'
     ];
   }
 
   public function extraFields() {
     return [
-			'eventoGrupos',
-			'grupos',
+      'eventoAcciones',
+      'eventoGrupos',
+      'grupos',
+      'redes',
       'resultados',
     ];
   }
 
-	public function getEventoGrupos() {
-		return $this->hasMany(EventoGrupo::className(), ['idEvento' => 'id']);
-	}
+  public function getEventoAcciones() {
+    return $this->hasMany(EventoAccion::class, ['idEvento' => 'id']);
+  }
+
+  public function getEventoGrupos() {
+    return $this->hasMany(EventoGrupo::className(), ['idEvento' => 'id']);
+  }
 
-	public function getGrupos() {
-		return $this->hasMany(Grupo::className(), ['id' => 'idGrupo'])->viaTable('EventoGrupo', ['idEvento' => 'id']);
-	}
+  public function getGrupos() {
+    return $this->hasMany(Grupo::className(), ['id' => 'idGrupo'])->viaTable('EventoGrupo', ['idEvento' => 'id']);
+  }
 
-	public function getResultados() {
-		return $this->hasMany(Resultado::className(), ['idEvento' => 'id']);
-	}
+  public function getRedes() {
+    return $this->hasMany(Red::class, ['idEvento' => 'id']);
+  }
 
-}
+  public function getResultados() {
+    return $this->hasMany(Resultado::className(), ['idEvento' => 'id']);
+  }
+}

+ 25 - 0
modules/v1/models/EventoAccion.php

@@ -0,0 +1,25 @@
+<?php
+
+namespace v1\models;
+
+use app\models\EventoAccion as ModelsEventoAccion;
+
+class EventoAccion extends ModelsEventoAccion {
+
+  public function fields() { 
+    return [
+      'idEvento',
+      'accion',
+    ];
+  }
+
+  public function extraFields() { 
+    return [
+      'evento'
+    ];
+  }
+  
+  public function getEvento() {
+    return $this->hasOne(Evento::class, ['id' => 'idEvento']);
+  }
+}

+ 27 - 0
modules/v1/models/Red.php

@@ -0,0 +1,27 @@
+<?php
+
+namespace v1\models;
+
+use app\models\Red as ModelsRed;
+
+class Red extends ModelsRed {
+
+  public function fields() { 
+    return [
+      'idEvento',
+      'key',
+      'url',
+      'redSocial',
+    ];
+  }
+
+  public function extraFields() { 
+    return [
+      'evento'
+    ];
+  }
+
+  public function getEvento() {
+    return $this->hasOne(Evento::class, ['id' => 'idEvento']);
+  }
+}