contributions/confirmations/behaviour/base/confirmationhandler.base.php
Go to the documentation of this file.00001 <?php 00002 /** 00003 * Base class for handling confirmation requests 00004 * 00005 * @author Gerd Riesselmann 00006 * @ingroup Confirmations 00007 */ 00008 class ConfirmationHandlerBase implements IConfirmationHandler { 00009 const SUCCESS = 'SUCCESS'; 00010 const EXPIRED = 'EXPIRED'; 00011 const NOTFOUND = 'NOTFOUND'; 00012 00013 /** 00014 * The confirmation to work upon 00015 * 00016 * @var DAOConfirmation 00017 */ 00018 protected $confirmation = null; 00019 00020 /** 00021 * Constructor 00022 * 00023 * @param DAOConfirmations 00024 */ 00025 public function __construct($confirmation) { 00026 $this->confirmation = $confirmation; 00027 } 00028 00029 /** 00030 * Confirm a Confirmation 00031 * 00032 * Invokes do_confirm(), which should be overloaded by subclasses 00033 * 00034 * @return Status 00035 */ 00036 public function confirm() { 00037 $confirmation = $this->confirmation; 00038 $success = self::NOTFOUND; 00039 if ($confirmation) { 00040 $success = $confirmation->expirationdate > time() ? self::SUCCESS : self::EXPIRED; 00041 $temp = clone($confirmation); 00042 $temp->delete(); 00043 } 00044 return $this->do_confirm($confirmation, $success); 00045 } 00046 00047 /** 00048 * Template method to be overloaded by subclasses to do what should be done 00049 * on successfull confirmation 00050 * 00051 * @param DAOConfirmations Data of confirmation, not necessarily up to date, depending on status 00052 * @param enum Indicates success or failure 00053 * @return Status 00054 */ 00055 protected function do_confirm($confirmation, $success) { 00056 switch ($success) { 00057 case self::SUCCESS: 00058 return new Message(tr('Your request was confirmed', 'confirmations')); 00059 case self::EXPIRED: 00060 return new Status(tr('Your request has already expired and could not be confirmed', 'confirmations')); 00061 default: 00062 return new Status(tr('No confirmations found for your request', 'confirmations')); 00063 } 00064 } 00065 00066 /** 00067 * Invoked when this confirmation is created 00068 * 00069 * INvokes do_created(), which should be overloaded by subclasses 00070 * 00071 * @return Status 00072 */ 00073 public function created() { 00074 $confirmation = $this->confirmation; 00075 if ($confirmation) { 00076 return $this->do_created($confirmation); 00077 } 00078 return new Status('Confirmation missing in creation. Wrong Confirmation Handler name?'); 00079 } 00080 00081 /** 00082 * Template method to be overloaded by subclasses to do what should be done 00083 * on creation 00084 * 00085 * @param DAOConfirmations Data of confirmation 00086 * @return Status 00087 * 00088 */ 00089 protected function do_created($confirmation) { 00090 return new Status(); 00091 } 00092 }