Exemplo n.º 1
0
    }

    /**
     * @inheritdoc
     */
    public function attributeLabels()
    {
        return [
<?php foreach ($labels as $name => $label): ?>
            <?= "'$name' => " . $generator->generateString($label) . ",\n" ?>
<?php endforeach; ?>
        ];
    }

<?php if (!empty($generator->especializado)): 
        $tramite = TiposTramite::findOne($generator->especializado);
        foreach ($tramite->atributos as $atributo) :
            

?>
    public function get<?= Inflector::id2camel($atributo->nombre, '_') ?>()
    {
        <?php 
            switch ($atributo->tipoAtributo->nombre) {
                case app\models\TiposAtributo::ENTERO:
                case app\models\TiposAtributo::BOLEANO:
                    echo "return (int) \$this->retriveAttr({$atributo->id},{$atributo->pasoId})->valor;";
                    break;
                case app\models\TiposAtributo::FLOTANTE:
                    echo "return (float) \$this->retriveAttr({$atributo->id},{$atributo->pasoId})->valor;";
                    break;
Exemplo n.º 2
0
    public function generateRulesEspeciales($paso)
    {
        $types = [];
        $lengths = [];

        if(empty($this->especializado))
                return null;
        /*foreach ($table->columns as $column) {
            if ($column->autoIncrement) {
                continue;
            }
            if (!$column->allowNull && $column->defaultValue === null) {
                $types['required'][] = $column->name;
            }
            switch ($column->type) {
                case Schema::TYPE_SMALLINT:
                case Schema::TYPE_INTEGER:
                case Schema::TYPE_BIGINT:
                    $types['integer'][] = $column->name;
                    break;
                case Schema::TYPE_BOOLEAN:
                    $types['boolean'][] = $column->name;
                    break;
                case Schema::TYPE_FLOAT:
                case 'double': // Schema::TYPE_DOUBLE, which is available since Yii 2.0.3
                case Schema::TYPE_DECIMAL:
                case Schema::TYPE_MONEY:
                    $types['number'][] = $column->name;
                    break;
                case Schema::TYPE_DATE:
                case Schema::TYPE_TIME:
                case Schema::TYPE_DATETIME:
                case Schema::TYPE_TIMESTAMP:
                    $types['safe'][] = $column->name;
                    break;
                default: // strings
                    if ($column->size > 0) {
                        $lengths[$column->size][] = $column->name;
                    } else {
                        $types['string'][] = $column->name;
                    }
            }
        }*/
        $tramite = TiposTramite::findOne($this->especializado);
        foreach ($tramite->atributos as $atributo) 
        {
            if($atributo->pasoId==$paso)
            {
                $types[$atributo->tipoAtributo->nombre][]=$atributo->nombre;
                if($atributo->allowNull==0)
                    $types['required'][] = $atributo->nombre;
                if($atributo->attrLength>0)
                    $lengths[$atributo->attrLength][] = $atributo->nombre;
            }

        }

        $rules = [];
        foreach ($types as $type => $columns) {
            $rules[] = "[['" . implode("', '", $columns) . "'], '$type']";
        }
        foreach ($lengths as $length => $columns) {
            $rules[] = "[['" . implode("', '", $columns) . "'], 'string', 'max' => $length]";
        }

        // Unique indexes rules
       /* try {
            $db = $this->getDbConnection();
            $uniqueIndexes = $db->getSchema()->findUniqueIndexes($table);
            foreach ($uniqueIndexes as $uniqueColumns) {
                // Avoid validating auto incremental columns
                if (!$this->isColumnAutoIncremental($table, $uniqueColumns)) {
                    $attributesCount = count($uniqueColumns);

                    if ($attributesCount == 1) {
                        $rules[] = "[['" . $uniqueColumns[0] . "'], 'unique']";
                    } elseif ($attributesCount > 1) {
                        $labels = array_intersect_key($this->generateLabels($table), array_flip($uniqueColumns));
                        $lastLabel = array_pop($labels);
                        $columnsList = implode("', '", $uniqueColumns);
                        $rules[] = "[['" . $columnsList . "'], 'unique', 'targetAttribute' => ['" . $columnsList . "'], 'message' => 'The combination of " . implode(', ', $labels) . " and " . $lastLabel . " has already been taken.']";
                    }
                }
            }
        } catch (NotSupportedException $e) {
            // doesn't support unique indexes information...do nothing
        }*/

        

        return $rules;
    }
Exemplo n.º 3
0
 private function psalvar($paso)
 {
     $transaction = Yii::$app->db->beginTransaction();
     $datos = [];
     try {
         $this->pasoActualId = $paso->id;
         $this->tipoTramiteId = $this->tipoDeTramite();
         $datos['tipoTramiteId'] = $this->tipoDeTramite();
         $this->scenario = $this->pasoActualId;
         if (!$this->save()) {
             print_r($this->errors);
             return false;
         }
         foreach ($paso->atributos as $atributo) {
             $valor = $this->retriveAttr($atributo->id, $paso->id);
             $valor->tramiteId = $this->id;
             if ($valor->isNewRecord && !$this->permisosPorPaso[$paso->id][USUARIOS::$CREAR]) {
                 $transaction->rollBack();
                 throw new ForbiddenHttpException('No tiene Permiso para generar esta operacion');
                 return false;
             }
             if (!$valor->isNewRecord && !$this->permisosPorPaso[$paso->id][USUARIOS::$ACTUALIZAR]) {
                 $transaction->rollBack();
                 throw new ForbiddenHttpException('No tiene Permiso para actualizar estos datos');
                 return false;
             }
             if (!$valor->save()) {
                 print_r($this->errors);
                 $transaction->rollBack();
                 return false;
             }
             $datos[$atributo->nombre] = $valor->valor;
         }
         $paso = $this->retriveSiguientePaso();
         $this->pasoActualId = $paso->id;
         $datos['pasoActualId'] = $paso->id;
         $datos['id'] = $this->id;
         $datos['observaciones'] = $this->observaciones;
         TiposTramite::findOne($this->pasoActualId);
         if (empty($this->folio)) {
             $ciclo = $this->ciclo;
             if (empty($ciclo)) {
                 $configuracion = Configuracion::findOne(1);
                 //print_r($configuracion);
                 $this->ciclo = $configuracion->cicloActual;
             }
             $folio = Folios::find()->where(['ciclo_id' => $this->ciclo, 'tipoTramite_id' => $this->tipoTramiteId])->one();
             if (empty($folio)) {
                 $folio = new Folios();
                 $folio->ciclo_id = $this->ciclo;
                 $folio->tipoTramite_id = $this->tipoTramiteId;
                 $folio->proximofolio = 1;
             }
             $this->folio = $folio->proximofolio;
             $folio->proximofolio = $folio->proximofolio + 1;
             if (!$folio->save()) {
                 $transaction->rollBack();
                 //print_r($folio);
                 return false;
             }
         }
         if (!$this->save()) {
             $transaction->rollBack();
             return false;
         }
         $transaction->commit();
         return $datos;
     } catch (Exception $e) {
         $transaction->rollBack();
         return false;
     }
     return false;
 }