Example #1
0
 public function draw($id = 'untitled')
 {
     //start up
     if ($this->draggable) {
         array_unshift($this->columns, ['label' => '', 'type' => 'draggy', 'name' => 'draggy']);
     }
     if ($this->deletable) {
         self::column('delete', 'delete', '');
     }
     if ($this->grouped) {
         $last_group = '';
     }
     $colspan = count($this->columns);
     $rowspan = count($this->rows);
     //build <thead>
     $columns = [];
     foreach ($this->columns as $column) {
         $columns[] = '<th class="type-' . $column['type'] . ' ' . $column['name'] . '">' . $column['label'] . '</th>';
     }
     $head = '<thead><tr>' . implode($columns) . '</tr></thead>';
     //build rows
     $bodies = $rows = [];
     foreach ($this->rows as $row) {
         $columns = [];
         $link = true;
         foreach ($this->columns as $column) {
             //handle groupings
             if ($this->grouped && $last_group != $row->{$this->grouped}) {
                 $last_group = $row->{$this->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 = config('center.icons.drag');
             } elseif ($column['type'] == 'delete') {
                 $value = '<a href="' . $row->delete . '">' . ($row->deleted_at ? config('center.icons.deleted') : config('center.icons.undeleted')) . '</a>';
             } elseif ($column['type'] == 'image') {
                 $value = '<img src="' . $row->{$column['name'] . '_url'} . '" width="' . $column['width'] . '" height="' . $column['height'] . '">';
                 if (isset($row->link)) {
                     $value = '<a href="' . $row->link . '">' . $value . '</a>';
                 }
             } elseif ($column['type'] == 'stripe_charge') {
                 $value = $row->{$column['name']} ? '<a href="https://dashboard.stripe.com/payments/' . $row->{$column['name']} . '" target="_blank">' . config('center.icons.new_window') . ' ' . trans('center::site.stripe_open') . '</a>' : '';
             } else {
                 $value = Str::limit(strip_tags($row->{$column['name']}));
                 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);
                 } elseif ($column['type'] == 'checkbox') {
                     $value = $value ? trans('center::site.yes') : trans('center::site.no');
                 } elseif ($column['type'] == 'money') {
                     $value = '$' . number_format($value, 2);
                 }
                 if (isset($row->link) && $link) {
                     if ($column['type'] == 'color') {
                         $value = '<a href="' . $row->link . '" style="background-color: ' . $value . '"></a>';
                     } else {
                         if ($value == '') {
                             $value = '&hellip;';
                         }
                         $value = '<a href="' . $row->link . '">' . $value . '</a>';
                         $link = false;
                     }
                 }
             }
             //create cell
             $columns[] = '<td class="type-' . $column['type'] . ' ' . $column['name'] . '">' . $value . '</td>';
         }
         //create row
         $rows[] = '<tr' . (empty($row->id) ? '' : ' id="' . $row->id . '"') . ($this->deletable && $row->deleted_at ? ' class="inactive"' : '') . '>' . implode($columns) . '</tr>';
     }
     $bodies[] = '<tbody>' . implode($rows) . '</tbody>';
     //output
     return '<table id="' . $id . '" class="table table-condensed' . ($this->draggable ? ' draggable" data-draggable-url="' . $this->draggable : '') . '" data-csrf-token="' . Session::token() . '">' . $head . implode($bodies) . '</table>';
 }
Example #2
0
 public function delete($table, $row_id)
 {
     $table = config('center.tables.' . $table);
     # Security
     if (!isset($table->name)) {
         return redirect()->action('\\LeftRight\\Center\\Controllers\\TableController@index')->with('error', trans('center::site.table_does_not_exist'));
     } elseif (!LoginController::checkPermission($table->name, 'edit') || !$table->editable) {
         return redirect()->action('\\LeftRight\\Center\\Controllers\\RowController@index', $table->name)->with('error', trans('center::site.no_permissions_edit'));
     }
     //toggle instance with active or inactive
     $deleted_at = Request::input('active') == 1 ? null : new DateTime();
     //todo check if updated_at and updated_by exist before updating
     DB::table($table->name)->where('id', $row_id)->update(['deleted_at' => $deleted_at, 'updated_at' => new DateTime(), 'updated_by' => Auth::user()->id]);
     /*update object meta
     		DB::table(config('center.db.objects'))->where('id', $table->id)->update(array(
     			'count'=>DB::table($table->name)->whereNull('deleted_at')->count(),
     			'updated_at'=>new DateTime,
     			'updated_by'=>Auth::user()->id,
     		));*/
     $updated = DB::table($table->name)->where('id', $row_id)->value('updated_at');
     return \LeftRight\Center\Libraries\Dates::relative($updated);
 }