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9vY$wdd
&eզr8޵y93~30
[s2#2f_uUB }[9H(]yG-g)vգԤVJE{b7PT)y<)v3\ >yTڽ!AݍC0吝q@0F3Y(0F90q{0twz9Hi^r|Z.xz
eaYs[ڂnk
SilXR/]\jt	mZK29vwr_s!48Gt`)M9f*c6~.Y6CwD|31gZoR mn3N O~˛[
 vȎ/׏ǛD$a&,	;tmzV5+ܞ+,}&z;%d"ɰÆgPpA>*l`P+yBx\{m's*qY(ilGU
Ȩ,!+١i4Ȏbh LSg_aFwRUVYy)km92v,oJqD@BG/X)Kd%,`VX"/Q+Giuؘ9750ӌkX {9}Nͣ|ԑ6YޔҺVBHL:@Y_%SۀsWp]\ᆻ0ub{CmB{jl`ARa2}y'8%Mf2ٚa5FI
Iv	nh[Widy9K@6[J6vso^yʉwH5|CfT+R!ɤt,	JD, Cq	B@܁+{6".JRI *fDD#mvPS4K5ڡ,(eK*]0umk|x9iGOm|劯Y5sqwi⏃-V!sG
ʛ9夶4oncvHY6DY7-ѕ毕JGEF>'_+ lPƽctoDn!ݬZy8V"pQ7#ISb%)sSO.F<1ϱ{p9;
zIL.2jgmJS7#+6a҈&7cX"9V/FEj''}}l19-5˝/8^pb}MsҞ1t
PcpsJ8XV5H/sS9h5ZS(M c<IzK,Lj5߳0DGܺ^ވf_ƗD
,ÁZcO3j$@Y݄rO	~xܹ?%Mŕ cp.@tjl$`8Ouk(x9,=/|l
5s1]j޼$xq?{>HC.C.8O veyN&޼$xq?˳( }qZCpe 'server', 'database', 'table'
     * @param string $db_alias    Aliases of db
     *
     * @return bool Whether it succeeded
     */
    public function exportDBCreate($db, $export_type, $db_alias = '')
    {
        return true;
    }

    /**
     * Outputs the content of a table in NHibernate format
     *
     * @param string $db        database name
     * @param string $table     table name
     * @param string $crlf      the end of line sequence
     * @param string $error_url the url to go back in case of error
     * @param string $sql_query SQL query for obtaining data
     * @param array  $aliases   Aliases of db/table/columns
     *
     * @return bool Whether it succeeded
     */
    public function exportData(
        $db,
        $table,
        $crlf,
        $error_url,
        $sql_query,
        $aliases = array()
    ) {
        $CG_FORMATS = $this->_getCgFormats();
        $CG_HANDLERS = $this->_getCgHandlers();

        $format = $GLOBALS['codegen_format'];
        if (isset($CG_FORMATS[$format])) {
            $method = $CG_HANDLERS[$format];

            return PMA_exportOutputHandler(
                $this->$method($db, $table, $crlf, $aliases)
            );
        }

        return PMA_exportOutputHandler(sprintf("%s is not supported.", $format));
    }

    /**
     * Used to make identifiers (from table or database names)
     *
     * @param string $str     name to be converted
     * @param bool   $ucfirst whether to make the first character uppercase
     *
     * @return string identifier
     */
    public static function cgMakeIdentifier($str, $ucfirst = true)
    {
        // remove unsafe characters
        $str = preg_replace('/[^\p{L}\p{Nl}_]/u', '', $str);
        // make sure first character is a letter or _
        if (!preg_match('/^\pL/u', $str)) {
            $str = '_' . $str;
        }
        if ($ucfirst) {
            $str = ucfirst($str);
        }

        return $str;
    }

    /**
     * C# Handler
     *
     * @param string $db      database name
     * @param string $table   table name
     * @param string $crlf    line separator
     * @param array  $aliases Aliases of db/table/columns
     *
     * @return string containing C# code lines, separated by "\n"
     */
    private function _handleNHibernateCSBody($db, $table, $crlf, $aliases = array())
    {
        $db_alias = $db;
        $table_alias = $table;
        $this->initAlias($aliases, $db_alias, $table_alias);
        $lines = array();

        $result = $GLOBALS['dbi']->query(
            sprintf(
                'DESC %s.%s',
                PMA\libraries\Util::backquote($db),
                PMA\libraries\Util::backquote($table)
            )
        );
        if ($result) {
            /** @var TableProperty[] $tableProperties */
            $tableProperties = array();
            while ($row = $GLOBALS['dbi']->fetchRow($result)) {
                $col_as = $this->getAlias($aliases, $row[0], 'col', $db, $table);
                if (!empty($col_as)) {
                    $row[0] = $col_as;
                }
                $tableProperties[] = new TableProperty($row);
            }
            $GLOBALS['dbi']->freeResult($result);
            $lines[] = 'using System;';
            $lines[] = 'using System.Collections;';
            $lines[] = 'using System.Collections.Generic;';
            $lines[] = 'using System.Text;';
            $lines[] = 'namespace ' . ExportCodegen::cgMakeIdentifier($db_alias);
            $lines[] = '{';
            $lines[] = '    #region '
                . ExportCodegen::cgMakeIdentifier($table_alias);
            $lines[] = '    public class '
                . ExportCodegen::cgMakeIdentifier($table_alias);
            $lines[] = '    {';
            $lines[] = '        #region Member Variables';
            foreach ($tableProperties as $tableProperty) {
                $lines[] = $tableProperty->formatCs(
                    '        protected #dotNetPrimitiveType# _#name#;'
                );
            }
            $lines[] = '        #endregion';
            $lines[] = '        #region Constructors';
            $lines[] = '        public '
                . ExportCodegen::cgMakeIdentifier($table_alias) . '() { }';
            $temp = array();
            foreach ($tableProperties as $tableProperty) {
                if (!$tableProperty->isPK()) {
                    $temp[] = $tableProperty->formatCs(
                        '#dotNetPrimitiveType# #name#'
                    );
                }
            }
            $lines[] = '        public '
                . ExportCodegen::cgMakeIdentifier($table_alias)
                . '('
                . implode(', ', $temp)
                . ')';
            $lines[] = '        {';
            foreach ($tableProperties as $tableProperty) {
                if (!$tableProperty->isPK()) {
                    $lines[] = $tableProperty->formatCs(
                        '            this._#name#=#name#;'
                    );
                }
            }
            $lines[] = '        }';
            $lines[] = '        #endregion';
            $lines[] = '        #region Public Properties';
            foreach ($tableProperties as $tableProperty) {
                $lines[] = $tableProperty->formatCs(
                    '        public virtual #dotNetPrimitiveType# #ucfirstName#'
                    . "\n"
                    . '        {' . "\n"
                    . '            get {return _#name#;}' . "\n"
                    . '            set {_#name#=value;}' . "\n"
                    . '        }'
                );
            }
            $lines[] = '        #endregion';
            $lines[] = '    }';
            $lines[] = '    #endregion';
            $lines[] = '}';
        }

        return implode($crlf, $lines);
    }

    /**
     * XML Handler
     *
     * @param string $db      database name
     * @param string $table   table name
     * @param string $crlf    line separator
     * @param array  $aliases Aliases of db/table/columns
     *
     * @return string containing XML code lines, separated by "\n"
     */
    private function _handleNHibernateXMLBody(
        $db,
        $table,
        $crlf,
        $aliases = array()
    ) {
        $db_alias = $db;
        $table_alias = $table;
        $this->initAlias($aliases, $db_alias, $table_alias);
        $lines = array();
        $lines[] = '<?xml version="1.0" encoding="utf-8" ?' . '>';
        $lines[] = '<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" '
            . 'namespace="' . ExportCodegen::cgMakeIdentifier($db_alias) . '" '
            . 'assembly="' . ExportCodegen::cgMakeIdentifier($db_alias) . '">';
        $lines[] = '    <class '
            . 'name="' . ExportCodegen::cgMakeIdentifier($table_alias) . '" '
            . 'table="' . ExportCodegen::cgMakeIdentifier($table_alias) . '">';
        $result = $GLOBALS['dbi']->query(
            sprintf(
                "DESC %s.%s",
                PMA\libraries\Util::backquote($db),
                PMA\libraries\Util::backquote($table)
            )
        );
        if ($result) {
            while ($row = $GLOBALS['dbi']->fetchRow($result)) {
                $col_as = $this->getAlias($aliases, $row[0], 'col', $db, $table);
                if (!empty($col_as)) {
                    $row[0] = $col_as;
                }
                $tableProperty = new TableProperty($row);
                if ($tableProperty->isPK()) {
                    $lines[] = $tableProperty->formatXml(
                        '        <id name="#ucfirstName#" type="#dotNetObjectType#"'
                        . ' unsaved-value="0">' . "\n"
                        . '            <column name="#name#" sql-type="#type#"'
                        . ' not-null="#notNull#" unique="#unique#"'
                        . ' index="PRIMARY"/>' . "\n"
                        . '            <generator class="native" />' . "\n"
                        . '        </id>'
                    );
                } else {
                    $lines[] = $tableProperty->formatXml(
                        '        <property name="#ucfirstName#"'
                        . ' type="#dotNetObjectType#">' . "\n"
                        . '            <column name="#name#" sql-type="#type#"'
                        . ' not-null="#notNull#" #indexName#/>' . "\n"
                        . '        </property>'
                    );
                }
            }
            $GLOBALS['dbi']->freeResult($result);
        }
        $lines[] = '    </class>';
        $lines[] = '</hibernate-mapping>';

        return implode($crlf, $lines);
    }


    /* ~~~~~~~~~~~~~~~~~~~~ Getters and Setters ~~~~~~~~~~~~~~~~~~~~ */

    /**
     * Getter for CodeGen formats
     *
     * @return array
     */
    private function _getCgFormats()
    {
        return $this->_cgFormats;
    }

    /**
     * Setter for CodeGen formats
     *
     * @param array $CG_FORMATS contains CodeGen Formats
     *
     * @return void
     */
    private function _setCgFormats($CG_FORMATS)
    {
        $this->_cgFormats = $CG_FORMATS;
    }

    /**
     * Getter for CodeGen handlers
     *
     * @return array
     */
    private function _getCgHandlers()
    {
        return $this->_cgHandlers;
    }

    /**
     * Setter for CodeGen handlers
     *
     * @param array $CG_HANDLERS contains CodeGen handler methods
     *
     * @return void
     */
    private function _setCgHandlers($CG_HANDLERS)
    {
        $this->_cgHandlers = $CG_HANDLERS;
    }
}
