public function delete($user_id) { $deleted_at = Input::get('active') == 1 ? null : new DateTime(); DB::table(DB_USERS)->where('id', $user_id)->update(array('updated_by' => Auth::user()->id, 'updated_at' => new DateTime(), 'deleted_at' => $deleted_at)); $updated = DB::table(DB_USERS)->where('id', $user_id)->pluck('updated_at'); return Dates::relative($updated); }
public function draw($class = false) { if ($class) { $class = ' ' . $class; } //start up if (self::$draggable) { array_unshift(self::$columns, ['head' => '', 'type' => 'draggy']); } if (self::$deletable) { self::$columns[] = ['head' => '', 'type' => 'delete']; } if (self::$grouped) { $last_group = ''; } $colspan = count(self::$columns); $rowspan = count(self::$rows); //build <thead> $columns = self::$columns; foreach ($columns as &$column) { if ($column['type'] == 'color') { $column['head'] = ' '; } $column = '<th class="' . self::column_class($column['type']) . '">' . $column['head'] . '</th>'; } $columns = implode($columns); $head = '<thead><tr>' . $columns . '</tr></thead>'; //build rows $bodies = $rows = []; foreach (self::$rows as $row) { $columns = []; $link = true; foreach (self::$columns as $column) { //handle groupings if (self::$grouped && $last_group != $row->{self::$grouped}) { $last_group = $row->{self::$grouped}; if (count($rows)) { $bodies[] = '<tbody>' . implode($rows) . '</tbody>'; } $bodies[] = '<tr class="group"><td colspan=' . $colspan . '">' . $last_group . '</td></tr>'; $rows = []; } //process value if necessary if ($column['type'] == 'draggy') { $value = '<i class="glyphicon glyphicon-align-justify"></i>'; } elseif ($column['type'] == 'delete') { $value = '<a href="' . $row->delete . '">' . (!$row->deleted_at ? '<i class="glyphicon glyphicon-ok-circle"></i>' : '<i class="glyphicon glyphicon-remove-circle"></i>') . '</a>'; } elseif ($column['type'] == 'image') { $value = '<a href="' . $row->link . '"><img src="' . $row->{$column['key'] . '_url'} . '" width="' . $column['width'] . '" height="' . $column['height'] . '"></a>'; } else { $value = Str::limit(strip_tags($row->{$column['key']})); if ($column['type'] == 'updated_at') { $value = Dates::relative($value); } elseif ($column['type'] == 'time') { $value = Dates::time($value); } elseif ($column['type'] == 'date') { $value = Dates::absolute($value); } elseif ($column['type'] == 'date-relative') { $value = Dates::relative($value); } elseif (in_array($column['type'], ['datetime', 'timestamp'])) { $value = Dates::absolute($value); } if (isset($row->link) && $link) { if ($column['type'] == 'color') { $value = '<a href="' . $row->link . '" style="background-color: ' . $value . '"></a>'; } else { if ($value == '') { $value = '…'; } $value = '<a href="' . $row->link . '">' . $value . '</a>'; $link = false; } } } //create cell $columns[] = '<td class="' . self::column_class($column['type']) . '">' . $value . '</td>'; } //create row $rows[] = '<tr' . (empty($row->id) ?: ' id="' . $row->id . '"') . (self::$deletable && $row->deleted_at ? ' class="inactive"' : '') . '>' . implode($columns) . '</tr>'; } $bodies[] = '<tbody>' . implode($rows) . '</tbody>'; //output return '<table id="foobar" class="table table-condensed' . $class . (self::$draggable ? ' draggable" data-draggable-url="' . self::$draggable : '') . '">' . $head . implode($bodies) . '</table>'; }
public function delete($object_name, $instance_id) { $object = DB::table(DB_OBJECTS)->where('name', $object_name)->first(); //toggle instance with active or inactive $deleted_at = Input::get('active') == 1 ? null : new DateTime(); DB::table($object->name)->where('id', $instance_id)->update(array('deleted_at' => $deleted_at, 'updated_at' => new DateTime(), 'updated_by' => Auth::user()->id)); //update object meta DB::table(DB_OBJECTS)->where('id', $object->id)->update(array('count' => DB::table($object->name)->whereNull('deleted_at')->count(), 'updated_at' => new DateTime(), 'updated_by' => Auth::user()->id)); $updated = DB::table($object->name)->where('id', $instance_id)->pluck('updated_at'); return Dates::relative($updated); }