1 <?php
2
3 Yii::import('system.gii.generators.crud.CrudCode');
4
5 Yii::setPathOfAlias("gtc", dirname(__FILE__) . DIRECTORY_SEPARATOR . '..');
6 Yii::import('gtc.components.*');
7 Yii::import('gtc.fullCrud.CodeProvider');
8 Yii::import('gtc.fullCrud.providers.*');
9
10 class FullCrudCode extends CrudCode
11 {
12
13 public $validation = 3;
14 public $identificationColumn = null;
15 public $baseControllerClass = 'Controller';
16 public $codeProvider;
17 public $authTemplate = "yii_user_management_access_control";
18 public $messageCatalog = "crud";
19 public $template = "slim";
20
21 public function prepare()
22 {
23 $this->codeProvider = new CodeProvider;
24 if (!$this->identificationColumn) {
25 $this->identificationColumn = $this->tableSchema->primaryKey;
26 }
27
28 if (!array_key_exists($this->identificationColumn, $this->tableSchema->columns)) {
29 $this->addError('identificationColumn',
30 'The specified column can not be found in the models attributes. <br /> Please specify a valid attribute. If unsure, leave the field empty.');
31 }
32
33 parent::prepare();
34 }
35
36 public function rules()
37 {
38 return array_merge(
39 parent::rules(),
40 array(
41 array('validation, authTemplate', 'required'),
42 array('identificationColumn', 'safe'),
43 array('messageCatalog', 'match', 'pattern' => '/^[a-zA-Z_][\w.]*$/',
44 'message' => '{attribute} should only contain word characters.'),
45 )
46 );
47 }
48
49 public function validateModel($attribute, $params)
50 {
51
52
53 if ($this->model) {
54 Yii::import($this->model, true);
55 }
56 parent::validateModel($attribute, $params);
57 }
58
59 public function attributeLabels()
60 {
61 return array_merge(parent::attributeLabels(),
62 array(
63 'validation' => 'Validation method',
64 ));
65 }
66
67 public function init()
68 {
69 parent::init();
70 }
71
72
73
74 public static function suggestName($columns)
75 {
76 foreach ($columns as $column) {
77 if ($column->isPrimaryKey) {
78 $fallbackName = $column->name;
79 }
80 if (!$column->isForeignKey
81 && !$column->isPrimaryKey
82 && $column->type != 'INT'
83 && $column->type != 'INTEGER'
84 && $column->type != 'BOOLEAN'
85 ) {
86 return $column->name;
87 break;
88 }
89 }
90 return $fallbackName;
91 }
92
93 94 95 96 97
98 public function getRelations()
99 {
100 return CActiveRecord::model($this->modelClass)->relations();
101 }
102
103 104 105 106 107 108 109
110 public function generateActiveLabel($modelClass, $column)
111 {
112 return "echo " . parent::generateActiveLabel($modelClass, $column);
113 }
114
115 116 117 118 119 120 121
122 public function generateActiveField($modelClass, $column)
123 {
124 $providers = array(
125 "gtc.fullCrud.providers.P3CrudFieldProvider",
126 "gtc.fullCrud.providers.FullCrudFieldProvider",
127 "system.gii.generators.crud.CrudCode",
128 );
129 foreach ($providers AS $provider) {
130 $class = Yii::import($provider);
131 if (method_exists($class, "generateActiveField")) {
132 if ($class::generateActiveField($modelClass, $column) !== null) {
133 if ($provider === "system.gii.generators.crud.CrudCode") {
134 return "echo " . $class::generateActiveField($modelClass, $column);
135 }
136 else {
137 return $class::generateActiveField($modelClass, $column);
138 }
139
140 }
141 }
142 }
143 }
144 }
145
146 ?>
147