コード例 #1
0
ファイル: Columns.php プロジェクト: tashik/phalcon_core
 /**
  * Generates grid columns object
  *
  * @param \Engine\Crud\Grid\Extjs $grid
  * @return string
  */
 public static function _(Grid $grid)
 {
     $code = "\n            columnsGet: function(){\n                return [";
     $columns = [];
     foreach ($grid->getColumns() as $column) {
         if ($column instanceof Column) {
             $type = $column->getType();
             /*if (!method_exists(__CLASS__, '_'.$type)) {
                   throw new \Engine\Exception("Field with type '".$type."' haven't render method in '".__CLASS__."'");
               }*/
             switch ($type) {
                 case 'image':
                     $columnCode = forward_static_call(['static', '_' . $type], $column);
                     break;
                 case 'check':
                     $columnCode = forward_static_call(['static', '_' . $type], $column);
                     break;
                 default:
                     $columnCode = forward_static_call(['static', '_column'], $column);
                     break;
             }
             $columns[] = $columnCode;
         }
     }
     $code .= implode(",", $columns);
     $code .= "\n                ]\n            },\n            ";
     return $code;
 }
コード例 #2
0
ファイル: Model.php プロジェクト: tashik/phalcon_core
 /**
  * Generates a widget to show a html grid
  *
  * @param \Engine\Crud\Grid\Extjs $grid
  * @return string
  */
 public static function _(Grid $grid)
 {
     $code = "\n        Ext.define('" . static::getModelName() . "', {\n            extend: 'Ext.data.Model',";
     $columns = [];
     $validations = [];
     $primary = false;
     foreach ($grid->getColumns() as $column) {
         if ($column instanceof Column) {
             $type = $column->getType();
             if (!method_exists(__CLASS__, '_' . $type)) {
                 throw new \Engine\Exception("Field with type '" . $type . "' haven't render method in '" . __CLASS__ . "'");
             }
             $columnCode = forward_static_call(['self', '_' . $type], $column);
             //$validationCode = "{field: '".$field."', type: }";
             /*
             * type:
                presence
                length
                inclusion
                exclusion
                format
             */
             $columns[] = $columnCode;
             //$validations[] = $validationCode;
             if ($column instanceof Column\Primary) {
                 $primary = $column->getKey();
             }
         }
     }
     $code .= "\n            fields: [" . implode(",", $columns) . "\n            ],";
     $code .= "\n            validations: [" . implode(",", $validations) . "]";
     if ($primary !== false) {
         $code .= ",\n            idProperty: '" . $primary . "'";
     }
     $code .= "\n        });";
     return $code;
 }