/[webpac]/openisis/0.9.9e/php/demo.php
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Annotation of /openisis/0.9.9e/php/demo.php

Parent Directory Parent Directory | Revision Log Revision Log


Revision 604 - (hide annotations)
Mon Dec 27 21:49:01 2004 UTC (19 years, 5 months ago) by dpavlin
File size: 6359 byte(s)
import of new openisis release, 0.9.9e

1 dpavlin 604 <?php // vim:syntax=php
2     /*
3     The Malete project - the Z39.2/Z39.50 database framework of OpenIsis.
4     Version 0.9.x (patchlevel see file Version)
5     Copyright (C) 2001-2004 by Erik Grziwotz, erik@openisis.org
6    
7     This library is free software; you can redistribute it and/or
8     modify it under the terms of the GNU Lesser General Public
9     License as published by the Free Software Foundation; either
10     version 2.1 of the License, or (at your option) any later version.
11    
12     This library is distributed in the hope that it will be useful,
13     but WITHOUT ANY WARRANTY; without even the implied warranty of
14     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15     Lesser General Public License for more details.
16    
17     You should have received a copy of the GNU Lesser General Public
18     License along with this library; if not, write to the Free Software
19     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20    
21     see README for more information
22     EOH */
23    
24     // $Id: demo.php,v 1.3 2004/11/02 13:44:42 kripke Exp $
25     // demo for the Isis package
26    
27     require 'Isis.php'; // use require 'Isis/Rec.php' if you need only this
28     ?><html><head>
29     <title>Demo for package Isis</title>
30     </head><body>
31     <?php
32    
33     // get request parameters a and b
34     // (as well as any plain numeric and v%d style
35     $param = Isis_Http::fromReq( array(
36     'a' => 22, 'b' => 42
37     ) );
38    
39     // create a db with field list ("fdt")
40     $fdt = array(
41     'title' => 24,
42     'author' => 70,
43     'keywords' => 69
44     );
45     $db = new Isis_Db($fdt, 'test');
46    
47     // a special value using lotsa subfields
48     $subs = 'initial aParis bUnesco b<test=foo> c-1965';
49     // create record using various add parameters
50     $r = new Isis_Rec(
51     // set the db
52     '-db', $db,
53     // first some lines from CDS, some using field names, some plain int tags
54     'keywords', 'Paper on: <plant physiology><moisture><temperature><wind><measurement and instruments><ecosystems>',
55     'author', 'Magalhaes, A.C.',
56     24, '<The> Controlled climate in the plant chamber',
57     76, 'Les Politiques de la communication en Yougoslavie zfre',
58     'author', 'Franco, C.M.',
59     26, $subs,
60     // a field to test del
61     77, 'ave Caesar',
62     // a field using tab as subfield separator
63     42, "foo\tbar\tbaz",
64     // a field containing newline
65     99, "two\nlines",
66     // a serialized record (as of toString) as parameter
67     "70\tyet another author\n99two more\n99lines\na 0 field\n42\tthe\tanswer"
68     );
69    
70     // dump the stuff
71     ?>
72     <h2>dump of record</h2>
73     have <?=$r->len()?> fields
74     <pre>--
75     <?=htmlspecialchars($r->toString())?>--</pre>
76    
77     <h2>examples of field selector</h2>
78     <?php
79    
80     // more dump -- don't
81     // print_r($r->tag); // print_r corrupts data with 4.3.1
82     // print_r($r->map());
83    
84     $r->del( 77 ); // ... morituri te salutant
85    
86     // various examples how to access fields
87     foreach ($db->fdt as $name => $tag)
88     while ($v = $r->mhl($tag))
89     echo "$name = $v<br/>\n";
90    
91     ?>
92    
93     <!-- single select -->
94     v26^a = <?=$r->h(26,'a')?><br>
95     <?php
96     // can't use multiple of this on same tag w/o resetting,
97     // since the magic loop would advance to the next occurence of tag
98     $r->res();
99     // more convenient to get them all at once
100     // the same as Isis_rec::fmt($r->v(26),'&abc'),
101     foreach ($r->h(26,'abc') as $k => $v)
102     echo "v26^$k = $v<br>\n";
103     ?>
104    
105     <!-- select by name -->
106     v69 = <?=$r->mhl('keywords')?><br>
107     v76 = <?=$r->mhl(76)?><br>
108     <!-- use tabbed subfield w/o marker -->
109     v42(1) = <?=$r->h(42,'(1)')?>
110    
111     <?php
112     // more formatting tests on subs
113     echo "<h2>formats returning arrays on '$subs'</h2>\n";
114     foreach (array(
115     '&cab(..',
116     '&*(..',
117     '&(..',
118     '&bca(1..',
119     '&MHLcab(..'
120     ) as $fmt) {
121     echo "\n\n<h3>Format &quot;$fmt&quot;</h3>\n";
122     foreach (Isis_rec::fmt($subs,$fmt) as $k => $v)
123     echo "v26^$k = $v<br/>\n";
124     }
125     ?>
126    
127     <h2>embedding and TEXT mode</h2>
128     <?php
129     $q = new Isis_Rec( 77, 'sunset strip' );
130     // embed r into q
131     $q->embed( $r );
132     $s = $q->toString(ISIS_REC_TEXT);
133     echo "<h3>record embedded</h3>\n<pre>---\n$s---\n</pre>\n";
134     $q->del();
135     // restore from the string
136     $q->parse( $s, ISIS_REC_TEXT );
137     // extract the original r
138     $recs = $q->recs();
139     $r = $recs[0];
140     $r->db = $db;
141     echo "<h3>record restored from field 22</h3>\n",
142     "<pre>---\n", $r->toString(), "---\n</pre>\n";
143     ?>
144    
145     <h2>set operator</h2>
146     <?php
147     // change titles, adding one
148     $r->set( 'title', 'new title', 'second new title' );
149     // change 99s, removing one
150     $r->set( 99, 'now a oneliner' );
151     // change author[1] only, also test array parameter
152     $r->set( 'author', array(1, 'Blanco', 0) );
153     echo "<pre>---\n", $r->toString(), "---\n</pre>\n";
154     ?>
155    
156     <h2>server</h2>
157     <?php
158     $db = new Isis_Db($fdt, 'test', new Isis_Server());
159     if ( !$db->srv->sock )
160     echo "could not contact server\n";
161     else {
162     ?>
163     <h3>terms beginning with a</h3>
164     <?php
165     $terms = $db->terms('a');
166     echo "got ",count($terms), "terms for 'a'</br>\n";
167     foreach ($terms as $t) {
168     list($cnt, $term) = explode("\t", $t);
169     echo "'$term'($cnt) ";
170     }
171     echo "</br>\n";
172     ?>
173     <h3>query reading records</h3>
174     <?php
175     $recs = $db->query('plant water');
176     echo "got ",count($recs), "records for 'plant water'</br>\n";
177     foreach ($recs as $r)
178     echo "<pre>---\n", $r->toString(), "---\n</pre>\n";
179     ?>
180     <h3>query reading mfns</h3>
181     <?php
182     $mfns = $db->query('plant + water + devel$', false);
183     do {
184     echo "got ",count($mfns), " mfns: ", join(',',$mfns),"</br>\n";
185     } while ($mfns = $db->query(null,false));
186     ?>
187     <h3>reading 42, 43</h3>
188     <?php
189     $recs = $db->read( array(42,43) );
190     foreach ($recs as $r)
191     echo "<pre>---\n", $r->toString(), "---\n</pre>\n";
192     ?>
193     <h3>reading 42</h3>
194     <?php
195     $r = $db->read(42);
196     echo "<pre>---\n", $r->toString(), "---\n</pre>\n";
197     ?>
198     <h3>writing 42</h3>
199     <?php
200     $r->append('author', 'one more author');
201     echo "<pre>---\n", $r->toString(), "---\n</pre>\n";
202     $mfns = $db->write($r);
203     echo "wrote ",count($mfns), " mfns: ", join(',',$mfns),"</br>\n";
204     ?>
205     <h3>writing 42 as new record</h3>
206     <?php
207     $r->head = '';
208     $mfns = $db->write($r);
209     echo "wrote ",count($mfns), " mfns: ", join(',',$mfns),"</br>\n";
210     ?>
211     <h3>indexing author fields as 70 in split mode</h3>
212     <?php
213     $idx = new Isis_Rec();
214     $idx->head = 's';
215     $idx->set( 70, $r->get('author') );
216     echo "<pre>---\n", $idx->toString(), "---\n</pre>\n";
217     $res = $db->index($idx);
218     echo "got $res</br>\n";
219     ?>
220     <h3>query one near author</h3>
221     <?php
222     $mfns = $db->query('one .. author', false);
223     echo "got ",count($mfns), " mfns: ", join(',',$mfns),"</br>\n";
224     ?>
225     <?php
226     } // end else could contact server
227     ?>
228     </body></html>

  ViewVC Help
Powered by ViewVC 1.1.26