29 Aralık 2009 Salı

ADVTemplateListView Class

MVC (Model View Controller) temeline dayanan bir anlayış ile ADVTemplateList modelimizi HTML görünümüne çevirmesi için bir yönetici View sınıfı oluşturdum. Bu View sınıfı sayesinde reklam şablonlarımız kolaylıkla listelenebiliyor, listelenen şablonlar sayfalar haline getirilebiliyor ve bu sayfalar tek tek listelenebiliyorlar.
Hazırlamış olduğum ADVTemplateListView Class dosyasının kodu şöyle:

<?php
/**
  * This class is used to represent the view part of the Template List.
  * 
  * @author Behçet MUTLU
  * @copyright 2009
  */
class ADVTemplateListView {
        
      private $templateList;
      private $currentPage;
      private $pageSize;
      
      
      /**
      * ADVTemplateListView::__constructor()
      * 
      * This is the default constructor of the view class.
      * 
      * @param mixed $templateList
      * @param integer $currentPage
      * @param integer $pageSize
      * @return void
      */
      public function __construct($templateList, $currentPage = 0, $pageSize = 4)
      {
          $this->templateList = $templateList;
          $this->currentPage = $currentPage;
          $this->pageSize = $pageSize;
      }
      
      public function getNextPage()
      {
          $output = "<ul class=\"tmpList\">";
          $currentIndex = $this->currentPage * $this->pageSize;
          $nextIndex = min($currentIndex + $this->pageSize, $this->templateList->getTemplateCount());
          
          for($i = $currentIndex; $i < $nextIndex; $i++)
          {
            $output.= $this->_toHTML($this->templateList->getTemplateAt($i));
          }
          
          $output.= "</ul>";
          
          $this->currentPage += 1;
          
          return $output;
      }
      
      /**
      * ADVTemplateListView::_toHTML()
      * 
      * This method is used to get the HTML output of template thumbnail
      * 
      * <li>
      *    <a href="#">Şablon #4</a>
      *    <div class="thumb"><img src="adv_templates/template1/thumb.jpg" width="178" height="148" /></div>
      * </li>
      * 
      * @param mixed $template
      * @return
      */
      private function _toHTML($template)
      {
          $output = "<li>";
          
          $output.= "<a href=\"#\">" . $template->getName() . "</a>";
          
          $output.="<div class=\"thumb\"><img src=\"". $template->getThumbnail()
          ."\" width=\"178\" height=\"148\"></div>";
          
          return $output . "</li>";
      }
  
  }

?>

ADV Manager Şablon Kategorileri Tasarımı


Reklam Yöneticimizin Şablon listeleme ekranını hazırladım. Bu bölüm reklam editörümüzün hemen üzerinde görüntülenecek ve kullanıcılar diledikleri anda tasarımlarını seçerek düzenleme işlemlerini yapabilecekler. Şablon listesi daha önce hazırladığım ADVTemplateList Class'ı tarafından oluşturulan listeden yüklenecektir. Yine her bir şablon ile ilgili veriler de bu sınıf sayesinde eklenerek düzenleme işlemleri yapılabilecektir.

26 Aralık 2009 Cumartesi

ADVTemplateList Class Test

ADVTemplateList sınıfımızı test edebilmek için hazırladığım kod da aşağıdaki gibi.

<?php
/**
  * This is the tester of ADVTemplateList class
  * 
  * @author Behçet MUTLU
  * @copyright 2009
  */

    include_once("../system.core.php");
    
    $list = new ADVTemplateList($_SERVER["DOCUMENT_ROOT"]."ADVManager/adv_templates/");
    
    if($list->isReady())
          pre($list->getList());
    else
        print("List is not ready!");
    
?>

Bu kodun çıktısı şu şekilde.

DEBUG:  Template at "C:/wamp/www/ADVManager/adv_templates/Kopyas� template1" does not contain template.xml schema file.


DEBUG:  XML file, "C:/wamp/www/ADVManager/adv_templates/template1/template.xml" loaded successfully.

Array
(
    [0] => ADVTemplate Object
        (
            [name:ADVTemplate:private] => Template 1
            [author:ADVTemplate:private] => Behçet MUTLU
            [datecreated:ADVTemplate:private] => 25-12-2009
            [copyright:ADVTemplate:private] => 2009 Adres Gezgini
            [website:ADVTemplate:private] => www.adresgezgini.com.tr
            [thumbnail:ADVTemplate:private] => adv_templates/template1/thumb.jpg
            [schema:ADVTemplate:private] => C:/wamp/www/ADVManager/adv_templates/template1/template.xml
            [isReady:ADVTemplate:private] => 1
            [xml:ADVTemplate:private] => Array
                (
                    [template] => Array
                        (
                            [0] => 

                            [info] => Array
                                (
                                    [0] => 
    
                                    [name] => Template 1
                                    [author] => Behçet MUTLU
                                    [copyright] => 2009 Adres Gezgini
                                    [website] => www.adresgezgini.com.tr
                                    [thumbnail] => adv_templates/template1/thumb.jpg
                                    [datecreated] => 25-12-2009
                                )

                            [fields] => Array
                                (
                                    [0] => 
    
                                    [image] => Array
                                        (
                                            [0] => Array
                                                (
                                                    [0] => 
        
                                                    [title] => Logo Resmi
                                                    [description] => Eklemek istediğiniz logo resmini dosyadan seçiniz.
                                                    [default] => library/image_64x64.png
                                                    [@id] => image1
                                                    [@width] => 64
                                                    [@height] => 64
                                                )

                                            [1] => Array
                                                (
                                                    [0] => 
        
                                                    [title] => Ürün Resmi
                                                    [description] => Eklemek istediğiniz ürün resmini dosyadan seçiniz.
                                                    [default] => library/image_128x169.png
                                                    [@id] => image2
                                                    [@width] => 128
                                                    [@height] => 169
                                                )

                                        )

                                    [text] => Array
                                        (
                                            [0] => Array
                                                (
                                                    [0] => 
        
                                                    [title] => Başlık Yazısı
                                                    [description] => Eklemek istediğiniz başlık yazısını belirtiniz.
                                                    [default] => Başlık Yazısı
                                                    [font] => Arial
                                                    [color] => 000000
                                                    [size] => 20
                                                    [@id] => text1
                                                    [@max] => 100
                                                    [@min] => 10
                                                )

                                            [1] => Array
                                                (
                                                    [0] => 
        
                                                    [title] => Web Site Adresi
                                                    [description] => Eklemek istediğiniz web site adresinizi belirtiniz.
                                                    [default] => www.websiteniz.com.tr
                                                    [font] => Arial
                                                    [color] => 000000
                                                    [size] => 12
                                                    [@id] => text2
                                                    [@max] => 100
                                                    [@min] => 10
                                                )

                                            [2] => Array
                                                (
                                                    [0] => 
        
                                                    [title] => Buton Yazısı
                                                    [description] => Eklemek istediğiniz buton yazısını belirtiniz.
                                                    [default] => Bilgi İçin Tıklayınız
                                                    [font] => Impact
                                                    [color] => 000000
                                                    [size] => 18
                                                    [@id] => text3
                                                    [@max] => 100
                                                    [@min] => 10
                                                )

                                        )

                                )

                        )

                )

            [fields:ADVTemplate:private] => Array
                (
                    [0] => 
    
                    [image] => Array
                        (
                            [0] => Array
                                (
                                    [0] => 
        
                                    [title] => Logo Resmi
                                    [description] => Eklemek istediğiniz logo resmini dosyadan seçiniz.
                                    [default] => library/image_64x64.png
                                    [@id] => image1
                                    [@width] => 64
                                    [@height] => 64
                                )

                            [1] => Array
                                (
                                    [0] => 
        
                                    [title] => Ürün Resmi
                                    [description] => Eklemek istediğiniz ürün resmini dosyadan seçiniz.
                                    [default] => library/image_128x169.png
                                    [@id] => image2
                                    [@width] => 128
                                    [@height] => 169
                                )

                        )

                    [text] => Array
                        (
                            [0] => Array
                                (
                                    [0] => 
        
                                    [title] => Başlık Yazısı
                                    [description] => Eklemek istediğiniz başlık yazısını belirtiniz.
                                    [default] => Başlık Yazısı
                                    [font] => Arial
                                    [color] => 000000
                                    [size] => 20
                                    [@id] => text1
                                    [@max] => 100
                                    [@min] => 10
                                )

                            [1] => Array
                                (
                                    [0] => 
        
                                    [title] => Web Site Adresi
                                    [description] => Eklemek istediğiniz web site adresinizi belirtiniz.
                                    [default] => www.websiteniz.com.tr
                                    [font] => Arial
                                    [color] => 000000
                                    [size] => 12
                                    [@id] => text2
                                    [@max] => 100
                                    [@min] => 10
                                )

                            [2] => Array
                                (
                                    [0] => 
        
                                    [title] => Buton Yazısı
                                    [description] => Eklemek istediğiniz buton yazısını belirtiniz.
                                    [default] => Bilgi İçin Tıklayınız
                                    [font] => Impact
                                    [color] => 000000
                                    [size] => 18
                                    [@id] => text3
                                    [@max] => 100
                                    [@min] => 10
                                )

                        )

                )

            [values:ADVTemplate:private] => Array
                (
                    [image1] => library/image_64x64.png
                    [image2] => library/image_128x169.png
                    [text1] => Başlık Yazısı
                    [text2] => www.websiteniz.com.tr
                    [text3] => Bilgi İçin Tıklayınız
                )

        )

)

ADVTemplateList Class ile Tema Listesinin Alınması

ADVTemplateList sınıfı reklam yöneticimiz tarafından kullanılacak ve şablon listemizi hazırlayacak olan sınıftır. Amacı belirtilen bir veya birden fazla klasör içerisinde bulunan şablon dosyalarını okuyarak ADVTemplate objeleri listesini hazırlamasıdır.
Bu sınıf oluşturulurken listesini hazırlayacağı klasör konumuna zorunlu olarak ihtiyaç duymaktadır. Hazırladığım sınıfın kaynak kodu şu şekilde geliştirildi.
<?php
/**
  * This class is used to represent the list of Templates that are in a directory.
  * 
  * @author Behçet MUTLU
  * @copyright 2009 Adres Gezgini
  */
  class ADVTemplateList {
    
      private $dir;
      private $list;
      private $ready;
      
      /**
      * This is the default constructor of the class that needs directory to be 
      * traversed of which contains the templates.
      * 
      * @param mixed $dir
      * @return void
      */
      public function __construct($dir)
      {
          $this->dir = $dir;
          $this->_initialize();
      }
      
      /**
      * This method is used to initialize the private variables of the class that
      * are used by this class.
      * 
      * @return void
      */
      private function _initialize()
      {
          $this->list = $this->_getTemplates($this->dir);
          
          $this->ready = $this->list != false;
      }
      
      /**
      * This method is used to traverse the list of the directories of given directory
      * and collect the list of templates in to an array and return, if the directory
      * exist template list, otherwise false.
      * 
      * @param mixed $directory to be traversed
      * @param mixed $exempt to exclude from listing
      * @param mixed $templates the referance to be used 
      *                         if we want collect from multiple directories
      * @return template list or false
      */
      private function _getTemplates($directory, 
                                      $exempt = array('.','..','.ds_store','.svn'), 
                                      &$templates = array()) 
      {
          if( ! ($handle = @opendir($directory))) // with @ character we are avoiding the wrong path error to be displayed as an exception
              return false;
          
          while(false !== ($resource = readdir($handle))) {
              if(!in_array(strtolower($resource),$exempt)) {
                  if(is_dir($directory.$resource.'/'))
                  {
                      if(file_exists($directory.$resource."/template.xml"))
                       $templates[] = new ADVTemplate($directory.$resource."/template.xml");
                      else
                       debug("Template at \"" . $directory.$resource . "\" does not contain  <i>template.xml</i> schema file.");
                  }
              }
          }
          closedir($handle);
          return $templates;
      } 
      
      /**
      * The setter methods of the class
      * @param value to set
      */
      public function setList($value) { $this->list = $value; }
      public function setDir($value) { $this->dir = $value; $this->_initialize();}
      
      /**
      * The getter methods of the class
      * 
      * @return values requested
      */
      public function getList() { return $this->list; }
      public function getDir() { return $this->dir; }
      public function isReady() { return $this->ready; }
  }
?>

Şablon Klasör Taraması

Hazırladığımız şablonların herbirini bir klasör içerisinde barındırıdığımızda, bu klasör altında bulunan tüm şablonların tek tek taranarak sistemde görüntülenmesi için basit bir Klasör Tarama kodu hazırladım. Bu kod, belirtilen klasör altındaki klasörlerin içerisinde eğer varsa template.xml dosyasını şablon olarak yüklenmesini sağlıyor.
Şimdilik bu kodu ufkumuzu genişletmesi için hazırladım, tema yükleme işleminin oldukça kolaylaşacağını ve temaların sisteme uyumluluğunun hat safhada olacağını belirtmeliyim.
Hazırladığım kod şu şekilde:
/**
 * This is the test of directory listing of the adv_templates directory
 * 
 * @author Behçet MUTLU
 * @copyright 2009
 */

require_once("system/system.core.php");
@$dir = $_SERVER["DOCUMENT_ROOT"]."ADVManager/adv_templates/";

function _readdir($dir)
{
    $dh = opendir($dir);
    while (false !== ($filename = readdir($dh))) {
        $files[] = $filename;
    }
    return $files;
}

$files = _readdir($dir);

foreach($files as $file)
{
    if(is_dir($dir.$file) && $file != "." && $file != "..")
    {
        echo ">$file\n";
        foreach(_readdir($dir.$file) as $temp_file)
        {
            if($temp_file == "template.xml")
            {
                $adv = new ADVTemplate($dir.$file . "/template.xml");
                pre($adv);
            }
        }
    }
}
Bu kodun geri döndürdüğü çıktı ise şu şekildeydi:
>template1

DEBUG:  XML file, "C:/wamp/www/ADVManager/adv_templates/template1/template.xml" loaded successfully.

ADVTemplate Object
(
    [name:ADVTemplate:private] => Template 1
    [author:ADVTemplate:private] => Behçet MUTLU
    [datecreated:ADVTemplate:private] => 25-12-2009
    [copyright:ADVTemplate:private] => 2009 Adres Gezgini
    [website:ADVTemplate:private] => www.adresgezgini.com.tr
    [thumbnail:ADVTemplate:private] => adv_templates/template1/thumb.jpg
    [schema:ADVTemplate:private] => C:/wamp/www/ADVManager/adv_templates/template1/template.xml
    [isReady:ADVTemplate:private] => 1
    [xml:ADVTemplate:private] => Array
        (
            [template] => Array
                (
                    [0] => 

                    [info] => Array
                        (
                            [0] => 
    
                            [name] => Template 1
                            [author] => Behçet MUTLU
                            [copyright] => 2009 Adres Gezgini
                            [website] => www.adresgezgini.com.tr
                            [thumbnail] => adv_templates/template1/thumb.jpg
                            [datecreated] => 25-12-2009
                        )

                    [fields] => Array
                        (
                            [0] => 
    
                            [image] => Array
                                (
                                    [0] => Array
                                        (
                                            [0] => 
        
                                            [title] => Logo Resmi
                                            [description] => Eklemek istediğiniz logo resmini dosyadan seçiniz.
                                            [default] => library/image_64x64.png
                                            [@id] => image1
                                            [@width] => 64
                                            [@height] => 64
                                        )

                                    [1] => Array
                                        (
                                            [0] => 
        
                                            [title] => Ürün Resmi
                                            [description] => Eklemek istediğiniz ürün resmini dosyadan seçiniz.
                                            [default] => library/image_128x169.png
                                            [@id] => image2
                                            [@width] => 128
                                            [@height] => 169
                                        )

                                )

                            [text] => Array
                                (
                                    [0] => Array
                                        (
                                            [0] => 
        
                                            [title] => Başlık Yazısı
                                            [description] => Eklemek istediğiniz başlık yazısını belirtiniz.
                                            [default] => Başlık Yazısı
                                            [font] => Arial
                                            [color] => 000000
                                            [size] => 20
                                            [@id] => text1
                                            [@max] => 100
                                            [@min] => 10
                                        )

                                    [1] => Array
                                        (
                                            [0] => 
        
                                            [title] => Web Site Adresi
                                            [description] => Eklemek istediğiniz web site adresinizi belirtiniz.
                                            [default] => www.websiteniz.com.tr
                                            [font] => Arial
                                            [color] => 000000
                                            [size] => 12
                                            [@id] => text2
                                            [@max] => 100
                                            [@min] => 10
                                        )

                                    [2] => Array
                                        (
                                            [0] => 
        
                                            [title] => Buton Yazısı
                                            [description] => Eklemek istediğiniz buton yazısını belirtiniz.
                                            [default] => Bilgi İçin Tıklayınız
                                            [font] => Impact
                                            [color] => 000000
                                            [size] => 18
                                            [@id] => text3
                                            [@max] => 100
                                            [@min] => 10
                                        )

                                )

                        )

                )

        )

    [fields:ADVTemplate:private] => Array
        (
            [0] => 
    
            [image] => Array
                (
                    [0] => Array
                        (
                            [0] => 
        
                            [title] => Logo Resmi
                            [description] => Eklemek istediğiniz logo resmini dosyadan seçiniz.
                            [default] => library/image_64x64.png
                            [@id] => image1
                            [@width] => 64
                            [@height] => 64
                        )

                    [1] => Array
                        (
                            [0] => 
        
                            [title] => Ürün Resmi
                            [description] => Eklemek istediğiniz ürün resmini dosyadan seçiniz.
                            [default] => library/image_128x169.png
                            [@id] => image2
                            [@width] => 128
                            [@height] => 169
                        )

                )

            [text] => Array
                (
                    [0] => Array
                        (
                            [0] => 
        
                            [title] => Başlık Yazısı
                            [description] => Eklemek istediğiniz başlık yazısını belirtiniz.
                            [default] => Başlık Yazısı
                            [font] => Arial
                            [color] => 000000
                            [size] => 20
                            [@id] => text1
                            [@max] => 100
                            [@min] => 10
                        )

                    [1] => Array
                        (
                            [0] => 
        
                            [title] => Web Site Adresi
                            [description] => Eklemek istediğiniz web site adresinizi belirtiniz.
                            [default] => www.websiteniz.com.tr
                            [font] => Arial
                            [color] => 000000
                            [size] => 12
                            [@id] => text2
                            [@max] => 100
                            [@min] => 10
                        )

                    [2] => Array
                        (
                            [0] => 
        
                            [title] => Buton Yazısı
                            [description] => Eklemek istediğiniz buton yazısını belirtiniz.
                            [default] => Bilgi İçin Tıklayınız
                            [font] => Impact
                            [color] => 000000
                            [size] => 18
                            [@id] => text3
                            [@max] => 100
                            [@min] => 10
                        )

                )

        )

    [values:ADVTemplate:private] => Array
        (
            [image1] => library/image_64x64.png
            [image2] => library/image_128x169.png
            [text1] => Başlık Yazısı
            [text2] => www.websiteniz.com.tr
            [text3] => Bilgi İçin Tıklayınız
        )

)

ADVTemplate Class Test

ADVTemplate sınıfımızın test edilmesini sağlamak ve değerlerin bir listesini görmek amaçlı bir kod parçası hazırladım. Bu kod, hem temamızın yaratılması sırasında hem de yaratıldıktan sonraki zamanlarda veri değişikliği yaparak sonçları gösteriyor.
Test kodumuz şu şekilde;
/**
 * This is the tester file of the ADVTemplate class.
 * 
 * @author Behçet MUTLU
 * @copyright 2009 Adres Gezgini
 */

include_once("../system.core.php");

$adv = new ADVTemplate("template-1.xml", array("image1"=>"image1.png", "image2"=>"test2.png"));

$adv->setValueOf("image1","test1.png");
echo "< pre>";
$adv->toString();
echo "< /pre>"; 
Test kodumuzun sonuçlanmış olduğu ekran çıktısı da şöyle;
DEBUG:  XML file, "template-1.xml" loaded successfully.

ADVTemplate Object
(
    [name:ADVTemplate:private] => Template 1
    [author:ADVTemplate:private] => Behçet MUTLU
    [datecreated:ADVTemplate:private] => 25-12-2009
    [copyright:ADVTemplate:private] => 2009 Adres Gezgini
    [website:ADVTemplate:private] => www.adresgezgini.com.tr
    [schema:ADVTemplate:private] => template-1.xml
    [isReady:ADVTemplate:private] => 1
    [xml:ADVTemplate:private] => Array
        (
            [template] => Array
                (
                    [0] => 

                    [info] => Array
                        (
                            [0] => 
    
                            [name] => Template 1
                            [author] => Behçet MUTLU
                            [copyright] => 2009 Adres Gezgini
                            [website] => www.adresgezgini.com.tr
                            [datecreated] => 25-12-2009
                        )

                    [fields] => Array
                        (
                            [0] => 
    
                            [image] => Array
                                (
                                    [0] => Array
                                        (
                                            [0] => 
        
                                            [title] => Logo Resmi
                                            [description] => Eklemek istediğiniz logo resmini dosyadan seçiniz.
                                            [default] => library/image_64x64.png
                                            [@id] => image1
                                            [@width] => 64
                                            [@height] => 64
                                        )

                                    [1] => Array
                                        (
                                            [0] => 
        
                                            [title] => Ürün Resmi
                                            [description] => Eklemek istediğiniz ürün resmini dosyadan seçiniz.
                                            [default] => library/image_128x169.png
                                            [@id] => image2
                                            [@width] => 128
                                            [@height] => 169
                                        )

                                )

                            [text] => Array
                                (
                                    [0] => Array
                                        (
                                            [0] => 
        
                                            [title] => Başlık Yazısı
                                            [description] => Eklemek istediğiniz başlık yazısını belirtiniz.
                                            [default] => Başlık Yazısı
                                            [font] => Arial
                                            [color] => 000000
                                            [size] => 20
                                            [@id] => text1
                                            [@max] => 100
                                            [@min] => 10
                                        )

                                    [1] => Array
                                        (
                                            [0] => 
        
                                            [title] => Web Site Adresi
                                            [description] => Eklemek istediğiniz web site adresinizi belirtiniz.
                                            [default] => www.websiteniz.com.tr
                                            [font] => Arial
                                            [color] => 000000
                                            [size] => 12
                                            [@id] => text2
                                            [@max] => 100
                                            [@min] => 10
                                        )

                                    [2] => Array
                                        (
                                            [0] => 
        
                                            [title] => Buton Yazısı
                                            [description] => Eklemek istediğiniz buton yazısını belirtiniz.
                                            [default] => Bilgi İçin Tıklayınız
                                            [font] => Impact
                                            [color] => 000000
                                            [size] => 18
                                            [@id] => text3
                                            [@max] => 100
                                            [@min] => 10
                                        )

                                )

                        )

                )

        )

    [fields:ADVTemplate:private] => Array
        (
            [0] => 
    
            [image] => Array
                (
                    [0] => Array
                        (
                            [0] => 
        
                            [title] => Logo Resmi
                            [description] => Eklemek istediğiniz logo resmini dosyadan seçiniz.
                            [default] => library/image_64x64.png
                            [@id] => image1
                            [@width] => 64
                            [@height] => 64
                        )

                    [1] => Array
                        (
                            [0] => 
        
                            [title] => Ürün Resmi
                            [description] => Eklemek istediğiniz ürün resmini dosyadan seçiniz.
                            [default] => library/image_128x169.png
                            [@id] => image2
                            [@width] => 128
                            [@height] => 169
                        )

                )

            [text] => Array
                (
                    [0] => Array
                        (
                            [0] => 
        
                            [title] => Başlık Yazısı
                            [description] => Eklemek istediğiniz başlık yazısını belirtiniz.
                            [default] => Başlık Yazısı
                            [font] => Arial
                            [color] => 000000
                            [size] => 20
                            [@id] => text1
                            [@max] => 100
                            [@min] => 10
                        )

                    [1] => Array
                        (
                            [0] => 
        
                            [title] => Web Site Adresi
                            [description] => Eklemek istediğiniz web site adresinizi belirtiniz.
                            [default] => www.websiteniz.com.tr
                            [font] => Arial
                            [color] => 000000
                            [size] => 12
                            [@id] => text2
                            [@max] => 100
                            [@min] => 10
                        )

                    [2] => Array
                        (
                            [0] => 
        
                            [title] => Buton Yazısı
                            [description] => Eklemek istediğiniz buton yazısını belirtiniz.
                            [default] => Bilgi İçin Tıklayınız
                            [font] => Impact
                            [color] => 000000
                            [size] => 18
                            [@id] => text3
                            [@max] => 100
                            [@min] => 10
                        )

                )

        )

    [values:ADVTemplate:private] => Array
        (
            [image1] => test.png
            [image2] => test2.png
            [text1] => Başlık Yazısı
            [text2] => www.websiteniz.com.tr
            [text3] => Bilgi İçin Tıklayınız
        )

)

ADVTemplate Class

Reklam temamızı temsil etmesi amacı ile bir sınıf hazırladık. Bu sınıfın görevi, reklam temasının şemasını XML dosyasından okuyarak, gerekli bilgileri kendi içerisinde barındırmasını sağlamak. Reklam yöneticisi tarafından sürekli kullanılacağı ve bir probelme el vermemesi açısından, isReady fonksiyonu ile de hazır olup olmadığı test edilebilir kılındı. Dolayısı ile, herhangi bir memory overflow olayında veya geç okunma olayında kullanıcıya hata yerine sistem kendi kendini yenileyerek her defasında kesin sonuç geri döndürecek.
Hazırlamış olduğum sınıfın kodu şöyle:
/**
 * This class is used to represent a ADV Template to provide required fileld and values along
 * the reqistration process of the advertisement.
 * This class uses Domdocument object library to load xml schema file.
 * 
 * @author Behçet MUTLU
 * @copyright 2009 Adres Gezgini
 */

class ADVTemplate {
    
    private $name;
    private $author;
    private $datecreated;
    private $copyright;
    private $website;
    private $schema;
 private $isReady;
 private $xml;
 private $fields;
 private $values;

 /**
 * This is the general constructor of the ADV Template class that used to initialize the
 * ADV Template itself with given arguments.
 */
 public function __construct($schema = "", $values = array())
 {
  $this->schema = $schema;
        $this->isReady = false;
  
  if($this->schema != "")
   $this->load();
   
        if(sizeof($values) > 0)
            $this->setValues($values);
 }
    
    /**
 * This method is used to initialize the Template from the schema file and set the values
 */
 private function initialize()
 {
  $this->name = $this->xml["template"]["info"]["name"];
        $this->author = $this->xml["template"]["info"]["author"];
        $this->datecreated = $this->xml["template"]["info"]["datecreated"];
        $this->copyright = $this->xml["template"]["info"]["copyright"];
        $this->website = $this->xml["template"]["info"]["website"];
        $this->fields = $this->xml["template"]["fields"];
        
        foreach($this->fields as $fieldType)
        {
            if($fieldType != 0)
                foreach($fieldType as $field)
                {
                    if($field != 0)
                        $this->values[$field["@id"]] = isset($field["default"]) ? $field["default"] : "";
                }
        }
 }

 /**
 * This method is used to initialize the Template from the schema file and set the values
 */
 public function load()
 {
  $xml = new CArray2xml2array();

  if($xml->setXMLFile($this->schema))
        {
            $this->xml = $xml->toArray();
            
            $this->isReady = true;
            
            $this->initialize();
   debug("XML file, \"" . $xml->getXMLFile() . "\" loaded successfully.","pre");
  }
        else
  {
            $this->isReady = false;
   debug("Error: XML file could not be loaded!");
  }
 }
    
    /**
 * This method is used to learn if the xml file is ready or not
 */
 public function ready()
    {
        return $this->isReady;
    }
 
 
 /**
 * This method is used to set value of the class
 */
 public function setName($value) { $this->name = $value; }
 public function setAuthor($value) { $this->name = $value; }
 public function setWebsite($value) { $this->website = $value; }
 public function setDatecreated($value) { $this->datecreated = $value; }
 public function setCopyright($value) { $this->copyright = $value; }
 public function setSchema($value) { $this->schema = $value; }
    public function setFields($value) { $this->fields = $value; }
    public function setXml($value) { $this->xml = $value; }
    
    /**
 * This method is used to get value of the class
 */
 public function getName() { return $this->name; }
    public function getAuthor() { return $this->author; }
    public function getWebsite() { return $this->website; }
    public function getDatecreated() { return $this->datecreated; }
    public function getCopyright() { return $this->copyright; }
    public function getSchema() { return $this->schema; }
    public function getFields() { return $this->fields; }
    public function getXml() { return $this->xml; }
    
    /**
 * This method is used to set value of the class
 */
 public function setValueOf($id, $value)
 {
  $this->values[$id] = $value;
 }
    
    /**
 * This method is used to set values of the class
    * The spacial thing here is setting only given indexes but keeping the rest of
    * the values remain same.
 */
 public function setValues($values)
 {
        foreach($values as $id=>$value)
            $this->setValueOf($id,$value); 
 }
    
    
    /**
 * This method is used to get a string output of this object.
 */
 public function toString()
 {
        print_r($this);
 }
}