private static function getPrinter($page, $filter) { // число элементов на странице по умолчанию $defaultPageSize = 6; $query = Printer::find()->select(['id', 'title', 'intro_text', 'main_img'])->where(['show_item' => 1]); // общее число элементов, которые будут выведены на страницу $totalCount = $query->count(); // создаем объект постраничной навигации $pagination = self::getPagination($defaultPageSize, $totalCount, $page, $filter); $elements = $query->limit($pagination->limit)->offset($pagination->offset)->all(); return ['pagination' => $pagination, 'elements' => $elements]; }
public function actionPrint() { $printer_subcategory = PrinterSubcategory::find()->all(); $elements = []; foreach ($printer_subcategory as $key => $value) { $element = Printer::find()->select(['id', 'title', 'main_img'])->where(['show_item' => 1, 'id_cat' => $value->id])->orderBy('rand()')->one(); if (count($element) == 0) { $element = $value; } else { $element['alias'] = $value->alias; } $elements[$value->name] = $element; } return $this->render('print', ['elements' => $elements]); }
/** * Restore the specified resource from storage. * * @param int $id * @return Response */ public function restore(Printer $printer) { $printer->restore(); return redirect()->route('printers-trash'); }
/** * -- STORE the specified resource * * @param int $id * @return Response */ public function store(Request $request) { // -- check if its our form if (Session::token() !== $request->input('_token')) { $status = 401; $this->ajax_result['html'] = 'Unauthorized attempt to create option'; } else { $status = 200; $printer = Printer::find($request->input('printer_id')); $element = new PrinterElement(); $element->printer_id = $request->input('printer_id'); $element->name = $request->input('element-name'); $element->type = $request->input('element-type'); $element->color = $request->input('element-color'); $element->amount = $request->input('element-amount'); $element->amount_min = $request->input('element-amount-min'); $element->amount_max = $request->input('element-amount-max'); $element->save(); $this->ajax_result['html'] = view('printers._printer_elements_table')->with('printer', $printer)->render(); } return response()->json($this->ajax_result, $status); }