2011-01-16 22:51:39 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
final class AphrontErrorView extends AphrontView {
|
|
|
|
|
2011-02-06 01:43:28 +01:00
|
|
|
const SEVERITY_ERROR = 'error';
|
|
|
|
const SEVERITY_WARNING = 'warning';
|
2011-02-06 07:36:21 +01:00
|
|
|
const SEVERITY_NOTICE = 'notice';
|
2012-02-28 04:21:41 +01:00
|
|
|
const SEVERITY_NODATA = 'nodata';
|
2011-02-06 01:43:28 +01:00
|
|
|
|
2011-01-16 22:51:39 +01:00
|
|
|
private $title;
|
|
|
|
private $errors;
|
2011-02-06 01:43:28 +01:00
|
|
|
private $severity;
|
2011-06-10 03:56:47 +02:00
|
|
|
private $id;
|
2011-01-16 22:51:39 +01:00
|
|
|
|
|
|
|
public function setTitle($title) {
|
|
|
|
$this->title = $title;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
2011-02-06 01:43:28 +01:00
|
|
|
public function setSeverity($severity) {
|
|
|
|
$this->severity = $severity;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
2011-01-16 22:51:39 +01:00
|
|
|
public function setErrors(array $errors) {
|
|
|
|
$this->errors = $errors;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
2011-06-10 03:56:47 +02:00
|
|
|
public function setID($id) {
|
|
|
|
$this->id = $id;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
2011-01-16 22:51:39 +01:00
|
|
|
final public function render() {
|
|
|
|
|
2011-02-06 01:43:28 +01:00
|
|
|
require_celerity_resource('aphront-error-view-css');
|
|
|
|
|
2011-01-16 22:51:39 +01:00
|
|
|
$errors = $this->errors;
|
|
|
|
if ($errors) {
|
|
|
|
$list = array();
|
|
|
|
foreach ($errors as $error) {
|
2013-01-18 03:43:35 +01:00
|
|
|
$list[] = phutil_tag(
|
2011-01-16 22:51:39 +01:00
|
|
|
'li',
|
|
|
|
array(),
|
2013-01-18 03:43:35 +01:00
|
|
|
$error);
|
2011-01-16 22:51:39 +01:00
|
|
|
}
|
2012-09-11 18:55:27 +02:00
|
|
|
$list = phutil_render_tag(
|
|
|
|
'ul',
|
|
|
|
array(
|
|
|
|
'class' => 'aphront-error-view-list',
|
|
|
|
),
|
|
|
|
implode("\n", $list));
|
2011-01-16 22:51:39 +01:00
|
|
|
} else {
|
|
|
|
$list = null;
|
|
|
|
}
|
|
|
|
|
|
|
|
$title = $this->title;
|
|
|
|
if (strlen($title)) {
|
2013-01-18 03:43:35 +01:00
|
|
|
$title = phutil_tag(
|
2012-09-11 18:55:27 +02:00
|
|
|
'h1',
|
|
|
|
array(
|
|
|
|
'class' => 'aphront-error-view-head',
|
|
|
|
),
|
2013-01-18 03:43:35 +01:00
|
|
|
$title);
|
2011-01-16 22:51:39 +01:00
|
|
|
} else {
|
|
|
|
$title = null;
|
|
|
|
}
|
|
|
|
|
2011-02-06 01:43:28 +01:00
|
|
|
$this->severity = nonempty($this->severity, self::SEVERITY_ERROR);
|
|
|
|
|
|
|
|
$more_classes = array();
|
|
|
|
$more_classes[] = 'aphront-error-severity-'.$this->severity;
|
|
|
|
$more_classes = implode(' ', $more_classes);
|
|
|
|
|
2012-10-16 18:44:43 +02:00
|
|
|
return phutil_render_tag(
|
|
|
|
'div',
|
|
|
|
array(
|
|
|
|
'id' => $this->id,
|
|
|
|
'class' => 'aphront-error-view '.$more_classes,
|
|
|
|
),
|
|
|
|
$title.
|
2011-06-10 03:56:47 +02:00
|
|
|
phutil_render_tag(
|
|
|
|
'div',
|
|
|
|
array(
|
2012-10-16 18:44:43 +02:00
|
|
|
'class' => 'aphront-error-view-body',
|
2011-06-10 03:56:47 +02:00
|
|
|
),
|
2012-10-16 18:44:43 +02:00
|
|
|
$this->renderChildren().
|
|
|
|
$list));
|
2011-01-16 22:51:39 +01:00
|
|
|
}
|
|
|
|
}
|