-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
1fa6028
commit b105578
Showing
4 changed files
with
101 additions
and
52 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
<?php | ||
|
||
namespace App\View\Helper; | ||
|
||
use Cake\View\Helper; | ||
|
||
class ValidationErrorsHelper extends Helper | ||
{ | ||
|
||
public function array_flatten($array) { | ||
if (!is_array($array)) { | ||
return false; | ||
} | ||
$result = []; | ||
foreach ($array as $key => $value) { | ||
if (is_array($value)) { | ||
$result = array_merge($result, $this->array_flatten($value)); | ||
} else { | ||
$result[$key] = $value; | ||
} | ||
} | ||
return $result; | ||
} | ||
|
||
public function flatten_array($arg) { | ||
return is_array($arg) ? array_reduce($arg, function ($c, $a) { return array_merge($c, $this->flatten_array($a)); }, []) : [$arg]; | ||
} | ||
|
||
public function flatten($array, $prefix = '') { | ||
$result = []; | ||
foreach ($array as $key => $value) { | ||
if (is_array($value)) { | ||
$result += $this->flatten($value, $prefix . $key . '.'); | ||
} else { | ||
$result[$prefix . $key] = $value; | ||
} | ||
} | ||
return $result; | ||
} | ||
|
||
public function displayErrors($entity) | ||
{ | ||
if (empty($errors)) { | ||
return ''; | ||
} | ||
|
||
$myarr = $this->flatten($errors); | ||
$output = '<div class="alert alert-danger alert-dismissible fade in" role="alert"> | ||
<button type="button" class="close" data-dismiss="alert" aria-label="Close"> | ||
<span aria-hidden="true">×</span></button>'; | ||
|
||
$i = 0; | ||
foreach ($myarr as $value) { | ||
$i++; | ||
if ($i <= 3) { | ||
$output .= '<i class="fa fa-exclamation-triangle"></i> ' . h($value) . '<br/>'; | ||
} | ||
} | ||
|
||
if (count($myarr) > 3) { | ||
$output .= '<small class="accordion-toggle" data-toggle="collapse" data-target="#demo"> | ||
more... | ||
</small> | ||
<div id="demo" class="collapse">'; | ||
$i = 0; | ||
foreach ($myarr as $value) { | ||
$i++; | ||
if ($i > 3) { | ||
$output .= '<i class="fa fa-exclamation-triangle"></i> ' . h($value) . '<br/>'; | ||
} | ||
} | ||
$output .= '</div>'; | ||
} | ||
|
||
$output .= '</div>'; | ||
|
||
return $output; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,48 +1,9 @@ | ||
<div class="alert alert-block alert-error fade in"> | ||
<button data-dismiss="alert" class="close" type="button">×</button> | ||
<h5 class="alert-heading"> | ||
<h5 class="alert-heading"> | ||
<?php | ||
echo $message; | ||
echo $message; | ||
?> | ||
</h5> | ||
<p> | ||
<?php | ||
function array_flatten($array) { | ||
if (!is_array($array)) { | ||
return FALSE; | ||
} | ||
$result = array(); | ||
foreach ($array as $key => $value) { | ||
if (is_array($value)) { | ||
$result = array_merge($result, array_flatten($value)); | ||
} | ||
else { | ||
$result[$key] = $value; | ||
} | ||
} | ||
return $result; | ||
} | ||
|
||
// pr(array_flatten($this->validationErrors)); | ||
$myarr = array_flatten($this->validationErrors); | ||
</h5> | ||
|
||
if(isset($myarr[0])) echo '<i class="icon-warning-sign"></i> '.$myarr[0].'<br/>'; | ||
if(isset($myarr[1])) echo '<i class="icon-warning-sign"></i> '.$myarr[1].'<br/>'; | ||
if(isset($myarr[2])) echo '<i class="icon-warning-sign"></i> '.$myarr[2].'<br/>'; | ||
if(count($myarr) > 2) { | ||
?> | ||
<small class="accordion-toggle" data-toggle="collapse" data-target="#demo"> | ||
more... | ||
</small> | ||
<div id="demo" class="collapse"> | ||
<?php | ||
for ($i = 3; $i < count($myarr); $i++) { | ||
if($i <= 12) { echo '<i class="icon-warning-sign"></i> '.$myarr[$i].'<br/>'; } | ||
} | ||
?> | ||
</div> | ||
<?php | ||
} | ||
?> | ||
</p> | ||
</div> | ||
</div> |