<?php

/**
 * Subclass for performing query and update operations on the 'tblblogentry' table.
 *
 * 
 *
 * @package lib.model
 */ 
class TblblogentryPeer extends BaseTblblogentryPeer
{
  public static function doSelect(Criteria $criteria, PropelPDO $con = null)
  {
    if ($criteria->getOffset() > 900 && @$_SERVER['HTTP_REFERER'] == null) {
      //$link = $_SERVER['SERVER_NAME'].$_SERVER['REQUEST_URI'];
      //throw new Exception('Direct access denied: '.$link);
      return null;
    }
    return BaseTblblogentryPeer::doSelect($criteria, $con);
  }

  /**
   * Insert presentation, document,... into blog
   *
   * @param int $cat_id: id of blogcategory
   * @param int $pr_id: id of presentation
   * @return true if success
   */
  public static function insertSource($cat_id, $source_id, $source_status = 0, $source_lesson = null) {
    $tblblogcategory = TblblogcategoryPeer::retrieveByPk($cat_id);
    if (!$tblblogcategory || $tblblogcategory->getCatBlog() != blogStore::$blogId) return false;
    $tblblogentry = $tblblogcategory->addBlogEntry($source_id, $source_status, $source_lesson, blogStore::$userId);

    if ($tblblogentry != null && blogStore::getBlogStyle() > 1)
      foreach ($tblblogcategory->getDependCategories() as $dependcategory)
        $dependcategory->addBlogEntry($source_id, $source_status, $source_lesson, blogStore::$userId);

    return $tblblogentry;
  }

  public static function getEntryByLessons($cat_id, $lesson, &$entries, &$count) {
    $c = new Criteria();
    $c->add(TblblogentryPeer::ENTRY_CATEGORY, $cat_id);
    $c->add(TblblogentryPeer::ENTRY_LESSON, $lesson? $lesson: null);
    $c->add(TblblogentryPeer::ENTRY_STATUS, 2, Criteria::LESS_THAN);
    $c->addDescendingOrderByColumn(TblblogentryPeer::ENTRY_MODIFYDATE);
    $count = TblblogentryPeer::doCount($c);
    $c->setLimit(3);
    $entries = TblblogentryPeer::doSelect($c);
  }
}
