/** * {@inheritdoc} * * @param int $offset * @param int $limit * @param array $params * @return array|int|mixed */ public function readSet($offset = 0, $limit = 10, $params = array()) { $select = Db::select('*')->from('test', 't'); if ($limit) { $selectPart = $select->getQueryPart('select'); $selectPart = 'SQL_CALC_FOUND_ROWS ' . current($selectPart); $select->select($selectPart); $select->setLimit($limit); $select->setOffset($offset); } $result = $select->execute('\\Application\\Test\\Row'); if ($limit) { $total = Db::fetchOne('SELECT FOUND_ROWS()'); } else { $total = sizeof($result); } if (sizeof($result) < $total && Request::METHOD_GET == Request::getMethod()) { Response::setStatusCode(206); Response::setHeader('Content-Range', 'items ' . $offset . '-' . ($offset + sizeof($result)) . '/' . $total); } return $result; }
<?php /** * List of user images in JSON * * @author Anton Shevchuk * @created 12.02.13 14:18 */ /** * @namespace */ namespace Application; use Bluz\Proxy\Db; return function () { $this->useJson(); if (!$this->user()) { throw new Exception('User not found'); } $userId = $this->user()->id; $images = Db::select('*')->from('media', 'm')->where('type LIKE (?)', 'image/%')->andWhere('userId = ?', $userId)->execute('Application\\Media\\Row'); $result = array(); foreach ($images as $image) { $result[] = ["title" => $image->title, "image" => $image->file, "thumb" => $image->preview, "folder" => $image->module]; } return $result; };