PageRenderTime 69ms CodeModel.GetById 41ms RepoModel.GetById 1ms app.codeStats 0ms

/lib/generator/sfAdminGenerator.class.php

https://github.com/theodo/symfony1.0-backports
PHP | 788 lines | 475 code | 90 blank | 223 comment | 114 complexity | 6e95ceee07e9753debec11ccca8157dc MD5 | raw file
Possible License(s): LGPL-2.1, AGPL-3.0, BSD-3-Clause
  1. <?php
  2. /*
  3. * This file is part of the symfony package.
  4. * (c) 2004-2006 Fabien Potencier <fabien.potencier@symfony-project.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. /**
  10. * Admin generator.
  11. *
  12. * This class generates an admin module.
  13. *
  14. * This class calls two ORM specific methods:
  15. * getAllColumns()
  16. * and
  17. * getAdminColumnForField($field, $flag = null)
  18. *
  19. * @package symfony
  20. * @subpackage generator
  21. * @author Fabien Potencier <fabien.potencier@symfony-project.com>
  22. * @version SVN: $Id$
  23. */
  24. abstract class sfAdminGenerator extends sfCrudGenerator
  25. {
  26. protected
  27. $fields = array();
  28. /**
  29. * Returns HTML code for a help icon.
  30. *
  31. * @param string The column name
  32. * @param string The field type (list, edit)
  33. *
  34. * @return string HTML code
  35. */
  36. public function getHelpAsIcon($column, $type = '')
  37. {
  38. $help = $this->getParameterValue($type.'.fields.'.$column->getName().'.help');
  39. if ($help)
  40. {
  41. return "[?php echo image_tag(sfConfig::get('sf_admin_web_dir').'/images/help.png', array('align' => 'absmiddle', 'alt' => __('".$this->escapeString($help)."'), 'title' => __('".$this->escapeString($help)."'))) ?]";
  42. }
  43. return '';
  44. }
  45. /**
  46. * Returns HTML code for a help text.
  47. *
  48. * @param string The column name
  49. * @param string The field type (list, edit)
  50. *
  51. * @return string HTML code
  52. */
  53. public function getHelp($column, $type = '')
  54. {
  55. $help = $this->getParameterValue($type.'.fields.'.$column->getName().'.help');
  56. if ($help)
  57. {
  58. return "<div class=\"sf_admin_edit_help\">[?php echo __('".$this->escapeString($help)."') ?]</div>";
  59. }
  60. return '';
  61. }
  62. /**
  63. * Returns HTML code for an action button.
  64. *
  65. * @param string The action name
  66. * @param array The parameters
  67. * @param boolean Whether to add a primary key link or not
  68. *
  69. * @return string HTML code
  70. */
  71. public function getButtonToAction($actionName, $params, $pk_link = false)
  72. {
  73. $params = (array) $params;
  74. $options = isset($params['params']) ? sfToolkit::stringToArray($params['params']) : array();
  75. $method = 'button_to';
  76. $li_class = '';
  77. $only_for = isset($params['only_for']) ? $params['only_for'] : null;
  78. // default values
  79. if ($actionName[0] == '_')
  80. {
  81. $actionName = substr($actionName, 1);
  82. $default_name = strtr($actionName, '_', ' ');
  83. $default_icon = sfConfig::get('sf_admin_web_dir').'/images/'.$actionName.'_icon.png';
  84. $default_action = $actionName;
  85. $default_class = 'sf_admin_action_'.$actionName;
  86. if ($actionName == 'save' || $actionName == 'save_and_add' || $actionName == 'save_and_list')
  87. {
  88. $method = 'submit_tag';
  89. $options['name'] = $actionName;
  90. }
  91. if ($actionName == 'delete')
  92. {
  93. $options['post'] = true;
  94. if (!isset($options['confirm']))
  95. {
  96. $options['confirm'] = 'Are you sure?';
  97. }
  98. $li_class = 'float-left';
  99. $only_for = 'edit';
  100. }
  101. }
  102. else
  103. {
  104. $default_name = strtr($actionName, '_', ' ');
  105. $default_icon = sfConfig::get('sf_admin_web_dir').'/images/default_icon.png';
  106. $default_action = 'List'.sfInflector::camelize($actionName);
  107. $default_class = '';
  108. }
  109. $name = isset($params['name']) ? $params['name'] : $default_name;
  110. $icon = isset($params['icon']) ? sfToolkit::replaceConstants($params['icon']) : $default_icon;
  111. $action = isset($params['action']) ? $params['action'] : $default_action;
  112. $url_params = $pk_link ? '?'.$this->getPrimaryKeyUrlParams() : '\'';
  113. if (!isset($options['class']))
  114. {
  115. if ($default_class)
  116. {
  117. $options['class'] = $default_class;
  118. }
  119. else
  120. {
  121. $options['style'] = 'background: #ffc url('.$icon.') no-repeat 3px 2px';
  122. }
  123. }
  124. $li_class = $li_class ? ' class="'.$li_class.'"' : '';
  125. $html = '<li'.$li_class.'>';
  126. if ($only_for == 'edit')
  127. {
  128. $html .= '[?php if ('.$this->getPrimaryKeyIsSet().'): ?]'."\n";
  129. }
  130. else if ($only_for == 'create')
  131. {
  132. $html .= '[?php if (!'.$this->getPrimaryKeyIsSet().'): ?]'."\n";
  133. }
  134. else if ($only_for !== null)
  135. {
  136. throw new sfConfigurationException(sprintf('The "only_for" parameter can only takes "create" or "edit" as argument ("%s")', $only_for));
  137. }
  138. if ($method == 'submit_tag')
  139. {
  140. $html .= '[?php echo submit_tag(__(\''.$name.'\'), '.var_export($options, true).') ?]';
  141. }
  142. else
  143. {
  144. $phpOptions = var_export($options, true);
  145. // little hack
  146. $phpOptions = preg_replace("/'confirm' => '(.+?)(?<!\\\)'/", '\'confirm\' => __(\'$1\')', $phpOptions);
  147. $html .= '[?php echo button_to(__(\''.$name.'\'), \''.$this->getModuleName().'/'.$action.$url_params.', '.$phpOptions.') ?]';
  148. }
  149. if ($only_for !== null)
  150. {
  151. $html .= '[?php endif; ?]'."\n";
  152. }
  153. $html .= '</li>'."\n";
  154. return $html;
  155. }
  156. /**
  157. * Returns HTML code for an action link.
  158. *
  159. * @param string The action name
  160. * @param array The parameters
  161. * @param boolean Whether to add a primary key link or not
  162. *
  163. * @return string HTML code
  164. */
  165. public function getLinkToAction($actionName, $params, $pk_link = false)
  166. {
  167. $options = isset($params['params']) ? sfToolkit::stringToArray($params['params']) : array();
  168. // default values
  169. if ($actionName[0] == '_')
  170. {
  171. $actionName = substr($actionName, 1);
  172. $name = $actionName;
  173. $icon = sfConfig::get('sf_admin_web_dir').'/images/'.$actionName.'_icon.png';
  174. $action = $actionName;
  175. if ($actionName == 'delete')
  176. {
  177. $options['post'] = true;
  178. if (!isset($options['confirm']))
  179. {
  180. $options['confirm'] = 'Are you sure?';
  181. }
  182. }
  183. }
  184. else
  185. {
  186. $name = isset($params['name']) ? $params['name'] : $actionName;
  187. $icon = isset($params['icon']) ? sfToolkit::replaceConstants($params['icon']) : sfConfig::get('sf_admin_web_dir').'/images/default_icon.png';
  188. $action = isset($params['action']) ? $params['action'] : 'List'.sfInflector::camelize($actionName);
  189. }
  190. $url_params = $pk_link ? '?'.$this->getPrimaryKeyUrlParams() : '\'';
  191. $phpOptions = var_export($options, true);
  192. // little hack
  193. $phpOptions = preg_replace("/'confirm' => '(.+?)(?<!\\\)'/", '\'confirm\' => __(\'$1\')', $phpOptions);
  194. return '<li>[?php echo link_to(image_tag(\''.$icon.'\', array(\'alt\' => __(\''.$name.'\'), \'title\' => __(\''.$name.'\'))), \''.$this->getModuleName().'/'.$action.$url_params.($options ? ', '.$phpOptions : '').') ?]</li>'."\n";
  195. }
  196. /**
  197. * Returns HTML code for a column in edit mode.
  198. *
  199. * @param string The column name
  200. * @param array The parameters
  201. *
  202. * @return string HTML code
  203. */
  204. public function getColumnEditTag($column, $params = array())
  205. {
  206. // user defined parameters
  207. $user_params = $this->getParameterValue('edit.fields.'.$column->getName().'.params');
  208. $user_params = is_array($user_params) ? $user_params : sfToolkit::stringToArray($user_params);
  209. $params = $user_params ? array_merge($params, $user_params) : $params;
  210. if ($column->isComponent())
  211. {
  212. return "get_component('".$this->getModuleName()."', '".$column->getName()."', array('type' => 'edit', '{$this->getSingularName()}' => \${$this->getSingularName()}))";
  213. }
  214. else if ($column->isPartial())
  215. {
  216. return "get_partial('".$column->getName()."', array('type' => 'edit', '{$this->getSingularName()}' => \${$this->getSingularName()}))";
  217. }
  218. // default control name
  219. $params = array_merge(array('control_name' => $this->getSingularName().'['.$column->getName().']'), $params);
  220. // default parameter values
  221. $type = $column->getCreoleType();
  222. if ($type == CreoleTypes::DATE)
  223. {
  224. $params = array_merge(array('rich' => true, 'calendar_button_img' => sfConfig::get('sf_admin_web_dir').'/images/date.png'), $params);
  225. }
  226. else if ($type == CreoleTypes::TIMESTAMP)
  227. {
  228. $params = array_merge(array('rich' => true, 'withtime' => true, 'calendar_button_img' => sfConfig::get('sf_admin_web_dir').'/images/date.png'), $params);
  229. }
  230. // user sets a specific tag to use
  231. if ($inputType = $this->getParameterValue('edit.fields.'.$column->getName().'.type'))
  232. {
  233. if ($inputType == 'plain')
  234. {
  235. return $this->getColumnListTag($column, $params);
  236. }
  237. else
  238. {
  239. return $this->getPHPObjectHelper($inputType, $column, $params);
  240. }
  241. }
  242. // guess the best tag to use with column type
  243. return parent::getCrudColumnEditTag($column, $params);
  244. }
  245. /**
  246. * Returns all column categories.
  247. *
  248. * @param string The parameter name
  249. *
  250. * @return array The column categories
  251. */
  252. public function getColumnCategories($paramName)
  253. {
  254. if (is_array($this->getParameterValue($paramName)))
  255. {
  256. $fields = $this->getParameterValue($paramName);
  257. // do we have categories?
  258. if (!isset($fields[0]))
  259. {
  260. return array_keys($fields);
  261. }
  262. }
  263. return array('NONE');
  264. }
  265. /**
  266. * Wraps content with a credential condition.
  267. *
  268. * @param string The content
  269. * @param array The parameters
  270. *
  271. * @return string HTML code
  272. */
  273. public function addCredentialCondition($content, $params = array())
  274. {
  275. if (isset($params['credentials']))
  276. {
  277. $credentials = str_replace("\n", ' ', var_export($params['credentials'], true));
  278. return <<<EOF
  279. [?php if (\$sf_user->hasCredential($credentials)): ?]
  280. $content
  281. [?php endif; ?]
  282. EOF;
  283. }
  284. else
  285. {
  286. return $content;
  287. }
  288. }
  289. /**
  290. * Gets sfAdminColumn objects for a given category.
  291. *
  292. * @param string The parameter name
  293. *
  294. * @return array sfAdminColumn array
  295. */
  296. public function getColumns($paramName, $category = 'NONE')
  297. {
  298. $phpNames = array();
  299. // user has set a personnalized list of fields?
  300. $fields = $this->getParameterValue($paramName);
  301. if (is_array($fields))
  302. {
  303. // categories?
  304. if (isset($fields[0]))
  305. {
  306. // simulate a default one
  307. $fields = array('NONE' => $fields);
  308. }
  309. if (!$fields)
  310. {
  311. return array();
  312. }
  313. foreach ($fields[$category] as $field)
  314. {
  315. list($field, $flags) = $this->splitFlag($field);
  316. $phpNames[] = $this->getAdminColumnForField($field, $flags);
  317. }
  318. }
  319. else
  320. {
  321. // no, just return the full list of columns in table
  322. return $this->getAllColumns();
  323. }
  324. return $phpNames;
  325. }
  326. /**
  327. * Gets modifier flags from a column name.
  328. *
  329. * @param string The column name
  330. *
  331. * @return array An array of detected flags
  332. */
  333. public function splitFlag($text)
  334. {
  335. $flags = array();
  336. while (in_array($text[0], array('=', '-', '+', '_', '~')))
  337. {
  338. $flags[] = $text[0];
  339. $text = substr($text, 1);
  340. }
  341. return array($text, $flags);
  342. }
  343. /**
  344. * Gets a parameter value.
  345. *
  346. * @param string The key name
  347. * @param mixed The default value
  348. *
  349. * @return mixed The parameter value
  350. */
  351. public function getParameterValue($key, $default = null)
  352. {
  353. if (preg_match('/^([^\.]+)\.fields\.(.+)$/', $key, $matches))
  354. {
  355. return $this->getFieldParameterValue($matches[2], $matches[1], $default);
  356. }
  357. else
  358. {
  359. return $this->getValueFromKey($key, $default);
  360. }
  361. }
  362. /**
  363. * Gets a field parameter value.
  364. *
  365. * @param string The key name
  366. * @param string The type (list, edit)
  367. * @param mixed The default value
  368. *
  369. * @return mixed The parameter value
  370. */
  371. protected function getFieldParameterValue($key, $type = '', $default = null)
  372. {
  373. $retval = $this->getValueFromKey($type.'.fields.'.$key, $default);
  374. if ($retval !== null)
  375. {
  376. return $retval;
  377. }
  378. $retval = $this->getValueFromKey('fields.'.$key, $default);
  379. if ($retval !== null)
  380. {
  381. return $retval;
  382. }
  383. if (preg_match('/\.name$/', $key))
  384. {
  385. // default field.name
  386. return sfInflector::humanize(($pos = strpos($key, '.')) ? substr($key, 0, $pos) : $key);
  387. }
  388. else
  389. {
  390. return null;
  391. }
  392. }
  393. /**
  394. * Gets the value for a given key.
  395. *
  396. * @param string The key name
  397. * @param mixed The default value
  398. *
  399. * @return mixed The key value
  400. */
  401. protected function getValueFromKey($key, $default = null)
  402. {
  403. $ref =& $this->params;
  404. $parts = explode('.', $key);
  405. $count = count($parts);
  406. for ($i = 0; $i < $count; $i++)
  407. {
  408. $partKey = $parts[$i];
  409. if (!isset($ref[$partKey]))
  410. {
  411. return $default;
  412. }
  413. if ($count == $i + 1)
  414. {
  415. return $ref[$partKey];
  416. }
  417. else
  418. {
  419. $ref =& $ref[$partKey];
  420. }
  421. }
  422. return $default;
  423. }
  424. /**
  425. * Wraps a content for I18N.
  426. *
  427. * @param string The key name
  428. * @param string The defaul value
  429. *
  430. * @return string HTML code
  431. */
  432. public function getI18NString($key, $default = null, $withEcho = true)
  433. {
  434. $value = $this->escapeString($this->getParameterValue($key, $default));
  435. // find %%xx%% strings
  436. preg_match_all('/%%([^%]+)%%/', $value, $matches, PREG_PATTERN_ORDER);
  437. $this->params['tmp']['display'] = array();
  438. foreach ($matches[1] as $name)
  439. {
  440. $this->params['tmp']['display'][] = $name;
  441. }
  442. $vars = array();
  443. foreach ($this->getColumns('tmp.display') as $column)
  444. {
  445. if ($column->isLink())
  446. {
  447. $vars[] = '\'%%'.$column->getName().'%%\' => link_to('.$this->getColumnListTag($column).', \''.$this->getModuleName().'/edit?'.$this->getPrimaryKeyUrlParams().')';
  448. }
  449. elseif ($column->isPartial())
  450. {
  451. $vars[] = '\'%%_'.$column->getName().'%%\' => '.$this->getColumnListTag($column);
  452. }
  453. else if ($column->isComponent())
  454. {
  455. $vars[] = '\'%%~'.$column->getName().'%%\' => '.$this->getColumnListTag($column);
  456. }
  457. else
  458. {
  459. $vars[] = '\'%%'.$column->getName().'%%\' => '.$this->getColumnListTag($column);
  460. }
  461. }
  462. // strip all = signs
  463. $value = preg_replace('/%%=([^%]+)%%/', '%%$1%%', $value);
  464. $i18n = '__(\''.$value.'\', '."\n".'array('.implode(",\n", $vars).'))';
  465. return $withEcho ? '[?php echo '.$i18n.' ?]' : $i18n;
  466. }
  467. /**
  468. * Replaces constants in a string.
  469. *
  470. * @param string
  471. *
  472. * @return string
  473. */
  474. public function replaceConstants($value)
  475. {
  476. // find %%xx%% strings
  477. preg_match_all('/%%([^%]+)%%/', $value, $matches, PREG_PATTERN_ORDER);
  478. $this->params['tmp']['display'] = array();
  479. foreach ($matches[1] as $name)
  480. {
  481. $this->params['tmp']['display'][] = $name;
  482. }
  483. foreach ($this->getColumns('tmp.display') as $column)
  484. {
  485. $value = str_replace('%%'.$column->getName().'%%', '{'.$this->getColumnGetter($column, true, 'this->').'}', $value);
  486. }
  487. return $value;
  488. }
  489. /**
  490. * Returns HTML code for a column in list mode.
  491. *
  492. * @param string The column name
  493. * @param array The parameters
  494. *
  495. * @return string HTML code
  496. */
  497. public function getColumnListTag($column, $params = array())
  498. {
  499. $user_params = $this->getParameterValue('list.fields.'.$column->getName().'.params');
  500. $user_params = is_array($user_params) ? $user_params : sfToolkit::stringToArray($user_params);
  501. $params = $user_params ? array_merge($params, $user_params) : $params;
  502. $type = $column->getCreoleType();
  503. $columnGetter = $this->getColumnGetter($column, true);
  504. if ($column->isComponent())
  505. {
  506. return "get_component('".$this->getModuleName()."', '".$column->getName()."', array('type' => 'list', '{$this->getSingularName()}' => \${$this->getSingularName()}))";
  507. }
  508. else if ($column->isPartial())
  509. {
  510. return "get_partial('".$column->getName()."', array('type' => 'list', '{$this->getSingularName()}' => \${$this->getSingularName()}))";
  511. }
  512. else if ($type == CreoleTypes::DATE || $type == CreoleTypes::TIMESTAMP)
  513. {
  514. $format = isset($params['date_format']) ? $params['date_format'] : ($type == CreoleTypes::DATE ? 'D' : 'f');
  515. return "($columnGetter !== null && $columnGetter !== '') ? format_date($columnGetter, \"$format\") : ''";
  516. }
  517. elseif ($type == CreoleTypes::BOOLEAN)
  518. {
  519. return "$columnGetter ? image_tag(sfConfig::get('sf_admin_web_dir').'/images/tick.png') : '&nbsp;'";
  520. }
  521. else
  522. {
  523. return "$columnGetter";
  524. }
  525. }
  526. /**
  527. * Returns HTML code for a column in filter mode.
  528. *
  529. * @param string The column name
  530. * @param array The parameters
  531. *
  532. * @return string HTML code
  533. */
  534. public function getColumnFilterTag($column, $params = array())
  535. {
  536. $user_params = $this->getParameterValue('list.fields.'.$column->getName().'.params');
  537. $user_params = is_array($user_params) ? $user_params : sfToolkit::stringToArray($user_params);
  538. $params = $user_params ? array_merge($params, $user_params) : $params;
  539. if ($column->isComponent())
  540. {
  541. return "get_component('".$this->getModuleName()."', '".$column->getName()."', array('type' => 'filter'))";
  542. }
  543. else if ($column->isPartial())
  544. {
  545. return "get_partial('".$column->getName()."', array('type' => 'filter', 'filters' => \$filters))";
  546. }
  547. $type = $column->getCreoleType();
  548. $default_value = "isset(\$filters['".$column->getName()."']) ? \$filters['".$column->getName()."'] : null";
  549. $unquotedName = 'filters['.$column->getName().']';
  550. $name = "'$unquotedName'";
  551. if ($column->isForeignKey())
  552. {
  553. $params = $this->getObjectTagParams($params, array('include_blank' => true, 'related_class'=>$this->getRelatedClassName($column), 'text_method'=>'__toString', 'control_name'=>$unquotedName));
  554. return "object_select_tag($default_value, null, $params)";
  555. }
  556. else if ($type == CreoleTypes::DATE)
  557. {
  558. // rich=false not yet implemented
  559. $params = $this->getObjectTagParams($params, array('rich' => true, 'calendar_button_img' => sfConfig::get('sf_admin_web_dir').'/images/date.png'));
  560. return "input_date_range_tag($name, $default_value, $params)";
  561. }
  562. else if ($type == CreoleTypes::TIMESTAMP)
  563. {
  564. // rich=false not yet implemented
  565. $params = $this->getObjectTagParams($params, array('rich' => true, 'withtime' => true, 'calendar_button_img' => sfConfig::get('sf_admin_web_dir').'/images/date.png'));
  566. return "input_date_range_tag($name, $default_value, $params)";
  567. }
  568. else if ($type == CreoleTypes::BOOLEAN)
  569. {
  570. $defaultIncludeCustom = '__("yes or no")';
  571. $option_params = $this->getObjectTagParams($params, array('include_custom' => $defaultIncludeCustom));
  572. $params = $this->getObjectTagParams($params);
  573. // little hack
  574. $option_params = preg_replace("/'".preg_quote($defaultIncludeCustom)."'/", $defaultIncludeCustom, $option_params);
  575. $options = "options_for_select(array(1 => __('yes'), 0 => __('no')), $default_value, $option_params)";
  576. return "select_tag($name, $options, $params)";
  577. }
  578. else if ($type == CreoleTypes::CHAR || $type == CreoleTypes::VARCHAR || $type == CreoleTypes::TEXT || $type == CreoleTypes::LONGVARCHAR)
  579. {
  580. $size = ($column->getSize() < 15 ? $column->getSize() : 15);
  581. $params = $this->getObjectTagParams($params, array('size' => $size));
  582. return "input_tag($name, $default_value, $params)";
  583. }
  584. else if ($type == CreoleTypes::INTEGER || $type == CreoleTypes::TINYINT || $type == CreoleTypes::SMALLINT || $type == CreoleTypes::BIGINT)
  585. {
  586. $params = $this->getObjectTagParams($params, array('size' => 7));
  587. return "input_tag($name, $default_value, $params)";
  588. }
  589. else if ($type == CreoleTypes::FLOAT || $type == CreoleTypes::DOUBLE || $type == CreoleTypes::DECIMAL || $type == CreoleTypes::NUMERIC || $type == CreoleTypes::REAL)
  590. {
  591. $params = $this->getObjectTagParams($params, array('size' => 7));
  592. return "input_tag($name, $default_value, $params)";
  593. }
  594. else
  595. {
  596. $params = $this->getObjectTagParams($params, array('disabled' => true));
  597. return "input_tag($name, $default_value, $params)";
  598. }
  599. }
  600. /**
  601. * Escapes a string.
  602. *
  603. * @param string
  604. *
  605. * @param string
  606. */
  607. protected function escapeString($string)
  608. {
  609. return preg_replace('/\'/', '\\\'', $string);
  610. }
  611. }
  612. /**
  613. * Admin generator column.
  614. *
  615. * @package symfony
  616. * @subpackage generator
  617. * @author Fabien Potencier <fabien.potencier@symfony-project.com>
  618. * @version SVN: $Id$
  619. */
  620. class sfAdminColumn
  621. {
  622. protected
  623. $phpName = '',
  624. $column = null,
  625. $flags = array();
  626. /**
  627. * Constructor.
  628. *
  629. * @param string The column php name
  630. * @param string The column name
  631. * @param array The column flags
  632. */
  633. public function __construct($phpName, $column = null, $flags = array())
  634. {
  635. $this->phpName = $phpName;
  636. $this->column = $column;
  637. $this->flags = (array) $flags;
  638. }
  639. /**
  640. * Returns true if the column maps a database column.
  641. *
  642. * @return boolean true if the column maps a database column, false otherwise
  643. */
  644. public function isReal()
  645. {
  646. return $this->column ? true : false;
  647. }
  648. /**
  649. * Gets the name of the column.
  650. *
  651. * @return string The column name
  652. */
  653. public function getName()
  654. {
  655. return sfInflector::underscore($this->phpName);
  656. }
  657. /**
  658. * Returns true if the column is a partial.
  659. *
  660. * @return boolean true if the column is a partial, false otherwise
  661. */
  662. public function isPartial()
  663. {
  664. return in_array('_', $this->flags) ? true : false;
  665. }
  666. /**
  667. * Returns true if the column is a component.
  668. *
  669. * @return boolean true if the column is a component, false otherwise
  670. */
  671. public function isComponent()
  672. {
  673. return in_array('~', $this->flags) ? true : false;
  674. }
  675. /**
  676. * Returns true if the column has a link.
  677. *
  678. * @return boolean true if the column has a link, false otherwise
  679. */
  680. public function isLink()
  681. {
  682. return (in_array('=', $this->flags) || $this->isPrimaryKey()) ? true : false;
  683. }
  684. /**
  685. * Gets the php name of the column.
  686. *
  687. * @return string The php name
  688. */
  689. public function getPhpName()
  690. {
  691. return $this->phpName;
  692. }
  693. // FIXME: those methods are only used in the propel admin generator
  694. public function __call($name, $arguments)
  695. {
  696. return $this->column ? $this->column->$name() : null;
  697. }
  698. }