$iterators)
{
foreach($iterators as $iterator)
{
foreach ($iterator as $fileinfo)
{
if (!$fileinfo->isDot())
{
if(substr($fileinfo->getFilename(),0,1) == '.')
continue;
$filename = explode('.',$fileinfo->getFilename());
$classname = $type.'_'.$filename[0];
if(!class_exists($classname))
continue;
$this->pool_classes[$classname] = new $classname();//::getInstance();
foreach($this->pool_classes[$classname]->get_events() as $event)
$this->bind($event,$classname);
if($type === 'notify' && $this->pool_classes[$classname]->is_avalaible())
$this->notifications[] = $classname;
}
}
}
}
return;
}
/**
* @return eventsmanager
*/
public static function getInstance()
{
if(!self::$_instance)
{
self::$_instance = new self();
}
return self::$_instance;
}
function trigger($event,$array_params=array(),&$object = false)
{
if(array_key_exists($event, $this->events))
{
foreach($this->events[$event] as $classname)
{
$this->pool_classes[$classname]->fire($event,$array_params,$object);
}
}
return;
}
function bind($event, $object_name)
{
if(!array_key_exists($event, $this->events))
$this->events[$event] = array();
$this->events[$event][] = $object_name;
}
function notify($usr_id, $event_type, $datas, $mailed=false)
{
$conn = connection::getInstance();
$sql = 'INSERT INTO notifications (id, usr_id, type, unread, mailed, datas, created_on) VALUES
(null, "'.$conn->escape_string($usr_id).'","'.$conn->escape_string($event_type).'","'.$conn->escape_string(1).'"
,"'.$conn->escape_string($mailed ? 1:0).'","'.$conn->escape_string($datas).'",NOW())';
return $conn->query($sql) ? true : false;
}
function get_json_notifications($page=0)
{
$conn = connection::getInstance();
$session = session::getInstance();
$unread = 0;
$total = 0;
$sql = 'SELECT count(id) as total, sum(unread) as unread FROM notifications WHERE usr_id="'.$session->usr_id.'"';
if($rs = $conn->query($sql))
{
if($row = $conn->fetch_assoc($rs))
{
$unread = $row['unread'];
$total = $row['total'];
}
$conn->free_result($rs);
}
$n = 10;
$sql = 'SELECT * FROM notifications WHERE usr_id="'.$session->usr_id.'" ORDER BY created_on DESC LIMIT '.((int)$page * $n).', '.$n;
$datas = array('notifications'=>array(),'next'=>'');
if($rs = $conn->query($sql))
{
while($row = $conn->fetch_assoc($rs))
{
$data = $this->pool_classes[$row['type']]->datas($row['datas'],$row['unread']);
if(!isset($this->pool_classes[$row['type']]))
{
$sql = 'DELETE FROM notifications WHERE id="'.$row['id'].'"';
$conn->query($sql);
continue;
}
$date_key = str_replace('-','_',substr($row['created_on'],0,10));
$display_date = phraseadate::getDate(new DateTime($row['created_on']));
if(!isset($datas['notifications'][$date_key]))
{
$datas['notifications'][$date_key] = array(
'display' => $display_date
,'notifications' => array()
);
}
$datas['notifications'][$date_key]['notifications'][$row['id']] = array(
'classname' => $data['class']
,'time' => phraseadate::getTime(new DateTime($row['created_on']))
,'icon' => ''
,'id' => $row['id']
,'text' => $data['text']
);
// $html = '
'.
// ' | '. // $html. // ' |
'. $datas['text'].' '.phraseadate::getPrettyString(new DateTime($row['created_on'])).'
'; $bloc[] = ''.
' | '. $html. ' |