public function ghostUpdate($data, $where) { $select = $this->select(); foreach ($where as $k => $v) { $select->where($k, $v); } $old = $this->fetchRow($select); if ($old) { $old = $old->toArray(); $new = array_merge($old, $data); foreach ($new as $k => &$row) { if (is_bool($row)) { if ($row) { $row = 't'; } else { $row = 'f'; } } } parent::update(array('ghost' => 't'), array('id = ?' => $old['id'])); unset($new['id']); unset($new['last_change']); parent::insert($new); return true; } else { return 0; } }
/** * Dodaje do whitelist wiele numerow telefonow * * Format parsowanego bloku tekstu: * XXAAABBBCCC OPIS-KOMENTARZ * XXAAABBBCCC OPIS-KOMENTARZ * XXAAABBBCCC OPIS-KOMENTARZ * * @return void */ public function addmanyAction() { $form = new Logic_Ws_Sms_Blacklist_Form_Many(); if ($this->getRequest()->isPost()) { if ($form->isValid($this->getRequest()->getPost())) { try { $validator = new Logic_Validate_NumberMobilePhone(); $values = $form->getValues(); $report = ''; $numbers = explode("\n", $values['params']); foreach ($numbers as $val) { $number = ''; $comment = ''; $val = trim($val); if ($val == '') { continue; } if (stripos($val, ' ')) { $number = substr($val, 0, stripos($val, ' ')); $comment = substr($val, stripos($val, ' ')); } else { $number = $val; } $report .= ' ' . $number . ' - '; if (!$validator->isValid($number)) { $report .= "nie poprawny format numeru;"; continue; } if ($this->_model->fetchRow($this->_model->select()->where('phone_number = ?', $number))) { $report .= "obecny na liście;"; continue; } $this->_model->insert(array('phone_number' => trim($number), 'number_comment' => trim($comment))); $report .= "dodany poprawnie;"; } $this->_helper->messenger->success($report); $this->_helper->redirector('index'); return; } catch (Logic_Ws_Exception $e) { $this->_helper->messenger->error($e->getMessage()); } catch (Logic_Exception $e) { $this->_helper->messenger->error(); } } } $this->view->form = $form; }
public function set($name, $value) { $count = parent::update(array('ghost' => 'true'), array('key = ?' => $name)); parent::insert(array('key' => $name, 'value' => $value)); $this->_cache->clean(); }