Tuesday, March 21, 2006

EventController.php



<?php
require_once 'config/config.php';
require_once 'helpers/SecurityHelper.php';
require_once 'helpers/ModelHelper.php';
require_once 'helpers/HTMLHelper.php';
require_once 'helpers/ApplicationHelper.php';
require_once 'models/Event.php';
require_once 'XNC/Form.php';

class EventController {

public static function process($action, $errors = null) {

switch($action) {

case 'new':
if (SecurityHelper::reportFailure(SecurityHelper::checkCurrentUserIsSignedIn())) { return; }
$form = new XNC_Form(array('month' => date('m', time()), 'day' => date('d', time()), 'year' => date('Y', time())));
include 'views/event/new.php';
break;

case 'create':
if (SecurityHelper::reportFailure(SecurityHelper::checkCurrentUserIsSignedIn())) { return; }
if ($errors = self::validate()) {
self::process('new', $errors);
return;
}
$event = XN_Content::create('Event');
self::copyPostVariablesToContentObject($event);
$event->isPrivate = TRUE;
$event->save();
self::addTags($_POST['event:tags'],$event);
header('Location:/index.php?controller=event&action=view&id=' . $event->id);
break;

case 'view':
$event = XN_Content::load(intval($_GET['id']));
$event->focus();
require_once 'models/Comment.php';
$comment = new Comment($event);
include 'views/event/view.php';
break;

case 'delete':
$event = XN_Content::load(intval($_GET['id']));
if (SecurityHelper::reportFailure(SecurityHelper::checkCurrentUserContributedOrIsAppOwner($event))) { return; }
XN_Content::delete($event);
header('Location:/index.php?controller=event&action=list');
break;

case 'edit':
$event = XN_Content::load(intval($_GET['id']));
if (SecurityHelper::reportFailure(SecurityHelper::checkCurrentUserContributedOrIsAppOwner($event))) { return; }
$form = new XNC_Form(self::formDefaults($event));
$event->focus();
$tags = HTMLHelper::popularTagsPlain($event);
include 'views/event/edit.php';
break;

case 'widgetInstructions':
include 'views/event/widgetInstructions.php';
break;

case 'update':
$event = XN_Content::load(intval($_GET['id']));
if (SecurityHelper::reportFailure(SecurityHelper::checkCurrentUserContributedOrIsAppOwner($event))) { return; }
if ($errors = self::validate()) {
self::process('edit', $errors);
return;
}
self::copyPostVariablesToContentObject($event);
$event->isPrivate = TRUE;
$event->save();
self::addTags($_POST['event:tags'],$event);
header('Location:/index.php?controller=event&action=view&id=' . $event->id);
break;

case 'list':
require_once 'XNC/Calendar.php';
$month = $_GET['month'] ? $_GET['month'] : date('m', time());
$year = $_GET['year'] ? $_GET['year'] : date('Y', time());
$previousMonth = ($month == 1) ? 12 : ($month - 1);
$previousYear = ($month == 1) ? ($year - 1) : $year;
$nextMonth = ($month == 12) ? 1 : ($month + 1);
$nextYear = ($month == 12) ? ($year + 1) : $year;
$query = XN_Query::create('Content')
->filter('owner')
->filter('type', 'eic', "Event")
->filter('my->date', '>=', ApplicationHelper::ISO8601Date($year, $month, 1), XN_Attribute::DATE)
->filter('my->date', '<', ApplicationHelper::ISO8601Date($nextYear, $nextMonth, 1), XN_Attribute::DATE);
$events = $query->;execute();
$birthdayQuery = XN_Query::create('Content')
->filter('owner')
->filter('type', 'eic', 'Person')
// Use intval to strip the leading 0 [Jon Aquino 2006-02-24]
->filter('my->parsedBirthMonth', '=', ''.intval($month));
foreach ($birthdayQuery->execute() as $person) {
$person->my->set('date', ApplicationHelper::ISO8601Date($year, $month, $person->my->parsedBirthDay), XN_Attribute::DATE);
$events []= $person;
}
$calendar = XNC_Calendar::create($month, $year, $events, 'my->date');
$monthEventCount = 0;
for ($i = 1; $i < $calendar->daysInMonth(); $i++) { $monthEventCount += count($calendar->getDayEvents($i)); }
include 'views/event/list.php';
break;

default:
throw new Exception('Unknown action: ' . $action);

}
}
private static function validate() {
$errors = ModelHelper::validate('Event');
if (ApplicationHelper::ISO8601Date($_POST['year'], $_POST['month'], $_POST['day']) === NULL) {
$errors[] = 'Date must be a valid mm/dd/yyyy date';
}
return $errors;
}
private static function copyPostVariablesToContentObject($event) {
ModelHelper::processContent(new Event(), $event);
$event->my->set('date', ApplicationHelper::ISO8601Date($_POST['year'], $_POST['month'], $_POST['day']), XN_Attribute::DATE);
}
private static function formDefaults($event) {
$defaults = ModelHelper::getDefaultsFromContent(new Event(), $event);
$defaults['year'] = gmdate('Y', strtotime($event->my->date));
$defaults['month'] = gmdate('m', strtotime($event->my->date));
// j not d -- see EXA-1569 [Jon Aquino 2006-03-13]
$defaults['day'] = gmdate('j', strtotime($event->my->date));
return $defaults;
}
private static function weekend($dayNumber) { return $dayNumber == 1 || $dayNumber == 7; }
private static function addTags($tags,$event) {
if (strlen($tags) > 0) {
try {
XN_Tag::addTags($event, $tags);
} catch (Exception $e) {
// ignore since the tag already exists
}
}
}
}
?>




Event.php


<?php

// Specify the absolute path, as this is included by scripts/api.php [Jon Aquino 2006-03-06]
require_once '/' . XN_Application::load()->relativeUrl . '/helpers/ApplicationHelper.php';

class Event {

// The variables are simply used to tell ModelHelper the names of the
// attributes in the content object (its "shape"). They are not actually
// populated. [Jon Aquino 2005-09-30]
public $title;
public $description;
public $location;
public $day;
public $month;
public $year;

public function __construct() {
$this->_rules['title'] = array('required', array('maxlength', 100));
$this->_rules['description'] = array(array('maxlength', 4000));
$this->_rules['location'] = array(array('maxlength', 100));
$this->_rules['day'] = array(array('maxlength', 2));
$this->_rules['month'] = array(array('maxlength', 2));
$this->_rules['year'] = array(array('maxlength', 4));
}

public static function currentEvents() {
$today = ApplicationHelper::ISO8601Date(date('Y', time()), date('m', time()), date('d', time()));
if ($_GET['currentEventsTestDate']) {
$currentEventsTestDate = split(',', $_GET['currentEventsTestDate']);
$today = ApplicationHelper::ISO8601Date($currentEventsTestDate[0], $currentEventsTestDate[1], $currentEventsTestDate[2]);
}
$n = 4;
$currentEvents = XN_Query::create('Content')
->filter('type','=','Event')
->filter('owner')
->filter('my->date', '>=', $today, XN_Attribute::DATE)
->end($n)
->order('my->date', 'asc', XN_Attribute::DATE)
->execute();
if (count($currentEvents) < $n) {
$recentEvents = XN_Query::create('Content')
->filter('type','=','Event')
->filter('owner')
->filter('my->date', '<', $today, XN_Attribute::DATE)
->end($n - count($currentEvents))
->order('my->date', 'desc', XN_Attribute::DATE)
->execute();
$currentEvents = array_merge(array_reverse($recentEvents), $currentEvents);
}
return $currentEvents;
}

}



event/view.php


<?php
require_once 'helpers/HTMLHelper.php';
HTMLHelper::displayErrors($errors); ?>
<h2><?php echo XN_Application::load()->name ?> Events</h2>
<form id="form" name="form" method="POST" action="/index.php?controller=event&amp;action=create&amp;">
<h3>Add your event!</h3>
<fieldset>
<dl>
<?php
include '_form.php' ?>
</dl>
</fieldset>
<p class="align-right"><input src="/images/but/addevent.gif" alt="Add Event" type="image"></p>
</form>

Sunday, March 19, 2006

Screenshot - 3_19_2006 , 10_37_17 PM.png

Screenshot - 3_19_2006 , 10_57_01 PM.png

Screenshot - 3_19_2006 , 10_54_53 PM.png

Screenshot - 3_19_2006 , 10_53_57 PM.png

Screenshot - 3_19_2006 , 10_43_46 PM.png

Screenshot - 3_19_2006 , 10_43_25 PM.png

Screenshot - 3_19_2006 , 10_36_49 PM.png

Screenshot - 3_19_2006 , 10_35_46 PM.png

Screenshot - 3_19_2006 , 10_30_56 PM.png

Screenshot - 3_19_2006 , 10_28_56 PM.png

Screenshot - 3_19_2006 , 10_25_27 PM.png

Screenshot - 3_19_2006 , 10_23_40 PM.png

Screenshot - 3_19_2006 , 10_50_31 AM.png

Screenshot - 3_19_2006 , 10_32_51 AM.png

Screenshot - 3_19_2006 , 10_22_48 AM.png

Screenshot - 3_19_2006 , 10_18_26 AM.png

Screenshot - 3_19_2006 , 10_08_26 AM.png

Screenshot - 3_19_2006 , 9_51_55 AM.png

Screenshot - 3_19_2006 , 9_14_06 AM.png

Screenshot - 3_19_2006 , 8_56_52 AM.png

Saturday, March 18, 2006

More questions from Optimal Thinking

What I value most about my home is the memories.
What I value most about memories is the connection to my childhood.
What I value most about my childhood is its freedom from stress and eagerness to make things.
I need freedom from stress, and I love inventing things.
 
What I value most about creating software is giving people powers they never had before.
I love pointing people to excellent tools (whether or not built by myself).
 
What I value most about my spiritual life is the layer of meaning it adds to life.
I need to see the meaning in life.
 
 

Friday, March 17, 2006

Denormalized CSS

I'd like to introduce the term "denormalized CSS", meaning CSS selectors with extremely low redundancy that can be combined in a multitude of semantic ways.

Wednesday, March 15, 2006

Some questions from Optimal Thinking

My favorite color is: neon blue
I look my best when: having had my hair cut, and wearing formal attire
My favorite artist is: hmm...
The sounds of nature I appreciate most are: dunno if it counts, but hearing lawnmowers on a sunny day - reminds me of childhood
My favorite music is: Imogen Heap
The funniest comedian I have heard is: Cosby show
The most cheerful person I know is: May Woo
The most comfortable chair in my home is: the swivel chair I purchased from a proper office store
I feel my best when: I have 7.5 hours of sleep. And contributed some brilliantly useful idea to the web. That lots of people are raving about :-)
The most enjoyable vacation I can recall is: Disneyland 1992
My favorite food is: fettucini alfredo
When it comes to friendship, my most positive attribute is: not giving advice when someone just wants to vent.
My greatest fantasy is: Throughout my life, to continually contribute brilliantly useful ideas to the web. That lots of people rave about :-)
The best action I can take today toward my most important goal is: reading highly acclaimed books in a variety of areas.

Sunday, March 12, 2006

idea: MindMaps as a form of prayer or meditation

Friday, March 10, 2006

realization: you don't have to wait for things to be perfect to be happy

Sunday, March 05, 2006

a talent of mine: clarifying fuzzy ideas (including untangling spagghetified flow diagrams and isolating the cause of a software problem). Naming things descriptively and with precision.

re-realization: I need to keep reading highly recommended books. Not only is this tremendously fun and satisfying -- it also sparks a ton of good ideas in my brain. I forgot that my brain excels at taking the ideas of others and combining them in new ways.

- fixed my desktop computer by moving the NIC to a different slot and reinstalling the drivers from the CD
 
books to read (yum!)
- Mapping Inner Space
- Lessons Learned In Software Testing
- Optimal Thinking
- The Secret of Staying in Love
- The Non-Designer's Design Book
- Joel on Software
- In Search of Stupidity