/**
  * Returns HTML code for a field.
  *
  * @param sfModelGeneratorConfigurationField $field The field
  *
  * @return string HTML code
  */
 public function renderField($field)
 {
     $html = $this->getColumnGetter($field->getName(), true);
     if ($renderer = $field->getRenderer()) {
         $html = sprintf("{$html} ? call_user_func_array(%s, array_merge(array(%s), %s)) : ' '", $this->asPhp($renderer), $html, $this->asPhp($field->getRendererArguments()));
     } else {
         if ($field->isComponent()) {
             return sprintf("get_component('%s', '%s', array('type' => 'list', '%s' => \$%s))", $this->getModuleName(), $field->getName(), $this->getSingularName(), $this->getSingularName());
         } else {
             if ($field->isPartial()) {
                 return sprintf("get_partial('%s/%s', array('type' => 'list', '%s' => \$%s))", $this->getModuleName(), $field->getName(), $this->getSingularName(), $this->getSingularName());
             } else {
                 if ('Date' == $field->getType()) {
                     //            $html = sprintf("false !== strtotime($html) ? format_date(%s, \"%s\") : ' '", $html, $field->getConfig('date_format', 'f'));
                 } else {
                     if ('Boolean' == $field->getType()) {
                         $html = sprintf("get_partial('%s/list_field_boolean', array('value' => %s))", $this->getModuleName(), $html);
                     }
                 }
             }
         }
     }
     if ($field->isLink()) {
         $html = sprintf("link_to(%s, '%s', \$%s)", $html, $this->getUrlForAction('edit'), $this->getSingularName());
     }
     return $html;
 }
 /**
  * Returns HTML code for a field
  * 
  * @param   sfModelGeneratorConfigurationField  $field
  * @return  string  HTML code
  */
 public function renderField($field)
 {
     $html = $this->getColumnGetter($field->getName(), true);
     if ($renderer = $field->getRenderer()) {
         $html = sprintf("{$html} ? call_user_func_array( %s, array_merge( array(%s), %s ) ) : ' '", $this->asPhp($renderer), $html, $this->asPhp($field->getRendererArguments()));
     } else {
         if ($field->isComponent()) {
             return sprintf("Partial::component( '%s', '%s', array( 'type' => 'list', '%s' => \$%s ) )", $this->getModuleName(), $field->getName(), $this->getSingularName(), $this->getSingularName());
         } else {
             if ($field->isPartial()) {
                 return sprintf("Partial::get( '%s', array( 'type' => 'list', '%s' => \$%s ) )", $field->getName(), $this->getSingularName(), $this->getSingularName());
             } else {
                 if ('Date' == $field->getType()) {
                     $html = sprintf("false !== strtotime( {$html} ) ? Date::formatDate( %s, \"%s\" ) : ' '", $html, $field->getConfig('date_format', 'f'));
                 } else {
                     if ('Boolean' == $field->getType()) {
                         $html = sprintf("'<div class=\"ui-icon' . ( %s ? ' ui-icon-check' : ' ui-icon-close' ) . '\" title=\"'" . " . I18n::__( 'admin.label.' . ( %s ? '' : 'un' ) . 'checked' ) . '\"></div>'", $html, $html);
                     }
                 }
             }
         }
     }
     if ($field->isLink()) {
         $html = sprintf("Url::link( %s, '%s', \$%s )", $html, $this->getUrlForAction('edit'), $this->getSingularName());
     }
     return $html;
 }
 /**
  * Returns HTML code for a field.
  *
  * @param sfModelGeneratorConfigurationField $field The field
  *
  * @return string HTML code
  */
 public function renderField($field)
 {
     $fieldName = $field->getName();
     $html = $this->getColumnGetter($fieldName, true);
     if ($renderer = $field->getRenderer()) {
         $html = sprintf('%s ? call_user_func_array(%s, array_merge(array(%s), %s)) : "&nbsp;"', $html, $this->asPhp($renderer), $html, $this->asPhp($field->getRendererArguments()));
     } else {
         if ($field->isComponent()) {
             return sprintf("get_component('%s', '%s', array('type' => 'list', '%s' => \$%s))", $this->getModuleName(), $fieldName, $this->getSingularName(), $this->getSingularName());
         } else {
             if ($field->isPartial()) {
                 return sprintf("get_partial('%s/%s', array('type' => 'list', '%s' => \$%s))", $this->getModuleName(), $fieldName, $this->getSingularName(), $this->getSingularName());
             } else {
                 if ('Date' == $field->getType()) {
                     $html = sprintf("false !== strtotime({$html}) ? format_date(%s, \"%s\") : '&nbsp;'", $html, $field->getConfig('date_format', 'f'));
                 } else {
                     if ('Boolean' == $field->getType()) {
                         $html = "sprintf('<span class=\"bloc bool_%s {field: \\'%s\\'}\" title=\"%s\"></span>', " . $html . " ? 'tick' : 'cross', '" . $fieldName . "', __('Cliquer pour modifier'))";
                     }
                 }
             }
         }
     }
     if ($field->isLink()) {
         $html = sprintf("link_to(%s, '%s', \$%s)", $html, $this->getUrlForAction('edit'), $this->getSingularName());
     }
     return $html;
 }
Пример #4
0
 /**
  * Returns HTML code for a field.
  *
  * @param sfModelGeneratorConfigurationField $field The field
  *
  * @return string HTML code
  */
 public function renderField($field)
 {
     $fieldName = $field->getName();
     $html = $this->getColumnGetter($fieldName, true);
     if ($renderer = $field->getRenderer()) {
         $html = sprintf('%s ? call_user_func_array(%s, array_merge(array(%s), %s)) : "&nbsp;"', $html, $this->asPhp($renderer), $html, $this->asPhp($field->getRendererArguments()));
     } else {
         if ($field->isComponent()) {
             return sprintf("get_component('%s', '%s', array('type' => 'list', '%s' => \$%s))", $this->getModuleName(), $fieldName, $this->getSingularName(), $this->getSingularName());
         } else {
             if ($field->isPartial()) {
                 return sprintf("get_partial('%s/%s', array('type' => 'list', '%s' => \$%s))", $this->getModuleName(), $fieldName, $this->getSingularName(), $this->getSingularName());
             } else {
                 if ('Date' == $field->getType()) {
                     $html = sprintf("false !== strtotime({$html}) ? format_date(%s, \"%s\") : '&nbsp;'", $html, $field->getConfig('date_format', 'f'));
                 } else {
                     if ('Boolean' == $field->getType()) {
                         $html = "sprintf('<a class=\"s16block s16_%s {field: \\'%s\\'}\" title=\"%s\"></a>', " . $html . " ? 'tick' : 'cross', '" . $fieldName . "', __('Click to edit'))";
                     } elseif ($relation = $this->table->getRelationHolder()->getLocalByColumnName($fieldName)) {
                         if ('DmMedia' === $relation->getClass()) {
                             $html = '$' . $this->getSingularName() . "->get('" . $relation->getLocalColumnName() . "') ? get_partial('dmMedia/viewLittle', array('object' => \$" . $this->getSingularName() . "->get('" . $relation->getAlias() . "'))) : '-'";
                         } else {
                             $localModule = $this->moduleManager->getModuleByModel($relation->getClass());
                             if ($localModule && $localModule->hasAdmin()) {
                                 $html = "(\$sf_user->canAccessToModule('{$localModule->getKey()}')\n? _link(\${$this->getSingularName()}->get('{$relation->getAlias()}'))\n->text(\${$this->getSingularName()}->get('{$relation->getAlias()}')->__toString())\n->set('.associated_record.s16right.s16_arrow_up_right_medium')\n: \$" . $this->getSingularName() . "->get('" . $relation->getAlias() . "'))";
                             } else {
                                 $html = "\$" . $this->getSingularName() . "->get('" . $relation->getAlias() . "')";
                             }
                             $html = '$' . $this->getSingularName() . "->get('" . $relation->getLocalColumnName() . "') ? " . $html . " : '-'";
                         }
                     } elseif (substr($fieldName, -5) === '_list') {
                         if (!($relation = $this->table->getRelationHolder()->get($alias = dmString::camelize(substr($fieldName, 0, strlen($fieldName) - 5))))) {
                             $relation = $this->table->getRelationHolder()->get($alias = substr($fieldName, 0, strlen($fieldName) - 5));
                         }
                         if ($relation) {
                             $html = "\$sf_context->getServiceContainer()->mergeParameter('related_records_view.options', array(\n  'record' => \$" . $this->getSingularName() . ",\n  'alias'  => '" . $alias . "'\n))->getService('related_records_view')->render()";
                         }
                     } elseif ('dm_gallery' === $fieldName) {
                         $html = "get_partial('dmMedia/galleryLittle', array('record' => \$" . $this->getSingularName() . "));";
                     } else {
                         $html = 'htmlentities(dmString::truncate(' . $html . ', ' . $field->getConfig('truncate', sfConfig::get('dm_admin_list_truncate', 120)) . '), ENT_COMPAT, \'UTF-8\')';
                         if ($this->module->getTable()->isMarkdownColumn($fieldName)) {
                             $html = "str_replace(array('*', '#'), '', " . $html . ")";
                         }
                     }
                 }
             }
         }
     }
     if ($field->isLink()) {
         $html = sprintf("_link('@%s?action=edit&pk='.\$%s->getPrimaryKey())->text(%s)->addClass('link_edit')", $this->module->getUnderscore(), $this->getSingularName(), $html);
     }
     return $html;
 }
 /**
  * Renders the value of an admin-generator field in function of its type. This function is 
  * meant to render a "show" representation of a form field.
  * 
  * @param sfFormField $field: form field to render
  * @param mixed $value: the value to render
  * @return string 
  */
 public static function renderAdminFieldValue(sfForm $form, sfModelGeneratorConfigurationField $field, $value = null)
 {
     if (null === $value) {
         return '';
     }
     if ($renderer = $field->getRenderer()) {
         return call_user_func_array($renderer, array_merge(array($value), $field->getRendererArguments()));
     }
     $string = self::renderField($form, $field, $value, $field->getType());
     return $string;
 }