Пример #1
0
function bindDevicesTypeEntityArray($devicesTypeEntitys)
{
    $devicesTypeDtos = new DevicesTypeListDto();
    $devicesTypeDtoArray = array();
    foreach ($devicesTypeEntitys as $devicesTypeEntity => $value) {
        array_push($devicesTypeDtoArray, bindDevicesTypeEntity($value));
    }
    $devicesTypeDtos->setDevicesTypes($devicesTypeDtoArray);
    return $devicesTypeDtos;
}
Пример #2
0
function bindUserDeviceEntity($userDeviceEntity)
{
    if ($userDeviceEntity != null) {
        $userDeviceDto = new UserDeviceDto();
        $userDeviceDto->setUserDevicesId($userDeviceEntity->getUserDevicesId());
        $userDeviceDto->setUser(bindUserEntity($userDeviceEntity->getUser()));
        $userDeviceDto->setType(bindDevicesTypeEntity($userDeviceEntity->getType()));
        $userDeviceDto->setName($userDeviceEntity->getName());
        $userDeviceDto->setDevicePushId($userDeviceEntity->getDevicePushId());
        return $userDeviceDto;
    } else {
        return null;
    }
}
    $devicesTypesArray = array();
    foreach ($devicesTypeListDto->getDevicesTypes() as $devicesTypeDto) {
        $devicesTypeEntity = bindDevicesTypeDto($devicesTypeDto);
        $entityManager->persist($devicesTypeEntity);
        $entityManager->flush();
        array_push($devicesTypesArray, bindDevicesTypeEntity($devicesTypeEntity));
    }
    $devicesTypeListDto = new DevicesTypeListDto();
    $devicesTypeListDto->setDevicesTypes($devicesTypesArray);
    $devicesTypeListDto->printData($app);
});
$app->put('/devicestypes/:id', function ($id) use($app) {
    global $entityManager;
    $devicesTypeEntity = $entityManager->find("DevicesTypeEntity", $id);
    $entityManager->flush();
    $devicesTypeDto = bindDevicesTypeEntity($devicesTypeEntity);
    $devicesTypeDto->printData($app);
});
$app->delete('/devicestypes/:id', function ($id) use($app) {
    global $entityManager;
    $devicesTypeEntity = $entityManager->find("DevicesTypeEntity", $id);
    $entityManager->remove($devicesTypeEntity);
    $entityManager->flush();
});
/*Referances*/
$app->get('/devicestypes/:id/userdevices/types', function ($id) use($app) {
    global $entityManager;
    $userDeviceEntities = $entityManager->getRepository("UserDeviceEntity")->findBy(array('type' => $id));
    $userDevice = bindUserDeviceEntityArray($userDeviceEntities);
    $userDevice->printData($app);
});