Phundament App Class Reference
  • Package
  • Class
  • Tree

Packages

  • bootstrap
    • widgets
      • input
  • Image
  • None
  • p3admin
  • p3extensions
    • behaviors
    • commands
    • components
    • helpers
    • widgets
  • p3media
    • actions
    • controllers
    • models
  • p3pages
    • models
  • p3widgets
    • components
    • models
  • PHP
  • system
    • db
      • ar
    • gii
    • web
      • auth
      • helpers
      • widgets
  • yiiext
    • widgets
      • fancybox
      • lipsum
  • zii
    • widgets
      • grid

Classes

  • ActivationController
  • AdminController
  • AssignmentController
  • AssignmentForm
  • AuthChildForm
  • AuthItemController
  • AuthItemForm
  • BaseP3Widget
  • BaseP3WidgetMeta
  • BaseP3WidgetTranslation
  • Bootstrap
  • CImageComponent
  • CKEditor
  • CodeProvider
  • DefaultController
  • EChosen
  • EDbMigration
  • EditableField
  • EditableSaver
  • EMigrateCommand
  • ESelect2
  • EUserFlash
  • FullCrudFieldProvider
  • GenerateForm
  • IdentificationColumnValidator
  • InstallController
  • JSONEditorView
  • JuiJSONEditorInput
  • LoginController
  • LogoutController
  • Metadata
  • P3CrudFieldProvider
  • P3MediaController
  • P3MediaMetaController
  • P3MediaSelect
  • P3PageController
  • P3PageMetaController
  • P3PageTranslationController
  • P3Widget
  • P3WidgetController
  • P3WidgetMetaController
  • P3WidgetTranslation
  • P3WidgetTranslationController
  • ProfileController
  • ProfileFieldController
  • RAuthItemBehavior
  • RAuthItemChildDataProvider
  • RAuthItemDataProvider
  • RAuthItemParentDataProvider
  • RAuthorizer
  • RController
  • RDbAuthManager
  • RecoveryController
  • RegistrationController
  • RegistrationForm
  • RGenerator
  • Rights
  • RightsFilter
  • RightsModule
  • RInstaller
  • RPermissionDataProvider
  • RUserBehavior
  • RWebUser
  • UActiveForm
  • UploadHandler
  • UserChangePassword
  • UserController
  • UserIdentity
  • UserLogin
  • UserModule
  • UserRecoveryForm
  • UWdropDownDep
  • UWfile
  • UWjuiAutoComplete
  • UWjuidate
  • UWrelBelongsTo
  • WebUserBehavior
  1 <?php
  2 
  3 /**
  4  * Class to provide code snippets for CRUD generation
  5  */
  6 class CodeProvider
  7 {
  8 
  9     public function resolveController($relation)
 10     {
 11         $model      = new $relation[1];
 12         $reflection = new ReflectionClass($model);
 13         $module     = preg_match("/\/modules\/([a-zA-Z0-9]+)\//", $reflection->getFileName(), $matches);
 14 
 15         #$modulePrefix = (isset($matches[$module])) ? "/" . $matches[$module] . "/" : "";
 16         $modulePrefix = "";
 17 
 18         $controller = $modulePrefix . strtolower(substr($relation[1], 0, 1)) . substr($relation[1], 1);
 19 
 20         return $controller;
 21     }
 22 
 23     public function generateRelationHeader($model, $relationName, $relationInfo)
 24     {
 25         $controller = $this->resolveController($relationInfo); // TODO
 26 
 27         $code = "";
 28         #$code .= "echo '<span class=label>" . $relationInfo[0] . "</span>';";
 29 
 30         $code .= "\$this->widget('bootstrap.widgets.TbButtonGroup', array(
 31         'type'=>'', // '', 'primary', 'info', 'success', 'warning', 'danger' or 'inverse'
 32         'buttons'=>array(
 33             array('label'=>'{$relationName}', 'icon'=>'icon-list-alt', 'url'=> array('{$controller}/admin')),
 34                 array('icon'=>'icon-plus', 'url'=>array('" . $controller . "/create', '$relationInfo[1]' => array('$relationInfo[2]'=>\$model->{\$model->tableSchema->primaryKey}))),
 35         ),
 36     ));";
 37 
 38         return $code;
 39     }
 40 
 41     public function generateRelation($model, $relationName, $relationInfo)
 42     {
 43         if ($columns = CActiveRecord::model($relationInfo[1])->tableSchema->columns) {
 44 
 45             $suggestedfield = FullCrudCode::suggestName($columns);
 46             $field          = current($columns);
 47             $style          = $relationInfo[0] == 'CManyManyRelation' ? 'multiselect' : 'dropdownlist';
 48 
 49             if (is_object($field)) {
 50                 if ($relationInfo[0] == 'CManyManyRelation') {
 51                     $allowEmpty = 'false';
 52                 }
 53                 elseif ($relationInfo[0] == 'CHasOneRelation') {
 54                     $allowEmpty = (CActiveRecord::model($relationInfo[1])->tableSchema->columns[$relationInfo[2]]->allowNull ?
 55                         'true' : 'false');
 56 
 57                     return "if (\$model->{$relationName} !== null) echo \$model->{$relationName}->{$suggestedfield};";
 58                 }
 59                 else {
 60                     $allowEmpty = (CActiveRecord::model($model)->tableSchema->columns[$relationInfo[2]]->allowNull ?
 61                         'true' : 'false');
 62                 }
 63 
 64                 return ("\$this->widget(
 65                     'Relation',
 66                     array(
 67                             'model' => \$model,
 68                             'relation' => '{$relationName}',
 69                             'fields' => '{$suggestedfield}',
 70                             'allowEmpty' => {$allowEmpty},
 71                             'style' => '{$style}',
 72                             'htmlOptions' => array(
 73                                 'checkAll' => 'all'),
 74                             )
 75                         )");
 76             }
 77         }
 78     }
 79 
 80     /**
 81      * @param CActiveRecord   $modelClass
 82      * @param CDbColumnSchema $column
 83      */
 84     public function generateValueField($modelClass, $column, $view = false)
 85     {
 86         if ($column->isForeignKey) {
 87 
 88             $model = CActiveRecord::model($modelClass);
 89             $table = $model->getTableSchema();
 90             $fk    = $table->foreignKeys[$column->name];
 91 
 92             // We have to look into relations to find the correct model class (i.e. if models are generated with table prefix)
 93             // TODO: do not repeat yourself (foreach) - this is a hotfix
 94             foreach ($model->relations() as $key => $value) {
 95                 if (strcasecmp($value[2], $column->name) == 0) {
 96                     $relation = $value;
 97                 }
 98             }
 99 
100             if (!isset($relation)) {
101                 return "'" . $column->name . "'";
102             }
103 
104             $fmodel     = CActiveRecord::model($relation[1]);
105             $fmodelName = $relation[1];
106 
107             $modelTable = ucfirst($fmodel->tableName());
108             $fcolumns   = $fmodel->attributeNames();
109 
110             /* if (method_exists($fmodel,'get_label')) {
111               $fcolumns[1] = "_label";
112               } */
113 
114             //$rel = $model->getActiveRelation($column->name);
115             $relname = strtolower($fk[0]);
116             foreach ($model->relations() as $key => $value) {
117                 if (strcasecmp($value[2], $column->name) == 0) {
118                     $relname = $key;
119                 }
120             }
121             //return("\$model->{$relname}->{$fcolumns[1]}");
122             //return("CHtml::value(\$model,\"{$relname}.{$fcolumns[1]}\")");
123             //return("{$relname}.{$fcolumns[1]}");
124             if ($view === true) {
125                 return "array(
126                     'name'=>'{$column->name}',
127                     'value'=>CHtml::value(\$model,'{$relname}.{$fcolumns[1]}'),
128                     )";
129             }
130             elseif ($view == 'search') {
131                 return "echo \$form->dropDownList(\$model,'{$column->name}',CHtml::listData({$fmodelName}::model()->findAll(), '{$fmodel->getTableSchema()->primaryKey}', '{$fcolumns[1]}'),array('prompt'=>'all'))";
132             }
133             else {
134                 return "array(
135                     'name'=>'{$column->name}',
136                     'value'=>'CHtml::value(\$data,\\'{$relname}.{$fcolumns[1]}\\')',
137                             'filter'=>CHtml::listData({$fmodelName}::model()->findAll(), '{$fcolumns[0]}', '{$fcolumns[1]}'),
138                             )";
139             }
140             //{$relname}.{$fcolumns[1]}
141         }
142         else {
143             /*if (strtoupper($column->dbType) == 'BOOLEAN'
144                 or strtoupper($column->dbType) == 'TINYINT(1)' or
145                 strtoupper($column->dbType) == 'BIT'
146             ) {
147                 if ($view) {
148                     return "array(
149                     'name'=>'{$column->name}',
150                     'value'=>\$model->{$column->name}?'yes':'no',
151                     )";
152                 }
153                 else {
154                     return "array(
155                     'name'=>'{$column->name}',
156                     'value'=>'\$data->{$column->name}?'yes':'no',
157                             'filter'=>array('0'=>'no','1'=>'yes'),
158                             )";
159                 }
160             }
161             else {*/
162             if ($column->name == 'createtime'
163                 or $column->name == 'updatetime'
164                 or $column->name == 'timestamp'
165             ) {
166                 return "array(
167                 'name'=>'{$column->name}',
168                 'value' =>'date(\"Y. m. d G:i:s\", \$data->{$column->name})')";
169             }
170             else {
171                 return ("'" . $column->name . "'");
172             }
173             #}
174         }
175     }
176 
177 }
178 
179 ?>
180 
Phundament App Class Reference API documentation generated by ApiGen 2.8.0