Location: PHPKode > projects > Dbscript > db/library/dbscript/collection.php
<?php

  /**
   * dbscript for PHP 4 & 5 - restful crud framework
   * @version 0.3.0 -- 10-Jun-2007
   * @author Brian Hendrickson <hide@address.com>
   * @link http://dbscript.net/
   * @copyright Copyright 2007 Brian Hendrickson
   * @package dbscript
   * @license http://www.opensource.org/licenses/mit-license.php MIT License
   */

  /**
   * Collection
   * 
   * More info...
   * {@link http://dbscript.net/collection}
   * 
   * @package dbscript
   * @author Brian Hendrickson <hide@address.com>
   * @access public
   * @version 0.3.0
   */

class Collection extends GenericIterator {
  
  var $member_entry_iri;
  
  var $media_iri;
  
  var $resource;
  
  var $accept;
  
  var $members;
  
  var $fields;
  
  var $updated;
  
  // member_entry_iri will be a media link or member entry
  
  // a media link entry is a member entry that
  // contains metadata about a media resource
  
  function Collection( $resource, $accept = "text/html" ) {
    
    $this->_currentRow = 0;
    
    $this->EOF = false;
    
    $this->members = array();
    
    $this->fields = array();
        
    if ($resource == null)
      return;
    
    $request =& request_object();
    
    $db =& db_object();
    
    $this->resource = $resource;
    
    $this->accept = $accept;
        
    if ( $resource == 'introspection' ) {
      $tables = $db->get_tables();
      foreach ($tables as $t) {
        if (!(in_array($t, array( 'db_sessions', 'entries', 'categories_entries' )))
        && $t != classify($t)) {
          $m =& $db->get_table($t);
          if (!$m->hidden)
            $this->members[] = $t;
        }
      }
      return;
    } elseif ( $resource == 'login' ) {
      return;
    }
    
    if ($resource != classify($resource))
      $table =& $db->get_table( $this->resource );
    else
      return;
    
    // $member->member_entry_iri // Entry object of type 'member' or 'media link'
    
    // $member->media_iri = ; // (optional) Entry object of type 'media link'
    
    if ( isset( $table->params )) {
      foreach ( $table->params as $key=>$val ) {
        if (!(isset($this->$key)))
          $this->$key = $val;
      }
    }
    
    if ( !$request->id )
      $table->find();
    else
      $table->find( $request->id );
    
    if (isset($table->uri_key))
      $uri_key = $table->uri_key;
    else
      $uri_key = $table->primary_key;
    
    if ($table->rowcount() > 0) {
      $first = true;
      while ( $Member = $table->MoveNext() ) {
        if ( isset( $db->models['entries'] )) {
          $Entry = $Member->FirstChild( 'entries' );
          if ($Entry) {
            $Member->last_modified = $Entry->last_modified;
            $Member->etag = $Entry->etag;
          }
        }
        $this->members[$Member->$uri_key] = $resource;
        if ($first) {
          if ( isset( $db->models['entries'] )) {
            $this->updated = $Entry->last_modified;
          }
        }
        $first = false;
      }
      $table->rewind();
    }
    
  }
  
  function MoveNext() {
    $db =& db_object();
    $model =& $db->models[$this->resource];
    if ($model)
      return $model->MoveNext();
  }
  
  function MoveFirst() {
    $db =& db_object();
    $model =& $db->models[$this->resource];
    if ($model)
      return $model->MoveFirst();
  }
  
  function post() {
    // 201 created
    // redirect_to
  }
  
  function get() {
    // member representation
  }
  
  function put() {
    // 200 ok
    // redirect_to
  }
  
  function delete() {
    // 200 ok
    // redirect_to
  }
  
}

?>
Return current item: Dbscript