2011-01-16 13:51:39 -08:00
|
|
|
<?php
|
|
|
|
|
|
|
|
final class AphrontErrorView extends AphrontView {
|
|
|
|
|
2011-02-05 16:43:28 -08:00
|
|
|
const SEVERITY_ERROR = 'error';
|
|
|
|
const SEVERITY_WARNING = 'warning';
|
2011-02-05 22:36:21 -08:00
|
|
|
const SEVERITY_NOTICE = 'notice';
|
2012-02-27 19:21:41 -08:00
|
|
|
const SEVERITY_NODATA = 'nodata';
|
2011-02-05 16:43:28 -08:00
|
|
|
|
2011-01-16 13:51:39 -08:00
|
|
|
private $title;
|
|
|
|
private $errors;
|
2011-02-05 16:43:28 -08:00
|
|
|
private $severity;
|
2011-06-09 18:56:47 -07:00
|
|
|
private $id;
|
2013-01-26 17:14:58 -08:00
|
|
|
private $insideDialogue;
|
|
|
|
|
|
|
|
public function setInsideDialogue($inside_dialogue) {
|
|
|
|
$this->insideDialogue = $inside_dialogue;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
public function getInsideDialogue() {
|
|
|
|
return $this->insideDialogue;
|
|
|
|
}
|
2011-01-16 13:51:39 -08:00
|
|
|
|
|
|
|
public function setTitle($title) {
|
|
|
|
$this->title = $title;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
2011-02-05 16:43:28 -08:00
|
|
|
public function setSeverity($severity) {
|
|
|
|
$this->severity = $severity;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
2011-01-16 13:51:39 -08:00
|
|
|
public function setErrors(array $errors) {
|
|
|
|
$this->errors = $errors;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
2011-06-09 18:56:47 -07:00
|
|
|
public function setID($id) {
|
|
|
|
$this->id = $id;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
2013-01-26 17:14:58 -08:00
|
|
|
private function getBaseClass() {
|
|
|
|
if ($this->getInsideDialogue()) {
|
|
|
|
$class = 'aphront-error-view-dialogue';
|
|
|
|
} else {
|
|
|
|
$class = 'aphront-error-view';
|
|
|
|
}
|
|
|
|
return $class;
|
|
|
|
}
|
|
|
|
|
2011-01-16 13:51:39 -08:00
|
|
|
final public function render() {
|
|
|
|
|
2011-02-05 16:43:28 -08:00
|
|
|
require_celerity_resource('aphront-error-view-css');
|
|
|
|
|
2011-01-16 13:51:39 -08:00
|
|
|
$errors = $this->errors;
|
|
|
|
if ($errors) {
|
|
|
|
$list = array();
|
|
|
|
foreach ($errors as $error) {
|
2013-01-17 18:43:35 -08:00
|
|
|
$list[] = phutil_tag(
|
2011-01-16 13:51:39 -08:00
|
|
|
'li',
|
|
|
|
array(),
|
2013-01-17 18:43:35 -08:00
|
|
|
$error);
|
2011-01-16 13:51:39 -08:00
|
|
|
}
|
2013-01-18 00:32:58 -08:00
|
|
|
$list = phutil_tag(
|
2012-09-11 09:55:27 -07:00
|
|
|
'ul',
|
|
|
|
array(
|
|
|
|
'class' => 'aphront-error-view-list',
|
|
|
|
),
|
2013-01-18 00:32:58 -08:00
|
|
|
$list);
|
2011-01-16 13:51:39 -08:00
|
|
|
} else {
|
|
|
|
$list = null;
|
|
|
|
}
|
|
|
|
|
|
|
|
$title = $this->title;
|
|
|
|
if (strlen($title)) {
|
2013-01-17 18:43:35 -08:00
|
|
|
$title = phutil_tag(
|
2012-09-11 09:55:27 -07:00
|
|
|
'h1',
|
|
|
|
array(
|
|
|
|
'class' => 'aphront-error-view-head',
|
|
|
|
),
|
2013-01-17 18:43:35 -08:00
|
|
|
$title);
|
2011-01-16 13:51:39 -08:00
|
|
|
} else {
|
|
|
|
$title = null;
|
|
|
|
}
|
|
|
|
|
2011-02-05 16:43:28 -08:00
|
|
|
$this->severity = nonempty($this->severity, self::SEVERITY_ERROR);
|
|
|
|
|
2013-01-26 17:14:58 -08:00
|
|
|
$classes = array();
|
|
|
|
$classes[] = $this->getBaseClass();
|
|
|
|
$classes[] = 'aphront-error-severity-'.$this->severity;
|
|
|
|
$classes = implode(' ', $classes);
|
2011-02-05 16:43:28 -08:00
|
|
|
|
2013-02-06 16:53:49 -08:00
|
|
|
$children = $this->renderHTMLChildren();
|
|
|
|
$children[] = $list;
|
|
|
|
|
|
|
|
return phutil_tag(
|
2012-10-16 09:44:43 -07:00
|
|
|
'div',
|
|
|
|
array(
|
|
|
|
'id' => $this->id,
|
2013-01-26 17:14:58 -08:00
|
|
|
'class' => $classes,
|
2012-10-16 09:44:43 -07:00
|
|
|
),
|
2013-01-18 00:32:58 -08:00
|
|
|
array(
|
|
|
|
$title,
|
2013-02-06 16:53:49 -08:00
|
|
|
phutil_tag(
|
2013-01-18 00:32:58 -08:00
|
|
|
'div',
|
|
|
|
array(
|
|
|
|
'class' => 'aphront-error-view-body',
|
|
|
|
),
|
2013-02-06 16:53:49 -08:00
|
|
|
$children),
|
2013-01-18 00:32:58 -08:00
|
|
|
));
|
2011-01-16 13:51:39 -08:00
|
|
|
}
|
|
|
|
}
|