Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Class Members | File Members | Related Pages

base-user-action.inc.php

Go to the documentation of this file.
00001 <?
00011 class BaseUserAction extends MyObject
00012 {
00018     public static $actions = array(
00019         'high_five' => '/lib/img/actions/highfive.gif',
00020         'holler' => '/lib/img/actions/holler.gif',
00021         'hug' => '/lib/img/actions/hug.gif',
00022         'kiss' => '/lib/img/actions/kiss.gif',
00023         'laugh' => '/lib/img/actions/laugh.gif',
00024         'poke' => '/lib/img/actions/poke.gif',
00025         'slap' => '/lib/img/actions/slap.gif',
00026         'thumbs_down' => '/lib/img/actions/thumbsdown.gif',
00027         'thumbs_up' => '/lib/img/actions/thumbsup.gif',
00028         'wave' => '/lib/img/actions/wave.gif',
00029         'wink' => '/lib/img/actions/wink.gif',
00030         'yawn' => '/lib/img/actions/yawn.gif',
00031     );
00032     
00039     public function __construct($data = null, $table = 'user_actions')
00040     {
00041         parent::__construct($data, $table);
00042 
00043         $this->english = 'action';
00044     }
00045 
00051     public function drawActionsBox($user)
00052     {
00053         echo "<div class=\"userActions\">\n";
00054         echo "<div id=\"userActionText\">Give " . $user->getName(true) . " a ...</div>";
00055         foreach (self::$actions AS $action => $img)
00056             echo $this->getLink(".doaction?action=$action&id=$user->id", "<img src=\"$img\" alt=\"" . self::cleanAction($action) . "\">");
00057         echo "</div>";
00058     }
00059 
00066     public static function cleanAction($action)
00067     {
00068         $action = str_replace("_", " ", $action);
00069     
00070         return $action;
00071     }
00072     
00076     protected function getDeletePageXml()
00077     {
00078         return '';
00079     }
00080     
00084     protected function getEditPageXml()
00085     {
00086         return '';
00087     }
00088 
00095     public function getPagesXml()
00096     {
00097         $xml = parent::getPagesXml();
00098 
00099         $actions = '';
00100         foreach (self::$actions AS $action => $img)
00101             $actions .= "<option value=\"$action\"/>";
00102 
00103         $xml .= "
00104             <page name=\"doaction\">
00105                 <param name=\"id\" type=\"int\" required=\"1\"/>
00106                 <param name=\"action\" required=\"1\">
00107                     $actions
00108                 </param>
00109             </page>
00110             <page name=\"message\">
00111                 <param name=\"id\" type=\"int\" required=\"1\"/>
00112             </page>
00113         ";
00114 
00115         return $xml;
00116     }
00117 
00121     public function initDoActionPage()
00122     {
00123         global $me;
00124         
00125         $this->assertLogin();
00126 
00127         if ($me->id == $this->params('id'))
00128             throw new PageError('You cannot give something to yourself... on Ubersonic.');
00129 
00130         $this->pageTitle = 'Do an Action';
00131     }
00132 
00136     public function drawDoActionPage()
00137     {
00138         global $me;
00139         
00140         //save our action
00141         $this->sender_id = $me->id;
00142         $this->recipient_id = $this->params('id');
00143         $this->action = $this->params('action');
00144         $this->save();
00145 
00146         //draw our notifiction
00147         $user = new User($this->params('id'));
00148         echo "<p>You gave " . $user->getName(true) . " a <b>" . self::cleanAction($this->action) . "</b>.</p>";
00149 
00150         //add an alert!
00151         $user->addAlert($this->getUrl(".view?id=$this->id"), $me->getName() . " gave you a " . self::cleanAction($this->action));
00152 
00153         //draw the reason form
00154         $form = $this->createMessageForm();
00155         $form->draw();
00156     }
00157 
00161     public function initMessagePage()
00162     {
00163         global $me;
00164 
00165         $this->assertLogin();
00166         $this->id = $this->params('id');
00167 
00168         if ($this->sender_id != $me->id)
00169             throw new PageError('You can only add a message to an action you sent!');
00170 
00171         $this->pageTitle = "Attach Message";
00172     }
00173 
00177     public function drawMessagePage()
00178     {
00179         $form = $this->createMessageForm();
00180         if ($form->isSubmittedAndValid())
00181         {
00182             $this->message = $form->getData('message');
00183             $this->save();
00184 
00185             echo "<p>Your message has been added.</p>";
00186         }
00187         
00188         $form->drawIfNeeded();
00189     }
00190 
00196     public function createMessageForm()
00197     {
00198         $form = new Form();
00199         $form->action = $this->getUrl(".message?id=$this->id");
00200 
00201         $form->add('LabelField', 'help', array(
00202             'title' => '',
00203             'text' => 'Attach a message below to go along with your action.'
00204         ));
00205         $form->add('TextField', 'message', array(
00206             'title' => '',
00207             'width' => '100%'
00208         ));
00209 
00210         $form->addSubmit('Add Message');
00211 
00212         return $form;
00213     }
00214 
00220     public function canView()
00221     {
00222         global $me;
00223         
00224         return ($this->recipient_id == $me->id);
00225     }
00226 
00230     public function initViewPage()
00231     {
00232         $this->assertLogin();
00233 
00234         parent::initViewPage();
00235 
00236         $this->pageTitle = 'View Action';
00237     }
00238 
00243     public function drawViewPage()
00244     {
00245         //draw oour message
00246         echo $this->getMessage();
00247         
00248         //self destruct
00249         echo "<p><b>Note: this message will self-destruct after you leave this page.</b></p>";
00250         $this->delete();
00251 
00252         //continue the cycle... =)
00253         echo "<h3>Respond!</h3>";
00254         $sender = new User($this->sender_id);
00255         $this->drawActionsBox($sender);
00256     }
00257 
00261     public function drawRow()
00262     {
00263         //draw oour message
00264         echo $this->getMessage() . " - " . $this->getLink(".view?id=$this->id", "View / Respond");
00265     }
00266 
00272     public function getMessage()
00273     {
00274         $sender = new User($this->sender_id);
00275         
00276         //draw our action
00277         $s = "<p>" . $sender->getName(true) . " gave you a <b>" . self::cleanAction($this->action) . "</b>";
00278         if ($this->message)
00279             $s .= " and said, \"<i>" . Linkify::bbcode($this->message) . "</i>\"";
00280     
00281         return $s;
00282     }
00283 
00287     public function getRssItem()
00288     {
00289         $item = parent::getRssItem();
00290 
00291         $item->title = self::CleanAction($this->action);
00292         $item->description = $this->getMessage(); 
00293     
00294         return $item;
00295     }
00296     
00300     public function getPublicData()
00301     {
00302         $item = parent::getPublicData();
00303         
00304         $sender = new User($this->sender_id);
00305         
00306         $item['action']= self::CleanAction($this->action);
00307         $item['message'] = $this->message; 
00308         $item['full'] = $this->getMessage();
00309         $item['sender'] = $sender->getName();
00310         $item['sender_id'] = $sender->getName();
00311 
00312         return $sender;
00313     }
00314 
00318     public function getCreateFieldsArray()
00319     {
00320         $arr = parent::getCreateFieldsArray();
00321 
00322         unset($arr['edit_date']);
00323         unset($arr['user_id']);
00324     
00325         $arr['sender_id'] = "sender_id int(11) default 0 not null";
00326         $arr['recipient_id'] = "recipient_id int(11) default 0 not null";
00327         $arr['action'] = "action varchar(64) default '' not null";
00328         $arr['message'] = "message varchar(255) default '' not null";
00329 
00330         return $arr;
00331     }
00332 
00336     public function getCreateIndexesArray()
00337     {
00338         $arr = parent::getCreateIndexesArray();
00339 
00340         unset($arr['edit_date']);
00341         unset($arr['user_id']);
00342 
00343         $arr['sender_id'] = "key(sender_id)";
00344         $arr['recipient_id'] = "key(recipient_id)";
00345     
00346         return $arr;
00347     }
00348 }
00349 ?>

Generated on Fri Oct 27 12:26:40 2006 for BaseJumper by doxygen 1.3.9.1