Example #1
0
 public function readFromDBResult(DBResult $result)
 {
     if (!$result instanceof DBResult) {
         $e = new Err('', Err::E_READ_NOT_DBS_RESULT);
         $this->MessagePool->addErrorException($e);
         throw $e;
     }
     if ($this->entity !== $result->getDBSimpleEntity()) {
         $e = new Err('', Err::E_WRONG_DB_RESULT_ENTITY);
         $this->MessagePool->addErrorException($e);
         throw $e;
     }
     if ($arResult = $result->Fetch()) {
         $primaryKey = $this->entity->getMainTablePrimaryKey();
         if (!array_key_exists($primaryKey, $arResult) && !$this->_checkUniqueIndex($arResult, $foundUniqueName)) {
             $e = new Err('', Err::E_READ_NO_IDENTITY_FIELD);
             $this->MessagePool->addErrorException($e);
             throw $e;
         }
         foreach ($arResult as $field => &$value) {
             if (in_array($field, $this->entityFields)) {
                 $this->fieldsValues[$field] = $value;
             }
         }
     } else {
         $this->MessagePool->addErrorException(new Err('', Err::E_FIND_RECORD));
         return false;
     }
     $this->bNewRecord = false;
     return true;
 }
Example #2
0
 /**
  * @param DBResult $rs
  * @param array $arErrors
  * @return bool
  */
 public function deleteByDBResult(DBResult $rs, array &$arErrors = null)
 {
     $bResult = false;
     $bSuccess = false;
     $iCount = 0;
     if ($rs instanceof DBResult && $rs->getDBSimpleEntity() === $this) {
         if ($this->_mainTablePrimaryKey !== null) {
             while ($arRow = $rs->Fetch()) {
                 $iCount++;
                 $bSuccess = false;
                 if (array_key_exists($this->_mainTablePrimaryKey, $arRow)) {
                     $bSuccess = $this->delete($arRow[$this->_mainTablePrimaryKey]);
                     if (!$bSuccess && $arErrors !== null) {
                         $arErrors[] = $this->getLastError('ARRAY');
                     }
                 }
                 $bResult = $bResult && $bSuccess;
             }
         } else {
             // TODO: Тут получаем поля уникального индекса и по его полям вызываем deleteByFilter
         }
     } else {
         // TODO: Тут выкидываем ошибку. Потому что нельзя удалять записи сущности плученные с помощью класса другой сущности
     }
     return $bResult;
 }