RE: [phplib] sql_query->form customization? From: Torrey Hoffman (torrey.hoffman <email protected>)
Date: 08/22/00

Here's how I subclassed the sql_query to do a default query:

------- in file my.querywidget.inc.php3 ----------------

class My_QueryWidget extends Sql_Query {
        var $classname = "My_QueryWidget";

        function set_default_query($base, $field, $comp, $input)
        {
                // Note: only sets the default query if no query exists.
                if (!isset($GLOBALS[$base]["sel_1"]))
                {
                        $GLOBALS[$base]["sel_1"] = $field;
                        $GLOBALS[$base]["comp_1"] = $comp;
                        $GLOBALS[$base]["input_1"] = $input;
                }
        }
}

-------------------------

<?php
/*
** example for phplist, some names changed from my real code
** "Stuff" is actually something else where I work, of course
** I have at least 5 different pages like this, almost identical, that
** are used for viewing different lists of things from a database and
linking to
** edit forms.
*/
  require("header.inc.php3"); // All the usual page
startup, same on all pages.
                                                        // includes
my.querywidget, opens the session, etc.
  $perm->check("Edit_Stuff");
  echo "<h1>Edit Stuff</h1>";

  require("tablearrays.inc.php3"); // defines the $stuff_fields
array

  $db = new My_DB; // overloaded with query
functions

  $t = new My_Subclassed_Table;

  $t->tm_init($stuff_fields, "stuff_form.php3", "id", "stuff");
           // the tm_init just sets a bunch of variables.
        // my table subclass makes each row a link to an editing
        // form (stuff_form.php3), linked by id

  $qbase = "sqlwdgt";

  if (!isset($sqlWidgetStuff))
  {
        $sqlWidgetStuff = new My_QueryWidget;
        $sqlWidgetStuff->tm_init();
        $sess->register("sqlWidgetStuff");
  }

  // - - - - - - -
  // Here's the important line that sets the default query if none exists:
  //
  $sqlWidgetStuff->set_default_query($qbase, "id", ">", "0");

  // Another possible example:
  // $sqlWidgetStuff->set_default_query($qbase, "name", "<=", "B");

  $strWhere = $sqlWidgetStuff->where($qbase, 1);
  printf($sqlWidgetStuff->form($qbase, $stuff_fields, "query"));
  $db->query_Stuff_Where($strWhere);

  // this is a convenient function in my subclass that produces a nice table
from the query results
  $t->doit($db);

  require("trailer.inc.php3");
?>

---------------------------------------------------------------------
To unsubscribe, e-mail: phplib-unsubscribe <email protected>
For additional commands, e-mail: phplib-help <email protected>