示例#1
0
 /**
  * Suggest events to tag
  * @since Version 3.10.0
  * @param \Railpage\Images\Image $imageObject
  * @return array
  */
 public static function SuggestEvents(Image $imageObject)
 {
     if (!$imageObject->DateCaptured instanceof DateTime) {
         return;
     }
     $Database = (new AppCore())->getDatabaseConnection();
     $query = "SELECT COUNT(*) AS num FROM image_link WHERE namespace = ? AND image_id = ?";
     $params = [(new Event())->namespace, $imageObject->id];
     if ($Database->fetchOne($query, $params) > 0) {
         return;
     }
     $Events = new Events();
     $list = $Events->getEventsForDate($imageObject->DateCaptured);
     foreach ($list as $k => $row) {
         $Event = new Event($row['event_id']);
         printArray($Event->namespace);
         die;
         $list[$k]['url'] = sprintf("/services?method=railpage.image.tag&image_id=%d&object=%s&object_id=%d", $imageObject->id, "\\Railpage\\Events\\Event", $row['event_id']);
     }
     return $list;
 }
示例#2
0
 /**
  * Generate the calendar table
  * Borrowed from https://css-tricks.com/snippets/php/build-a-calendar-table/
  *
  * @since Version 3.9.1
  * @return string
  */
 public function generateCalendar()
 {
     /**
      * Load the Events class for later on
      */
     $Events = new Events();
     // Create array containing abbreviations of days of week.
     $daysOfWeek = array('Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday');
     // What is the first day of the month in question?
     $firstDayOfMonth = mktime(0, 0, 0, $this->month, 1, $this->year);
     // How many days does this month contain?
     $numberDays = date('t', $firstDayOfMonth);
     // Retrieve some information about the first day of the month in question
     $dateComponents = getdate($firstDayOfMonth);
     // What is the index value (0-6) of the first day of the month in question
     $dayOfWeek = $dateComponents['wday'];
     // Create the table tag opener and day headers
     $calendar = "<table class='calendar'>";
     //$calendar .= "<caption>" . $this->name . " " . $this->year . "</caption>";
     $calendar .= "<thead><tr>";
     // Create the calendar headers
     foreach ($daysOfWeek as $day) {
         $calendar .= "<th class='header'>" . $day . "</th>";
     }
     // Create the rest of the calendar
     // Initiate the day counter, starting with the 1st.
     $currentDay = 1;
     $calendar .= "</tr></thead><tbody><tr>";
     // The variable $dayOfWeek is used to
     // ensure that the calendar
     // display consists of exactly 7 columns.
     if ($dayOfWeek > 0) {
         for ($i = 0; $i < $dayOfWeek; $i++) {
             $calendar .= "<td class='notday'>&nbsp;</td>";
         }
     }
     $month = str_pad($this->month, 2, "0", STR_PAD_LEFT);
     while ($currentDay <= $numberDays) {
         // Seventh column (Saturday) reached. Start a new row.
         if ($dayOfWeek == 7) {
             $dayOfWeek = 0;
             $calendar .= "</tr><tr>";
         }
         $currentDayRel = str_pad($currentDay, 2, "0", STR_PAD_LEFT);
         $date = sprintf("%s-%s-%s", $this->year, $month, $currentDayRel);
         $calendar .= sprintf("<td class='isday %s' valign='top' rel='%s'>", $date == date("Y-m-d") ? "today" : "", $date);
         $calendar .= sprintf("<span class='daynum'>%d</span>", $currentDay);
         /**
          * Get events on this date
          */
         foreach ($Events->getEventsForDate(new DateTime($date)) as $row) {
             $calendar .= sprintf("<a class='event-link' href='%s'><time datetime='%s'>%s</time></a>", $row['url'], (new DateTime($row['date'] . " " . $row['start']))->format(DATE_ISO8601), $row['title']);
         }
         $calendar .= "</td>";
         // Increment counters
         $currentDay++;
         $dayOfWeek++;
     }
     // Complete the row of the last week in month, if necessary
     if ($dayOfWeek != 7) {
         $remainingDays = 7 - $dayOfWeek;
         for ($i = 0; $i < $remainingDays; $i++) {
             $calendar .= "<td class='notday'>&nbsp;</td>";
         }
     }
     $calendar .= "</tr></tbody>";
     $calendar .= "</table>";
     return $calendar;
 }