Listing Uncompleted Public Events

Let’s say you have a project that for some reason you need visitors of your website to be updated on. Let’s also say that you don’t want them to see all events and tasks, but just those that are uncompleted and in a category you created called public. And, it’s important that you also show who is working on the task (who pinned it).

Remember that while we call these “to-dos” in Torch “events”, they don’t necessarily have a time/date. An event is anything you check off as complete or uncomplete.

Code:

<?php
$username = "ben@wbpsystems.com";
$password = "password";

$xmltext = "<?xml version='1.0' encoding='ISO-8859-1'?>\n<request></request>";

$rxe = new SimpleXMLElement($xmltext);
$rxe->addChild('project','TOKEN');

$search = $rxe->addChild('search');
$search->addChild('type','events');
$search->addChild('phrase','complete:no category:public');

$post = $rxe->asXML();

$ch = curl_init ();
curl_setopt($ch,CURLOPT_URL,"https://creativearc.mytorch.net/api.php");
curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch,CURLOPT_USERPWD,"$username:$password");
curl_setopt($ch,CURLOPT_POST,1);
curl_setopt($ch,CURLOPT_POSTFIELDS,$post);
$result = curl_exec ($ch);
curl_close($ch);

$displayxml = new SimpleXMLElement($result);

foreach($displayxml->event as $event){
  echo "<div class='event'>";
  echo "<div class='title'>" . $event->title . "</div>";

  foreach($event->pin as $pinned){
    echo "<div class='pin'>" . $pinned . "</div>";
  }

  if(strlen(trim($event->description))>0){
    echo "<div class='description'>" . trim($event->description) . "</div>";
  }

  echo "</div>";
}
?>