Advertisement
Guest User

Untitled

a guest
Feb 20th, 2020
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.20 KB | None | 0 0
  1. class Widget
  2. {
  3.     protected $title;
  4.     protected $value
  5.     protected $total;
  6.  
  7.     public function getType()
  8.     {
  9.         return 'widget';
  10.     }
  11. }
  12.  
  13. class BarWidget extends Widget
  14. {
  15.     public function getType()
  16.     {
  17.         return 'bar';
  18.     }
  19. }
  20.  
  21. class CircleWidget extends Widget
  22. {
  23.     protected $radius;
  24.     protected $stroke;
  25.     protected $duration;
  26.  
  27.     public function getType()
  28.     {
  29.         return 'circle';
  30.     }
  31. }
  32.  
  33. class WidgetRenderer
  34. {
  35.     public function render(array $widgets)
  36.     {
  37.         $output = [];
  38.  
  39.         foreach ($widgets as $widget) {
  40.             $output[] = [
  41.                 'type' => $widget->getType(),
  42.                 'title' => $widget->getTitle(),
  43.                 ...
  44.             ];
  45.         }
  46.  
  47.         return $output;
  48.     }
  49. }
  50.  
  51. $bar = new Bar();
  52. $bar->setTitle("Conversion rate {$repData->getKitActivationsAllTime()}/{$repData->getKitSetupsAllTime()}");
  53. $bar->setValue($repData->getKitActivationsAllTime());
  54.  
  55. $circle = new Circle();
  56. $circle->setTitle('Visits today');
  57. $circle->setValue($repData->getVisitsCountToday());
  58.  
  59. $widgets = [
  60.     $bar,
  61.     $circle,
  62. ];
  63.  
  64. $renderer = new WidgetRenderer();
  65. $renderer->render($widgets); // JSON
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement