public static function getRelatedEntityIdsForMap($entity_id, $num = 10, $include_cats = array(), $exclude_cats = array(), $exclude_ids = array())
 {
     $exclude_ids = EntityTable::removeCustomIds($exclude_ids);
     $db = Doctrine_Manager::connection();
     $sql = "SELECT l.entity2_id, COUNT(l.id) AS num " . "FROM link l " . "WHERE l.entity1_id = ? AND l.entity2_id <> ? " . (count($exclude_ids) ? "AND l.entity2_id NOT IN (" . join($exclude_ids, ",") . ") " : "") . (count($include_cats) ? "AND l.category_id IN (" . join($include_cats, ",") . ") " : "") . (count($exclude_cats) ? "AND l.category_id NOT IN (" . join($exclude_cats, ",") . ") " : "") . "GROUP BY l.entity2_id " . "ORDER BY num DESC LIMIT " . $num;
     $params = array($entity_id, $entity_id);
     $stmt = $db->execute($sql, $params);
     return $stmt->fetchAll(PDO::FETCH_COLUMN);
 }