function tableBody($rows, $data, $buttons) { $keys = array_keys($data); $response = ""; $i = 1; foreach ($rows as $row) { $response .= "<tr><td>" . $i . "</td>"; foreach ($keys as $key) { if (strpos($key, '->') !== false) { $key = explode('->', $key); $response .= "<td>" . $row->{$key}[0]->{$key}[1] . "</td>"; } elseif (!is_array($row->{$key})) { $response .= "<td>"; if ($key == "created_at" || $key == "updated_at") { $response .= "<span class='datetime'>" . jDate::forge($row->{$key})->format('H:i:s %Y/%m/%d') . "</span>"; } elseif (strpos($key, 'date') !== false) { $response .= "<span class='datetime'>" . jDate::forge($row->{$key})->format('%Y/%m/%d') . "</span>"; } else { $response .= Lang::has('translate.' . $row->{$key}) ? trans('translate.' . $row->{$key}) : $row->{$key}; } $response .= "</td>"; } } $response .= '<td><div class="btn-group"> <button class="btn btn-default btn-xs" type="button">' . trans('translate.Actions') . '</button> <button data-toggle="dropdown" class="btn btn-xs btn-primary dropdown-toggle" type="button"> <span class="caret"></span><span class="sr-only">Toggle Dropdown</span> </button> <ul role="menu" class="dropdown-menu pull-right">'; foreach ($buttons as $button) { preg_match('/\\{(.*?)\\}/', $button['url'], $param); $url = preg_replace("/\\{[^)]+\\}/", $row->{$param}[1], $button['url']); $response .= '<li><a href="' . $url . '">'; if (Lang::has('translate.' . $button['label'])) { $response .= trans('translate.' . $button['label']); } else { $response .= $button['label']; } $response .= '</a></li>'; } $response .= '</ul> </div></td>'; $response .= "</tr>"; $i = $i + 1; } return $response; }
/** * Return a date in ago format * * @param string $column * @return string */ public function diff($column = 'created_at') { return \jDate::forge($this->{$column})->ago(); }