Exemplo n.º 1
0
 /**
  * @todo Sprawdzić wysyłanie maili, być może jest zdublowany mechanizm wysyłania powiadomien w przypadku akceptacji
  * 
  * @param type $data
  * @param Zend_Db_Table_Row $row
  * @return type
  * @throws Exception 
  */
 public function saveFormData($data, Zend_Db_Table_Row $row = null)
 {
     $utils = new Logic_Utilities();
     $delegation = new Delegation();
     $dataRow = array_shift($data);
     if (null === $row) {
         $id_state = $dataRow["id_state"];
         unset($dataRow["id_state"]);
         try {
             $idRow = $delegation->createRow($dataRow)->save();
         } catch (Exception $exc) {
             throw new Exception('Błąd podczas zapisu do bazy danych! Treść: ' . $exc->getMessage());
         }
         $delegationNo = Logic_Utilities::generate_deleg_no($idRow);
         try {
             $delegation->findOne($idRow)->setFromArray(array('deleg_no' => $delegationNo, 'id_state' => $id_state, 'send_mail' => $dataRow['send_mail']))->save();
         } catch (Exception $exc) {
             throw new Exception('Błąd podczas zapisu numeru delegacji! Treść: ' . $exc->getMessage());
         }
     } else {
         try {
             if ($data['id_state'] != Logic_ItemAbstract::STATE_NEW) {
                 if ($row->id_state != $data['id_state']) {
                     $row->setFromArray($data)->save();
                 } else {
                     throw new Exception('Krok który próbowałeś zapisać został już wykonany.');
                 }
             } else {
                 if (!(($row->id_state == Logic_ItemAbstract::STATE_APPROVED || $row->id_state == Logic_ItemAbstract::STATE_ACCEPTED) && $data['id_state'] == Logic_ItemAbstract::STATE_NEW)) {
                     $row->setFromArray($data)->save();
                 } else {
                     throw new Exception('Delegacja jest już w przesłana do kolejnego etapu');
                 }
             }
         } catch (Exception $exc) {
             throw new Exception('Błąd podczas zapisu do bazy danych! Treść: ' . $exc->getMessage());
         }
     }
     if ($dataRow['id_state'] === self::STATE_NEW) {
         return $delegationNo;
     }
     // to może być zdublowany mechanizm wysyłania maila
     /*
      if ($dataRow['id_state'] !== self::STATE_ACCEPTED) {
      $mailer = new Logic_Mailer(Zend_Controller_Front::getInstance()->getParam('bootstrap')->getResource('view'), null);
      $user = Zend_Auth::getInstance()->getIdentity();
     
      $params['user_full_name'] = $user->first_name . ' ' . $user->surname;
      $params['email'] = $user->email;
     
      try {
      $mailer->acceptDelegation($params);
      } catch (Exception $exc) {
      throw new Exception('Błąd podczas wysyłania maila do osoby akceptującej delegację! Treść: ' . $exc->getMessage());
      }
      }
     */
     return $delegationNo;
 }
Exemplo n.º 2
0
 /**
  * Metoda logująca zmiany wprowadzane w poszczególnych tabelach.
  * W celu skorzystania należy w pliku Row modelu ustawić
  * pole $_logEnable na true
  * @param type $array
  * @throws Zend_Db_Table_Row_Exception
  */
 public function setFromArray(array $array)
 {
     $row = parent::setFromArray($array);
     if ($this->getLogEnable()) {
         try {
             $logger = Zend_Registry::get('log_app');
         } catch (Exception $e) {
             throw new Zend_Db_Table_Row_Exception('The logger "log_app" for row changes log is not set!', 0, $e);
         }
         $changeData = $this->getAllModified();
         if ($changeData['old'] != null && $changeData['new'] != null) {
             $old = Zend_Json_Encoder::encode($changeData['old']);
             $new = Zend_Json_Encoder::encode($changeData['new']);
             $id = $this->_getPrimaryKey();
             $logger->setEventItem('table_name', $this->getTable()->getName());
             $logger->setEventItem('schema_name', $this->getTable()->info('schema'));
             $logger->setEventItem('new', $new);
             if ($id[$this->getIterator()->key()] != null) {
                 $logger->setEventItem('row_id', $id[$this->getIterator()->key()]);
                 $logger->setEventItem('old', $old);
                 $logger->info('update');
             } else {
                 $logger->setEventItem('row_id', $this->save());
                 $logger->info('insert');
             }
         }
     }
     return $row;
 }
Exemplo n.º 3
0
 /**
  * Edit action
  */
 public function editAction()
 {
     // Get the request object
     $request = $this->getRequest();
     $populateWithDefaultValues = true;
     // Check if a form is sent
     if ($request->isPost()) {
         $postData = $request->getPost();
         $postData = $this->_parsePostData($postData);
         if (!isset($postData['form_class']) || isset($postData['form_class']) && $postData['form_class'] == get_class($this->_form)) {
             $populateWithDefaultValues = false;
             //Populate the post data to the form
             $this->_form->populate($postData);
             if ($this->_form->cancel->isChecked()) {
                 // Cancel button is pressed
                 $this->_redirect($this->_redirectUrlCancel);
             } elseif ($this->_form->delete !== null && $this->_form->delete->isChecked()) {
                 // Delete button is pressed
                 $this->_redirect($this->_redirectUrlDelete);
             } elseif ($this->validateForm($postData)) {
                 // Form is sent
                 try {
                     // Parse the form data
                     $item = $this->_getItem('edit');
                     if (array_key_exists('form_class', $item)) {
                         unset($item['form_class']);
                     }
                     if (array_key_exists('form_name', $item)) {
                         unset($item['form_name']);
                     }
                     // Save the item
                     $this->_item->setFromArray($item);
                     $this->_item->save();
                     // Actions after the query
                     $this->_afterQuery('edit');
                     // Set the form description
                     $this->_form->setDescription('The item is succesfully saved');
                     $this->_flashMessenger->addMessage('Saved the item succesfully.');
                     // Redirect to the index
                     $this->_redirect($this->_redirectUrlEdit);
                 } catch (Exception $exception) {
                     $this->_form->addErrorMessage($exception->getMessage());
                 }
             }
         }
     }
     if ($populateWithDefaultValues) {
         // Initialize the form with the item values
         $this->_form->populate($this->_getDefaultFormValues());
     }
     // Set the class "error" to subforms with errors
     if (method_exists($this->_form, 'setErrorClass')) {
         $this->_form->setErrorClass('error');
     }
     // Parse the form to the view
     $this->view->form = $this->_form;
 }
Exemplo n.º 4
0
 public function process(array $post, Zend_Db_Table_Row $row)
 {
     $this->setDefaults($row->toArray());
     //
     if (sizeof($post) && $this->isValid($post)) {
         try {
             $row->setFromArray($this->getValues());
             $row->save();
             return true;
         } catch (Exception $e) {
             $this->addDescription('There was an error saving your details');
             return $this;
         }
     }
     return $this;
 }
Exemplo n.º 5
0
 /**
  * Set a bunch of attributes at once
  *
  * @param  Array   hash of attributes and their values
  * @param  boolean (optional) whether to enforce restrictions on setting attributes
  * @return RoleModel
  */
 public function setAttributes($attributes, $restrict = true)
 {
     // make sure what was passed in was an array
     if (!is_array($attributes)) {
         throw new exception('RoleModel::setAttributes() requires an array.');
     }
     // check to make sure that an invalid or restricted property has not been referenced
     foreach ($attributes as $attribute => $value) {
         if (!isset($this->row->{$attribute})) {
             throw new Exception("Attempt to set property [{$attribute}] which does not exist.");
         }
         if ($restrict && in_array($attribute, self::$restrictedAttributes)) {
             throw new Exception("Attempt to set property [{$attribute}] which is restricted.");
         }
     }
     $this->row->setFromArray($attributes);
     return $this;
 }
Exemplo n.º 6
0
 /**
  * Save the row
  *
  * @param object $result    The current result item
  * @return void
  * @throws
  */
 protected function _saveRow($result)
 {
     try {
         $this->_tableRow->setFromArray($this->_data);
         unset($this->_data);
         $this->_tableRow->save();
         if ($this->_showProgress && !empty($result->id) && !empty($result->name)) {
             echo '<h1>' . 'Successful ' . $this->_rowAction . ' of ' . $result->id . ': ' . $result->name . '</h1>' . PHP_EOL;
         }
     } catch (Exception $e) {
         if ($this->_showProgress && !empty($result->id) && !empty($result->name)) {
             echo '<h1 class="error">' . 'Error attempting to ' . $this->_rowAction . ' ' . $result->id . ': ' . $result->name . '</h1>' . PHP_EOL;
         }
         throw new TicketEvolution_DataLoader_Exception($e);
     }
 }
Exemplo n.º 7
0
 /**
  * Sets all data in the row from an array.
  *
  * @param  array $data
  * @return Zend_Db_Table_Row_Abstract Provides a fluent interface
  */
 public function setFromArray($data)
 {
     $data_clear = array();
     foreach ($this->_table->getMetadata() as $name => $value) {
         if ($name == "id") {
             continue;
         }
         if (isset($data[$name])) {
             $data_clear[$name] = $data[$name];
         }
     }
     foreach ($this->_table->getManyToManyTables() as $manyTable => $toManyTable) {
         $this->_manyToManyData[$manyTable] = $data[$manyTable];
     }
     return parent::setFromArray($data_clear);
 }
 /**
  * Save the row
  *
  * @param object $result    The current result item
  * @return void
  * @throws
  */
 protected function _saveRow($result)
 {
     if ($this->_rowAction === 'INSERT' && $this->endpointState === 'deleted') {
         // No need to INSERT rows of deleted items.
         if ($this->_showProgress) {
             echo '<p>Skipping INSERT of deleted item ' . $result->id . '</p>' . PHP_EOL;
         }
         unset($this->_data);
     } else {
         try {
             $this->_tableRow->setFromArray($this->_data);
             unset($this->_data);
             $this->_tableRow->save();
             if ($this->_showProgress) {
                 $message = 'Successful ' . $this->_rowAction . ' of ' . $result->id;
                 if (!empty($result->name)) {
                     $message .= ': ' . $result->name;
                 }
                 echo '<p>' . $message . '</p>' . PHP_EOL;
             }
         } catch (Exception $e) {
             if ($this->_showProgress) {
                 $message = 'Error attempting to ' . $this->_rowAction . ' ' . $result->id;
                 if (!empty($result->name)) {
                     $message .= ': ' . $result->name;
                 }
                 echo '<h2 class="error">' . $message . '</h2>' . PHP_EOL;
             }
             throw new namespace\Exception($e);
         }
     }
 }