Commits

Anonymous committed 770940c Merge

Merge with local changes

  • Participants
  • Parent commits 8fefd96, 2c5cf2a

Comments (0)

Files changed (3)

generators/AweCrud/AweCrudCode.php

             return "\$form->dropDownListRow(\$model, '{$column->name}', CHtml::listData({$relatedModelClass}::model()->findAll(), '{$foreignPk}', {$relatedModelClass}::representingColumn()){$prompt})";
         }
 
-        if (strtoupper($column->dbType) == 'TINYINT(1)'
+        if($column->name == $this->hasUpload()) {
+            return "\$form->fileFieldRow(\$model, '{$column->name}[]', array('multiple' => 'multiple'))";
+        } elseif (strtoupper($column->dbType) == 'TINYINT(1)'
             || strtoupper($column->dbType) == 'BIT'
             || strtoupper($column->dbType) == 'BOOL'
             || strtoupper($column->dbType) == 'BOOLEAN'
         return $controller;
     }
 
+    public function hasUpload()
+    {
+        foreach($this->tableSchema->columns as $column)
+        {
+            if (in_array($column->name, $this->imageFields))
+            {
+                return $column->name;
+                break;
+            }
+        }
+
+        return false;
+    }
 }

generators/AweCrud/AweCrudGenerator.php

     protected function getModels()
     {
         $models = array();
-        $files = scandir(Yii::getPathOfAlias('application.models'));
+        $files = ($commonFiles = Yii::getPathOfAlias('common.models')) ? scandir($commonFiles) : array();
+        $files = array_merge(scandir(Yii::getPathOfAlias('application.models')), $files);
         foreach ($files as $file) {
             if ($file[0] !== '.' && CFileHelper::getExtension($file) === 'php') {
                 $fileClassName = substr($file, 0, strpos($file, '.'));

generators/AweModel/AweModelCode.php

         'timestamp',
         'updatedat'
     );
+    public $imageFields = array(
+        'image',
+        'picture',
+        'photo',
+        'pic',
+        'profile_pic',
+        'profile_picture',
+        'profilepic',
+        'profilepicture',
+        'avatar',
+        'file_name'
+    );
     public $time_fields;
     public $validRelatedRecordBehaviors = array(
         'ActiveRecordRelation' => 'EActiveRecordRelationBehavior',
                 'relations' => isset($this->relations[$className]) ? $this->relations[$className] : array(),
                 'representingColumn' => $this->getRepresentingColumn($table), // The representing column for the table.
                 'connectionId' => $this->connectionId,
+                'hasUpload' => $this->hasUpload($table)
             );
             // Setup base model information.
             $this->baseModelPath = $this->modelPath . '._base';
         $numerical = array();
         $length = array();
         $safe = array();
+        $file = array();
         foreach ($table->columns as $column) {
             if ($column->autoIncrement) {
                 continue;
             if ($r and !in_array($column->name, $this->time_fields)) {
                 $required[] = $column->name;
             }
-            if ($column->type === 'integer') {
+            if(in_array($column->name, $this->imageFields)) {
+                $file[]=$column->name;
+            } elseif ($column->type === 'integer') {
                 $integers[] = $column->name;
             } elseif ($column->type === 'double') {
                 $numerical[] = $column->name;
             }
         }
         if ($required !== array()) {
-            $rules[] = "array('" . implode(', ', $required) . "', 'required')";
+            $rules[] = "array(\t'" . implode(', ', $required) . "',\n\t\t\t\t\t'required',\n\t\t\t\t\t'message' => Yii::t('app', 'Field is required')\n\t\t\t)";
         }
         if ($integers !== array()) {
-            $rules[] = "array('" . implode(', ', $integers) . "', 'numerical', 'integerOnly'=>true)";
+            $rules[] = "array(\t'" . implode(', ', $integers) . "',\n\t\t\t\t\t'numerical',\n\t\t\t\t\t'integerOnly'=>true\n\t\t\t)";
         }
         if ($numerical !== array()) {
-            $rules[] = "array('" . implode(', ', $numerical) . "', 'numerical')";
+            $rules[] = "array(\t'" . implode(', ', $numerical) . "',\n\t\t\t\t\t'numerical'\n\t\t\t)";
         }
         if ($length !== array()) {
             foreach ($length as $len => $cols) {
-                $rules[] = "array('" . implode(', ', $cols) . "', 'length', 'max'=>$len)";
+                $rules[] = "array(\t'" . implode(', ', $cols) . "',\n\t\t\t\t\t'length',\n\t\t\t\t\t'max'=>$len,\n\t\t\t\t\t'tooLong' => Yii::t('app', 'Field is required')\n\t\t\t)";
             }
         }
+        if($file !== array()) {
+            $rules[]="array(\t'".implode(', ',$file)."',\n\t\t\t\t\t'file',\n\t\t\t\t\t'maxSize' => Yii::app()->params['imageMaxSize'],\n\t\t\t\t\t'maxFiles' => 50,\n\t\t\t\t\t'tooLarge' => Yii::app()->params['messageTooLarge'],\n\t\t\t\t\t'types' => Yii::app()->params['imageGoodType'],\n\t\t\t\t\t'wrongType' => Yii::app()->params['imageGoodType'],\n\t\t\t\t\t'allowEmpty' => true,\n\t\t\t)";
+        }
         if ($safe !== array()) {
-            $rules[] = "array('" . implode(', ', $safe) . "', 'safe')";
+            $rules[] = "array(\t'" . implode(', ', $safe) . "',\n\t\t\t\t\t'safe'\n\t\t\t)";
         }
 
         return $rules;
             $rules[] = "array('" . implode(
                 ', ',
                 $null
-            ) . "', 'default', 'setOnEmpty' => true, 'value' => null)";
+            ) . "',\n\t\t\t\t\t'default',\n\t\t\t\t\t'setOnEmpty' => true,\n\t\t\t\t\t'value' => null\n\t\t\t)";
         }
 
         return array_merge($this->parentGenerateRules($table), $rules);
         }
         return 'null';
     }
+    
+    public function hasUpload($table)
+    {
+        foreach ($table->columns as $name=>$col)
+        {
+            if (in_array($name, $this->imageFields))
+            {
+                return $name;
+                break;
+            }
+        }
+
+        return false;
+    }
 
 }