From teste, 6 Years ago, written in Plain Text.
Embed
  1. <?php
  2. /**
  3.  * MessageList
  4.  *
  5.  * @version    1.0
  6.  * @package    control
  7.  * @author     Pablo Dall'Oglio
  8.  * @copyright  Copyright (c) 2006 Adianti Solutions Ltd. (http://www.adianti.com.br)
  9.  * @license    http://www.adianti.com.br/framework-license
  10.  */
  11. class MessageList extends TElement
  12. {
  13.     public function __construct($param)
  14.     {
  15.         parent::__construct('ul');
  16.        
  17.         try
  18.         {
  19.             TTransaction::open('communication');
  20.            
  21.             // load the messages to the logged user
  22.             $system_messages = SystemMessage::where('checked', '=', 'N')->where('system_user_to_id', '=', TSession::getValue('userid'))->orderBy('id', 'desc')->load();
  23.            
  24.             if ($param['theme'] == 'theme2')
  25.             {
  26.                 $this->class = 'dropdown-menu dropdown-messages';
  27.                
  28.                 $a = new TElement('a');
  29.                 $a->{'class'} = "dropdown-toggle";
  30.                 $a->{'data-toggle'}="dropdown";
  31.                 $a->{'href'} = "#";
  32.                
  33.                 $a->add( TElement::tag('i',    '', array('class'=>"fa fa-envelope fa-fw")) );
  34.                 $a->add( TElement::tag('span', count($system_messages), array('class'=>"badge badge-notify")) );
  35.                 $a->add( TElement::tag('i',    '', array('class'=>"fa fa-caret-down")) );
  36.                 $a->show();
  37.                
  38.                 TTransaction::open('permission');
  39.                 foreach ($system_messages as $system_message)
  40.                 {
  41.                     $name    = SystemUser::find($system_message->system_user_id)->name;
  42.                     $date    = $this->getShortPastTime($system_message->dt_message);
  43.                     $subject = $system_message->subject;
  44.                    
  45.                     $li  = new TElement('li');
  46.                     $a   = new TElement('a');
  47.                     $div = new TElement('div');
  48.                    
  49.                     $a->href = 'index.php?class=SystemMessageFormView&method=onView&id='.$system_message->id;
  50.                     $a->generator = 'adianti';
  51.                     $li->add($a);
  52.                     $a->add($div);
  53.                     $div->add( TElement::tag('strong', $name) );
  54.                     $div->add( TElement::tag('span', TElement::tag('em', $date), array('class' => 'pull-right text-muted') ) );
  55.                    
  56.                     $div2 = new TElement('div');
  57.                     $div2->add($subject);
  58.                     $a->add($div2);
  59.                    
  60.                     parent::add($li);
  61.                     parent::add( TElement::tag('li', '', array('class' => 'divider') ) );
  62.                 }
  63.                 TTransaction::close();
  64.                
  65.                 $li = new TElement('li');
  66.                 $a = new TElement('a');
  67.                 $li->add($a);
  68.                 $a->class='text-center';
  69.                 $a->href = 'index.php?class=SystemMessageList&method=filterInbox';
  70.                 $a->generator = 'adianti';
  71.                 $a->add( TElement::tag('strong', _t('Read messages')) );
  72.                 $a->add( $i = TElement::tag('i', '', array('class'=>'fa fa-inbox') ));
  73.                 parent::add($li);
  74.                
  75.                 parent::add( TElement::tag('li', '', array('class' => 'divider') ) );
  76.                
  77.                 $li = new TElement('li');
  78.                 $a = new TElement('a');
  79.                 $li->add($a);
  80.                 $a->class='text-center';
  81.                 $a->href = 'index.php?class=SystemMessageForm';
  82.                 $a->generator = 'adianti';
  83.                 $a->add( TElement::tag('strong', _t('Send message')) );
  84.                 $a->add( $i = TElement::tag('i', '', array('class'=>'fa fa-envelope-o') ));
  85.                 parent::add($li);
  86.             }
  87.             else if ($param['theme'] == 'theme3')
  88.             {
  89.                 $this->class = 'dropdown-menu';
  90.                
  91.                 $a = new TElement('a');
  92.                 $a->{'class'} = "dropdown-toggle";
  93.                 $a->{'data-toggle'}="dropdown";
  94.                 $a->{'href'} = "#";
  95.                
  96.                 $a->add( TElement::tag('i',    '', array('class'=>"fa fa-envelope fa-fw")) );
  97.                 $a->add( TElement::tag('span', count($system_messages), array('class'=>"label label-success")) );
  98.                 $a->show();
  99.                
  100.                 $li_master = new TElement('li');
  101.                 $ul_wrapper = new TElement('ul');
  102.                 $ul_wrapper->{'class'} = 'menu';
  103.                 $li_master->add($ul_wrapper);
  104.                
  105.                 parent::add( TElement::tag('li', _t('Messages'), ['class'=>'header']));
  106.                 parent::add($li_master);
  107.                
  108.                 TTransaction::open('permission');
  109.                 foreach ($system_messages as $system_message)
  110.                 {
  111.                     $name    = SystemUser::find($system_message->system_user_id)->name;
  112.                     $date    = $this->getShortPastTime($system_message->dt_message);
  113.                     $subject = $system_message->subject;
  114.                    
  115.                     $li  = new TElement('li');
  116.                     $a   = new TElement('a');
  117.                     $div = new TElement('div');
  118.                    
  119.                     $a->href = 'index.php?class=SystemMessageFormView&method=onView&id='.$system_message->id;
  120.                     $a->generator = 'adianti';
  121.                     $li->add($a);
  122.                    
  123.                     $div->{'class'} = 'pull-left';
  124.                     $div->add( TElement::tag('i', '', array('class' => 'fa fa-user fa-2x') ) );
  125.                    
  126.                     $h4 = new TElement('h4');
  127.                     $h4->add( $name );
  128.                     $h4->add( TElement::tag('small', TElement::tag('i', $date, array('class' => 'fa fa-clock-o') ) ) );
  129.                    
  130.                     $a->add($div);
  131.                     $a->add($h4);
  132.                     $a->add( TElement::tag('p', $subject) );
  133.                    
  134.                     $ul_wrapper->add($li);
  135.                 }
  136.                
  137.                 TTransaction::close();
  138.                
  139.                 parent::add(TElement::tag('li', TElement::tag('a', _t('Read messages'), array('href'=>'index.php?class=SystemMessageList&method=filterInbox', 'generator'=>'adianti') ), array('class'=>'footer')));
  140.                 parent::add(TElement::tag('li', TElement::tag('a', _t('Send message'), array('href'=>'index.php?class=SystemMessageForm', 'generator'=>'adianti') ), array('class'=>'footer')));
  141.             }
  142.             else if ($param['theme'] == 'theme4')
  143.             {
  144.                 $this->class = 'dropdown-menu';
  145.                
  146.                 $a = new TElement('a');
  147.                 $a->{'class'} = "dropdown-toggle";
  148.                 $a->{'data-toggle'}="dropdown";
  149.                 $a->{'href'} = "#";
  150.                
  151.                 $a->add( TElement::tag('i',    'email', array('class'=>"material-icons")) );
  152.                 $a->add( TElement::tag('span', count($system_messages), array('class'=>"label-count")) );
  153.                 $a->show();
  154.                
  155.                 $li_master = new TElement('li');
  156.                 $ul_wrapper = new TElement('ul');
  157.                 $ul_wrapper->{'class'} = 'menu';
  158.                 $ul_wrapper->{'style'} = 'list-style:none';
  159.                 $li_master->{'class'} = 'body';
  160.                 $li_master->add($ul_wrapper);
  161.                
  162.                 parent::add( TElement::tag('li', _t('Messages'), ['class'=>'header']));
  163.                 parent::add($li_master);
  164.                
  165.                 TTransaction::open('permission');
  166.                 foreach ($system_messages as $system_message)
  167.                 {
  168.                     $name    = SystemUser::find($system_message->system_user_id)->name;
  169.                     $date    = $this->getShortPastTime($system_message->dt_message);
  170.                     $subject = $system_message->subject;
  171.                    
  172.                     $li  = new TElement('li');
  173.                     $a   = new TElement('a');
  174.                     $div = new TElement('div');
  175.                     $div2= new TElement('div');
  176.                    
  177.                     $a->href = 'index.php?class=SystemMessageFormView&method=onView&id='.$system_message->id;
  178.                     $a->class = 'waves-effect waves-block';
  179.                     $a->generator = 'adianti';
  180.                     $li->add($a);
  181.                    
  182.                     $div->{'class'} = 'icon-circle bg-light-green';
  183.                     $div2->{'class'} = 'menu-info';
  184.                    
  185.                     $div->add( TElement::tag('i', '', array('class' => 'fa fa-user fa-2x') ) );
  186.                    
  187.                     $h4 = new TElement('h4');
  188.                     $h4->add( $name );
  189.                     $h4->add( $subject );
  190.                    
  191.                     $div2->add($h4);
  192.                     $a->add($div);
  193.                     $a->add($div2);
  194.                    
  195.                     $p = new TElement('p');
  196.                     $p->add( TElement::tag('i', 'access_time', ['class' => 'material-icons']) );
  197.                     $p->add( $date );
  198.                    
  199.                     $div2->add( $p );
  200.                     $ul_wrapper->add($li);
  201.                 }
  202.                
  203.                 TTransaction::close();
  204.                
  205.                 parent::add(TElement::tag('li', TElement::tag('a', _t('Read messages'), array('href'=>'index.php?class=SystemMessageList&method=filterInbox', 'generator'=>'adianti') ), array('class'=>'footer')));
  206.                 parent::add(TElement::tag('li', TElement::tag('a', _t('Send message'), array('href'=>'index.php?class=SystemMessageForm', 'generator'=>'adianti') ), array('class'=>'footer')));
  207.             }
  208.            
  209.             TTransaction::close();
  210.         }
  211.         catch (Exception $e)
  212.         {
  213.             new TMessage('error', $e->getMessage());
  214.         }
  215.     }
  216.    
  217.     public function getShortPastTime($from)
  218.     {
  219.         $to = date('Y-m-d H:i:s');
  220.         $start_date = new DateTime($from);
  221.         $since_start = $start_date->diff(new DateTime($to));
  222.         if ($since_start->y > 0)
  223.             return $since_start->y.' years ';
  224.         if ($since_start->m > 0)
  225.             return $since_start->m.' months ';
  226.         if ($since_start->d > 0)
  227.             return $since_start->d.' days ';
  228.         if ($since_start->h > 0)
  229.             return $since_start->h.' hours ';
  230.         if ($since_start->i > 0)
  231.             return $since_start->i.' minutes ';
  232.         if ($since_start->s > 0)
  233.             return $since_start->s.' seconds ';    
  234.     }
  235. }
  236.