/** * Builds am SQL delete statment for the given entity and mappings. * * @todo Escape table names and column names. * @param object $oEntity * @param EntityMapping $oMapping * @param \PDO $sPDO */ public function delete($oEntity, EntityMapping $oMapping, \PDO $sPDO) { $aMapping = $oMapping->getMappingForEntity($oEntity); $sIdAttrName = $aMapping[EntityMapping::KEY_PRIMARY_ID][EntityMapping::ATTR_PROPERTY]; $sTableName = $aMapping[EntityMapping::KEY_TABLE]; $oReflect = new \ReflectionClass($oEntity); $oProperty = $oReflect->getProperty($sIdAttrName); $oProperty->setAccessible(true); $mId = $oProperty->getValue($oEntity); //Escape table name and colum names. $oStmt = $sPDO->prepare(PrepareStatement::DELETE_STATEMENT . ' ' . $sTableName . ' WHERE ' . $sIdAttrName . ' = :id'); $oStmt->bindParam(':id', $mId); return $oStmt; }
/** * Fetches the last insert ID and assigns it to the persisted entity. * * @param \PDO $oPDO * @param object $oEntity */ private function setIdForLastInsert(\PDO $oPDO, $oEntity) { $oReflect = new \ReflectionClass(\get_class($oEntity)); $aMapping = $this->oMapper->getMappingForEntity($oEntity); $sIdAttrName = $aMapping[EntityMapping::KEY_PRIMARY_ID][EntityMapping::ATTR_PROPERTY]; $oProperty = $oReflect->getProperty($sIdAttrName); $oProperty->setAccessible(true); $oProperty->setValue($oEntity, $oPDO->lastInsertId()); $this->mLastInsertID = $oPDO->lastInsertId(); }