/** * Paginate the entries into snipped collection * * @return string The HTML String that appended to our template */ public function paginate() { $limit = $this->limit; if (is_null($limit)) { return; } $all = $this->entries->count(); $average = ceil($all / $limit); if ($average == 1) { return; } $skip = $this->app->request->get('!skip'); for ($i = 0; $i < $average; $i++) { $isCurrent = $skip == $i * $limit; $this->links[$i] = array('uri' => '?!skip=' . $i * $limit, 'isCurrent' => $isCurrent); if ($isCurrent) { $this->current = $i; } } return $this->app->theme->partial($this->partialTemplate, array('links' => $this->links, 'baseUrl' => $this->baseUrl, 'current' => $this->current, 'app' => $this->app)); }
/** * Get data from rest service. * * @param \Norm\Cursor $cursor * * @throws \Exception * * @return array */ public function restGet($cursor) { if ($cursor instanceof Cursor) { $name = $cursor->getCollection()->getName(); $criteria = $cursor->getCriteria(); $limit = $cursor->limit(); $skip = $cursor->skip(); $sorts = $cursor->sort(); $query = array(); foreach ($criteria as $key => $value) { $query[$key] = $value; } if ($limit) { $query['!limit'] = $limit; } if ($skip) { $query['!skip'] = $skip; } if (!empty($sorts)) { foreach ($sorts as $key => $value) { $query["!sort[{$key}]"] = $value; } } $qs = array(); foreach ($query as $key => $value) { if (is_array($value)) { foreach ($value as $k => $v) { $qs[] = '!' . $key . '=' . $v; } } else { $qs[] = $key . '=' . $value; } } if ($qs) { $qs = '?' . implode('&', $qs); } else { $qs = ''; } $url = $this->option('baseUrl') . '/' . $name . '.json' . $qs; $client = new Client(); $response = $client->get($url)->send(); return json_decode($response->getBody(true), true); } else { throw new Exception('Unimplemented yet!'); } }
public function grammarDistinct(Cursor $cursor, $key) { $sql = "FROM {$cursor->getCollection()->getName()}"; $sql = 'SELECT DISTINCT(' . $key . ') ' . $sql; return $sql; }