przewiń do treści

PHP, MySQL i MVC. Tworzenie witryn WWW opartych na bazie danych

Włodzimierz Gajda

class WskaznikProjektu extends Pointer
{
  function getFirst()
  {
    $c = new Criteria();
    $c->setLimit(1);
    $c->addAscendingOrderByColumn(ProjektPeer::SLUG);
    if ($tmp = ProjektPeer::doSelectOne($c)) {
      $this->ptr_first = $tmp;
      if (
        $this->ptr_current &&
        ($this->ptr_first->getSlug() == $this->ptr_current->getSlug())
      ) {
        $this->ptr_first = false;
      }
    }
  }

  function getPrevious()
  {
    if ($this->ptr_current) {
      $c = new Criteria();
      $c->setLimit(1);
      $c->addDescendingOrderByColumn(ProjektPeer::SLUG);
      $c->add(ProjektPeer::SLUG, $this->ptr_current->getSlug(), Criteria::LESS_THAN);
      if ($tmp = ProjektPeer::doSelectOne($c)) {
        $this->ptr_previous = $tmp;
      }
    }
  }

  function getNext()
  {
    if ($this->ptr_current) {
      $c = new Criteria();
      $c->setLimit(1);
      $c->addAscendingOrderByColumn(ProjektPeer::SLUG);
      $c->add(ProjektPeer::SLUG, $this->ptr_current->getSlug(), Criteria::GREATER_THAN);
      if ($tmp = ProjektPeer::doSelectOne($c)) {
        $this->ptr_next = $tmp;
      }
    }
  }

  function getLast()
  {
    $c = new Criteria();
    $c->setLimit(1);
    $c->addDescendingOrderByColumn(ProjektPeer::SLUG);
    if ($tmp = ProjektPeer::doSelectOne($c)) {
      $this->ptr_last = $tmp;
      if (
        $this->ptr_current &&
        ($this->ptr_last->getSlug() == $this->ptr_current->getSlug())
      ) {
        $this->ptr_last = false;
      }
    }
  }

}

Listing 18.8. Klasa WskaznikProjektu

Rozdział 18. Następny, poprzedni, czyli przewijanie zawartości witryny WWW

listing-18-08.txt

Reklama

Szkolenia z Symfony 2.0