Esempio n. 1
0
 /**
  * count related items
  *
  * This function draws a nice table to show how many items are related to
  * the anchor that has the focus.
  *
  * @param string the target reference
  * @param string the label to use, if any
  * @return string some XHTML snippet to send to the browser
  */
 public static function stat_related_to($anchor, $label = NULL)
 {
     global $context;
     // describe related content
     $related = '';
     $lines = 2;
     // stats for related categories, but only within categories
     if (strpos($anchor, 'category:') === 0) {
         if (($stats = Categories::stat_for_anchor($anchor)) && $stats['count']) {
             $cells = array();
             $cells[] = i18n::s('Categories');
             $cells[] = 'center=' . $stats['count'];
             $cells[] = 'center=' . Skin::build_date($stats['oldest_date']);
             $cells[] = 'center=' . Skin::build_date($stats['newest_date']);
             $related .= Skin::table_row($cells, $lines++);
         }
     }
     // stats for related sections, but only within sections
     if (strpos($anchor, 'section:') === 0) {
         if (($stats = Sections::stat_for_anchor($anchor)) && $stats['count']) {
             $cells = array();
             $cells[] = i18n::s('Sections');
             $cells[] = 'center=' . $stats['count'];
             $cells[] = 'center=' . Skin::build_date($stats['oldest_date']);
             $cells[] = 'center=' . Skin::build_date($stats['newest_date']);
             $related .= Skin::table_row($cells, $lines++);
         }
     }
     // stats for related articles, but only within sections
     if (strpos($anchor, 'section:') === 0) {
         if (($stats = Articles::stat_for_anchor($anchor)) && $stats['count']) {
             $cells = array();
             $cells[] = i18n::s('Pages');
             $cells[] = 'center=' . $stats['count'];
             $cells[] = 'center=' . Skin::build_date($stats['oldest_date']);
             $cells[] = 'center=' . Skin::build_date($stats['newest_date']);
             $related .= Skin::table_row($cells, $lines++);
         }
     }
     // stats for related images
     include_once $context['path_to_root'] . 'images/images.php';
     if (($stats = Images::stat_for_anchor($anchor)) && $stats['count']) {
         $cells = array();
         $cells[] = i18n::s('Images');
         $cells[] = 'center=' . $stats['count'];
         $cells[] = 'center=' . Skin::build_date($stats['oldest_date']);
         $cells[] = 'center=' . Skin::build_date($stats['newest_date']);
         $related .= Skin::table_row($cells, $lines++);
     }
     // stats for related locations
     include_once $context['path_to_root'] . 'locations/locations.php';
     if (($stats = Locations::stat_for_anchor($anchor)) && $stats['count']) {
         $cells = array();
         $cells[] = i18n::s('Locations');
         $cells[] = 'center=' . $stats['count'];
         $cells[] = 'center=' . Skin::build_date($stats['oldest_date']);
         $cells[] = 'center=' . Skin::build_date($stats['newest_date']);
         $related .= Skin::table_row($cells, $lines++);
     }
     // stats for related tables
     include_once $context['path_to_root'] . 'tables/tables.php';
     if (($stats = Tables::stat_for_anchor($anchor)) && $stats['count']) {
         $cells = array();
         $cells[] = i18n::s('Tables');
         $cells[] = 'center=' . $stats['count'];
         $cells[] = 'center=' . Skin::build_date($stats['oldest_date']);
         $cells[] = 'center=' . Skin::build_date($stats['newest_date']);
         $related .= Skin::table_row($cells, $lines++);
     }
     // stats for related files
     if (($stats = Files::stat_for_anchor($anchor)) && $stats['count']) {
         $cells = array();
         $cells[] = i18n::s('Files');
         $cells[] = 'center=' . $stats['count'];
         $cells[] = 'center=' . Skin::build_date($stats['oldest_date']);
         $cells[] = 'center=' . Skin::build_date($stats['newest_date']);
         $related .= Skin::table_row($cells, $lines++);
     }
     // stats for related dates
     include_once $context['path_to_root'] . 'dates/dates.php';
     if (($stats = Dates::stat_for_anchor($anchor)) && $stats['count']) {
         $cells = array();
         $cells[] = i18n::s('Dates');
         $cells[] = 'center=' . $stats['count'];
         $cells[] = 'center=' . Skin::build_date($stats['oldest_date']);
         $cells[] = 'center=' . Skin::build_date($stats['newest_date']);
         $related .= Skin::table_row($cells, $lines++);
     }
     // stats for related comments
     include_once $context['path_to_root'] . 'comments/comments.php';
     if (($stats = Comments::stat_for_anchor($anchor)) && $stats['count']) {
         $cells = array();
         $cells[] = i18n::s('Comments');
         $cells[] = 'center=' . $stats['count'];
         $cells[] = 'center=' . Skin::build_date($stats['oldest_date']);
         $cells[] = 'center=' . Skin::build_date($stats['newest_date']);
         $related .= Skin::table_row($cells, $lines++);
     }
     // stats for related links
     include_once $context['path_to_root'] . 'links/links.php';
     if (($stats = Links::stat_for_anchor($anchor)) && $stats['count']) {
         $cells = array();
         $cells[] = i18n::s('Links');
         $cells[] = 'center=' . $stats['count'];
         $cells[] = 'center=' . Skin::build_date($stats['oldest_date']);
         $cells[] = 'center=' . Skin::build_date($stats['newest_date']);
         $related .= Skin::table_row($cells, $lines++);
     }
     // stats for related versions
     include_once $context['path_to_root'] . 'versions/versions.php';
     if (($stats = Versions::stat_for_anchor($anchor)) && $stats['count']) {
         $cells = array();
         $cells[] = i18n::s('Versions');
         $cells[] = 'center=' . $stats['count'];
         $cells[] = 'center=' . Skin::build_date($stats['oldest_date']);
         $cells[] = 'center=' . Skin::build_date($stats['newest_date']);
         $related .= Skin::table_row($cells, $lines++);
     }
     // ensure we have a label
     if (!$label) {
         $label = i18n::s('Following items are attached to this record and will be impacted as well.');
     }
     // stats for related items in a neat table
     if ($related) {
         // make a nice table
         $related = '<p>' . $label . "</p>\n" . Skin::table_prefix('') . Skin::table_row(array(i18n::s('Table'), i18n::s('Records'), i18n::s('Creation date'), i18n::s('Last edition')), 'header') . $related . Skin::table_suffix();
         // put it in a box
         $related = Skin::build_box(i18n::s('Related items'), $related);
     }
     // job done
     return $related;
 }