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;
|
2013-01-27 02:14:58 +01:00
|
|
|
private $insideDialogue;
|
|
|
|
|
|
|
|
public function setInsideDialogue($inside_dialogue) {
|
|
|
|
$this->insideDialogue = $inside_dialogue;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
public function getInsideDialogue() {
|
|
|
|
return $this->insideDialogue;
|
|
|
|
}
|
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;
|
|
|
|
}
|
|
|
|
|
2013-01-27 02:14:58 +01:00
|
|
|
private function getBaseClass() {
|
|
|
|
if ($this->getInsideDialogue()) {
|
|
|
|
$class = 'aphront-error-view-dialogue';
|
|
|
|
} else {
|
|
|
|
$class = 'aphront-error-view';
|
|
|
|
}
|
|
|
|
return $class;
|
|
|
|
}
|
|
|
|
|
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
|
|
|
}
|
2013-01-18 09:32:58 +01:00
|
|
|
$list = phutil_tag(
|
2012-09-11 18:55:27 +02:00
|
|
|
'ul',
|
|
|
|
array(
|
|
|
|
'class' => 'aphront-error-view-list',
|
|
|
|
),
|
2013-01-18 09:32:58 +01:00
|
|
|
$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);
|
|
|
|
|
2013-01-27 02:14:58 +01:00
|
|
|
$classes = array();
|
|
|
|
$classes[] = $this->getBaseClass();
|
|
|
|
$classes[] = 'aphront-error-severity-'.$this->severity;
|
|
|
|
$classes = implode(' ', $classes);
|
2011-02-06 01:43:28 +01:00
|
|
|
|
2013-02-11 23:55:35 +01:00
|
|
|
$children = $this->renderChildren();
|
2013-02-07 01:53:49 +01:00
|
|
|
$children[] = $list;
|
|
|
|
|
|
|
|
return phutil_tag(
|
2012-10-16 18:44:43 +02:00
|
|
|
'div',
|
|
|
|
array(
|
|
|
|
'id' => $this->id,
|
2013-01-27 02:14:58 +01:00
|
|
|
'class' => $classes,
|
2012-10-16 18:44:43 +02:00
|
|
|
),
|
2013-01-18 09:32:58 +01:00
|
|
|
array(
|
|
|
|
$title,
|
2013-02-07 01:53:49 +01:00
|
|
|
phutil_tag(
|
2013-01-18 09:32:58 +01:00
|
|
|
'div',
|
|
|
|
array(
|
|
|
|
'class' => 'aphront-error-view-body',
|
|
|
|
),
|
2013-02-07 01:53:49 +01:00
|
|
|
$children),
|
2013-01-18 09:32:58 +01:00
|
|
|
));
|
2011-01-16 22:51:39 +01:00
|
|
|
}
|
|
|
|
}
|