| 15 | | |
| 16 | | /** |
| 17 | | * This function attempts to find the "best" engine to route a given post to. |
| 18 | | */ |
| 19 | | public function findBestEngine() |
| 20 | | { |
| 21 | | $engines = Doctrine::getTable('aPage')->createQuery() |
| 22 | | ->addWhere('engine = ?', 'aBlog') |
| 23 | | ->execute(); |
| 24 | | |
| 25 | | if(count($engines) == 0) |
| 26 | | return ''; |
| 27 | | else if(count($engines) == 1) |
| 28 | | return $engines[0]; |
| 29 | | |
| 30 | | //When there are more than one engine page we need to use some heuristics to |
| 31 | | //guess what the best page is. |
| 32 | | $catIds = array(); |
| 33 | | foreach($this->Categories as $category) |
| 34 | | { |
| 35 | | $catIds[$category['id']] = $category['id']; |
| 36 | | } |
| 37 | | |
| 38 | | if(count($catIds) < 1) |
| 39 | | return $engines[0]; |
| 40 | | |
| 41 | | $best = array(0, ''); |
| 42 | | |
| 43 | | foreach($engines as $engine) |
| 44 | | { |
| 45 | | $score = 0; |
| 46 | | foreach($engine->BlogCategories as $category) |
| 47 | | { |
| 48 | | if(isset($catIds[$category['id']])) |
| 49 | | $score = $score + 1; |
| 50 | | } |
| 51 | | if($score > $best[0]) |
| 52 | | { |
| 53 | | $best = $engine; |
| 54 | | } |
| 55 | | } |
| 56 | | |
| 57 | | return $best; |
| 58 | | } |
| 59 | | |
| | 15 | protected $engine = 'aBlog'; |