public function actionDefault() { $cache = new Cache($this->context->cacheStorage, 'Homepage'); $counts = $cache->load('homepagecounts'); if ($counts === NULL) { $subjectsCount = $this->context->createServicePlaces()->fetchVisible()->count(); $eventsCount = $this->context->createServiceTimes()->fetchPublic()->group('event_time.event_id')->count(); $categoriesCount = $this->context->createServiceCategories()->where('subject', '1')->count(); $counts = array('sc' => $subjectsCount, 'ec' => $eventsCount, 'cc' => $categoriesCount); $cache->save('homepagecounts', $counts, array(Cache::EXPIRE => '1 hour', Cache::SLIDING => true, Cache::TAGS => array('event', 'events', 'places', 'place'))); } $this->template->subjectsCount = $counts['sc']; $this->template->eventsCount = $counts['ec']; $this->template->categoriesCount = $counts['cc']; $def = $cache->load('homepagecities'); if ($def === NULL) { $res = Model\Subjects::fetchLocalitiesToCities(); $cnt = 0; foreach ($res as $r) { $cnt = $cnt + $r['cnt']; } $def = array($res, $cnt); $cache->save('homepagecities', $def, array('expire' => 100000, 'tags' => 'cities')); } $this->template->cities = $def[0]; $this->template->citiesCount = $def[1]; $this->template->circles = $this->context->createServiceCircles()->order('shift')->where('visible', 1)->limit(4); }
public function saveSubject(AppForm $form) { $values = $form->getValues(); $update = false; $subjects = new \Model\Subjects($this->ns); /* @todo nahradit za nove ukladani subjektu */ $params = $this->request->getParameters(); if (isset($params['id'])) { $id = $params['id']; $update = true; } else { $id = 0; } try { if ($update) { $values['approved'] = 0; $subjects->update($id, $values); } else { $values['user_id'] = $this->user->id; $id = $subjects->insert($values); } } catch (Exception $e) { if ($e->getCode() == 1062) { // Duplicate entry $form->addError('Podnik s tímto názvem již existuje. Prosím zvolte nový či specifikujte položku Místní název, čtvrť.'); } else { $form->addError($e->getMessage()); } } catch (DibiException $e) { $form->addError($e->getMessage()); } if ($form->isSuccess()) { $this->cleanCache('subjects', 'subject'); $this->flashMessage('Successfully saved.', 'ok'); if ($update) { $this->redirect('editSubject', array('id' => $id)); } else { $this->redirect('uploadPhotosSubject', array('subject_id' => $id)); } } }