コード例 #1
0
ファイル: ProgressBar.php プロジェクト: myclabs/muih
 /**
  * @param float $percent 0 <= percent <= 100.
  * @param string $type
  * @param string $content
  */
 public function __construct($percent, $type = self::TYPE_DEFAULT, $content = null)
 {
     if ($percent > 100) {
         $percent = 100;
     }
     if ($percent < 0) {
         $percent = 0;
     }
     $this->addClass('progress');
     if (empty($content)) {
         $content = new GenericTag('span');
         $content->addClass('sr-only');
         $content->setContent($percent . '%');
     }
     $this->content = new GenericTag('div');
     $this->content->addClass('progress-bar');
     if (!in_array($type, $this->types)) {
         $type = self::TYPE_DEFAULT;
     }
     if ($type !== self::TYPE_DEFAULT) {
         $this->content->addClass('progress-bar-' . $type);
     }
     $this->content->setAttribute('role', 'progress');
     $this->content->setAttribute('aria-valuenow', $percent);
     $this->content->setAttribute('aria-valuemin', 0);
     $this->content->setAttribute('aria-valuemax', 100);
     $this->content->setAttribute('style', 'width="' . $percent . '%"');
     parent::__construct('div', $content);
 }