public function getThumb() { $image = $this->getImage(); $thumb = null; if ($image) { $path = \Brands\Model\Brands::getImagePath($this->id, $image); if (file_exists($path)) { $parts = explode('/', $path); $parts[count($parts) - 1] = 'thumbs/' . $parts[count($parts) - 1]; $thumb = implode('/', $parts); if (!file_exists($thumb)) { try { $resizer = new \Micro\Image\Native($path); $resizer->resizeAndFill(50, 150); $resizer->save($thumb); } catch (\Exception $e) { $thumb = null; } } } } return $thumb; }
public function ajaxGetBrandsAction() { $response = array(); $query = $this->request->getParam('query'); if (mb_strlen($query, 'UTF-8') > 2) { $brandsModel = new Brands(); $brandsModel->addWhere('name', $query . '%'); $brandsModel->getJoinSelect()->group('name')->order(new Expr('NULL')); foreach ($brandsModel->getItems() as $item) { $response[] = array('id' => $item['name'], 'name' => $item['name']); } } return new Response\JsonResponse($response); }