From 7b2c07787abcab33f2e38f1662fc2287befb2794 Mon Sep 17 00:00:00 2001 From: Jason Woofenden Date: Mon, 8 Nov 2010 22:55:13 -0500 Subject: [PATCH] added tem_auto_once() and friends --- metaform/template.html | 28 +++++++++++++--------------- metaform/template.php | 23 ++--------------------- template.php | 30 +++++++++++++++++++++++++++++- 3 files changed, 44 insertions(+), 37 deletions(-) diff --git a/metaform/template.html b/metaform/template.html index c818b3c..b00c0ad 100644 --- a/metaform/template.html +++ b/metaform/template.html @@ -19,17 +19,15 @@ - - -
- + +
+

~~data html~~

- -
- - -
- + +
+ + +
@@ -112,22 +110,22 @@
Cancel
- +

~plural cap~ Listing

- +

[Add a new ~singular~]

- + - +
~caption~ ~caption~ 
~~~name~ ~enc~~~~~~name~ ~enc~~~(blank) [delete this ~singular~]
- +

No ~plural~ in database.

diff --git a/metaform/template.php b/metaform/template.php index d8f663b..945942e 100644 --- a/metaform/template.php +++ b/metaform/template.php @@ -69,27 +69,7 @@ function ~file_name~_get_fields() { return $data; } - -# You may pass a "where clause" for the db query. -function ~file_name~_display_listing($where = 'order by ~always_field~ limit 100') { - $rows = db_get_assocs('~table_name~', 'id,~name~', $where); - if($rows == false || count($rows) == 0) { - tem_set('listings', array('empty_listing' => true)); - return; - } - # make sure there's something clickable - foreach($rows as &$row) { - if($row['~always_field~'] == '') { - $row['~always_field~'] = '--'; - } - } - tem_set('listings', array( - 'populated_listing' => true, - 'rows' => $rows)); - return true; -} - function ~file_name~_main() { if(!logged_in_as_admin()) { $_REQUEST['url'] = this_url(); @@ -141,7 +121,8 @@ function ~file_name~_edit_main() { if(!$edit_id) { if(!isset($_REQUEST['~file_name~_new']) && !isset($_REQUEST['~always_field~'])) { - ~file_name~_display_listing(); + $listing_rows = db_get_assocs('~table_name~', 'id,~name~', 'order by ~always_field~ limit 100'); + tem_set('listings', $listing_rows); return; } diff --git a/template.php b/template.php index cbb9466..697761e 100644 --- a/template.php +++ b/template.php @@ -324,6 +324,13 @@ function tem_auto_show(&$value) { return $value; } +# 'empty' sections will be shown only if the corresponding data value is the +# empty string +function tem_auto_empty(&$value) { + if($value === '') return true; + return null; +} + # 'nonempty' sections will not be shown if the corresponding data # value is the empty string function tem_auto_nonempty(&$value) { @@ -331,7 +338,7 @@ function tem_auto_nonempty(&$value) { return $value; } -# 'not' sections will not be shown if the corresponding data +# 'unset' sections will not be shown if the corresponding data # value is not set (opposite of default) function tem_auto_unset(&$value) { if($value === null) { @@ -352,6 +359,27 @@ function tem_auto_evenodd(&$values) { return $values; } +# 'once' sections are shown exactly once if the value is set (and not at all +# otherwise.) This is useful when an array value would otherwise cause the +# section to be displayed multiple times. +function tem_auto_once(&$value) { + if($value === null) return null; + return true; +} + +function tem_auto_once_if(&$value) { + if($value) return true; + return null; +} + +# 'once' sections are shown exactly once if php evaluates the value to false +# (and not at all otherwise.) This is useful when an array value would +# otherwise cause the section to be displayed multiple times. +function tem_auto_once_else(&$value) { + if($value) return null; + return true;; +} + -- 1.7.10.4