Exemplo n.º 1
0
 /**
  * @param Account $account
  * @return bool
  */
 function UpdateColumns(&$account)
 {
     $existColumns = array();
     if (is_array($account->Columns) && count($account->Columns) > 0) {
         if (!$this->_connector->Execute($this->_commandCreator->SelectAccountColumnsData($account->IdUser))) {
             return false;
         } else {
             while (($row = $this->_connector->GetNextRecord()) != false) {
                 $existColumns[(int) $row->id_column] = $row->column_value;
             }
         }
         $cnt = count($existColumns);
         foreach ($account->Columns as $id_column => $colun_value) {
             if ($cnt > 0) {
                 if (isset($existColumns[$id_column])) {
                     if ($existColumns[$id_column] != $colun_value) {
                         $result = $this->_connector->Execute($this->_commandCreator->UpdateColumnData($account->IdUser, $id_column, $colun_value));
                         if (!$result) {
                             return false;
                         }
                     }
                 } else {
                     $result = $this->_connector->Execute($this->_commandCreator->InsertColumnData($account->IdUser, $id_column, $colun_value));
                     if (!$result) {
                         return false;
                     }
                 }
             } else {
                 $result = $this->_connector->Execute($this->_commandCreator->InsertColumnData($account->IdUser, $id_column, $colun_value));
                 if (!$result) {
                     return false;
                 }
             }
         }
     }
     return true;
 }