Ejemplo n.º 1
0
 /**
  * Find the number of favorites for the user.
  *
  * @return int
  */
 public function totalUserFavorites()
 {
     if (Module::getModuleByName('user_favorites')) {
         return count(UserFavoritesModule::getFavorites(Auth::id()));
     } else {
         return 0;
     }
 }
Ejemplo n.º 2
0
 /**
  * Favorites menu.
  *
  * @return Menu|null
  */
 protected function menuFavorites()
 {
     global $controller;
     $show_user_favorites = $this->tree && Module::getModuleByName('user_favorites') && Auth::check();
     $show_tree_favorites = $this->tree && Module::getModuleByName('gedcom_favorites');
     if ($show_user_favorites && $show_tree_favorites) {
         $favorites = array_merge(FamilyTreeFavoritesModule::getFavorites($this->tree->getTreeId()), UserFavoritesModule::getFavorites(Auth::id()));
     } elseif ($show_user_favorites) {
         $favorites = UserFavoritesModule::getFavorites(Auth::id());
     } elseif ($show_tree_favorites) {
         $favorites = FamilyTreeFavoritesModule::getFavorites($this->tree->getTreeId());
     } else {
         $favorites = array();
     }
     $submenus = array();
     $records = array();
     foreach ($favorites as $favorite) {
         switch ($favorite['type']) {
             case 'URL':
                 $submenus[] = new Menu($favorite['title'], $favorite['url']);
                 break;
             case 'INDI':
             case 'FAM':
             case 'SOUR':
             case 'OBJE':
             case 'NOTE':
                 $record = GedcomRecord::getInstance($favorite['gid'], $this->tree);
                 if ($record && $record->canShowName()) {
                     $submenus[] = new Menu($record->getFullName(), $record->getHtmlUrl());
                     $records[] = $record;
                 }
                 break;
         }
     }
     if ($show_user_favorites && isset($controller->record) && $controller->record instanceof GedcomRecord && !in_array($controller->record, $records)) {
         $submenus[] = new Menu(I18N::translate('Add to favorites'), '#', '', array('onclick' => 'jQuery.post("module.php?mod=user_favorites&mod_action=menu-add-favorite", {xref:"' . $controller->record->getXref() . '"},function(){location.reload();})'));
     }
     if (empty($submenus)) {
         return null;
     } else {
         return new Menu(I18N::translate('Favorites'), '#', 'menu-favorites', array(), $submenus);
     }
 }