예제 #1
0
 public function renderEdit($id)
 {
     $this->template->title = 'Edit article';
     if ($id > 0) {
         $this->template->item = $item = $this->items->fetch($id);
         if (!$item) {
             $this->flashMessage('No item with ID ' . $id, 'err');
             $this->redirect('default');
         }
         $this['form']->setDefaults($item);
         $this['form']['published']->setValue(Date::getDate($item->published, '%e.%m.%Y'));
     }
     $this->template->form = $this['form'];
 }
예제 #2
0
 /**
  * @param $data
  */
 public function insert($data)
 {
     $this->cleanData($data);
     $data['code'] = \Nette\Utils\Strings::webalize($data['name']);
     if (isset($data['published'])) {
         $data['published'] = Date::getTimestamp($data['published'] . ":00");
     } else {
         $data['published'] = new \Nette\DateTime();
     }
     $data['created'] = new \Nette\DateTime();
     dibi::begin();
     dibi::query('INSERT INTO [article]', $data);
     $id = dibi::insertId();
     if (isset($data['keywords'])) {
         $this->updateTags($id, $data['keywords']);
     }
     dibi::commit();
     return $id;
 }
예제 #3
0
 public function saveItem($input)
 {
     $savingForm = new AppForm();
     $savingForm = $input;
     $update = false;
     $values = $savingForm->getValues();
     //dump($values);
     if (isset($this->request->post['id'])) {
         $id = $this->request->post['id'];
         $update = true;
     } else {
         $id = '';
     }
     $data['id'] = $id;
     $data['active'] = $values['active'] ? 1 : 0;
     $data['username'] = trim($values['username']);
     $data['name'] = trim($values['name']);
     $data['surname'] = trim($values['surname']);
     $data['role'] = trim($values['role']);
     $data['email'] = trim($values['email']);
     $data['homepage'] = trim($values['homepage']);
     $data['telephone'] = trim($values['telephone']);
     $data['street'] = trim($values['street']);
     $data['city'] = trim($values['city']);
     $data['country_id'] = trim($values['country_id']);
     $data['zip'] = trim($values['zip']);
     $data['icq'] = trim($values['icq']);
     $data['aim'] = trim($values['aim']);
     $data['jabber'] = trim($values['jabber']);
     $data['skype'] = trim($values['skype']);
     $data['birthday'] = $values['birthday'] != '' ? new \DibiDateTime(\soundake\utils\Date::getTimestamp($values['birthday'])) : NULL;
     $data['description'] = trim($values['description']);
     $data['sex'] = trim($values['sex']);
     $data['password'] = trim($values['heslokreslo']);
     try {
         if ($update) {
             $this->items->update($id, $data);
         } else {
             $id = $this->items->insert($data);
         }
     } catch (DibiException $e) {
         $this->flashMessage('Error! ' . $e->getMessage(), 'err');
     }
     if ($savingForm['save']->isSubmittedBy()) {
         $this->flashMessage('User has been saved.', 'ok');
         $this->redirect('edit', array('id' => $id));
     } elseif ($savingForm['add']->isSubmittedBy()) {
         $this->flashMessage('User has been saved.', 'ok');
         $this->redirect('add');
     } else {
         $this->flashMessage('User has been saved.', 'ok');
         $this->redirect('default');
     }
 }