TP-Docs
HTML5 Icon HTML5 Icon HTML5 Icon
TP on Social Media

Recent

Welcome to TinyPortal. Please login or sign up.

Members
  • Total Members: 3,973
  • Latest: NonStop
Stats
  • Total Posts: 196,219
  • Total Topics: 21,352
  • Online today: 556
  • Online ever: 8,223 (February 19, 2025, 04:35:35 AM)
Users Online

Calendar Event Details Block

Started by jpark, August 14, 2007, 01:42:20 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

jpark

I wanted a block that showed details of calendar events and not just a listing of the dates and event titles.  So this is what I was able to get but I have an issue maybe someone could help me fix?

I used Thurnok's Custom Post Prefills for the forum linked to my calendar so the event details are all in the form of

Date:
Time:
Place:

Notes:

I got this forum to show up using an edited boardnews ssi on a right block.  (I copied the boardnews ssi and made a new ssi called calendarEvents and deleted the topic start date, topic starter, comments and edit lines)  So currently, it looks really nice as a detailed events block.  But the events are, as expected, ordered by topic post date.  How could I call the event date so they are ordered by that instead?

This is the edited boardnews ssi:
// Show the calendar events in boardnews style with details.
function ssi_calendarEvents($board = null, $limit = null, $start = null, $length = null, $output_method = 'echo')
{
global $scripturl, $db_prefix, $txt, $settings, $modSettings, $context;
global $func;

loadLanguage('Stats');

// Must be integers....
if ($limit === null)
$limit = isset($_GET['limit']) ? (int) $_GET['limit'] : 3;
else
$limit = (int) $limit;

if ($start === null)
$start = isset($_GET['start']) ? (int) $_GET['start'] : 0;
else
$start = (int) $start;

if ($board !== null)
$board = (int) $board;
elseif (isset($_GET['board']))
$board = (int) $_GET['board'];

if ($length === null)
$length = isset($_GET['length']) ? (int) $_GET['length'] : 0;
else
$length = (int) $length;

$limit = max(0, $limit);
$start = max(0, $start);

// Make sure guests can see this board.
$request = db_query("
SELECT ID_BOARD
FROM {$db_prefix}boards
WHERE " . ($board === null ? '' : "ID_BOARD = $board
AND ") . "FIND_IN_SET(-1, memberGroups)
LIMIT 1", __FILE__, __LINE__);
if (mysql_num_rows($request) == 0)
{
if ($output_method == 'echo')
die($txt['smf_news_error2']);
else
return array();
}
list ($board) = mysql_fetch_row($request);
mysql_free_result($request);

// Load the message icons - the usual suspects.
$stable_icons = array('xx', 'thumbup', 'thumbdown', 'exclamation', 'question', 'lamp', 'smiley', 'angry', 'cheesy', 'grin', 'sad', 'wink', 'moved', 'recycled', 'wireless');
$icon_sources = array();
foreach ($stable_icons as $icon)
$icon_sources[$icon] = 'images_url';

// Find the post ids.
$request = db_query("
SELECT ID_FIRST_MSG
FROM {$db_prefix}topics
WHERE ID_BOARD = $board
ORDER BY ID_FIRST_MSG DESC
LIMIT $start, $limit", __FILE__, __LINE__);
$posts = array();
while ($row = mysql_fetch_assoc($request))
$posts[] = $row['ID_FIRST_MSG'];
mysql_free_result($request);

if (empty($posts))
return array();

// Find the posts.
$request = db_query("
SELECT
m.icon, m.subject, m.body, IFNULL(mem.realName, m.posterName) AS posterName, m.posterTime,
t.numReplies, t.ID_TOPIC, m.ID_MEMBER, m.smileysEnabled, m.ID_MSG, t.locked
FROM ({$db_prefix}topics AS t, {$db_prefix}messages AS m)
LEFT JOIN {$db_prefix}members AS mem ON (mem.ID_MEMBER = m.ID_MEMBER)
WHERE t.ID_FIRST_MSG IN (" . implode(', ', $posts) . ")
AND m.ID_MSG = t.ID_FIRST_MSG
ORDER BY t.ID_FIRST_MSG DESC
LIMIT " . count($posts), __FILE__, __LINE__);
$return = array();
while ($row = mysql_fetch_assoc($request))
{
// If we want to limit the length of the post.
if (!empty($length) && $func['strlen']($row['body']) > $length)
{
$row['body'] = $func['substr']($row['body'], 0, $length);

// The first space or line break. (<br />, etc.)
$cutoff = max(strrpos($row['body'], ' '), strrpos($row['body'], '<'));

if ($cutoff !== false)
$row['body'] = $func['substr']($row['body'], 0, $cutoff);
$row['body'] .= '...';
}

$row['body'] = parse_bbc($row['body'], $row['smileysEnabled'], $row['ID_MSG']);

// Check that this message icon is there...
if (empty($modSettings['messageIconChecks_disable']) && !isset($icon_sources[$row['icon']]))
$icon_sources[$row['icon']] = file_exists($settings['theme_dir'] . '/images/post/' . $row['icon'] . '.gif') ? 'images_url' : 'default_images_url';

censorText($row['subject']);
censorText($row['body']);

$return[] = array(
'id' => $row['ID_TOPIC'],
'message_id' => $row['ID_MSG'],
'icon' => '<img src="' . $settings[$icon_sources[$row['icon']]] . '/post/' . $row['icon'] . '.gif" align="middle" alt="' . $row['icon'] . '" border="0" />',
'subject' => $row['subject'],
'time' => timeformat($row['posterTime']),
'timestamp' => forum_time(true, $row['posterTime']),
'body' => $row['body'],
'href' => $scripturl . '?topic=' . $row['ID_TOPIC'] . '.0',
'link' => '<a href="' . $scripturl . '?topic=' . $row['ID_TOPIC'] . '.0">' . $row['numReplies'] . ' ' . ($row['numReplies'] == 1 ? $txt['smf_news_1'] : $txt['smf_news_2']) . '</a>',
'replies' => $row['numReplies'],
'comment_href' => !empty($row['locked']) ? '' : $scripturl . '?action=post;topic=' . $row['ID_TOPIC'] . '.' . $row['numReplies'] . ';num_replies=' . $row['numReplies'],
'comment_link' => !empty($row['locked']) ? '' : '<a href="' . $scripturl . '?action=post;topic=' . $row['ID_TOPIC'] . '.' . $row['numReplies'] . ';num_replies=' . $row['numReplies'] . '">' . $txt['smf_news_3'] . '</a>',
'new_comment' => !empty($row['locked']) ? '' : '<a href="' . $scripturl . '?action=post;topic=' . $row['ID_TOPIC'] . '.' . $row['numReplies'] . '">' . $txt['smf_news_3'] . '</a>',
'poster' => array(
'id' => $row['ID_MEMBER'],
'name' => $row['posterName'],
'href' => !empty($row['ID_MEMBER']) ? $scripturl . '?action=profile;u=' . $row['ID_MEMBER'] : '',
'link' => !empty($row['ID_MEMBER']) ? '<a href="' . $scripturl . '?action=profile;u=' . $row['ID_MEMBER'] . '">' . $row['posterName'] . '</a>' : $row['posterName']
),
'locked' => !empty($row['locked']),
'is_last' => false
);
}
mysql_free_result($request);

if (empty($return))
return $return;

$return[count($return) - 1]['is_last'] = true;

if ($output_method != 'echo')
return $return;

foreach ($return as $news)
{
echo '
<div class="smalltext">
<a href="', $news['href'], '">', $news['icon'], ' <b>', $news['subject'], '</b></a>
<div class="post" style="padding: 0ex 0;">', $news['body'], '</div>
</div>';

if (!$news['is_last'])
echo '
<hr style="margin: 2ex 0;" width="100%" />';
}
}


Notice how in the picture below, my events are not listed in order...

jpark

hmm.. perhaps there isn't an easy solution to this...

JPDeni

I'm afraid there isn't. I've been thinking about this since you first posted and I don't see a way to parse the date from within the post in order to use it for sorting.

jpark

:(  <sigh>... i guess i'll have to do some sort of manual date manipulation...  it would really be so nice if this worked...

stormlrd

thats actually sweet looking i dont know if i can do anything to it or not but I definitly like it :)

JPDeni

I've still been thinking about this and it occurred to me that you might be able to accomplish the same thing by taking a different approach.

As I understand it, each of your events is described in a separate topic, right? You can (and maybe already do) link a topic to the calendar. Once the topic is linked to the calendar, you can adapt one of the ssi calendar functions to display the upcoming events. The calendar would do the sorting for you, but the display would be the first post in the linked topic.

Does this make any sense?

jpark

hmm... sort of?  so take a look at the calendar code and direct it to the calendar forum instead of the event dates?  I'm not sure I'll figure it out but i'll definitely take a look at that.. thanks for the idea.  I'll report back if I make any progress :)

Bloodlvst

I can't make this work... it just gives me a blank block...

I copied and pasted the code into my SSI.php and made a phpbox with

ssi_calendarEvents();

jpark

try putting the number of the board where you have your calendar events where it says "#":

ssi_calendarEvents(#);

jpark

#9
okay.. i'm trying to get the hang of this php thing so it's really taking me a long time to figure this out but I started taking a different approach, as per JPDeni.  I looked at the Calendar in a php-block block code snippet and just took the events part of it to get the title of the event and the date range. 

Now if only I can figure out how to call the linked topic if one exists so the body of the linked topic in the form of time:, place:, and notes: can be added...

This was the code I was using (php block).  If someone knows how to call the linked topic to get the topic body, it would help a lot.

global $scripturl, $modSettings, $context, $db_prefix, $user_profile, $user_info, $txt, $settings, $func;

smf_loadCalendarInfo();

$now = mktime() + $modSettings['time_offset'] * 3600;

$today = date('j',$now);
$year = date('Y',$now);
$month = date('n',$now);

$days = array($today=>array(NULL,NULL,'<a class="smalltext" style="color:#515151; font-weight:bold; border:solid 1px black; background-color: white; padding: 0px 4px 0px 4px;" href="'.$scripturl.'?action=calendar;sa=post;month='.$month.';year='.$year.';day='.$today.'" target="_self">'.$today.'</a>'));

$day_name_length = 2;

$month_href = $scripturl . '?action=calendar&month=' . $month;
$first_day = 0;
$pn = array();

$first_of_month = gmmktime(0,0,0,$month,1,$year);

$day_names = array();                                      #generate all the day names according to the current locale
for($n=0,$t=(3+$first_day)*86400; $n<7; $n++,$t+=86400)    #January 4, 1970 was a Sunday
    $day_names[$n] = ucfirst(gmstrftime('%A',$t));         #%A means full textual day name

list($month, $year, $month_name, $weekday) = explode(',',gmstrftime('%m,%Y,%B,%w',$first_of_month));

$weekday = ($weekday + 7 - $first_day) % 7;                #adjust for $first_day
$title   = htmlentities(ucfirst($month_name)).' '.$year;   #note that some locales don't capitalize month and day names

@list($p, $pl) = each($pn); @list($n, $nl) = each($pn); #previous and next links, if applicable
if($p) $p = '<span class="smalltext">'.($pl ? '<a href="'.htmlspecialchars($pl).'">'.$p.'</a>' : $p).'</span> ';
if($n) $n = ' <span class="smalltext">'.($nl ? '<a href="'.htmlspecialchars($nl).'">'.$n.'</a>' : $n).'</span>';

/////////////////////////////////////////////////////////////////
//   EVENTS SECTION
//
if (!empty($context['calendar_events']))
{

    foreach ($context['calendar_events'] as $event)
    {
        $query = db_query(
            "SELECT startDate
            FROM {$db_prefix}calendar
            WHERE ID_EVENT='".$event['id']."'", __FILE__, __LINE__);
        $row = mysql_fetch_assoc($query);
        $startdate = strtotime($row['startDate']);
        mysql_free_result($query);


        $query = db_query(
            "SELECT endDate
            FROM {$db_prefix}calendar
            WHERE ID_EVENT='".$event['id']."'", __FILE__, __LINE__);
        $row = mysql_fetch_assoc($query);
        $enddate = strtotime($row['endDate']);
        mysql_free_result($query);




        echo '<div align="left">';
        echo $event['link'] ;
        echo '<br />';
        echo 'Date: '; echo '' . date("n/j (D)",$startdate) . '';
   if ($enddate !== $startdate)
      {
        echo ' - '; echo '' . date("n/j (D)",$enddate) . '';
      }
        echo '<br /><br />';
        echo '</div>';
    }
}

This website is proudly hosted on Crocweb Cloud Website Hosting.