source: pro-bachkim-filespace/sourcecode/api.violet.vn/www/plugins/sfPropel13Plugin/lib/propel/generator/sfPropel13CrudGenerator.class.php

Last change on this file was 19, checked in by dungnv, 11 years ago
File size: 5.6 KB
Line 
1<?php
2/*
3 * This file is part of the sfPropel13Plugin package.
4 * (c) 2007 Joshua May <notjosh@gmail.com>
5 *
6 * For the full copyright and license information, please view the LICENSE
7 * file that was distributed with this source code.
8 */
9
10class sfPropel13CrudGenerator extends sfPropelCrudGenerator
11{
12  public function getColumnEditTag($column, $params = array())
13  {
14    // user defined parameters
15    $user_params = $this->getParameterValue('edit.fields.'.$column->getName().'.params');
16    $user_params = is_array($user_params) ? $user_params : sfToolkit::stringToArray($user_params);
17    $params      = $user_params ? array_merge($params, $user_params) : $params;
18
19    if ($column->isComponent())
20    {
21      return "get_component('".$this->getModuleName()."', '".$column->getName()."', array('type' => 'edit', '{$this->getSingularName()}' => \${$this->getSingularName()}))";
22    }
23    else if ($column->isPartial())
24    {
25      return "get_partial('".$column->getName()."', array('type' => 'edit', '{$this->getSingularName()}' => \${$this->getSingularName()}))";
26    }
27
28    // default control name
29    $params = array_merge(array('control_name' => $this->getSingularName().'['.$column->getName().']'), $params);
30
31    // default parameter values
32    $type = $column->getType();
33    if ($type == PropelColumnTypes::DATE)
34    {
35      $params = array_merge(array('rich' => true, 'calendar_button_img' => sfConfig::get('sf_admin_web_dir').'/images/date.png'), $params);
36    }
37    else if ($type == PropelColumnTypes::TIMESTAMP)
38    {
39      $params = array_merge(array('rich' => true, 'withtime' => true, 'calendar_button_img' => sfConfig::get('sf_admin_web_dir').'/images/date.png'), $params);
40    }
41
42    // user sets a specific tag to use
43    if ($inputType = $this->getParameterValue('edit.fields.'.$column->getName().'.type'))
44    {
45      if ($inputType == 'plain')
46      {
47        return $this->getColumnListTag($column, $params);
48      }
49      else
50      {
51        return $this->getPHPObjectHelper($inputType, $column, $params);
52      }
53    }
54
55    // guess the best tag to use with column type
56    return $this->getCrudColumnEditTag($column, $params);
57  }
58 
59  public function getCrudColumnEditTag($column, $params = array())
60  {
61    $type = $column->getType();
62
63    if ($column->isForeignKey())
64    {
65      if (!$column->isNotNull() && !isset($params['include_blank']))
66      {
67        $params['include_blank'] = true;
68      }
69
70      return $this->getPHPObjectHelper('select_tag', $column, $params, array('related_class' => $this->getRelatedClassName($column)));
71    }
72    else if ($type == PropelColumnTypes::DATE)
73    {
74      // rich=false not yet implemented
75      return $this->getPHPObjectHelper('input_date_tag', $column, $params, array('rich' => true));
76    }
77    else if ($type == PropelColumnTypes::TIMESTAMP)
78    {
79      // rich=false not yet implemented
80      return $this->getPHPObjectHelper('input_date_tag', $column, $params, array('rich' => true, 'withtime' => true));
81    }
82    else if ($type == PropelColumnTypes::BOOLEAN)
83    {
84      return $this->getPHPObjectHelper('checkbox_tag', $column, $params);
85    }
86    else if ($type == PropelColumnTypes::CHAR || $type == PropelColumnTypes::VARCHAR)
87    {
88      $size = ($column->getSize() > 20 ? ($column->getSize() < 80 ? $column->getSize() : 80) : 20);
89      return $this->getPHPObjectHelper('input_tag', $column, $params, array('size' => $size));
90    }
91    else if ($type == PropelColumnTypes::INTEGER || $type == PropelColumnTypes::TINYINT || $type == PropelColumnTypes::SMALLINT || $type == PropelColumnTypes::BIGINT)
92    {
93      return $this->getPHPObjectHelper('input_tag', $column, $params, array('size' => 7));
94    }
95    else if ($type == PropelColumnTypes::FLOAT || $type == PropelColumnTypes::DOUBLE || $type == PropelColumnTypes::DECIMAL || $type == PropelColumnTypes::NUMERIC || $type == PropelColumnTypes::REAL)
96    {
97      return $this->getPHPObjectHelper('input_tag', $column, $params, array('size' => 7));
98    }
99    else if ($type == PropelColumnTypes::CLOB || $type == PropelColumnTypes::LONGVARCHAR)
100    {
101      return $this->getPHPObjectHelper('textarea_tag', $column, $params, array('size' => '30x3'));
102    }
103    else
104    {
105      return $this->getPHPObjectHelper('input_tag', $column, $params, array('disabled' => true));
106    }
107  }
108 
109  public function getColumnListTag($column, $params = array())
110  {
111    $user_params = $this->getParameterValue('list.fields.'.$column->getName().'.params');
112    $user_params = is_array($user_params) ? $user_params : sfToolkit::stringToArray($user_params);
113    $params      = $user_params ? array_merge($params, $user_params) : $params;
114
115    $type = $column->getType();
116   
117    $columnGetter = $this->getColumnGetter($column, true);
118
119    if ($column->isComponent())
120    {
121      return "get_component('".$this->getModuleName()."', '".$column->getName()."', array('type' => 'list', '{$this->getSingularName()}' => \${$this->getSingularName()}))";
122    }
123    else if ($column->isPartial())
124    {
125      return "get_partial('".$column->getName()."', array('type' => 'list', '{$this->getSingularName()}' => \${$this->getSingularName()}))";
126    }
127    else if ($type == PropelColumnTypes::DATE || $type == PropelColumnTypes::TIMESTAMP)
128    {
129      $format = isset($params['date_format']) ? $params['date_format'] : ($type == PropelColumnTypes::DATE ? 'D' : 'f');
130      return "($columnGetter !== null && $columnGetter !== '') ? format_date($columnGetter, \"$format\") : ''";
131    }
132    elseif ($type == PropelColumnTypes::BOOLEAN)
133    {
134      return "$columnGetter ? image_tag(sfConfig::get('sf_admin_web_dir').'/images/tick.png') : '&nbsp;'";
135    }
136    else
137    {
138      return "$columnGetter";
139    }
140  }
141}
Note: See TracBrowser for help on using the repository browser.