summaryrefslogtreecommitdiff
path: root/framework/Wsat/TWsatBaseGenerator.php
blob: 1facb13fa21388d2b34ebe51e292891263299bcb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
<?php

/**
 * @author Daniel Sampedro Bello <darthdaniel85@gmail.com>
 * @link http://www.pradosoft.com/
 * @copyright Copyright &copy; 2005-2014 PradoSoft
 * @license http://www.pradosoft.com/license/
 * @version $Id$
 * @since 3.3
 * @package Wsat
 */
Prado::using('System.Data.Common.TDbMetaData');

class TWsatBaseGenerator
{

        /**
         * @return TDbMetaData for retrieving metadata information, such as
         * table and columns information, from a database connection.
         */
        protected $_dbMetaData;

        /**
         * Output folder where AR classes will be saved.
         */
        protected $_opFile;

        function __construct()
        {
                if (!class_exists("TActiveRecordManager", false))
                        throw new Exception("You need to enable the ActiveRecord module in your application configuration file.");
                $ar_manager = TActiveRecordManager::getInstance();
                $_conn = $ar_manager->getDbConnection();
                $_conn->Active = true;
                $this->_dbMetaData = TDbMetaData::getInstance($_conn);
        }

        public function setOpFile($op_file_namespace)
        {
                $op_file = Prado::getPathOfNamespace($op_file_namespace);
                if (empty($op_file))
                        throw new Exception("You need to fix your output folder namespace.");
                if (!is_dir($op_file))
                        mkdir($op_file, 0777, true);
                $this->_opFile = $op_file;
        }

        public function renderAllTablesInformation()
        {
                foreach ($this->getAllTableNames() as $table_name)
                {
                        echo $table_name . "<br>";
                        $tableInfo = $this->_dbMetaData->getTableInfo($table_name);
                        echo "Table info:" . "<br>";
                        echo "<pre>";
                        print_r($tableInfo);
                        echo "</pre>";
                }
        }

        public function getAllTableNames()
        {
                $tableNames = $this->_dbMetaData->findTableNames();
                $index = array_search('pradocache', $tableNames);
                if($index)
                        array_splice($tableNames, $index, 1);
                return $tableNames;
        }

        public static function pr($data)
        {
                echo "<pre>";
                print_r($data);
                echo "</pre>";
        }

}

?>