summaryrefslogtreecommitdiff
path: root/lib/prado/framework/Wsat/pages/TWsatScaffolding.php
blob: 4d7eff5179b0539d9355539688a2dd7856547657 (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
<?php

/**
 * @author Daniel Sampedro Bello <darthdaniel85@gmail.com>
 * @link https://github.com/pradosoft/prado
 * @copyright Copyright &copy; 2005-2016 The PRADO Group
 * @license https://github.com/pradosoft/prado/blob/master/COPYRIGHT
 * @version $Id$
 * @since 3.3
 * @package Wsat.pages
 */
Prado::using("System.Wsat.TWsatScaffoldingGenerator");

class TWsatScaffolding extends TPage
{

        public function onInit($param)
        {
                parent::onInit($param);
                $this->startVisual();
        }

        private function startVisual()
        {
                $scf_generator = new TWsatScaffoldingGenerator();
                foreach ($scf_generator->getAllTableNames() as $tableName)
                {
                        $dynChb = new TCheckBox();
                        $dynChb->ID = "cb_$tableName";
                        $dynChb->Text = ucfirst($tableName);
                        $dynChb->Checked = true;
                        $this->registerObject("cb_$tableName", $dynChb);
                        $this->tableNames->getControls()->add($dynChb);
                        $this->tableNames->getControls()->add("</br>");
                }
        }

        /**
         * Generate Scaffolding code for selected tables
         * @param type $sender
         */
        public function generate($sender)
        {
                if ($this->IsValid)
                {
                        try
                        {
                                $scf_generator = new TWsatScaffoldingGenerator();
                                $scf_generator->setOpFile($this->output_folder->Text);
                                foreach ($scf_generator->getAllTableNames() as $tableName)
                                {
                                        $id = "cb_$tableName";
                                        $obj = $this->tableNames->findControl($id);
                                        if($obj!==null && $obj->Checked)
                                        {
                                                $scf_generator->generateCRUD($tableName);
                                        }
                                }
                                
                                $this->feedback_panel->CssClass = "green_panel";
                                $this->generation_msg->Text = "The code has been generated successfully.";
                        } catch (Exception $ex)
                        {
                                $this->feedback_panel->CssClass = "red_panel";
                                $this->generation_msg->Text = $ex->getMessage();
                        }
                        $this->feedback_panel->Visible = true;
                }

                //   $scf_generator->renderAllTablesInformation();
        }
}