function traitEntityItemDelete() { $this->traitEntity_assertReason($this->model, 'delete'); $data = ['vendor' => (string) static::getVendor(), 'entity' => \Str::snake($this->getEntity())]; if ($this->model->deleted_at) { // $this->model->restore(); // dd(); $data['state'] = -1; $data['message'] = static::translateAction('item|delete.success.hard', ['model' => $this->model]); $data['models'][] = ['id' => $this->model->id]; $this->model->forceDelete(); } else { $this->model->delete(); $data['state'] = 0; $data['message'] = static::translateAction('item|delete.success.soft', ['model' => $this->model]); $row_types = ManagerRowType::get(ManagerRowType::makeKey(static::getVendor(), static::getEntity())); $rows = []; foreach ($row_types as $row_type) { $rows[$row_type] = (string) Accessor::factory($this->model)->row($row_type); } $data['models'][] = ['id' => $this->model->id, 'model' => $this->model->toArray(), 'rows' => $rows]; } $this->traitAjax_set($data); Event::notify('larakit::model_delete-admin', $data); return $this->traitAjax_response(); }
function traitEntityRestore() { $this->traitEntity_assertReason($this->model, 'restore'); $this->model->restore(); $row_types = ManagerRowType::get(ManagerRowType::makeKey(static::getVendor(), static::getEntity())); $rows = []; foreach ($row_types as $row_type) { $rows[$row_type] = (string) Accessor::factory($this->model)->row($row_type); } $data = ['models' => [['model' => $this->model->toArray(), 'rows' => $rows, 'id' => $this->model->id]], 'vendor' => (string) static::getVendor(), 'entity' => \Str::snake($this->getEntity()), 'message' => sprintf($this->traitEntityItemRestore_success(), $this->model), 'state' => 1]; Event::notify('larakit::model_restore-admin', $data); $this->traitAjax_set($data); return $this->traitAjax_response(); }
function traitEntityHasMany_item() { if (\Request::method() == 'POST') { $this->traitEntityHasMany_save(); //переоткроем модель $model_name = $this->getClassModel(); if ($model_name::isSoftDelete()) { $model = $model_name::withTrashed()->with($this->relation)->find(\Route::input('id')); } else { $model = $model_name::with($this->relation)->find(\Route::input('id')); } $row_types = ManagerRowType::get(ManagerRowType::makeKey(static::getVendor(), static::getEntity())); $rows = []; foreach ($row_types as $row_type) { $rows[$row_type] = (string) Accessor::factory($model)->row($row_type); } $data = ['models' => [['rows' => $rows, 'model' => $model->toArray(), 'id' => $model->id]], 'vendor' => (string) static::getVendor(), 'entity' => \Str::snake(static::getEntity()), 'message' => sprintf($this->traitEntityHasMany_successMessage(), $model)]; Event::notify('larakit::model_edit-admin', $data); $this->traitAjax_set($data); return $this->traitAjax_response(); } $this->traitAjax_set('id', $this->model->id)->traitAjax_set('result', 'curtain')->traitAjax_set('vendor', (string) \Str::snake($this->getVendor()))->traitAjax_set('entity', (string) \Str::snake($this->getEntity()))->traitAjax_set('model', $this->model->toArray())->traitAjax_set('header', (string) $this->traitEntityHasMany_header())->traitAjax_set('body', (string) $this->traitEntityHasMany_body())->traitAjax_set('footer', (string) $this->traitEntityHasMany_footer()); return $this->traitAjax_response(); }
function traitEntityBelongsTo_item() { if (\Request::method() == 'POST') { $id = (int) \Input::get('belongs_to'); $this->model->{$this->getRelationKey()} = $id; $this->model->save(); // ->sync($ids); //переоткроем модель $model_name = $this->getClassModel(); /** @var Model $model */ if ($model_name::isSoftDelete()) { $model = $model_name::withTrashed(); } else { $model = $model_name::select(); } //откроем со всеми связями, которые могут потребоваться для шаблона ROW foreach ($model->getModel()->getRelations() as $relation) { $model->with($relation); } $model = $model->find(\Route::input('id')); $row_types = ManagerRowType::get(ManagerRowType::makeKey(static::getVendor(), static::getEntity())); $rows = []; foreach ($row_types as $row_type) { $rows[$row_type] = (string) Accessor::factory($model)->row($row_type); } $data = ['models' => [['rows' => $rows, 'model' => $model->toArray(), 'id' => $model->id]], 'vendor' => (string) static::getVendor(), 'entity' => \Str::snake(static::getEntity()), 'message' => sprintf($this->traitEntityBelongsTo_successMessage(), $model)]; Event::notify('larakit::model_edit-admin', $data); $this->traitAjax_set($data); return $this->traitAjax_response(); } $this->traitAjax_set('id', $this->model->id)->traitAjax_set('result', 'curtain')->traitAjax_set('vendor', static::getVendor())->traitAjax_set('entity', $this->getEntity())->traitAjax_set('model', $this->model->toArray())->traitAjax_set('header', (string) $this->traitEntityBelongsTo_header())->traitAjax_set('body', (string) $this->traitEntityBelongsTo_body())->traitAjax_set('footer', (string) $this->traitEntityBelongsTo_footer()); return $this->traitAjax_response(); }
function traitEntityItemToggle() { $field = \Input::get('field'); $this->traitEntity_assertReason($this->model, 'toggle_' . $field); $method = \Str::camel('switch_' . $field); if (!is_callable([$this, $method])) { throw new Exception('Поле не является тумблером'); } $message = call_user_func([$this, $method]); $this->model->save(); $row_types = ManagerRowType::get(ManagerRowType::makeKey(static::getVendor(), static::getEntity())); $rows = []; foreach ($row_types as $row_type) { $rows[$row_type] = (string) Accessor::factory($this->model)->row($row_type); } $data = ['models' => [['rows' => $rows, 'model' => $this->model->toArray(), 'id' => $this->model->id]], 'vendor' => (string) static::getVendor(), 'entity' => \Str::snake(static::getEntity()), 'message' => $message ? sprintf($message, $this->model) : 'Значение поля изменено на противоположное']; if (in_array($field, $this->traitEntityItemToggle_mass())) { $rows = []; $model_name = get_class($this->model); foreach ($model_name::get() as $model) { $rows = []; foreach ($row_types as $row_type) { $rows[$row_type] = (string) Accessor::factory($model)->row($row_type); } $data['models'][] = ['rows' => $rows, 'model' => $model->toArray(), 'id' => $model->id]; } } $this->traitAjax_set($data); return $this->traitAjax_response(); }
function row($type = null, $ext = []) { $vendor = (string) $this->getVendor(); $entity = (string) $this->getEntity(); $row_types = (array) ManagerRowType::get(ManagerRowType::makeKey($vendor, $entity)); $append = $type && in_array($type, $row_types) ? $type : ''; if ('attach' == $type) { $tpl = 'larakit::!.partials.attach_row'; } else { if (!$append) { return ''; } $tpl = ($vendor ? $vendor . '::' : '') . '!.partials.' . $entity . '.row.' . $append; } return (string) \View::make($tpl, array_merge((array) $ext, ['model' => $this->model, 'vendor' => $vendor, 'entity' => $entity])); }
function traitEntityEditJson_success() { $class_model = get_class($this->model); $model = $class_model::findOrFail($this->model->id); $row_types = ManagerRowType::get(ManagerRowType::makeKey(static::getVendor(), static::getEntity())); $rows = []; foreach ($row_types as $row_type) { $rows[$row_type] = (string) Accessor::factory($model)->row($row_type); } $data = ['models' => [['rows' => $rows, 'model' => $model->toArray(), 'id' => $model->id]], 'vendor' => (string) static::getVendor(), 'entity' => \Str::snake(static::getEntity()), 'message' => sprintf($this->traitEntityEdit_successMessage(), $model)]; Event::notify('larakit::model_edit-admin', $data); $this->traitAjax_set($data); return $this->traitAjax_response(); }