[interchange-cvs] interchange - heins modified 2 files

interchange-core@icdevgroup.org interchange-core@icdevgroup.org
Mon Oct 14 17:36:01 2002


User:      heins
Date:      2002-10-14 21:35:03 GMT
Modified:  dist/lib/UI/profiles process_filter
Added:     code/Filter next_sequential.filter
Log:
* Add new filter, "next_sequential". Allows selection of a next-sequential
  value based on a field (and qualified by a field).

  [filter op=3D"next_sequential.survey_q.sort"][cgi sort][/filter]

  will:

  	1. Return the existing value if present.
	2. If existing value is blank, return max + 1 in the sort field,
		i.e. equivalent to:

			SELECT sort FROM survey_q
			ORDER BY sort DESC
			LIMIT 1

  If another argument of a field name is passed, i.e.

	  filter =3D> 'next_sequential.survey_q.sort.sel',

  then you get:

			SELECT sort FROM survey_q
			WHERE sel =3D '[cgi sel]'
			ORDER BY sort DESC
			LIMIT 1

  This allows a next-sequential numbering for things that need it.

  Developed to support general-purpose survey UI for Ton's excellent
  product rating system.

* Profile "process_filter" updated to support this -- it had no ability
  to employ database entries in filters before, which could have been
  a maddeningly subtle problem with other people's attempts at such
  things.

Revision  Changes    Path
1.1                  interchange/code/Filter/next_sequential.filter


rev 1.1, prev_rev 1.0
Index: next_sequential.filter
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
## $Id: next_sequential.filter,v 1.1 2002/10/14 21:35:02 mheins Exp $
CodeDef next_sequential Filter
CodeDef next_sequential Routine <<EOR
sub {
	my ($value, $field, $table, $col, $qualifier) =3D @_;
#::logDebug("called next_sequential filter value=3D'$value' table=3D$table =
col=3D$col qual=3D$qualifier");
	return $value if length($value);
	$table ||=3D $CGI::values{mv_data_table};

	my $val;

	if(! $table) {
		return 1 if ! $field;
		return exists $CGI::values{$field}
				? ($CGI::values{$field})
				: ($::Values->{$field});
	}

	$col ||=3D $field;
=09
	eval {
		my $db =3D database_exists_ref($table)
			or die errmsg("next_sequential filter: no table '%s'", $table);
		my $tname =3D $db->name();
		my $q =3D "SELECT $col FROM $tname";
		if($qualifier) {
			my $qval =3D $CGI::values{$qualifier};
			$qval =3D $db->quote($qval, $qualifier);
			$q .=3D " WHERE $qualifier =3D $qval";
		}
		$q .=3D " ORDER BY $col desc";
#::logDebug("constructed query $q for next_sequential");
		my $ary =3D $db->query($q)
			or die errmsg("next_sequential filter query failed: %s", $q);
		return 1 unless @$ary;
		$val =3D $ary->[0][0];
		$val++;
	};

	if($@) {
		logError($@);
		return undef;
	}

	return $val;

}
EOR



2.2       +3 -1      interchange/dist/lib/UI/profiles/process_filter


rev 2.2, prev_rev 2.1
Index: process_filter
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
RCS file: /var/cvs/interchange/dist/lib/UI/profiles/process_filter,v
retrieving revision 2.1
retrieving revision 2.2
diff -u -r2.1 -r2.2
--- process_filter	6 Oct 2001 07:03:36 -0000	2.1
+++ process_filter	14 Oct 2002 21:35:02 -0000	2.2
@@ -1,5 +1,7 @@
 __NAME__ process_filter
-[perl]
+[flag type=3Dwrite table=3D"[cgi mv_data_table]"]
+[perl tables=3D"[list-databases]"]
+# $Id: process_filter,v 2.2 2002/10/14 21:35:02 mheins Exp $
 	my @filters =3D grep /^ui_filter:/, keys %$CGI;
   FILTERS: {
 	last FILTERS unless @filters;