Basics

// JobeetJobTable.class.php
function getActiveJobs() {
    $q = $this->createQuery('j')->where('j.expires_at > ?', 
                                         date('Y-m-d H:i:s', time()));
    return $q->execute();
}
// still in JobeetJob_Table.class.php, this is overiding save() to set a auto expired date
function save(Doctrine_Connection $conn) {
    if ($this->isNew() && !$this->expiredAt()) {
        $c = $this->getCreatedAt()? $this->getDateTimeObject('created_at')->format('U'):time(); 
        $this->setExpiredAt(date('Y-m-d H:i:s', $c + 86400*30));
    }
    parent::save($conn);
}

// JobeetJobCategoryTable.php
function getWithJobs () {    
    $q = $this->createQuery('c')->leftJoin('c.JobeetJobs j')
                ->where('j.expired_at > ?', date('Y-m-d H:i:s', time()));
    return $q->execute();
}
// the controller would look like this. 
function executeIndex() {
    $this->categories = Doctrine::getTable('JobeetCategory')->getWithJobs();
} 

// JobeetJobCategory.php
function getActiveJobs() {
    $q = Doctrine_Query::create()->from('JobeetJob j')
                                  ->where('j.category_id = ?', $this->getId() );
    return Doctrine_Query::getTable('JobeetJob')->getActiveJobs($q);
}

// action.class.php
function executeIndex() {
     // if it's here, it's actully
     // Doctrine_Query::create('q')->from('JobeetJob j')->where('j.expired_at >?', date...);
     $this->jobeet_jobs = Doctrine::getTable('JobeetJob')->getActiveJobs();
}
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s