Kalendář akcí

V tejto téme sa nachádzajú snippety (rozšírenia) pre Etomite.

Moderátor: Moderators

R - stick
Moderator & CLT
Moderator & CLT
Príspevky: 215
Dátum registrácie: Pi Sep 23, 2005 10:59 am
Bydlisko: Vysoké Studnice (u Jihlavy)
Kontaktovať používateľa:

Kalendář akcí

Príspevok od používateľa R - stick »

Potřebuji na webu udělat kalendář vystoupení- tzn termín, místo, čas, doplňkové informace. Víte někdo o něčem, aby se do dalo realizovat?
Používateľov profilový obrázok
_rasel^
ETOMITE Admin
ETOMITE Admin
Príspevky: 1122
Dátum registrácie: Ut Sep 20, 2005 1:03 am
Bydlisko: Košice (SR)
Kontaktovať používateľa:

Re: Kalendář akcí

Príspevok od používateľa _rasel^ »

Ahoj. Ako konkrétne by mal ten snippet vyzerať?

Napr. calSnippet zobrazí kalendár a pod ním zoznam udalostí. Zoznam udalosti tvoria dokumenty, ktoré sú uložené v rodičovskom priečinku (priečinkov môže byť viac) a dátum jednotlivej udalosti funkcia čerpá z popisu dokumentu, kde je uvedený dátum vo formáte YYYY-MM-DD a popis udalosti. Po kliknutí na udalosť sa zobrazí dokument v plnom znení.

Kód: Vybrať všetko

// Snippet name: calSnippet
// Snippet description: An events calendar
// Revision: 1.1 Works with Etomite 0.6.1-Final and later (and probably earlier too though not tested)
// Created By: Oliver Dain - Modified 2007-03-28

/******************************************************************************/
/* Instructions

to use insert something like: [[calSnippet?folders=14,17]]
Folders 14 and 17 hold the data you would like displayed on the calendar.
In this folder there should be documents whose description fields are something like:

2007-04-22 My fun event
2007-04-30 15:22 - 17:00 Another fun event

The first document indicates an event that takes place on April 22, 2007. It will show up with a
description of "My fun event" and will have no associated time. The 2nd document indicates an
event that takes place on April 30, 2007 from 3:22 pm until 5:00 pm. Note that dates and time MUST be specified
in YYYY-MM-DD format *with* leading zeros. Similarly if you give a time you *must* give a start and end time
and they must both be specified in military format with leading zeros. 

The calendar will list all events in the folders you specify on the calendar and will contain links to the
documents that describe those events. 

If you have one event that occurs many times you can create one document describing the event and
then use weblinks with different descriptions to indicate the various times the event occurs. */
/******************************************************************************/

/******************************************************************************/
/* Configuration stuff. Modify this stuff to change the appearance of the calendar */

//Day of week for the left-most column in the calendar. 0 == Sunday, 1 == Monday, etc.
$calStartDay = 1;

/******************************************************************************/
/* If you want to use style sheets uncomment this region and  create a style sheet with appropriate styles */
/*
$calTableStyle = 'class = "calTable"';
$calHeadCellStyle = 'class = "calHeadCell"';
$calPrevMonthStyle = 'class = "calTable calPrevMonthCell"';
$calNextMonthStyle = 'class = "calTable calNextMonthCell"';
$calCurMonthStyle = 'class = "calTable calCurMonthCell"';
$calEventStyle = 'class = "calEventCell calTable"';
$eventCountStyle = 'class = "calEventCount"'; //Style for "2 events" kind of things
$eventLinkStyle = 'class = "calEventsCount"';
$eventDayHeadingStyle = 'class = "eventDayHeading"';
$calMonthStyle = 'class = "calMonth"';
$calPrevLinkStyle = 'class = "calFBLink"';
$calNextLinkStyle = 'class = "calFBLink"';
$calTitleStyle = 'class = "calTitle"'; */
/******************************************************************************/

/******************************************************************************/
/* the following styles the calendar with inline styles.                                                                           */
$calTableStyle = 'style = "width: 100%;border-collapse: collapse;  table-layout: fixed;"';
$calHeadCellStyle = 'style = "border-style: solid; border-bottom-style: double; text-align: center;"';
$calPrevMonthStyle = 'style = "border-style: solid; height: 3em; vertical-align: top; background: #DCDCDC;"';
$calNextMonthStyle = 'style = "border-style: solid; height: 3em; vertical-align: top; background: #DCDCDC;"';
$calCurMonthStyle = 'style = "border-style: solid; height: 3em; vertical-align: top; background: #3366FF;"';
$calEventStyle = 'style = "border-style: solid; height: 3em; vertical-align: top; background: #FFD25F;"';
$eventCountStyle = 'style = "width: 100%; text-align: center;"'; //Style for "2 events" kind of things
$eventLinkStyle = '';
$eventDayHeadingStyle = 'style = "font-weight:bold; font-size: large;"';
$calMonthStyle = '';
$calPrevLinkStyle = '';
$calNextLinkStyle = '';
$calTitleStyle = 'style = "text-align: center; font-size: large; font-weight: bold;"';
/******************************************************************************/


/******************************************************************************/
/* This is what shows up for the left and right arrows if you want images uncomment the following and */
/* upload appropriate images to your site                                                                                              */
$leftArrow = '<img src="left.gif" class="calMonthArrow" />';
$rightArrow = '<img src="right.gif" class="calMonthArrow" />';
/******************************************************************************/

/******************************************************************************/
/* Regular text arrows                                                                                                                         */
$leftArrow = '<<';
$rightArrow = '>>';
/******************************************************************************/

/******************************************************************************/
/* Beginning of real code - you shouldn't have to modify anything below here                                       */

/* Note: its tempting to just add the number of seconds in a day to loop to the
   next day or do other date calculations, but due to leapyears, leapseconds and
   daylight savings time this doesn't work. The only safe thing is to use php's
   strtotime function which is text-based and weird, but its all they provide */


function error($message)
{
   return "<b>Error in snippet: $message</b>";
}

/* A function to do "real" mod arithmetic. With normal mod operator -1 % 7 == -1 instead of 6 */
function mod($x, $y)
{
   $ans = $x % $y;
   if ($ans < 0)
   {
     $ans = $y + $ans;
   }
   return $ans;
}

/* used to sort events by start time. Compare the "start" field in
   their arrays to sort */
function eventCompare($e1, $e2)
{
   if ($e1["start"] == $e2["start"])
   {
      return 0;
   }
   else
   {
      if ($e1["start"] > $e2["start"])
      {
         return +1;
      }
      else
      {
         return -1;
      }
   }
}

/* Given a bunch of data from the DB (an array of events) reprocess to build an array of
   arrays with such that $eventData[$date] = an array of of events on $date. Each
   event in the array is represented as yet another array with keys "description", 
   "start", and "stop". The arrays for each day will be sorted by the "start" times
   of the events with events having no associated time coming first and having a start
   time of 0. */
function buildEventArray($dbData)
{
   //Convert the eventData into an array of arrays with the date as the key
   $eventData = array();
   foreach ($dbData as $event)
   {
      //pull off the date part
      if(preg_match("/(\d{4,4})-(\d{2,2})-(\d{2,2}) (.*)/", $event["description"], $matches))
      {
        $eDate = mktime(0, 0, 0, $matches[2], $matches[3], $matches[1]);
        if (!array_key_exists($eDate, $eventData))
        {
          $eventData[$eDate] = array();
        }
        $event["description"] = $matches[4];
        if (preg_match("/^(\d{2,2}):(\d{2,2}) *- * (\d{2,2}):(\d{2,2}) (.*)/", $event["description"], $tMatches))
        {
           $event["description"] = $tMatches[5];
           $event["start"] = mktime($tMatches[1], $tMatches[2], 0, $matches[2], $matches[3], $matches[1]);
           $event["stop"] = mktime($tMatches[3], $tMatches[4], 0, $matches[2], $matches[3], $matches[1]);
        }
        else
        {
           $event["description"] = $matches[4];
           $event["start"] = 0;
           $event["stop"] = 0;
        }
        $eventData[$eDate][] = $event;
      }
   }  
   foreach($eventData as $key => $eventArray)
   {
      usort($eventArray, "eventCompare");
      $eventData[$key] = $eventArray;
   }
   return $eventData; 
}

//All our data will be returned in $ret
$ret = "";

//If a folder wasn't specified, exit
if (!isset($folders))
{
   return "";
}
else
{
   $folders = explode(",", $folders);
}

$curTime = time();
//What day is in the last column of the calendar?
$calEndDay = mod($calStartDay + 6, 7);

//What month are we processing?
if (isset($_REQUEST["month"]))
{
   $month = $_REQUEST["month"];
   if ($month < 1 || $month > 12)
   {
      return error("Month not in range.");
   }
}
else
{
   $month = date("m", $curTime);
}

//What year?
if(isset($_REQUEST["year"]))
{
   $year= $_REQUEST["year"];
   if ($year < 2005 || $year > 2050)
   {
     return error("Year not in range.");
   }
}
else
{ 
   $year = date("Y", $curTime);
}


///Make monthStart == 1st day of the month
$monthStart = mktime(0, 0, 0, $month, 1, $year);
$monthEnd = mktime(0, 0, 0, $month, date("t", $monthStart), $year);

$prevMonth = strtotime("-1 month", $monthStart);
$nextMonth = strtotime("+1 month", $monthStart);

/* This is the function we'll use to get the data, but for testing we manually create it */
$eventDataRaw = $etomite->getIntTableRows("id, description" ,"site_content", 
                                          "parent in (" . implode(", ", $folders) . ") and published " .
                                          'and description >= "' . date('Y-m-d', $monthStart) . 
                                          '" and description < "' . date('Y-m-d', $nextMonth)  . '"', 
                                          "description");

$eventDataRaw = array(0 => array ('id' => 0, 'description' => "2007-01-20 Fun Event"),
                   1 => array('id' => 2, 'description' => "2007-01-15 20:00 - 22:00 Different Event"),
                   2 => array('id' => 3, 'description' => "2007-01-15 09:00 - 12:00 Another event on the 15th"),
                   3 => array('id' => 4, 'description' => "2007-01-15 Untimed event"));
                   


$eventData = buildEventArray($eventDataRaw);

//Get an integer representing the day of the week. Sunday == 0
$monthStartDOW = date("w", $monthStart);
$monthEndDOW = date("w", $monthEnd);

$blankDaysStart = mod($monthStartDOW - $calStartDay, 7);
$calStartDate = strtotime("-$blankDaysStart days", $monthStart);
$blankDaysEnd = mod($calEndDay - $monthEndDOW, 7);
$calEndDate = strtotime("+$blankDaysEnd days", $monthEnd);

$ret .= "<div $calTitleStyle>";

$prevURL = $etomite->makeURL($etomite->documentObject[id], "", "?month=" . date('m', $prevMonth) 
        . "&year=" . date('Y', $prevMonth));

$nextURL = $etomite->makeURL($etomite->documentObject[id], "", "?month=" . date('m', $nextMonth) 
        . "&year=" . date('Y', $nextMonth));

$ret .= "<a $calPrevLinkStyle href='" . $prevURL . "'>" . $leftArrow . '</a> ';
$ret .= "<span $calMonthStyle>" . date("F, Y", $monthStart) . "</span>";
$ret .= " <a $calNextLinkStyle href='" . $nextURL. "'>" . $rightArrow . '</a> ';
$ret .= "</div>";

//Create the basic calendar table
$ret .= "<table $calTableStyle>\n";
//create the header row
$ret .= "<tr>\n";
for ($curDay = $calStartDate; $curDay <= strtotime("+ 6 days", $calStartDate); $curDay = strtotime("+ 1 day", $curDay))
{
   $ret .= "<td $calHeadCellStyle>" . date('D', $curDay) . "</td>\n";
}
$ret .= "</tr>\n<tr>\n";

$cellCount = 0;

for ($curDay = $calStartDate; $curDay <= $calEndDate; $curDay = strtotime("+ 1 day", $curDay))
{
   if($cellCount == 7)
   {
     $cellCount = 0;
     $ret .= "</tr>\n<tr>\n";
   }
   $numEventsCur = 0;
   if (array_key_exists($curDay, $eventData))
   {
     $ret .= "<td $calEventStyle>";
     $numEventsCur = count($eventData[$curDay]);
   }
   else if (date('m', $curDay) == $month)
   {
      $ret .= "<td $calCurMonthStyle>";
   }
   else if (date('m', $curDay) < $month)
   {
      $ret .= "<td $calPrevMonthStyle>";
   }
   else
   {
     $ret .= "<td $calNextMonthStyle>";
   }
   $ret .=  date("j", $curDay);
   if ($numEventsCur > 0)
   {
     $ret .= "<div $eventCountStyle>";
     $ret .= "<a $eventLinkStyle href=" . '"#anchorDay' . date("j", $curDay) . '">' . "$numEventsCur event";
     if ($numEventsCur > 1) {$ret .= "s";}
     $ret .= "</a></div>";
   }
   $ret .= "</td>\n";
   ++$cellCount;
}
$ret .= "</tr>\n";

$ret .= "</table><p/><hr/>\n";

/* Now list all the events */
$daysWithEvents = array_keys($eventData);
sort($daysWithEvents);
foreach ($daysWithEvents as $curDay) 
{
	$ret .= '<a id="anchorDay' . date('j', $curDay) . '"></a>' . "<div $eventDayHeadingStyle>" 
	        . date('l, F d, Y', $curDay) . "</div>\n";
	$ret .= "<ul>\n";
	//Convert the array of events to a map from description (without the date part) to document id
   $curDayEvents = $eventData[$curDay];	
	foreach($curDayEvents as $event)
	{
	   $ret .= "<li>";
      if (($event["start"]) > 0)
      {
         $ret .= date('g:i a', $event["start"]) . " - " . date('g:i a', $event["stop"]) . " ";
      }	   
	   $ret .= '<a href="[~' . $event["id"] . '~]">' . $event['description'] . "</a></li>\n";
	}
	$ret .= "</ul>";
}

return $ret;
..:: Etomite CMS → Rulezzz !.!.!. ::..
R - stick
Moderator & CLT
Moderator & CLT
Príspevky: 215
Dátum registrácie: Pi Sep 23, 2005 10:59 am
Bydlisko: Vysoké Studnice (u Jihlavy)
Kontaktovať používateľa:

Re: Kalendář akcí

Príspevok od používateľa R - stick »

Výstup by měl vypadat zhruba tak, jak je to na této stránce: http://www.jumpingdrums.info/cz-koncerty.html - tam to mám zatím provizorně v tabulce. Záznamy by měly být řazeny podle aktuálního data - tzn nejbližší vystoupení vždy navrch. Koncerty, které již proběhly by se pak měly zobrazovat na další stránce, opět s řazením data od nejdřívějšího do pozdnějšího.

Zatím jsem uvažoval, že bych použil snippet newslisting, nebo podobný kde bych rozšířil výpis o titulek, dlouhý název, popis, datum ukončení publikace a řazení dokumentu. Dokumenty bych řadil podle data ukončení publikace aby se zobrazovaly v akcích, které mají proběhnout jen dokumenty s platnou publikací, a v akcích, které proběhly jen dokumenty s ukončenou publikací. Do příslušných položek bych zadával údaje, které bych chtěl mít ve výpisu + do obsahu dokumentu podrobnější popis akce.

Nevím, jestli někdo něco podobného už řešil - mám pocit, že něco dělal Churchyard - jenže ten už tady nebyl dlouhý čas. Ale ten snippet, co jsi sem dal otestuji, díky.
Napísať odpoveď