Location: PHPKode > projects > ATUIN > atuin/app/models/rdfengine/RDFNodeChannel.php
<?php

require_once 'RDFNodeItem.php';
require_once 'RDFNodeImage.php';
require_once 'Translator.php';

/**
 * represents a single channel within a rdf file.
 * it contains an image object and a variable number
 * of item objects.
 *
 * @author Michael Lessnau
 * @version 0.1
 */
class RDFNodeChannel {

   /**
    * @var $rdfAbout string contains the about attribute
    */
   private $rdfAbout;

   /**
    * @var $dcSource string contains the dc:source attribute
    * which is used to specify the origin of the channel.
    * all sub-channels created within a channel should contain
    * the channels uri as $source value.
    */
   private $dcSource;

   /**
    * @var $dcPublisher string contains the dc:publisher attribute
    * which is used to specify 'atuin' as processing application
    */
   private $dcPublisher;

   /**
    * @var $dcCreator string contains the dc:creator attribute
    * which is used to specify the creator of the channel
    */
   private $dcCreator;

   /**
    * @var $dcDate string contains the dc:date attribute
    * which is used to save the time + daten when the channel
    * was created or modified the last time
    */
   private $dcDate;

   /**
    * @var $title string contains the title text element
    */
   private $title;

   /**
    * @var $link string contains the link text element
    */
   private $link;

   /**
    * @var $description string contains the description text element
    */
   private $description;

   /**
    * @var $image RDFNodeImage contains the image node
    */
   private $image;

   /**
    * @var $items RDFNodeItem[] contains multiple item nodes
    */
   private $items;
   
   /**
    * constructor
    */
   public function __construct( ) {
      $this->rdfAbout = '';
      $this->dcSource = '';
      $this->dcPublisher = '';
      $this->dcCreator = '';
      $this->dcDate = '';
      $this->title = '';
      $this->link = '';
      $this->description = '';
      unset( $this->image);
      $this->items = array( );
   }
   
   /**
    * destructor
    */
   public function __destruct( ) {
      // nop
   }
   
   /**
    * setting the class' attributes
    *
    * @param $name string attribute name
    * @param $value mixed attribute value
    */
   public function __set( $name, $value) {
      switch( $name) {
         case 'rdfAbout':
            $this->rdfAbout = $value;
            break;
         case 'dcSource':
            $this->dcSource = $value;
            break;
         case 'dcPublisher':
            $this->dcPublisher = $value;
            break;
         case 'dcCreator':
            $this->dcCreator = $value;
            break;
         case 'dcDate':
            $this->dcDate = $value;
            break;
         case 'title':
            $this->title = $value;
            break;
         case 'link':
            $this->link = $value;
            break;
         case 'description':
            $this->description = $value;
            break;
         case 'image':
            $this->image = $value;
            break;
         case 'items':
            $this->items = $value;
      }
   }
   
   /**
    * access the class' attributes
    *
    * @param $name string attribute name
    * @return string attribute value
    */
   public function __get( $name) {
      switch( $name) {
         case 'rdfAbout':
            return $this->rdfAbout;
         case 'dcSource':
            return $this->dcSource;
         case 'dcPublisher':
            return $this->dcPublisher;
         case 'dcCreator':
            return $this->dcCreator;
         case 'dcDate':
            return $this->dcDate;
         case 'title':
            return $this->title;
         case 'link':
            return $this->link;
         case 'description':
            return $this->description;
         case 'image':
            return $this->image;
         case 'items':
            return $this->items;
      }
      return false;
   }
   
   /**
    * appends an item object to $this->items[]
    *
    * @param $item RDFNodeItem item object
    */
   public function addItem( $item) {
      foreach( $this->items as $key => $i) {
         if( strcmp( $i->rdfAbout, $item->rdfAbout)==0) {
            $this->items[$key] = $item;
            return;   
         }
      }
      array_push( $this->items, $item);
   }   

   /**
    * serialize the channel.
    *
    * @param $indent string indentation
    * @return string serialized channel
    */
   public function toString( $indent) {
      $output = "\n";
      $output .= $indent . '<channel rdf:about="' . Translator::encode( $this->rdfAbout) . '">' . "\n";
      $output .= $indent . '  <dc:source>' . Translator::encode( $this->dcSource) . '</dc:source>' . "\n";
      $output .= $indent . '  <dc:publisher>' . Translator::encode( $this->dcPublisher) . '</dc:publisher>' . "\n";
      $output .= $indent . '  <dc:creator>' . Translator::encode( $this->dcCreator) . '</dc:creator>' . "\n";
      $output .= $indent . '  <dc:date>' . $this->dcDate . '</dc:date>' . "\n";
      $output .= $indent . '  <title>' . Translator::encode( $this->title) . '</title>' . "\n";
      $output .= $indent . '  <link>' . Translator::encode( $this->link) . '</link>' . "\n";
      $output .= $indent . '  <description>' . Translator::encode( $this->description) . '</description>' . "\n";
      if( isset( $this->image)) {
         $output .= $indent . '  <image rdf:resource="' . Translator::encode( $this->image->rdfAbout) . '" />' . "\n";
      }
      $output .= $indent . '  <items>' . "\n";
      $output .= $indent . '    <rdf:Seq>' . "\n";
      if( count( $this->items)>0) {
         foreach( $this->items as $item) {
            $output .= $indent . '      <rdf:li resource="' . Translator::encode( $item->rdfAbout) . '" />' . "\n";
         }
      }
      $output .= $indent . '    </rdf:Seq>' . "\n";
      $output .= $indent . '  </items>' . "\n";
      $output .= $indent . '</channel>' . "\n";
      if( isset( $this->image)) {
         $output .= "\n";
         $output .= $this->image->toString( $indent);
      }
      if( count( $this->items)>0) {
         foreach( $this->items as $item) {
            $output .= "\n";
            $output .= $item->toString( $indent);
         }
      }
      return $output;
   }
};

?>       
Return current item: ATUIN