\n{$tab}\t {$fieldName} true \n{$tab}<% else %>\n{$tab}\t {$fieldName} false \n{$tab}<% end_if %>\n";
}
/**
* A simple way of drawing a label and value on the template,
* e.g. "Sale Price: $SalePrice"
*
* @param string $fieldName The field name to display
* @param string $relationName If a "has_one" related object, make sure to show the value with dot syntax.
*/
public static function label_and_value($fieldName, $relationName = null) {
$tab = self::indent();
$related = ($relationName !== null) ? $relationName."." : "";
self::$tags .= "{$tab}
".FormField::name_to_label($fieldName).": \${$related}{$fieldName}
\n";
}
/**
* Draw a header field for a new relation
*
* @param string $relationName The name of the relation shown in this section of the template
*/
public static function start_relation($relationName) {
$tab = self::indent();
self::$tags .= "\n\n{$tab}".FormField::name_to_label($relationName)."
\n";
}
/**
* Open a new <% control %> block
*
* @param string $relationName The subject of the control block
*/
public static function open_control($relationName) {
$tab = self::indent();
self::$tags .= "{$tab}\n{$tab}<% control {$relationName} %>\n";
}
/**
* Given a set of fields, draw the contents of the control in a set of - tags.
*
* @param array $fields The fields that belong to the object in the control block
*/
public static function inner_control($fields) {
if(empty($fields)) return;
self::$level++;
$tab = self::indent();
self::$tags .= "{$tab}
- \n";
self::$level++;
foreach($fields as $fieldName => $type) {
if((string) $type === "Boolean") {
self::if_block($fieldName);
}
else {
self::label_and_value($fieldName);
}
}
self::$level--;
self::$tags .= "{$tab}
\n";
self::$level--;
}
/**
* End the control block, and close the
*/
public static function close_control() {
$tab = self::indent();
self::$tags .= "{$tab}<% end_control %>\n{$tab}
\n";
}
/**
* Close out the template and return all of the markup that has been created
*
* @return string
*/
public static function end_template() {
return self::$tags;
}
}