本文整理汇总了PHP中Language::getTheBest方法的典型用法代码示例。如果您正苦于以下问题:PHP Language::getTheBest方法的具体用法?PHP Language::getTheBest怎么用?PHP Language::getTheBest使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Language
的用法示例。
在下文中一共展示了Language::getTheBest方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: executeView
/**
* Executes view action : displays the user profile
*/
public function executeView()
{
$id = $this->getRequestParameter('id');
parent::executeView();
$hasPublicProfile = UserPrivateData::hasPublicProfile($id);
if (!$this->getUser()->isConnected() && !$hasPublicProfile) {
// page owner has not allowed anonymous users to access his personal page
$this->setTemplate('login');
} else {
if (!$this->document->isArchive() && $this->document['redirects_to'] == NULL) {
if ($hasPublicProfile) {
$this->getResponse()->addMeta('robots', 'index, follow');
} else {
$this->getResponse()->addMeta('robots', 'noindex, nofollow');
}
// get associated outings
$associated_outings = array();
$nb_outings = count(Association::countAllLinked(array($id), 'uo'));
$nb_outings_limit = 0;
if ($nb_outings > 0) {
$outing_params = array('users' => $id);
$nb_outings_limit = sfConfig::get('app_users_outings_limit');
$associated_outings = Outing::listLatest($nb_outings_limit, array(), array(), array(), $outing_params, false, false);
$associated_outings = Language::getTheBest($associated_outings, 'Outing');
}
$this->nb_outings = $nb_outings;
$this->nb_outings_limit = $nb_outings_limit;
$this->associated_outings = $associated_outings;
$forum_nickname = Punbb::getNickname($id);
$this->forum_nickname = $forum_nickname[0]['username'];
// check if user is forum and / or topoguide moderator
$this->forum_moderator = UserPrivateData::isForumModerator($id);
$user_permissions = Doctrine_Query::create()->from('User.groups.permissions, User.permissions')->where('User.id = ?', $id)->execute(array(), Doctrine::FETCH_ARRAY);
$topoguide_moderator = false;
$moderator_credential = sfConfig::get('app_credentials_moderator');
foreach ($user_permissions[0]['groups'] as $group) {
foreach ($group['permissions'] as $permission) {
if ($permission['name'] == $moderator_credential) {
$topoguide_moderator = true;
break 2;
}
}
}
foreach ($user_permissions[0]['permissions'] as $permission) {
if ($permission['name'] == $moderator_credential) {
$topoguide_moderator = true;
break;
}
}
$this->topoguide_moderator = $topoguide_moderator;
} else {
// only moderators and user itself should see archive versions of user docs
$this->filterAuthorizedPeople($id);
}
}
}
示例2: executeView
public function executeView()
{
parent::executeView();
if (!$this->document->isArchive() && $this->document['redirects_to'] == NULL) {
// get last geo-associated outings
$current_doc_id = $this->getRequestParameter('id');
$latest_outings = array();
$nb_outings = 0;
$outing_params = array('areas' => $current_doc_id);
$nb_outings = sfConfig::get('app_nb_linked_outings_areas');
$latest_outings = Outing::listLatest($nb_outings + 1, array(), array(), array(), $outing_params, false);
$latest_outings = Language::getTheBest($latest_outings, 'Outing');
$this->latest_outings = $latest_outings;
$this->nb_outings = $nb_outings;
$related_portals = array();
$id = $this->getRequestParameter('id');
$areas = array(array('id' => $id));
Portal::getLocalPortals($related_portals, $areas);
$this->related_portals = $related_portals;
$area_types_list = sfConfig::get('mod_areas_area_types_list');
$title = $this->document->get('name') . ' :: ' . $this->__($area_types_list[$this->document->get('area_type')]);
$this->setPageTitle($title);
}
}
示例3: executeAutocomplete
/**
* Executes autocomplete action.
* returns formated list of best matching names and their ids
*/
public function executeAutocomplete()
{
sfLoader::loadHelpers(array('General'));
$model = $this->model_class;
$module = c2cTools::model2module($model);
$string = $this->getRequestParameter($module . '_name');
// useful protection:
if (strlen($string) < sfConfig::get('app_autocomplete_min_chars')) {
return $this->renderText('<ul></ul>');
}
// return all documents matching $string in given module/model
// NB: autocomplete on outings only returns those for which the current user is linked to
// autocomplete on articles and images only returns collaborative and proper personal ones (all for moderators)
$user = $this->getUser();
$filter_personal_content = !$user->hasCredential('moderator') && ($module == 'articles' || $module == 'images');
$results = Document::searchByName($string, $model, $user->getId(), $filter_personal_content);
$nb_results = count($results);
if ($nb_results == 0) {
return $this->ajax_feedback_autocomplete('no results');
}
if ($nb_results > sfConfig::get('app_autocomplete_max_results') && $nb_results < sfConfig::get('app_list_maxline_number')) {
// if there are too many results to display, but if there is at least one exact match, it is in the results returned by the db query
// we display the exact matches, if any. We translate some special chars and capital letters
sfLoader::loadHelpers(array('General'));
$simple_string = remove_accents($string);
$exact_matches = array();
foreach ($results as $result) {
if (remove_accents($result[$this->model_class . 'I18n'][0]['name']) == $simple_string || $module == 'users' && remove_accents($result['private_data']['username']) == $simple_string) {
$exact_matches[] = $result;
}
}
if (count($exact_matches)) {
$results = $exact_matches;
} else {
return $this->ajax_feedback_autocomplete('Too many results. Please go on typing...');
}
} elseif ($nb_results == sfConfig::get('app_list_maxline_number')) {
// we have the maximum number of results returned by the db query, so we assume there are more
// before giving up and returning "too many results", we can try some extra things
// if we have lat lon info, we try to limit results to those in the neighboorhood
if ($this->hasRequestParameter('lat') && $this->hasRequestParameter('lon') && in_array($module, array('sites', 'huts', 'parkings', 'summits'))) {
$near_results = Document::searchByName($string, $model, $user->getId(), $filter_personal_content, false, array('lon' => floatval($this->getRequestParameter('lon')), 'lat' => floatval($this->getRequestParameter('lat'))));
$nb_near_results = count($near_results);
if ($nb_near_results && $nb_near_results < sfConfig::get('app_autocomplete_max_results')) {
$results = $near_results;
} else {
return $this->ajax_feedback_autocomplete('Too many results. Please go on typing...');
}
} else {
$exact_results = Document::searchByName($string, $model, $user->getId(), $filter_personal_content, true);
$nb_exact_results = count($exact_results);
if ($nb_exact_results) {
$results = $exact_results;
$exact_matches = true;
} else {
return $this->ajax_feedback_autocomplete('Too many results. Please go on typing...');
}
}
}
// build the actual results based on the user's prefered language
$items = Language::getTheBest($results, $model);
// if module = summit, site, parking or hut, check for similarities and if any, append regions for disambiguation
if (in_array($model, array('Summit', 'Site', 'Parking', 'Hut'))) {
$items_copy = $items;
for ($i = 1; $i < count($items); $i++) {
$item_cmp = array_shift($items_copy);
foreach ($items_copy as $item) {
if (levenshtein(remove_accents($item_cmp[$this->model_class . 'I18n'][0]['name']), remove_accents($item[$this->model_class . 'I18n'][0]['name'])) <= 3) {
$add_region = true;
break 2;
}
}
}
}
if (isset($add_region)) {
// retrieve attached regions best names
$q = Doctrine_Query::create()->select('m.id, g0.main_id, a.area_type, ai.name, ai.culture')->from("{$model} m")->leftJoin("m.geoassociations g0")->leftJoin('g0.AreaI18n ai')->leftJoin('ai.Area a')->addWhere('g0.main_id IN (' . implode(',', array_keys($items)) . ')')->addWhere("g0.type != 'dm'")->execute(array(), Doctrine::FETCH_ARRAY);
$areas_array = Language::getTheBestForAssociatedAreas($q);
// choose the best area description (like in homepage)
foreach ($areas_array as $item) {
$area_name = Area::getBestRegionDescription($item['geoassociations']);
if (!empty($area_name)) {
$items[$item['id']]['area_name'] = $area_name;
}
}
}
// create list of items
$html = '<ul>';
foreach ($items as $item) {
$identifier = $model == 'Document' ? $this->__(substr($item['module'], 0, -1)) . ' ' : '';
// if module = documents, add the object type inside brackets
switch ($model) {
case 'Outing':
$postidentifier = ' (' . $item['date'] . ')';
// if outings, we append the date
break;
//.........这里部分代码省略.........
示例4: executeView
//.........这里部分代码省略.........
$ranges = $perso->getPlacesFilter();
}
if (!in_array('act', $names)) {
$activities = $perso->getActivitiesFilter();
}
}
// latest outings
$nb_outings = $this->document->get('nb_outings');
$has_outings = !empty($nb_outings);
$this->has_outings = $has_outings;
if ($has_outings) {
$outing_url_params = array();
$outing_params = $this->document->get('outing_filter');
$outing_params = unpackUrlParameters($outing_params, $outing_url_params);
$outing_langs = $langs;
$outing_ranges = $ranges;
$outing_activities = $activities;
if (isset($outing_params['perso'])) {
$perso_params = explode('-', $outing_params['perso']);
if (array_intersect(array('areas', 'act', 'cult', 'no'), $perso_params)) {
if (!in_array('cult', $perso_params)) {
$outing_langs = array();
}
if (!in_array('areas', $perso_params)) {
$outing_ranges = array();
}
if (!in_array('act', $perso_params)) {
$outing_activities = array();
}
}
}
$latest_outings = Outing::listLatest($nb_outings, $outing_langs, $outing_ranges, $outing_activities, $outing_params);
// choose best language for outings and regions names
$latest_outings = Language::getTheBest($latest_outings, 'Outing');
$this->latest_outings = Language::getTheBestForAssociatedAreas($latest_outings);
$this->outing_url_params = $outing_url_params;
}
// latest articles
$nb_articles = $this->document->get('nb_articles');
$has_articles = !empty($nb_articles);
$this->has_articles = $has_articles;
if ($has_articles) {
$article_url_params = array();
$article_params = $this->document->get('article_filter');
$article_params = unpackUrlParameters($article_params, $article_url_params);
$this->latest_articles = Article::listLatest($nb_articles, $langs, $activities, $article_params);
$this->article_url_params = $article_url_params;
}
// latest images
if ($mobile_version) {
$nb_images = sfConfig::get('app_recent_documents_images_mobile_limit');
} else {
$nb_images = $this->document->get('nb_images');
}
$has_images = !empty($nb_images);
$this->has_images = $has_images;
if ($has_images) {
$image_url_params = array();
$image_params = $this->document->get('image_filter');
$image_params = unpackUrlParameters($image_params, $image_url_params);
$latest_images = Image::listLatest($nb_images, $langs, $ranges, $activities, $image_params);
$this->latest_images = Language::getTheBest($latest_images, 'Image');
$this->image_url_params = $image_url_params;
}
// latest videos
$nb_videos = $this->document->get('nb_videos');
示例5: executeView
//.........这里部分代码省略.........
}
}
$over_summit_name_2 = false;
$over_summit_name_3 = false;
foreach ($sub_summit_names as $sub_summit_name) {
if (!$over_summit_name_3 && strpos($sub_summit_name, $summit_name) === 0) {
$over_summit_name_2 = true;
} else {
if (!empty($over_summit_name) && strpos($sub_summit_name, $over_summit_name) !== false) {
$over_summit_name_3 = true;
}
}
}
if ($over_summit_name_2) {
$over_summit_name = $summit_name;
}
}
} else {
$associated_summits = $main_associated_summits;
}
$this->associated_summits = $associated_summits;
array_unshift($sub_summit_ids, $current_doc_id);
$this->ids = implode('-', $sub_summit_ids);
// second param will not display the summit name before the route when the summit is the one of the document
$associated_routes = Route::getAssociatedRoutesData($this->associated_docs, $this->__(' :') . ' ', $this->document->get('id'), $over_summit_name);
$this->associated_routes = $associated_routes;
$associated_books = c2cTools::sortArrayByName(array_filter($this->associated_docs, array('c2cTools', 'is_book')));
$doc_ids = array();
$associated_huts = array();
$associated_parkings = array();
$associated_routes_books = array();
if (count($associated_routes) || count($associated_sites)) {
foreach ($associated_routes as $route) {
if ($route['duration'] instanceof Doctrine_Null || $route['duration'] <= 4) {
$doc_ids[] = $route['id'];
}
}
foreach ($associated_sites as $site) {
$doc_ids[] = $site['id'];
}
if (count($doc_ids)) {
$book_ids = array();
foreach ($associated_books as $book) {
$book_ids[] = $book['id'];
}
$associated_route_docs = Association::findLinkedDocsWithBestName($doc_ids, $prefered_cultures, array('hr', 'ht', 'pr', 'pt', 'br'), false, false, $book_ids);
if (count($associated_route_docs)) {
$associated_route_docs = c2cTools::sortArray($associated_route_docs, 'elevation');
$associated_huts = array_filter($associated_route_docs, array('c2cTools', 'is_hut'));
$associated_parkings = Parking::getAssociatedParkingsData(array_filter($associated_route_docs, array('c2cTools', 'is_parking')));
$associated_routes_books = c2cTools::sortArray(array_filter($associated_route_docs, array('c2cTools', 'is_book')), 'name');
foreach ($associated_routes_books as $key => $book) {
$associated_routes_books[$key]['parent_id'] = true;
}
}
}
}
$this->associated_huts = $associated_huts;
$this->associated_parkings = $associated_parkings;
$associated_books = array_merge($associated_books, $associated_routes_books);
if (count($associated_books)) {
$associated_books = Book::getAssociatedBooksData($associated_books);
}
$this->associated_books = $associated_books;
// get associated outings
$latest_outings = array();
$nb_outings = 0;
if (count($associated_routes)) {
$outing_params = array('summits' => $this->ids);
$nb_outings = sfConfig::get('app_nb_linked_outings_docs');
$latest_outings = Outing::listLatest($nb_outings + 1, array(), array(), array(), $outing_params, false);
$latest_outings = Language::getTheBest($latest_outings, 'Outing');
}
$this->latest_outings = $latest_outings;
$this->nb_outings = $nb_outings;
$this->associated_images = Document::fetchAdditionalFieldsFor(array_filter($this->associated_docs, array('c2cTools', 'is_image')), 'Image', array('filename', 'image_type', 'date_time', 'width', 'height'));
$cab = count($associated_books);
$this->section_list = array('books' => $cab != 0, 'map' => (bool) $this->document->get('geom_wkt'));
$related_portals = array();
Portal::getRelatedPortals($related_portals, $this->associated_areas, $associated_routes);
$summit_type_index = $this->document->get('summit_type');
if ($summit_type_index == 5 && !in_array('raid', $related_portals)) {
$related_portals[] = 'raid';
}
$this->related_portals = $related_portals;
$summit_type_list = sfConfig::get('app_summits_summit_types');
$summit_type_list[1] = 'summit';
$summit_type = $this->__($summit_type_list[$summit_type_index]);
$doc_name = $summit_name;
$title = $doc_name;
if ($this->document->isArchive()) {
$version = $this->getRequestParameter('version');
$title .= ' :: ' . $this->__('revision') . ' ' . $version;
}
$title .= ' :: ' . $summit_type;
$this->setPageTitle($title);
$description = array($summit_type . ' :: ' . $doc_name, $this->document->get('elevation') . $this->__('meters'), $this->getAreasList());
$this->getResponse()->addMeta('description', implode(' - ', $description));
}
}
示例6: getTheBestLanguage
function getTheBestLanguage($array, $modelName)
{
return Language::getTheBest($array, $modelName);
}
示例7: executeView
//.........这里部分代码省略.........
$this->associated_sites = array_merge($this->associated_sites, $associated_parking_sites);
// associated sites should be empty!! Else it violates moderation rules
$this->ids = implode('-', $parking_ids);
} else {
$associated_routes = array_filter($this->associated_docs, array('c2cTools', 'is_route'));
$this->associated_sites = c2cTools::sortArrayByName(array_filter($this->associated_docs, array('c2cTools', 'is_site')));
$this->ids = $current_doc_id;
}
// get additional data for routes
$associated_routes = Route::getAssociatedRoutesData($associated_routes, $this->__(' :') . ' ', reset($summit_ids));
// these are the routes where the hut act as a summit
// they are displayed in a specific section
$summit_ids = $summit_routes_tmp = $summit_routes_ids = $associated_summit_routes = array();
if (count($associated_summits)) {
foreach ($associated_summits as $summit) {
$summit_ids[] = $summit['id'];
}
$summit_routes_tmp = Association::countAllLinked($summit_ids, 'sr');
foreach ($summit_routes_tmp as $route) {
$summit_routes_ids[] = $route['linked_id'];
}
}
if (count($summit_routes_ids)) {
foreach ($associated_routes as $key => $route) {
if (in_array($route['id'], $summit_routes_ids)) {
$associated_summit_routes[$key] = $route;
unset($associated_routes[$key]);
}
}
}
$this->associated_routes = $associated_routes;
$this->associated_summit_routes = $associated_summit_routes;
// We retrieve both the books directly linked
$associated_books = c2cTools::sortArrayByName(array_filter($this->associated_docs, array('c2cTools', 'is_book')));
// AND the books linked to linked routes
// FIXME we should probably also do this with linked sites
$route_ids = array();
$associated_routes_books = array();
if (count($associated_routes)) {
foreach ($associated_routes as $route) {
if ($route['duration'] instanceof Doctrine_Null || $route['duration'] <= 4) {
$route_ids[] = $route['id'];
}
}
if (count($route_ids)) {
$book_ids = array();
foreach ($associated_books as $book) {
$book_ids[] = $book['id'];
}
$associated_route_docs = Association::findLinkedDocsWithBestName($route_ids, $prefered_cultures, array('br'), false, false, $book_ids);
if (count($associated_route_docs)) {
$associated_route_docs = c2cTools::sortArray($associated_route_docs, 'name');
$associated_routes_books = array_filter($associated_route_docs, array('c2cTools', 'is_book'));
foreach ($associated_routes_books as $key => $book) {
$associated_routes_books[$key]['parent_id'] = true;
}
}
}
}
$associated_books = array_merge($associated_books, $associated_routes_books);
if (count($associated_books)) {
$associated_books = Book::getAssociatedBooksData($associated_books);
}
$this->associated_books = $associated_books;
// get associated outings
$latest_outings = array();
$nb_outings = 0;
if (!$is_gite_camping && count($associated_routes) || $is_gite_camping && count($parking_ids)) {
if (!$is_gite_camping) {
$outing_params = array('huts' => $current_doc_id);
} else {
$outing_params = array('parkings' => $this->ids);
}
$nb_outings = sfConfig::get('app_nb_linked_outings_docs');
$latest_outings = Outing::listLatest($nb_outings + 1, array(), array(), array(), $outing_params, false);
$latest_outings = Language::getTheBest($latest_outings, 'Outing');
}
$this->latest_outings = $latest_outings;
$this->nb_outings = $nb_outings;
// possibly related portals
$related_portals = array();
Portal::getRelatedPortals($related_portals, $this->associated_areas, $associated_routes);
$this->related_portals = $related_portals;
$cab = count($associated_books);
$this->section_list = array('books' => $cab != 0, 'map' => (bool) $this->document->get('geom_wkt'));
$hut_type_list = sfConfig::get('mod_huts_shelter_types_list');
$hut_type_index = $this->document->get('shelter_type');
$hut_type = $this->__($hut_type_list[$hut_type_index]);
$doc_name = $this->document->get('name');
$title = $doc_name;
if ($this->document->isArchive()) {
$version = $this->getRequestParameter('version');
$title .= ' :: ' . $this->__('revision') . ' ' . $version;
}
$title .= ' :: ' . $hut_type;
$this->setPageTitle($title);
$description = array($hut_type . ' :: ' . $doc_name, $this->getActivitiesList(), $this->getAreasList());
$this->getResponse()->addMeta('description', implode(' - ', $description));
}
}
示例8: executeView
/**
* Executes view action.
*/
public function executeView()
{
parent::executeView();
if (!$this->document->isArchive() && $this->document['redirects_to'] == NULL) {
$user = $this->getUser();
$prefered_cultures = $user->getCulturesForDocuments();
$current_doc_id = $this->getRequestParameter('id');
$main_associated_parkings = c2cTools::sortArray(array_filter($this->associated_docs, array('c2cTools', 'is_parking')), 'elevation');
// Idea here is to retrieve not only the routes linked directly to the parking, but also the ones
// associated to the sub(-sub)-parkings
// We also do this for products and huts
$parking_ids = array();
if (count($main_associated_parkings)) {
$associated_parkings = Association::createHierarchyWithBestName($main_associated_parkings, $prefered_cultures, array('type' => 'pp', 'current_doc_id' => $current_doc_id, 'keep_current_doc' => true));
$associated_parkings = Parking::getAssociatedParkingsData($associated_parkings);
// simply go through the list and get the next items that have a bigger level
$i = reset($associated_parkings);
while (!isset($i['is_doc'])) {
$i = next($associated_parkings);
}
$doc_level = $i['level'];
$i = next($associated_parkings);
while ($i !== false && $i['level'] > $doc_level) {
$parking_ids[] = $i['id'];
$i = next($associated_parkings);
}
if (count($parking_ids)) {
$this->associated_docs = array_merge($this->associated_docs, Association::findLinkedDocsWithBestName($parking_ids, $prefered_cultures, array('pr', 'ph', 'pf')));
}
} else {
$associated_parkings = $main_associated_parkings;
}
$this->associated_parkings = $associated_parkings;
array_unshift($parking_ids, $current_doc_id);
$this->ids = implode('-', $parking_ids);
$associated_routes = Route::getAssociatedRoutesData($this->associated_docs, $this->__(' :') . ' ');
$this->associated_routes = $associated_routes;
// related books (associated to the above mentioned routes)
$route_ids = array();
$associated_routes_books = array();
if (count($associated_routes)) {
foreach ($associated_routes as $route) {
if ($route['duration'] instanceof Doctrine_Null || $route['duration'] <= 4) {
$route_ids[] = $route['id'];
}
}
if (count($route_ids)) {
$associated_route_docs = Association::findLinkedDocsWithBestName($route_ids, $prefered_cultures, array('br'), false, false);
if (count($associated_route_docs)) {
$associated_route_docs = c2cTools::sortArray($associated_route_docs, 'name');
$associated_routes_books = array_filter($associated_route_docs, array('c2cTools', 'is_book'));
foreach ($associated_routes_books as $key => $book) {
$associated_routes_books[$key]['parent_id'] = true;
}
}
}
}
$cab = 0;
if (count($associated_routes_books)) {
$associated_books = Book::getAssociatedBooksData($associated_routes_books);
$this->associated_books = $associated_books;
$cab = count($associated_books);
}
// get associated outings (to the above mentionned routes)
$latest_outings = array();
$nb_outings = 0;
if (count($associated_routes)) {
$outing_params = array('parkings' => $this->ids);
$nb_outings = sfConfig::get('app_nb_linked_outings_docs');
$latest_outings = Outing::listLatest($nb_outings + 1, array(), array(), array(), $outing_params, false);
$latest_outings = Language::getTheBest($latest_outings, 'Outing');
}
$this->latest_outings = $latest_outings;
$this->nb_outings = $nb_outings;
// associated huts
$this->associated_huts = c2cTools::sortArray(array_filter($this->associated_docs, array('c2cTools', 'is_hut')), 'elevation');
// asscoiated products
$this->associated_products = c2cTools::sortArray(array_filter($this->associated_docs, array('c2cTools', 'is_product')), 'name');
// related portals
$related_portals = array();
$public_transportation_rating = $this->document->get('public_transportation_rating');
if (in_array($public_transportation_rating, array(1, 2, 4, 5))) {
$related_portals[] = 'cda';
}
Portal::getRelatedPortals($related_portals, $this->associated_areas, $associated_routes);
$this->related_portals = $related_portals;
$this->section_list = array('books' => $cab != 0, 'map' => (bool) $this->document->get('geom_wkt'));
$description = array($this->__('parking') . ' :: ' . $this->document->get('name'), $this->getAreasList());
$this->getResponse()->addMeta('description', implode(' - ', $description));
}
}
示例9: addAssociatedDocuments
public static function addAssociatedDocuments(&$docs, $type, $is_main, $data_fields = array(), $i18n_fields = array())
{
if (count($docs) == 0 || empty($data_fields) && empty($i18n_fields)) {
return array();
}
$modules = c2cTools::Type2Modules($type);
$main_module = $modules['main'];
$linked_module = $modules['linked'];
if (empty($main_module) || empty($linked_module)) {
return array();
}
$doc_ids = array();
foreach (array_keys($docs) as $key) {
$id = $docs[$key]['id'];
$doc_ids[] = $id;
$docs[$id] = $docs[$key];
unset($docs[$key]);
}
// retrieve associations
if ($main_module == $linked_module) {
$associations = Association::countAll($doc_ids, $type);
$module = $main_module;
} elseif ($is_main) {
$associations = Association::countAllLinked($doc_ids, $type);
$module = $linked_module;
} else {
$associations = Association::countAllMain($doc_ids, $type);
$module = $main_module;
}
if (count($associations) == 0) {
return array();
}
$linked_ids = array();
foreach ($associations as $assoc) {
if ($is_main) {
$doc_id = $assoc['main_id'];
$linked_id = $assoc['linked_id'];
} else {
$doc_id = $assoc['linked_id'];
$linked_id = $assoc['main_id'];
}
$linked_ids[] = $linked_id;
if (isset($docs[$doc_id]['linked_docs'])) {
$docs[$doc_id]['linked_docs'] = array_merge($docs[$doc_id]['linked_docs'], array($linked_id));
} else {
$docs[$doc_id]['linked_docs'] = array($linked_id);
}
}
$linked_ids = array_unique($linked_ids);
$conditions = array();
foreach ($linked_ids as $id) {
$conditions[] = '?';
}
// retrieve info on the linked docs (name etc)
$model = c2cTools::module2model($module);
$q = Doctrine_Query::create()->from("{$model} m")->where('m.id IN ( ' . implode(', ', $conditions) . ' )', $linked_ids);
if (!in_array('id', $data_fields)) {
$data_fields[] = 'id';
}
$q->addSelect('m.' . implode(', m.', $data_fields));
$has_name = false;
if (!empty($i18n_fields)) {
if (in_array('name', $i18n_fields)) {
if (!in_array('search_name', $i18n_fields)) {
$i18n_fields[] = 'search_name';
$i18n_fields[] = 'culture';
}
$has_name = true;
}
$q->addSelect('mi.' . implode(', mi.', $i18n_fields))->leftJoin('m.' . $model . 'I18n mi');
}
$linked_docs_info = $q->execute(array(), Doctrine::FETCH_ARRAY);
if ($has_name) {
$user_prefered_langs = sfContext::getInstance()->getUser()->getCulturesForDocuments();
$linked_docs_info = Language::getTheBest($linked_docs_info, $model);
}
// add linked docs info into $docs
foreach ($docs as $doc_id => $doc) {
if (isset($doc['linked_docs'])) {
foreach ($doc['linked_docs'] as $key => $linked_doc_id) {
$docs[$doc_id]['linked_docs'][$key] = $linked_docs_info[$linked_doc_id];
}
}
}
}