<?php
/* Autor...: William L. Taype Perez */
/* Esquema.: SEG_Tarea.xml */
/* Generado: 2021-06-25 23:59:59 */

/* Busqueda de registros de la tabla SEG_Tarea. */
abstract class BaseSEG_TareaFN extends SEG_TareaBN
{
    /* Declaracion de constantes */
    const IdTarea = "SEG_Tarea.IdTarea";
    const TareaDescripcion = "SEG_Tarea.TareaDescripcion";
    const BotonTexto = "SEG_Tarea.BotonTexto";
    const TareaTipo = "SEG_Tarea.TareaTipo";
    const ScriptId = "SEG_Tarea.ScriptId";
    const DeshabilitadoFlg = "SEG_Tarea.DeshabilitadoFlg";
    const IdPatron = "SEG_Tarea.IdPatron";
    const IdSubSistema = "SEG_Tarea.IdSubSistema";
    const InicialPassthru = "SEG_Tarea.InicialPassthru";
    const SeleccionFixed = "SEG_Tarea.SeleccionFixed";
    const SeleccionTemp = "SEG_Tarea.SeleccionTemp";
    const Settings = "SEG_Tarea.Settings";
    const OrdenarPor = "SEG_Tarea.OrdenarPor";
    const MantenerDatos = "SEG_Tarea.MantenerDatos";
    const LogSqlQuery = "SEG_Tarea.LogSqlQuery";
    const ScreenRefresh = "SEG_Tarea.ScreenRefresh";
    const UsaHttps = "SEG_Tarea.UsaHttps";
    const FechaCreacion = "SEG_Tarea.FechaCreacion";
    const UsuarioCreacion = "SEG_Tarea.UsuarioCreacion";
    const FechaModificacion = "SEG_Tarea.FechaModificacion";
    const UsuarioModificacion = "SEG_Tarea.UsuarioModificacion";

    public $a_Condition = array();
    public $a_OrderBy = array();
    public $a_GroupBy = array();
    public $b_Debug = false;

    /* Obtiene una conexion a la base de datos */
    public function getConnect()
    {
        $o_DBConnect = Conexion::getConexion();
        return $o_DBConnect;
    }

    public function getDebug()
    {
        if( SF_DEBUG )
        {
            $this->b_Debug = true;
        }
        return $this->b_Debug;
    }

    public function setDebug( $v )
    {
        $this->b_Debug = $v;
    }

    /* Obtiene la cadena de columas */
    public function getSelectColumns()
    {
        $s_SQLQuery = "SEG_Tarea.IdTarea AS IdTarea, ";
        $s_SQLQuery .= "SEG_Tarea.TareaDescripcion AS TareaDescripcion, ";
        $s_SQLQuery .= "SEG_Tarea.BotonTexto AS BotonTexto, ";
        $s_SQLQuery .= "SEG_Tarea.TareaTipo AS TareaTipo, ";
        $s_SQLQuery .= "SEG_Tarea.ScriptId AS ScriptId, ";
        $s_SQLQuery .= "SEG_Tarea.DeshabilitadoFlg AS DeshabilitadoFlg, ";
        $s_SQLQuery .= "SEG_Tarea.IdPatron AS IdPatron, ";
        $s_SQLQuery .= "SEG_Tarea.IdSubSistema AS IdSubSistema, ";
        $s_SQLQuery .= "SEG_Tarea.InicialPassthru AS InicialPassthru, ";
        $s_SQLQuery .= "SEG_Tarea.SeleccionFixed AS SeleccionFixed, ";
        $s_SQLQuery .= "SEG_Tarea.SeleccionTemp AS SeleccionTemp, ";
        $s_SQLQuery .= "SEG_Tarea.Settings AS Settings, ";
        $s_SQLQuery .= "SEG_Tarea.OrdenarPor AS OrdenarPor, ";
        $s_SQLQuery .= "SEG_Tarea.MantenerDatos AS MantenerDatos, ";
        $s_SQLQuery .= "SEG_Tarea.LogSqlQuery AS LogSqlQuery, ";
        $s_SQLQuery .= "SEG_Tarea.ScreenRefresh AS ScreenRefresh, ";
        $s_SQLQuery .= "SEG_Tarea.UsaHttps AS UsaHttps, ";
        $s_SQLQuery .= "SEG_Tarea.FechaCreacion AS FechaCreacion, ";
        $s_SQLQuery .= "SEG_Tarea.UsuarioCreacion AS UsuarioCreacion, ";
        $s_SQLQuery .= "SEG_Tarea.FechaModificacion AS FechaModificacion, ";
        $s_SQLQuery .= "SEG_Tarea.UsuarioModificacion AS UsuarioModificacion ";
        return $s_SQLQuery;
    }

    /* Establece el condicion de filtro de la lista resultante */
    public function addCondition( $s_Const, $s_Operator, $u_Value, $b_ComSimple = true )
    {
        $this->a_Condition[] = array( "COLUMN" => $s_Const, "OPERATOR" => $s_Operator, "VALUE" => $u_Value, "FLAG_COMILLAS" => $b_ComSimple );
    }

    /* Establece el orden de la lista resultante */
    public function addOrderBy( $s_Const, $b_OrderAsc = true )
    {
        $this->a_OrderBy[] = array( "COLUMN" => $s_Const, "ASC" => $b_OrderAsc );
    }

    /* Establece el orden de la lista resultante */
    public function addGroupBy( $s_Const )
    {
        $this->a_GroupBy[] = array( "COLUMN" => $s_Const );
    }

    /* Establece los valores desde un objeto SEG_TareaBN */
    public function setByBN( SEG_TareaBN $o_SEG_TareaBN )
    {
        if ( !is_null( $o_SEG_TareaBN->getIdTarea() ) )
        {
            $this->setIdTarea( $o_SEG_TareaBN->getIdTarea() );
        }
        if ( !is_null( $o_SEG_TareaBN->getTareaDescripcion() ) )
        {
            $this->setTareaDescripcion( $o_SEG_TareaBN->getTareaDescripcion() );
        }
        if ( !is_null( $o_SEG_TareaBN->getBotonTexto() ) )
        {
            $this->setBotonTexto( $o_SEG_TareaBN->getBotonTexto() );
        }
        if ( !is_null( $o_SEG_TareaBN->getTareaTipo() ) )
        {
            $this->setTareaTipo( $o_SEG_TareaBN->getTareaTipo() );
        }
        if ( !is_null( $o_SEG_TareaBN->getScriptId() ) )
        {
            $this->setScriptId( $o_SEG_TareaBN->getScriptId() );
        }
        if ( !is_null( $o_SEG_TareaBN->getDeshabilitadoFlg() ) )
        {
            $this->setDeshabilitadoFlg( $o_SEG_TareaBN->getDeshabilitadoFlg() );
        }
        if ( !is_null( $o_SEG_TareaBN->getIdPatron() ) )
        {
            $this->setIdPatron( $o_SEG_TareaBN->getIdPatron() );
        }
        if ( !is_null( $o_SEG_TareaBN->getIdSubSistema() ) )
        {
            $this->setIdSubSistema( $o_SEG_TareaBN->getIdSubSistema() );
        }
        if ( !is_null( $o_SEG_TareaBN->getInicialPassthru() ) )
        {
            $this->setInicialPassthru( $o_SEG_TareaBN->getInicialPassthru() );
        }
        if ( !is_null( $o_SEG_TareaBN->getSeleccionFixed() ) )
        {
            $this->setSeleccionFixed( $o_SEG_TareaBN->getSeleccionFixed() );
        }
        if ( !is_null( $o_SEG_TareaBN->getSeleccionTemp() ) )
        {
            $this->setSeleccionTemp( $o_SEG_TareaBN->getSeleccionTemp() );
        }
        if ( !is_null( $o_SEG_TareaBN->getSettings() ) )
        {
            $this->setSettings( $o_SEG_TareaBN->getSettings() );
        }
        if ( !is_null( $o_SEG_TareaBN->getOrdenarPor() ) )
        {
            $this->setOrdenarPor( $o_SEG_TareaBN->getOrdenarPor() );
        }
        if ( !is_null( $o_SEG_TareaBN->getMantenerDatos() ) )
        {
            $this->setMantenerDatos( $o_SEG_TareaBN->getMantenerDatos() );
        }
        if ( !is_null( $o_SEG_TareaBN->getLogSqlQuery() ) )
        {
            $this->setLogSqlQuery( $o_SEG_TareaBN->getLogSqlQuery() );
        }
        if ( !is_null( $o_SEG_TareaBN->getScreenRefresh() ) )
        {
            $this->setScreenRefresh( $o_SEG_TareaBN->getScreenRefresh() );
        }
        if ( !is_null( $o_SEG_TareaBN->getUsaHttps() ) )
        {
            $this->setUsaHttps( $o_SEG_TareaBN->getUsaHttps() );
        }
        if ( !is_null( $o_SEG_TareaBN->getFechaCreacion() ) )
        {
            $this->setFechaCreacion( $o_SEG_TareaBN->getFechaCreacion() );
        }
        if ( !is_null( $o_SEG_TareaBN->getUsuarioCreacion() ) )
        {
            $this->setUsuarioCreacion( $o_SEG_TareaBN->getUsuarioCreacion() );
        }
        if ( !is_null( $o_SEG_TareaBN->getFechaModificacion() ) )
        {
            $this->setFechaModificacion( $o_SEG_TareaBN->getFechaModificacion() );
        }
        if ( !is_null( $o_SEG_TareaBN->getUsuarioModificacion() ) )
        {
            $this->setUsuarioModificacion( $o_SEG_TareaBN->getUsuarioModificacion() );
        }
    }

    /**
    * @return SEG_TareaBN|null
    * @throws SQLException
    */
    public function selectByPK( $s_IdTarea )
    {
        if( is_null( $s_IdTarea ) ){ $s_IdTarea = '-1'; } 
 
        $s_SQLQuery = "SELECT ";
        $s_SQLQuery .= $this->getSelectColumns();
        $s_SQLQuery .= "FROM SEG_Tarea ";
        $s_SQLQuery .= "WHERE IdTarea = '".$s_IdTarea."' ";
        $s_SQLQuery .= "LIMIT 1;";
        if( $this->getDebug() ){ pr( $s_SQLQuery ); }
        $o_SEG_TareaBN = null;
        $o_Resource = $this->getConnect();
        $o_Statement = $o_Resource->prepareStatement( $s_SQLQuery );
        $o_ResultSet = $o_Statement->executeQuery();
        $i_NumRows   = $o_ResultSet->getRecordCount();
        if( $i_NumRows > 0 )
        {
            $o_ResultSet->next();
            $a_SQLRow = $o_ResultSet->getRow(); //devuele array
            $o_SEG_TareaBN = $this->insertObjectBN( $a_SQLRow );
        }
        return $o_SEG_TareaBN;
    }

    public function buildConsult()
    {
        $s_SQLQuery = "";
        if ( !is_null( $this->getIdTarea() ) ) $s_SQLQuery .= "SEG_Tarea.IdTarea = '".$this->getIdTarea()."' AND ";
        if ( !is_null( $this->getTareaDescripcion() ) ) $s_SQLQuery .= "SEG_Tarea.TareaDescripcion = '".$this->getTareaDescripcion()."' AND ";
        if ( !is_null( $this->getBotonTexto() ) ) $s_SQLQuery .= "SEG_Tarea.BotonTexto = '".$this->getBotonTexto()."' AND ";
        if ( !is_null( $this->getTareaTipo() ) ) $s_SQLQuery .= "SEG_Tarea.TareaTipo = '".$this->getTareaTipo()."' AND ";
        if ( !is_null( $this->getScriptId() ) ) $s_SQLQuery .= "SEG_Tarea.ScriptId = '".$this->getScriptId()."' AND ";
        if ( !is_null( $this->getDeshabilitadoFlg() ) ) $s_SQLQuery .= "SEG_Tarea.DeshabilitadoFlg = '".$this->getDeshabilitadoFlg()."' AND ";
        if ( !is_null( $this->getIdPatron() ) ) $s_SQLQuery .= "SEG_Tarea.IdPatron = '".$this->getIdPatron()."' AND ";
        if ( !is_null( $this->getIdSubSistema() ) ) $s_SQLQuery .= "SEG_Tarea.IdSubSistema = '".$this->getIdSubSistema()."' AND ";
        if ( !is_null( $this->getInicialPassthru() ) ) $s_SQLQuery .= "SEG_Tarea.InicialPassthru = '".$this->getInicialPassthru()."' AND ";
        if ( !is_null( $this->getSeleccionFixed() ) ) $s_SQLQuery .= "SEG_Tarea.SeleccionFixed = '".$this->getSeleccionFixed()."' AND ";
        if ( !is_null( $this->getSeleccionTemp() ) ) $s_SQLQuery .= "SEG_Tarea.SeleccionTemp = '".$this->getSeleccionTemp()."' AND ";
        if ( !is_null( $this->getSettings() ) ) $s_SQLQuery .= "SEG_Tarea.Settings = '".$this->getSettings()."' AND ";
        if ( !is_null( $this->getOrdenarPor() ) ) $s_SQLQuery .= "SEG_Tarea.OrdenarPor = '".$this->getOrdenarPor()."' AND ";
        if ( !is_null( $this->getMantenerDatos() ) ) $s_SQLQuery .= "SEG_Tarea.MantenerDatos = '".$this->getMantenerDatos()."' AND ";
        if ( !is_null( $this->getLogSqlQuery() ) ) $s_SQLQuery .= "SEG_Tarea.LogSqlQuery = '".$this->getLogSqlQuery()."' AND ";
        if ( !is_null( $this->getScreenRefresh() ) ) $s_SQLQuery .= "SEG_Tarea.ScreenRefresh = ".$this->getScreenRefresh()." AND ";
        if ( !is_null( $this->getUsaHttps() ) ) $s_SQLQuery .= "SEG_Tarea.UsaHttps = '".$this->getUsaHttps()."' AND ";
        if ( !is_null( $this->getFechaCreacion() ) ) $s_SQLQuery .= "SEG_Tarea.FechaCreacion = '".$this->getFechaCreacion()."' AND ";
        if ( !is_null( $this->getUsuarioCreacion() ) ) $s_SQLQuery .= "SEG_Tarea.UsuarioCreacion = '".$this->getUsuarioCreacion()."' AND ";
        if ( !is_null( $this->getFechaModificacion() ) ) $s_SQLQuery .= "SEG_Tarea.FechaModificacion = '".$this->getFechaModificacion()."' AND ";
        if ( !is_null( $this->getUsuarioModificacion() ) ) $s_SQLQuery .= "SEG_Tarea.UsuarioModificacion = '".$this->getUsuarioModificacion()."' AND ";
        if ( count( $this->a_Condition ) > 0 )
        {
            foreach ( $this->a_Condition as $a_Condition )
            {
                if( $a_Condition['FLAG_COMILLAS'] )
                {
                    $s_SQLQuery .= $a_Condition[ "COLUMN" ]." ".$a_Condition[ "OPERATOR" ]." '".$a_Condition[ "VALUE" ]."' AND ";
                }
                else
                {
                    $s_SQLQuery .= $a_Condition[ "COLUMN" ]." ".$a_Condition[ "OPERATOR" ]." ".$a_Condition[ "VALUE" ]." AND ";
                }
            }
        }
        $s_SQLQuery .= "1 = 1 ";
        return $s_SQLQuery;
    }

    public function selectNumRows()
    {
        $s_SQLQuery = "SELECT ";
        $s_SQLQuery .= "COUNT(*) AS cnt ";
        $s_SQLQuery .= "FROM SEG_Tarea WHERE ";
        $s_SQLQuery .= $this->buildConsult();
        
        if ( count( $this->a_GroupBy ) > 0 )
        {
            $s_SQLQuery .= "GROUP BY ";
            $s_Separator = "";
            foreach ( $this->a_GroupBy as $a_GroupBy )
            {
                $s_SQLQuery .= $s_Separator.$a_GroupBy[ "COLUMN" ]." ";
                $s_Separator = ", ";
            }
        }
        if( $this->getDebug() ){ pr( $s_SQLQuery ); }
        $o_Resource = $this->getConnect();
        $o_Statement = $o_Resource->prepareStatement( $s_SQLQuery );
        $o_ResultSet = $o_Statement->executeQuery();
        $o_ResultSet->next();
        $i_NumRows    = $o_ResultSet->getInt( 'cnt' );
        return $i_NumRows;
    }

    /**
    * @param null $i_Position
    * @param null $i_Rows
    * @return SEG_TareaBN[]
    * @throws SQLException
    */
    public function select( $i_Position = null, $i_Rows = null )
    {
        $s_SQLQuery = "SELECT ";
        $s_SQLQuery .= $this->getSelectColumns();
        $s_SQLQuery .= "FROM SEG_Tarea WHERE ";
        $s_SQLQuery .= $this->buildConsult();
        if ( count( $this->a_GroupBy ) > 0 )
        {
            $s_SQLQuery .= "GROUP BY ";
            $s_Separator = "";
            foreach ( $this->a_GroupBy as $a_GroupBy )
            {
                $s_SQLQuery .= $s_Separator.$a_GroupBy[ "COLUMN" ]." ";
                $s_Separator = ", ";
            }
        }
        if ( count( $this->a_OrderBy ) > 0 )
        {
            $s_SQLQuery = $s_SQLQuery."ORDER BY ";
            $s_Separator = "";
            foreach ( $this->a_OrderBy as $a_OrderBy )
            {
                $s_SQLQuery .= $s_Separator.$a_OrderBy[ "COLUMN" ]." ";
                if ( $a_OrderBy[ "ASC" ] === false ) $s_SQLQuery .= "DESC ";
                $s_Separator = ", ";
            }
        }
        if( !is_null( $i_Position ) && is_null( $i_Rows ) ) $s_SQLQuery .= "LIMIT ".$i_Position;
        if( !is_null( $i_Position ) && !is_null( $i_Rows ) ) $s_SQLQuery .= "LIMIT ".$i_Position.", ".$i_Rows;
        $s_SQLQuery .= ";";

        if( $this->getDebug() ){ pr( $s_SQLQuery ); }

        $a_SEG_TareaBN = array();
        $o_Resource = $this->getConnect();
        $o_Statement = $o_Resource->prepareStatement( $s_SQLQuery );
        $o_ResultSet = $o_Statement->executeQuery();
        $i_NumRows = $o_ResultSet->getRecordCount();
        if( $i_NumRows > 0 )
        {
            while( $o_ResultSet->next() ) 
            {
                $a_SQLRow = $o_ResultSet->getRow(); //devuele array
                $o_SEG_TareaBN = $this->insertObjectBN( $a_SQLRow );
                $a_SEG_TareaBN[] = $o_SEG_TareaBN;
            }
        }
        return $a_SEG_TareaBN;
    }

    /* Devuelve un objeto SEG_TareaBN desde un objeto propel */
    public function insertObjectBN( $a_SEG_Tarea )
    {
        $o_SEG_TareaBN = new SEG_TareaBN();
        if ( !is_null( $a_SEG_Tarea['IdTarea'] ) ) $o_SEG_TareaBN->setIdTarea( $a_SEG_Tarea['IdTarea'] );
        if ( !is_null( $a_SEG_Tarea['TareaDescripcion'] ) ) $o_SEG_TareaBN->setTareaDescripcion( $a_SEG_Tarea['TareaDescripcion'] );
        if ( !is_null( $a_SEG_Tarea['BotonTexto'] ) ) $o_SEG_TareaBN->setBotonTexto( $a_SEG_Tarea['BotonTexto'] );
        if ( !is_null( $a_SEG_Tarea['TareaTipo'] ) ) $o_SEG_TareaBN->setTareaTipo( $a_SEG_Tarea['TareaTipo'] );
        if ( !is_null( $a_SEG_Tarea['ScriptId'] ) ) $o_SEG_TareaBN->setScriptId( $a_SEG_Tarea['ScriptId'] );
        if ( !is_null( $a_SEG_Tarea['DeshabilitadoFlg'] ) ) $o_SEG_TareaBN->setDeshabilitadoFlg( $a_SEG_Tarea['DeshabilitadoFlg'] );
        if ( !is_null( $a_SEG_Tarea['IdPatron'] ) ) $o_SEG_TareaBN->setIdPatron( $a_SEG_Tarea['IdPatron'] );
        if ( !is_null( $a_SEG_Tarea['IdSubSistema'] ) ) $o_SEG_TareaBN->setIdSubSistema( $a_SEG_Tarea['IdSubSistema'] );
        if ( !is_null( $a_SEG_Tarea['InicialPassthru'] ) ) $o_SEG_TareaBN->setInicialPassthru( $a_SEG_Tarea['InicialPassthru'] );
        if ( !is_null( $a_SEG_Tarea['SeleccionFixed'] ) ) $o_SEG_TareaBN->setSeleccionFixed( $a_SEG_Tarea['SeleccionFixed'] );
        if ( !is_null( $a_SEG_Tarea['SeleccionTemp'] ) ) $o_SEG_TareaBN->setSeleccionTemp( $a_SEG_Tarea['SeleccionTemp'] );
        if ( !is_null( $a_SEG_Tarea['Settings'] ) ) $o_SEG_TareaBN->setSettings( $a_SEG_Tarea['Settings'] );
        if ( !is_null( $a_SEG_Tarea['OrdenarPor'] ) ) $o_SEG_TareaBN->setOrdenarPor( $a_SEG_Tarea['OrdenarPor'] );
        if ( !is_null( $a_SEG_Tarea['MantenerDatos'] ) ) $o_SEG_TareaBN->setMantenerDatos( $a_SEG_Tarea['MantenerDatos'] );
        if ( !is_null( $a_SEG_Tarea['LogSqlQuery'] ) ) $o_SEG_TareaBN->setLogSqlQuery( $a_SEG_Tarea['LogSqlQuery'] );
        if ( !is_null( $a_SEG_Tarea['ScreenRefresh'] ) ) $o_SEG_TareaBN->setScreenRefresh( ( integer ) $a_SEG_Tarea['ScreenRefresh'] );
        if ( !is_null( $a_SEG_Tarea['UsaHttps'] ) ) $o_SEG_TareaBN->setUsaHttps( $a_SEG_Tarea['UsaHttps'] );
        if ( !is_null( $a_SEG_Tarea['FechaCreacion'] ) ) $o_SEG_TareaBN->setFechaCreacion( utilTimestamp::getTimestamp( $a_SEG_Tarea['FechaCreacion'], "Y-m-d H:i:s" ) );
        if ( !is_null( $a_SEG_Tarea['UsuarioCreacion'] ) ) $o_SEG_TareaBN->setUsuarioCreacion( $a_SEG_Tarea['UsuarioCreacion'] );
        if ( !is_null( $a_SEG_Tarea['FechaModificacion'] ) ) $o_SEG_TareaBN->setFechaModificacion( utilTimestamp::getTimestamp( $a_SEG_Tarea['FechaModificacion'], "Y-m-d H:i:s" ) );
        if ( !is_null( $a_SEG_Tarea['UsuarioModificacion'] ) ) $o_SEG_TareaBN->setUsuarioModificacion( $a_SEG_Tarea['UsuarioModificacion'] );
        return $o_SEG_TareaBN;
    }
}
?>