Menu

[r535]: / functions / classes / class.Result.php  Maximize  Restore  History

Download this file

111 lines (99 with data), 2.7 kB

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
<?php
/**
*
* Class for printing outputs and saving logs to database
*
* Severity indexes:
* 0 = success
* 1 = warning
* 2 = error
*
*/
class Result {
/* exit methods - to override for api */
public $exit_method = "result"; //what to do when failed - result shows result, exception throws exception (for API)
/**
* show result
*
* @param [type] $uclass [result class - danger, success, warning, info]
* @param [type] $utext [text to display]
* @param boolean $die [controls stop of php execution]
* @return [type] [description]
*/
public function show($uclass="muted", $utext="No value provided", $die=false, $popup=false) {
# override for api !
if($this->exit_method == "exception") {
# ok, just return success
if ($uclass=="success") { return true; }
else { return $this->throw_exception ($utext); }
}
else {
# text
if(!is_array( $utext )) {}
# array
elseif( is_array( $utext ) && sizeof( $utext )>0) {
if(sizeof( $utext )==1) { # single value
$utext = $utext[0];
} else { # multiple values
$utext = "<ul>";
foreach( $utext as $l ) { $utext .= "<li>$l</li>"; }
$utext .= "</ul>";
}
}
# print popup or normal
if(!$popup) {
print "<div class='alert alert-".$uclass."'>".$utext."</div>";
}
else {
print '<div class="pHeader">'._("Error").'</div>';
print '<div class="pContent">';
print '<div class="alert alert-'.$uclass.'">'.$utext.'</div>';
print '</div>';
print '<div class="pFooter"><button class="btn btn-sm btn-default hidePopups">'._('Close').'</button></div>';
}
# die if set
if($die) die();
}
}
/**
* Shows result for cli functions
*
* @access public
* @param string $utext (default: "No value provided")
* @param bool $die (default: false)
* @return void
*/
public function show_cli ($utext="No value provided", $die=false) {
# text
if(!is_array( $utext )) {}
# array
elseif( is_array( $utext ) && sizeof( $utext )>0) {
if(sizeof( $utext )==1) { # single value
$utext = $utext[0];
} else { # multiple values
foreach( $utext as $l ) { $utext .= "\t* $l\n"; }
}
}
# print
print "Error:\n";
print $utext;
# die if set
if($die) die();
}
/**
* Exists with exception
*
* @access public
* @param mixed $content
* @return void
*/
public function throw_exception ($content) {
// include Exceptions class for API
include_once( dirname(__FILE__) . '../../../api/v2/controllers/Responses.php' );
// initialize exceptions
$Exceptions = new Responses ();
// throw error
$Exceptions->throw_exception(500, $content);
}
}
?>
Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.