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>";
      }
  
  }

?>

0 yorum:

Yorum Gönder