コード例 #1
0
ファイル: front.php プロジェクト: ZerGabriel/cms-1
 /**
  * 
  * @param string $field
  * @param string $value
  * @param Model_Page_Front $parent
  * @param boolean $include_hidden
  * @return boolean|\Model_Page_Front
  */
 public static function findByField($field, $value, $parent = NULL, $include_hidden = TRUE)
 {
     $page_cache_id = self::_get_cache_id(array($field, $value), $parent);
     if (isset(self::$_pages_cache[$page_cache_id])) {
         return self::$_pages_cache[$page_cache_id];
     }
     $page_class = get_called_class();
     $page = DB::select('page.*')->from(array('pages', 'page'))->where('page.' . $field, '=', $value)->where('status_id', 'in', self::get_statuses($include_hidden))->limit(1);
     if (Config::get('page', 'check_date') == Config::YES) {
         $page->where('published_on', '<=', DB::expr('NOW()'));
     }
     $parent_id = $parent instanceof Model_Page_Front ? $parent->id : NULL;
     if ($parent_id !== NULL) {
         $page->where('parent_id', '=', $parent_id);
     }
     $page = $page->cache_tags(array('pages'))->cached((int) Config::get('cache', 'front_page'))->as_object()->execute()->current();
     if (!$page) {
         return FALSE;
     }
     if ($page->parent_id and $parent === NULL) {
         $parent = self::findById($page->parent_id);
     }
     // hook to be able to redefine the page class with behavior
     if ($parent instanceof Model_Page_Front and !empty($parent->behavior_id)) {
         // will return Page by default (if not found!)
         $page_class = Behavior::load_page($parent->behavior_id);
     }
     // create the object page
     $page = new $page_class($page, $parent);
     self::$_pages_cache[$page_cache_id] = $page;
     return $page;
 }