partkeepr

fork of partkeepr
git clone https://git.e1e0.net/partkeepr.git
Log | Files | Refs | Submodules | README | LICENSE

commit 2a996371e1018961298f1e6c4d6398d90fdb55b6
parent bd7cc506579a68f1a23819440d84e04ba723f0f0
Author: Timo A. Hummel <timo@netraver.de>
Date:   Tue, 14 Jun 2011 06:12:27 +0200

Renamed PartDB2 to PartKeepr

Diffstat:
M.gitignore | 1+
MINSTALL | 2+-
MREADME.md | 12++++++------
Mbuild.xml | 2+-
Mcli-config.php | 12++++++------
Mconfig-test.php | 14+++++++-------
Mconfig.php | 18+++++++++---------
Mcronjobs/CreateStatisticSnapshot.php | 10+++++-----
Mdocumentation/ARCHITECTURE | 2+-
Mdocumentation/QUICK-INSTALL | 4++--
Rfrontend/css/PartDB2.css -> frontend/css/PartKeepr.css | 0
Mfrontend/image.php | 14+++++++-------
Mfrontend/index.php | 10+++++-----
Mfrontend/js/Components/CategoryEditor/CategoryEditorForm.js | 2+-
Mfrontend/js/Components/CategoryEditor/CategoryEditorTree.js | 12++++++------
Mfrontend/js/Components/CategoryEditor/CategoryEditorWindow.js | 6+++---
Mfrontend/js/Components/CategoryStore.js | 4++--
Mfrontend/js/Components/CategoryTree.js | 4++--
Mfrontend/js/Components/ConnectionButton.js | 2+-
Mfrontend/js/Components/Distributor/DistributorEditor.js | 6+++---
Mfrontend/js/Components/Distributor/DistributorEditorComponent.js | 8++++----
Mfrontend/js/Components/Distributor/DistributorGrid.js | 4++--
Mfrontend/js/Components/Editor/Editor.js | 2+-
Mfrontend/js/Components/Editor/EditorComponent.js | 4++--
Mfrontend/js/Components/Editor/EditorGrid.js | 2+-
Mfrontend/js/Components/Footprint/FootprintEditor.js | 6+++---
Mfrontend/js/Components/Footprint/FootprintEditorComponent.js | 8++++----
Mfrontend/js/Components/Footprint/FootprintGrid.js | 4++--
Mfrontend/js/Components/Manufacturer/ManufacturerEditor.js | 8++++----
Mfrontend/js/Components/Manufacturer/ManufacturerEditorComponent.js | 8++++----
Mfrontend/js/Components/Manufacturer/ManufacturerGrid.js | 4++--
Mfrontend/js/Components/Menu.js | 2+-
Mfrontend/js/Components/MenuBar.js | 32++++++++++++++++----------------
Mfrontend/js/Components/MessageLog.js | 2+-
Mfrontend/js/Components/Part/PartDisplay.js | 16++++++++--------
Mfrontend/js/Components/Part/PartDistributorGrid.js | 6+++---
Mfrontend/js/Components/Part/PartEditor.js | 32++++++++++++++++----------------
Mfrontend/js/Components/Part/PartEditorWindow.js | 4++--
Mfrontend/js/Components/Part/PartFilterPanel.js | 4++--
Mfrontend/js/Components/Part/PartManufacturerGrid.js | 6+++---
Mfrontend/js/Components/Part/PartParameterGrid.js | 10+++++-----
Mfrontend/js/Components/Part/PartStockHistory.js | 4++--
Mfrontend/js/Components/Part/PartStockWindow.js | 2+-
Mfrontend/js/Components/Part/PartsGrid.js | 6+++---
Mfrontend/js/Components/Part/PartsManager.js | 22+++++++++++-----------
Mfrontend/js/Components/PartUnit/PartUnitEditor.js | 6+++---
Mfrontend/js/Components/PartUnit/PartUnitEditorComponent.js | 8++++----
Mfrontend/js/Components/PartUnit/PartUnitGrid.js | 6+++---
Mfrontend/js/Components/Statistics/CurrentStatisticsDialog.js | 4++--
Mfrontend/js/Components/Statusbar.js | 8++++----
Mfrontend/js/Components/StorageLocation/StorageLocationEditor.js | 6+++---
Mfrontend/js/Components/StorageLocation/StorageLocationEditorComponent.js | 8++++----
Mfrontend/js/Components/StorageLocation/StorageLocationGrid.js | 4++--
Mfrontend/js/Components/TimeDisplay.js | 2+-
Mfrontend/js/Components/Unit/UnitEditor.js | 12++++++------
Mfrontend/js/Components/Unit/UnitEditorComponent.js | 8++++----
Mfrontend/js/Components/Unit/UnitGrid.js | 4++--
Mfrontend/js/Components/User/UserEditor.js | 6+++---
Mfrontend/js/Components/User/UserEditorComponent.js | 8++++----
Mfrontend/js/Components/User/UserGrid.js | 4++--
Mfrontend/js/Components/Widgets/CategoryComboBox.js | 4++--
Mfrontend/js/Components/Widgets/DistributorComboBox.js | 4++--
Mfrontend/js/Components/Widgets/FootprintComboBox.js | 4++--
Mfrontend/js/Components/Widgets/ManufacturerComboBox.js | 4++--
Mfrontend/js/Components/Widgets/PartParameterComboBox.js | 6+++---
Mfrontend/js/Components/Widgets/PartUnitComboBox.js | 4++--
Mfrontend/js/Components/Widgets/SiUnitField.js | 14+++++++-------
Mfrontend/js/Components/Widgets/SiUnitList.js | 2+-
Mfrontend/js/Components/Widgets/StorageLocationComboBox.js | 4++--
Mfrontend/js/Components/Widgets/UnitComboBox.js | 4++--
Mfrontend/js/Dialogs/Auth/LoginDialog.js | 20++++++++++----------
Mfrontend/js/Dialogs/ExceptionWindow.js | 2+-
Mfrontend/js/Dialogs/FileUploadDialog.js | 8++++----
Mfrontend/js/Models/Category.js | 4++--
Mfrontend/js/Models/Distributor.js | 4++--
Mfrontend/js/Models/Footprint.js | 4++--
Mfrontend/js/Models/Manufacturer.js | 4++--
Mfrontend/js/Models/ManufacturerICLogo.js | 4++--
Mfrontend/js/Models/Message.js | 2+-
Mfrontend/js/Models/Part.js | 4++--
Mfrontend/js/Models/PartDistributor.js | 4++--
Mfrontend/js/Models/PartManufacturer.js | 4++--
Mfrontend/js/Models/PartParameter.js | 4++--
Mfrontend/js/Models/PartUnit.js | 4++--
Mfrontend/js/Models/SiPrefix.js | 4++--
Mfrontend/js/Models/StockEntry.js | 4++--
Mfrontend/js/Models/StorageLocation.js | 4++--
Mfrontend/js/Models/Unit.js | 4++--
Mfrontend/js/Models/User.js | 4++--
Dfrontend/js/PartDB2.js | 334-------------------------------------------------------------------------------
Afrontend/js/PartKeepr.js | 334+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Mfrontend/js/Util/ServiceCall.js | 22+++++++++++-----------
Mfrontend/js/bugfixes.js | 4++--
Mfrontend/js/org.jerrymouse.util.locale/locales/de_DE.js | 40++++++++++++++++++++--------------------
Mfrontend/js/org.jerrymouse.util.locale/locales/en_US.js | 78+++++++++++++++++++++++++++++++++++++++---------------------------------------
Mfrontend/rest.php | 14+++++++-------
Mfrontend/service.php | 12++++++------
Mfrontend/upload.php | 18+++++++++---------
Msetup/tests/PDOTest.php | 2+-
Msetup/tests/SOAPTest.php | 2+-
Dsrc/de/RaumZeitLabor/PartDB2/Auth/AuthManager.php | 14--------------
Dsrc/de/RaumZeitLabor/PartDB2/Auth/AuthService.php | 37-------------------------------------
Dsrc/de/RaumZeitLabor/PartDB2/Auth/Exceptions/InvalidLoginDataException.php | 13-------------
Dsrc/de/RaumZeitLabor/PartDB2/Auth/Exceptions/UserAlreadyExistsException.php | 13-------------
Dsrc/de/RaumZeitLabor/PartDB2/Auth/Exceptions/UserDoesNotExistException.php | 13-------------
Dsrc/de/RaumZeitLabor/PartDB2/Auth/User.php | 184-------------------------------------------------------------------------------
Dsrc/de/RaumZeitLabor/PartDB2/Auth/UserManager.php | 58----------------------------------------------------------
Dsrc/de/RaumZeitLabor/PartDB2/Auth/UserManagerService.php | 21---------------------
Dsrc/de/RaumZeitLabor/PartDB2/Category/Category.php | 72------------------------------------------------------------------------
Dsrc/de/RaumZeitLabor/PartDB2/Category/CategoryManager.php | 138-------------------------------------------------------------------------------
Dsrc/de/RaumZeitLabor/PartDB2/Category/CategoryService.php | 120-------------------------------------------------------------------------------
Dsrc/de/RaumZeitLabor/PartDB2/Category/Exceptions/CategoryNotFoundException.php | 13-------------
Dsrc/de/RaumZeitLabor/PartDB2/Distributor/Distributor.php | 134-------------------------------------------------------------------------------
Dsrc/de/RaumZeitLabor/PartDB2/Distributor/DistributorManager.php | 74--------------------------------------------------------------------------
Dsrc/de/RaumZeitLabor/PartDB2/Distributor/DistributorService.php | 142-------------------------------------------------------------------------------
Dsrc/de/RaumZeitLabor/PartDB2/Footprint/Exceptions/FootprintNotFoundException.php | 13-------------
Dsrc/de/RaumZeitLabor/PartDB2/Footprint/Footprint.php | 33---------------------------------
Dsrc/de/RaumZeitLabor/PartDB2/Footprint/FootprintManager.php | 116-------------------------------------------------------------------------------
Dsrc/de/RaumZeitLabor/PartDB2/Footprint/FootprintService.php | 103-------------------------------------------------------------------------------
Dsrc/de/RaumZeitLabor/PartDB2/Image/CachedImage.php | 79-------------------------------------------------------------------------------
Dsrc/de/RaumZeitLabor/PartDB2/Image/Exceptions/InvalidImageTypeException.php | 9---------
Dsrc/de/RaumZeitLabor/PartDB2/Image/Image.php | 242-------------------------------------------------------------------------------
Dsrc/de/RaumZeitLabor/PartDB2/Image/TempImage.php | 18------------------
Dsrc/de/RaumZeitLabor/PartDB2/Manufacturer/Manufacturer.php | 139-------------------------------------------------------------------------------
Dsrc/de/RaumZeitLabor/PartDB2/Manufacturer/ManufacturerICLogo.php | 26--------------------------
Dsrc/de/RaumZeitLabor/PartDB2/Manufacturer/ManufacturerManager.php | 74--------------------------------------------------------------------------
Dsrc/de/RaumZeitLabor/PartDB2/Manufacturer/ManufacturerService.php | 142-------------------------------------------------------------------------------
Dsrc/de/RaumZeitLabor/PartDB2/ManufacturerICLogo/ManufacturerICLogoManager.php | 75---------------------------------------------------------------------------
Dsrc/de/RaumZeitLabor/PartDB2/ManufacturerICLogo/ManufacturerICLogoService.php | 89-------------------------------------------------------------------------------
Dsrc/de/RaumZeitLabor/PartDB2/Part/Part.php | 225-------------------------------------------------------------------------------
Dsrc/de/RaumZeitLabor/PartDB2/Part/PartDistributor.php | 114-------------------------------------------------------------------------------
Dsrc/de/RaumZeitLabor/PartDB2/Part/PartManager.php | 376-------------------------------------------------------------------------------
Dsrc/de/RaumZeitLabor/PartDB2/Part/PartManufacturer.php | 83-------------------------------------------------------------------------------
Dsrc/de/RaumZeitLabor/PartDB2/Part/PartService.php | 182-------------------------------------------------------------------------------
Dsrc/de/RaumZeitLabor/PartDB2/Part/PartUnit.php | 135-------------------------------------------------------------------------------
Dsrc/de/RaumZeitLabor/PartDB2/PartDB2.php | 224-------------------------------------------------------------------------------
Dsrc/de/RaumZeitLabor/PartDB2/PartDistributor/PartDistributorManager.php | 76----------------------------------------------------------------------------
Dsrc/de/RaumZeitLabor/PartDB2/PartDistributor/PartDistributorService.php | 89-------------------------------------------------------------------------------
Dsrc/de/RaumZeitLabor/PartDB2/PartParameter/PartParameter.php | 222-------------------------------------------------------------------------------
Dsrc/de/RaumZeitLabor/PartDB2/PartUnit/PartUnitManager.php | 97-------------------------------------------------------------------------------
Dsrc/de/RaumZeitLabor/PartDB2/PartUnit/PartUnitService.php | 82-------------------------------------------------------------------------------
Dsrc/de/RaumZeitLabor/PartDB2/REST/ApplicationController.php | 42------------------------------------------
Dsrc/de/RaumZeitLabor/PartDB2/REST/Model.php | 71-----------------------------------------------------------------------
Dsrc/de/RaumZeitLabor/PartDB2/REST/Request.php | 115-------------------------------------------------------------------------------
Dsrc/de/RaumZeitLabor/PartDB2/REST/Response.php | 21---------------------
Dsrc/de/RaumZeitLabor/PartDB2/Service/AdminService.php | 18------------------
Dsrc/de/RaumZeitLabor/PartDB2/Service/AnonService.php | 10----------
Dsrc/de/RaumZeitLabor/PartDB2/Service/Exceptions/ServiceException.php | 10----------
Dsrc/de/RaumZeitLabor/PartDB2/Service/RestfulService.php | 11-----------
Dsrc/de/RaumZeitLabor/PartDB2/Service/Service.php | 69---------------------------------------------------------------------
Dsrc/de/RaumZeitLabor/PartDB2/Service/ServiceManager.php | 86-------------------------------------------------------------------------------
Dsrc/de/RaumZeitLabor/PartDB2/Session/Exceptions/SessionNotFoundException.php | 12------------
Dsrc/de/RaumZeitLabor/PartDB2/Session/Session.php | 52----------------------------------------------------
Dsrc/de/RaumZeitLabor/PartDB2/Session/SessionManager.php | 60------------------------------------------------------------
Dsrc/de/RaumZeitLabor/PartDB2/SiPrefix/SiPrefix.php | 116-------------------------------------------------------------------------------
Dsrc/de/RaumZeitLabor/PartDB2/SiPrefix/SiPrefixService.php | 29-----------------------------
Dsrc/de/RaumZeitLabor/PartDB2/Statistic/StatisticService.php | 38--------------------------------------
Dsrc/de/RaumZeitLabor/PartDB2/Statistic/StatisticSnapshot.php | 112-------------------------------------------------------------------------------
Dsrc/de/RaumZeitLabor/PartDB2/Statistic/StatisticSnapshotManager.php | 34----------------------------------
Dsrc/de/RaumZeitLabor/PartDB2/Statistic/StatisticSnapshotUnit.php | 99-------------------------------------------------------------------------------
Dsrc/de/RaumZeitLabor/PartDB2/Stock/StockEntry.php | 193-------------------------------------------------------------------------------
Dsrc/de/RaumZeitLabor/PartDB2/Stock/StockService.php | 52----------------------------------------------------
Dsrc/de/RaumZeitLabor/PartDB2/StorageLocation/Exceptions/StorageLocationNotFoundException.php | 13-------------
Dsrc/de/RaumZeitLabor/PartDB2/StorageLocation/StorageLocation.php | 35-----------------------------------
Dsrc/de/RaumZeitLabor/PartDB2/StorageLocation/StorageLocationManager.php | 89-------------------------------------------------------------------------------
Dsrc/de/RaumZeitLabor/PartDB2/StorageLocation/StorageLocationService.php | 106-------------------------------------------------------------------------------
Dsrc/de/RaumZeitLabor/PartDB2/TempImage/TempImageService.php | 23-----------------------
Dsrc/de/RaumZeitLabor/PartDB2/Unit/Unit.php | 112-------------------------------------------------------------------------------
Dsrc/de/RaumZeitLabor/PartDB2/Unit/UnitManager.php | 81-------------------------------------------------------------------------------
Dsrc/de/RaumZeitLabor/PartDB2/Unit/UnitService.php | 92-------------------------------------------------------------------------------
Dsrc/de/RaumZeitLabor/PartDB2/User/UserManager.php | 65-----------------------------------------------------------------
Dsrc/de/RaumZeitLabor/PartDB2/User/UserService.php | 78------------------------------------------------------------------------------
Dsrc/de/RaumZeitLabor/PartDB2/Util/Configuration.php | 44--------------------------------------------
Dsrc/de/RaumZeitLabor/PartDB2/Util/Exceptions/OutOfRangeException.php | 7-------
Dsrc/de/RaumZeitLabor/PartDB2/Util/SerializableException.php | 59-----------------------------------------------------------
Dsrc/de/RaumZeitLabor/PartDB2/Util/Singleton.php | 21---------------------
Dsrc/de/RaumZeitLabor/PartDB2/Util/UtilService.php | 15---------------
Asrc/de/RaumZeitLabor/PartKeepr/Auth/AuthManager.php | 14++++++++++++++
Asrc/de/RaumZeitLabor/PartKeepr/Auth/AuthService.php | 37+++++++++++++++++++++++++++++++++++++
Asrc/de/RaumZeitLabor/PartKeepr/Auth/Exceptions/InvalidLoginDataException.php | 13+++++++++++++
Asrc/de/RaumZeitLabor/PartKeepr/Auth/Exceptions/UserAlreadyExistsException.php | 13+++++++++++++
Asrc/de/RaumZeitLabor/PartKeepr/Auth/Exceptions/UserDoesNotExistException.php | 13+++++++++++++
Asrc/de/RaumZeitLabor/PartKeepr/Auth/User.php | 184+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Asrc/de/RaumZeitLabor/PartKeepr/Auth/UserManager.php | 58++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Asrc/de/RaumZeitLabor/PartKeepr/Auth/UserManagerService.php | 21+++++++++++++++++++++
Asrc/de/RaumZeitLabor/PartKeepr/Category/Category.php | 72++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Asrc/de/RaumZeitLabor/PartKeepr/Category/CategoryManager.php | 138+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Asrc/de/RaumZeitLabor/PartKeepr/Category/CategoryService.php | 120+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Asrc/de/RaumZeitLabor/PartKeepr/Category/Exceptions/CategoryNotFoundException.php | 13+++++++++++++
Asrc/de/RaumZeitLabor/PartKeepr/Distributor/Distributor.php | 134+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Asrc/de/RaumZeitLabor/PartKeepr/Distributor/DistributorManager.php | 74++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Asrc/de/RaumZeitLabor/PartKeepr/Distributor/DistributorService.php | 142+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Asrc/de/RaumZeitLabor/PartKeepr/Footprint/Exceptions/FootprintNotFoundException.php | 13+++++++++++++
Asrc/de/RaumZeitLabor/PartKeepr/Footprint/Footprint.php | 33+++++++++++++++++++++++++++++++++
Asrc/de/RaumZeitLabor/PartKeepr/Footprint/FootprintManager.php | 116+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Asrc/de/RaumZeitLabor/PartKeepr/Footprint/FootprintService.php | 103+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Asrc/de/RaumZeitLabor/PartKeepr/Image/CachedImage.php | 79+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Asrc/de/RaumZeitLabor/PartKeepr/Image/Exceptions/InvalidImageTypeException.php | 9+++++++++
Asrc/de/RaumZeitLabor/PartKeepr/Image/Image.php | 242+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Asrc/de/RaumZeitLabor/PartKeepr/Image/TempImage.php | 18++++++++++++++++++
Asrc/de/RaumZeitLabor/PartKeepr/Manufacturer/Manufacturer.php | 139+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Asrc/de/RaumZeitLabor/PartKeepr/Manufacturer/ManufacturerICLogo.php | 26++++++++++++++++++++++++++
Asrc/de/RaumZeitLabor/PartKeepr/Manufacturer/ManufacturerManager.php | 74++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Asrc/de/RaumZeitLabor/PartKeepr/Manufacturer/ManufacturerService.php | 142+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Asrc/de/RaumZeitLabor/PartKeepr/ManufacturerICLogo/ManufacturerICLogoManager.php | 75+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Asrc/de/RaumZeitLabor/PartKeepr/ManufacturerICLogo/ManufacturerICLogoService.php | 89+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Asrc/de/RaumZeitLabor/PartKeepr/Part/Part.php | 225+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Asrc/de/RaumZeitLabor/PartKeepr/Part/PartDistributor.php | 114+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Asrc/de/RaumZeitLabor/PartKeepr/Part/PartManager.php | 376+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Asrc/de/RaumZeitLabor/PartKeepr/Part/PartManufacturer.php | 83+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Asrc/de/RaumZeitLabor/PartKeepr/Part/PartService.php | 182+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Asrc/de/RaumZeitLabor/PartKeepr/Part/PartUnit.php | 135+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Asrc/de/RaumZeitLabor/PartKeepr/PartDistributor/PartDistributorManager.php | 76++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Asrc/de/RaumZeitLabor/PartKeepr/PartDistributor/PartDistributorService.php | 89+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Asrc/de/RaumZeitLabor/PartKeepr/PartKeepr.php | 224+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Asrc/de/RaumZeitLabor/PartKeepr/PartParameter/PartParameter.php | 222+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Asrc/de/RaumZeitLabor/PartKeepr/PartUnit/PartUnitManager.php | 97+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Asrc/de/RaumZeitLabor/PartKeepr/PartUnit/PartUnitService.php | 82+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Asrc/de/RaumZeitLabor/PartKeepr/REST/ApplicationController.php | 42++++++++++++++++++++++++++++++++++++++++++
Asrc/de/RaumZeitLabor/PartKeepr/REST/Model.php | 71+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Asrc/de/RaumZeitLabor/PartKeepr/REST/Request.php | 115+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Asrc/de/RaumZeitLabor/PartKeepr/REST/Response.php | 21+++++++++++++++++++++
Asrc/de/RaumZeitLabor/PartKeepr/Service/AdminService.php | 18++++++++++++++++++
Asrc/de/RaumZeitLabor/PartKeepr/Service/AnonService.php | 10++++++++++
Asrc/de/RaumZeitLabor/PartKeepr/Service/Exceptions/ServiceException.php | 10++++++++++
Asrc/de/RaumZeitLabor/PartKeepr/Service/RestfulService.php | 11+++++++++++
Asrc/de/RaumZeitLabor/PartKeepr/Service/Service.php | 69+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Asrc/de/RaumZeitLabor/PartKeepr/Service/ServiceManager.php | 86+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Asrc/de/RaumZeitLabor/PartKeepr/Session/Exceptions/SessionNotFoundException.php | 12++++++++++++
Asrc/de/RaumZeitLabor/PartKeepr/Session/Session.php | 52++++++++++++++++++++++++++++++++++++++++++++++++++++
Asrc/de/RaumZeitLabor/PartKeepr/Session/SessionManager.php | 60++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Asrc/de/RaumZeitLabor/PartKeepr/SiPrefix/SiPrefix.php | 116+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Asrc/de/RaumZeitLabor/PartKeepr/SiPrefix/SiPrefixService.php | 29+++++++++++++++++++++++++++++
Asrc/de/RaumZeitLabor/PartKeepr/Statistic/StatisticService.php | 38++++++++++++++++++++++++++++++++++++++
Asrc/de/RaumZeitLabor/PartKeepr/Statistic/StatisticSnapshot.php | 112+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Asrc/de/RaumZeitLabor/PartKeepr/Statistic/StatisticSnapshotManager.php | 34++++++++++++++++++++++++++++++++++
Asrc/de/RaumZeitLabor/PartKeepr/Statistic/StatisticSnapshotUnit.php | 99+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Asrc/de/RaumZeitLabor/PartKeepr/Stock/StockEntry.php | 193+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Asrc/de/RaumZeitLabor/PartKeepr/Stock/StockService.php | 52++++++++++++++++++++++++++++++++++++++++++++++++++++
Asrc/de/RaumZeitLabor/PartKeepr/StorageLocation/Exceptions/StorageLocationNotFoundException.php | 13+++++++++++++
Asrc/de/RaumZeitLabor/PartKeepr/StorageLocation/StorageLocation.php | 35+++++++++++++++++++++++++++++++++++
Asrc/de/RaumZeitLabor/PartKeepr/StorageLocation/StorageLocationManager.php | 89+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Asrc/de/RaumZeitLabor/PartKeepr/StorageLocation/StorageLocationService.php | 106+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Asrc/de/RaumZeitLabor/PartKeepr/TempImage/TempImageService.php | 23+++++++++++++++++++++++
Asrc/de/RaumZeitLabor/PartKeepr/Unit/Unit.php | 112+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Asrc/de/RaumZeitLabor/PartKeepr/Unit/UnitManager.php | 81+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Asrc/de/RaumZeitLabor/PartKeepr/Unit/UnitService.php | 92+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Asrc/de/RaumZeitLabor/PartKeepr/User/UserManager.php | 65+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Asrc/de/RaumZeitLabor/PartKeepr/User/UserService.php | 78++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Asrc/de/RaumZeitLabor/PartKeepr/Util/Configuration.php | 44++++++++++++++++++++++++++++++++++++++++++++
Asrc/de/RaumZeitLabor/PartKeepr/Util/Exceptions/OutOfRangeException.php | 7+++++++
Asrc/de/RaumZeitLabor/PartKeepr/Util/SerializableException.php | 59+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Asrc/de/RaumZeitLabor/PartKeepr/Util/Singleton.php | 21+++++++++++++++++++++
Asrc/de/RaumZeitLabor/PartKeepr/Util/UtilService.php | 15+++++++++++++++
Mtesting/PartTest.php | 26+++++++++++++-------------
Mtesting/Service.php | 22+++++++++++-----------
Mtesting/SetupDatabase.php | 88++++++++++++++++++++++++++++++++++++++++----------------------------------------
Mtesting/genman.php | 6+++---
Mtests/Auth/AuthManagerTest.php | 6+++---
Mtests/Auth/UserManagerTest.php | 18+++++++++---------
Mtests/Auth/UserTest.php | 4++--
Mtests/Util/ConfigurationTest.php | 4++--
Mtests/bootstrap.php | 12++++++------
Dtests/reports/phpunit/allclasses-frame.html | 16----------------
Dtests/reports/phpunit/default/AuthManagerTest.html | 51---------------------------------------------------
Dtests/reports/phpunit/default/de\RaumZeitLabor\PartDB2\AuthManagerTest.html | 51---------------------------------------------------
Dtests/reports/phpunit/default/de\RaumZeitLabor\PartDB2\Tests\Auth\AuthManagerTest.html | 51---------------------------------------------------
Dtests/reports/phpunit/default/de\RaumZeitLabor\PartDB2\Tests\Auth\UserManagerTest.html | 69---------------------------------------------------------------------
Dtests/reports/phpunit/default/de\RaumZeitLabor\PartDB2\Tests\Auth\UserTest.html | 51---------------------------------------------------
Dtests/reports/phpunit/default/de\RaumZeitLabor\PartDB2\Tests\Util\ConfigurationTest.html | 51---------------------------------------------------
Dtests/reports/phpunit/default/package-frame.html | 17-----------------
Dtests/reports/phpunit/default/package-summary.html | 57---------------------------------------------------------
Dtests/reports/phpunit/index.html | 19-------------------
Dtests/reports/phpunit/overview-frame.html | 12------------
Dtests/reports/phpunit/overview-summary.html | 56--------------------------------------------------------
Dtests/reports/phpunit/stylesheet.css | 66------------------------------------------------------------------
Dtests/reports/phpunit/testsuites.xml | 28----------------------------
277 files changed, 7012 insertions(+), 7606 deletions(-)

diff --git a/.gitignore b/.gitignore @@ -4,3 +4,4 @@ .externalToolBuilders .settings .project +/tests/reports diff --git a/INSTALL b/INSTALL @@ -1,4 +1,4 @@ -PartDB2 Installation Instructions +PartKeepr Installation Instructions ================================= 1) Quick Installation diff --git a/README.md b/README.md @@ -1,10 +1,10 @@ README ====== -What is PartDB2? +What is PartKeepr? ---------------- -PartDB2 is an electronic part inventory management software. It helps you to keep track of your available parts and assist you with re-ordering parts. PartDB2 is designed for hackerspaces with multiple users, but you can also use it to manage your personal electronic part inventory. +PartKeepr is an electronic part inventory management software. It helps you to keep track of your available parts and assist you with re-ordering parts. PartKeepr is designed for hackerspaces with multiple users, but you can also use it to manage your personal electronic part inventory. Project Status -------------- @@ -16,13 +16,13 @@ you get the point. Demo Site --------- -To test everything which has been written so far, please visit http://partdb2.felicitus.org for a demo which is built +To test everything which has been written so far, please visit http://partkeepr.felicitus.org for a demo which is built from the git sources once an hour. Requirements ------------ -PartDB2 needs: +PartKeepr needs: * PHP 5.3.2 and up * APC (see http://www.php.net/manual/en/apc.installation.php how to install it) @@ -35,4 +35,4 @@ PartDB2 needs: Installation ------------ -Since this project is work-in-progress, please refer to the INSTALL document on how to install PartDB2.- \ No newline at end of file +Since this project is work-in-progress, please refer to the INSTALL document on how to install PartKeepr.+ \ No newline at end of file diff --git a/build.xml b/build.xml @@ -1,5 +1,5 @@ <?xml version="1.0" encoding="UTF-8"?> -<project name="partdb2" default="test-setup"> +<project name="partkeepr" default="test-setup"> <target name="test-setup" > <echo msg="Testing the installation..." /> diff --git a/cli-config.php b/cli-config.php @@ -1,14 +1,14 @@ <?php -use de\RaumZeitLabor\PartDB2\Service\ServiceManager; -use de\RaumZeitLabor\PartDB2\PartDB2; +use de\RaumZeitLabor\PartKeepr\Service\ServiceManager; +use de\RaumZeitLabor\PartKeepr\PartKeepr; use Doctrine\Common\ClassLoader; -include("src/de/RaumZeitLabor/PartDB2/PartDB2.php"); -PartDB2::initialize(""); +include("src/de/RaumZeitLabor/PartKeepr/PartKeepr.php"); +PartKeepr::initialize(""); -$em = PartDB2::getEM(); +$em = PartKeepr::getEM(); -$classes = PartDB2::getEntityClasses(); +$classes = PartKeepr::getEntityClasses(); $helperSet = new \Symfony\Component\Console\Helper\HelperSet(array( diff --git a/config-test.php b/config-test.php @@ -1,12 +1,12 @@ <?php -namespace de\RaumZeitLabor\PartDB2; +namespace de\RaumZeitLabor\PartKeepr; -use de\RaumZeitLabor\PartDB2\Util\Configuration; +use de\RaumZeitLabor\PartKeepr\Util\Configuration; -Configuration::setOption("partdb2.database.username", "partdb2"); -Configuration::setOption("partdb2.database.password", "partdb2"); -Configuration::setOption("partdb2.database.hostname", "localhost"); -Configuration::setOption("partdb2.database.dbname", "partdb2-test"); -Configuration::setOption("partdb2.database.driver", "pdo_mysql"); +Configuration::setOption("partkeepr.database.username", "partkeepr"); +Configuration::setOption("partkeepr.database.password", "partkeepr"); +Configuration::setOption("partkeepr.database.hostname", "localhost"); +Configuration::setOption("partkeepr.database.dbname", "partkeepr-test"); +Configuration::setOption("partkeepr.database.driver", "pdo_mysql"); ?> \ No newline at end of file diff --git a/config.php b/config.php @@ -1,13 +1,13 @@ <?php -namespace de\RaumZeitLabor\PartDB2; +namespace de\RaumZeitLabor\PartKeepr; -use de\RaumZeitLabor\PartDB2\Util\Configuration; +use de\RaumZeitLabor\PartKeepr\Util\Configuration; -Configuration::setOption("partdb2.database.username", "partdb2"); -Configuration::setOption("partdb2.database.password", "partdb2"); -Configuration::setOption("partdb2.database.hostname", "localhost"); -Configuration::setOption("partdb2.database.dbname", "partdb2"); -Configuration::setOption("partdb2.database.driver", "pdo_mysql"); +Configuration::setOption("partkeepr.database.username", "partkeepr"); +Configuration::setOption("partkeepr.database.password", "partkeepr"); +Configuration::setOption("partkeepr.database.hostname", "localhost"); +Configuration::setOption("partkeepr.database.dbname", "partkeepr"); +Configuration::setOption("partkeepr.database.driver", "pdo_mysql"); -Configuration::setOption("partdb2.images.path", __DIR__."/data/images/"); -Configuration::setOption("partdb2.images.cache", Configuration::getOption("partdb2.images.path")."cache/"); +Configuration::setOption("partkeepr.images.path", __DIR__."/data/images/"); +Configuration::setOption("partkeepr.images.cache", Configuration::getOption("partkeepr.images.path")."cache/"); diff --git a/cronjobs/CreateStatisticSnapshot.php b/cronjobs/CreateStatisticSnapshot.php @@ -1,13 +1,13 @@ <?php -namespace de\RaumZeitLabor\PartDB2\Cronjobs; +namespace de\RaumZeitLabor\PartKeepr\Cronjobs; declare(encoding = 'UTF-8'); -include("../src/de/RaumZeitLabor/PartDB2/PartDB2.php"); +include("../src/de/RaumZeitLabor/PartKeepr/PartKeepr.php"); -use de\RaumZeitLabor\PartDB2\PartDB2; -use de\RaumZeitLabor\PartDB2\Statistic\StatisticSnapshotManager; -PartDB2::initialize(); +use de\RaumZeitLabor\PartKeepr\PartKeepr; +use de\RaumZeitLabor\PartKeepr\Statistic\StatisticSnapshotManager; +PartKeepr::initialize(); diff --git a/documentation/ARCHITECTURE b/documentation/ARCHITECTURE @@ -1,4 +1,4 @@ -PartDB2 is based on current technologies. +PartKeepr is based on current technologies. PHP === diff --git a/documentation/QUICK-INSTALL b/documentation/QUICK-INSTALL @@ -1,4 +1,4 @@ -PartDB2 Quick Installation Guide +PartKeepr Quick Installation Guide ================================ BIG FAT WARNING! BIG FAT WARNING! BIG FAT WARNING! BIG FAT WARNING! @@ -62,7 +62,7 @@ phing test-setup Install the database and test data ---------------------------------- -Create the user partdb2, password partdb2 with access to the partdb2 database +Create the user partkeepr, password partkeepr with access to the partkeepr database in mysql (e.g. with phpmyadmin). Then execute the file testing/SetupDatabase.php from the command line. diff --git a/frontend/css/PartDB2.css b/frontend/css/PartKeepr.css diff --git a/frontend/image.php b/frontend/image.php @@ -1,16 +1,16 @@ <?php -namespace de\RaumZeitLabor\PartDB2\Frontend; -use de\RaumZeitLabor\PartDB2\Image\TempImage; +namespace de\RaumZeitLabor\PartKeepr\Frontend; +use de\RaumZeitLabor\PartKeepr\Image\TempImage; declare(encoding = 'UTF-8'); -use de\RaumZeitLabor\PartDB2\PartDB2; -use de\RaumZeitLabor\PartDB2\Image\Image; -use de\RaumZeitLabor\PartDB2\Manufacturer\ManufacturerICLogo; +use de\RaumZeitLabor\PartKeepr\PartKeepr; +use de\RaumZeitLabor\PartKeepr\Image\Image; +use de\RaumZeitLabor\PartKeepr\Manufacturer\ManufacturerICLogo; -include("../src/de/RaumZeitLabor/PartDB2/PartDB2.php"); +include("../src/de/RaumZeitLabor/PartKeepr/PartKeepr.php"); -PartDB2::initialize(""); +PartKeepr::initialize(""); $type = $_REQUEST["type"]; $id = $_REQUEST["id"]; diff --git a/frontend/index.php b/frontend/index.php @@ -3,7 +3,7 @@ <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/> - <title>PartDB2</title> + <title>PartKeepr</title> <link rel="icon" href="favicon.ico"/> @@ -19,7 +19,7 @@ <link rel="stylesheet" type="text/css" href="js/Ext.ux/statusbar/css/statusbar.css"/> - <link rel="stylesheet" type="text/css" href="css/PartDB2.css"/> + <link rel="stylesheet" type="text/css" href="css/PartKeepr.css"/> <script type="text/javascript" src="js/bugfixes.js"></script> <script type="text/javascript" src="js/Util/i18n.js"></script> @@ -49,7 +49,7 @@ <script type="text/javascript" src="js/org.jerrymouse.util.locale/locales/en_US.js"></script> <script type="text/javascript" src="js/org.jerrymouse.util.locale/locales/de_DE.js"></script> - <script type="text/javascript" src="js/PartDB2.js"></script> + <script type="text/javascript" src="js/PartKeepr.js"></script> <script type="text/javascript" src="js/Models/Footprint.js"></script> <script type="text/javascript" src="js/Models/StorageLocation.js"></script> @@ -155,8 +155,8 @@ $imagick = new Imagick(); ?> <script type="text/javascript"> -PartDB2.setMaxUploadSize(<?php echo $maxUploadSize; ?>); -PartDB2.setAvailableImageFormats(<?php echo json_encode($imagick->queryFormats()); ?>); +PartKeepr.setMaxUploadSize(<?php echo $maxUploadSize; ?>); +PartKeepr.setAvailableImageFormats(<?php echo json_encode($imagick->queryFormats()); ?>); </script> </body> diff --git a/frontend/js/Components/CategoryEditor/CategoryEditorForm.js b/frontend/js/Components/CategoryEditor/CategoryEditorForm.js @@ -1,4 +1,4 @@ -Ext.define('PartDB2.CategoryEditorForm', { +Ext.define('PartKeepr.CategoryEditorForm', { extend: 'Ext.form.Panel', layout: 'anchor', border: false, diff --git a/frontend/js/Components/CategoryEditor/CategoryEditorTree.js b/frontend/js/Components/CategoryEditor/CategoryEditorTree.js @@ -1,6 +1,6 @@ -PartDB2.CategoryEditorTree = Ext.define("CategoryEditorTree", { +PartKeepr.CategoryEditorTree = Ext.define("CategoryEditorTree", { alias: 'widget.CategoryEditorTree', - extend: 'PartDB2.CategoryTree', + extend: 'PartKeepr.CategoryTree', viewConfig: { animate: false, plugins: { @@ -31,7 +31,7 @@ PartDB2.CategoryEditorTree = Ext.define("CategoryEditorTree", { this.getStore().sort("name", "ASC"); - var call = new PartDB2.ServiceCall("Category", "moveCategory"); + var call = new PartKeepr.ServiceCall("Category", "moveCategory"); call.setLoadMessage(sprintf(i18n("Moving category %s..."), draggedRecord.get("name"))); call.setParameter("category", draggedRecord.get("id")); call.setParameter("target", targetRecord.get("id")); @@ -87,7 +87,7 @@ PartDB2.CategoryEditorTree = Ext.define("CategoryEditorTree", { Ext.Msg.confirm(i18n("Confirm Category Delete"), sprintf(i18n("Do you really wish to delete the category %s?"), this.menu.record.get("name")), this.onCategoryDelete, this); }, showCategoryAddDialog: function () { - var j = Ext.create("PartDB2.CategoryEditorWindow", { + var j = Ext.create("PartKeepr.CategoryEditorWindow", { record: null, parent: this.menu.record.get("id"), listeners: { @@ -98,7 +98,7 @@ PartDB2.CategoryEditorTree = Ext.define("CategoryEditorTree", { j.show(); }, showCategoryEditDialog: function () { - var j = Ext.create("PartDB2.CategoryEditorWindow", { + var j = Ext.create("PartKeepr.CategoryEditorWindow", { record: this.menu.record, parent: null, listeners: { @@ -131,7 +131,7 @@ PartDB2.CategoryEditorTree = Ext.define("CategoryEditorTree", { }, onCategoryDelete: function (btn) { if (btn == "yes") { - var call = new PartDB2.ServiceCall("Category", "deleteCategory"); + var call = new PartKeepr.ServiceCall("Category", "deleteCategory"); call.setLoadMessage(sprintf(i18n("Deleting category %s..."), this.menu.record.get("name"))); call.setParameter("id", this.menu.record.get("id")); call.setHandler(Ext.bind(this.onCategoryDeleted, this)); diff --git a/frontend/js/Components/CategoryEditor/CategoryEditorWindow.js b/frontend/js/Components/CategoryEditor/CategoryEditorWindow.js @@ -1,10 +1,10 @@ -Ext.define('PartDB2.CategoryEditorWindow', { +Ext.define('PartKeepr.CategoryEditorWindow', { extend: 'Ext.window.Window', border: false, width: 400, initComponent: function () { - this.form = Ext.create("PartDB2.CategoryEditorForm"); + this.form = Ext.create("PartKeepr.CategoryEditorForm"); this.buttons = [{ text: i18n("Save"), @@ -20,7 +20,7 @@ Ext.define('PartDB2.CategoryEditorWindow', { this.callParent(); - this.proxyRecord = Ext.create("PartDB2.Category"); + this.proxyRecord = Ext.create("PartKeepr.Category"); if (this.record) { this.proxyRecord.set("name", this.record.get("name")); diff --git a/frontend/js/Components/CategoryStore.js b/frontend/js/Components/CategoryStore.js @@ -1,4 +1,4 @@ -PartDB2.CategoryTreeStore = Ext.define("CategoryTreeStore", +PartKeepr.CategoryTreeStore = Ext.define("CategoryTreeStore", { extend: "Ext.data.TreeStore", model: 'Category', @@ -20,7 +20,7 @@ PartDB2.CategoryTreeStore = Ext.define("CategoryTreeStore", expanded: true }, constructor: function () { - this.proxy.extraParams.session = PartDB2.getSession(); + this.proxy.extraParams.session = PartKeepr.getSession(); this.callParent(); }, diff --git a/frontend/js/Components/CategoryTree.js b/frontend/js/Components/CategoryTree.js @@ -1,4 +1,4 @@ -PartDB2.CategoryTree = Ext.define("CategoryTree", { +PartKeepr.CategoryTree = Ext.define("CategoryTree", { alias: 'widget.CategoryTree', extend: 'Ext.tree.Panel', displayField: 'name', @@ -27,7 +27,7 @@ PartDB2.CategoryTree = Ext.define("CategoryTree", { this.loadCategories(); }, loadCategories: function () { - var call = new PartDB2.ServiceCall("Category", "getAllCategories"); + var call = new PartKeepr.ServiceCall("Category", "getAllCategories"); call.setLoadMessage(i18n("Loading categories...")); call.setHandler(Ext.bind(this.onCategoriesLoaded, this)); call.doCall(); diff --git a/frontend/js/Components/ConnectionButton.js b/frontend/js/Components/ConnectionButton.js @@ -1,4 +1,4 @@ -Ext.define('PartDB2.ConnectionButton', { +Ext.define('PartKeepr.ConnectionButton', { extend: 'Ext.Button', connectedIcon: 'resources/silkicons/connect.png', disconnectedIcon: 'resources/silkicons/disconnect.png', diff --git a/frontend/js/Components/Distributor/DistributorEditor.js b/frontend/js/Components/Distributor/DistributorEditor.js @@ -1,5 +1,5 @@ -Ext.define('PartDB2.DistributorEditor', { - extend: 'PartDB2.Editor', +Ext.define('PartKeepr.DistributorEditor', { + extend: 'PartKeepr.Editor', alias: 'widget.DistributorEditor', items: [{ xtype: 'textfield', @@ -23,5 +23,5 @@ Ext.define('PartDB2.DistributorEditor', { fieldLabel: i18n("Comment") }], saveText: i18n("Save Distributor"), - model: 'PartDB2.Distributor' + model: 'PartKeepr.Distributor' }); diff --git a/frontend/js/Components/Distributor/DistributorEditorComponent.js b/frontend/js/Components/Distributor/DistributorEditorComponent.js @@ -1,8 +1,8 @@ -Ext.define('PartDB2.DistributorEditorComponent', { - extend: 'PartDB2.EditorComponent', +Ext.define('PartKeepr.DistributorEditorComponent', { + extend: 'PartKeepr.EditorComponent', alias: 'widget.DistributorEditorComponent', - gridClass: 'PartDB2.DistributorGrid', - editorClass: 'PartDB2.DistributorEditor', + gridClass: 'PartKeepr.DistributorGrid', + editorClass: 'PartKeepr.DistributorEditor', newItemText: i18n("New Distributor"), initComponent: function () { this.createStore({ diff --git a/frontend/js/Components/Distributor/DistributorGrid.js b/frontend/js/Components/Distributor/DistributorGrid.js @@ -1,5 +1,5 @@ -Ext.define('PartDB2.DistributorGrid', { - extend: 'PartDB2.EditorGrid', +Ext.define('PartKeepr.DistributorGrid', { + extend: 'PartKeepr.EditorGrid', alias: 'widget.DistributorGrid', columns: [ {header: i18n("Distributor"), dataIndex: 'name', flex: 1} diff --git a/frontend/js/Components/Editor/Editor.js b/frontend/js/Components/Editor/Editor.js @@ -1,4 +1,4 @@ -Ext.define('PartDB2.Editor', { +Ext.define('PartKeepr.Editor', { extend: 'Ext.form.Panel', alias: 'widget.Editor', trackResetOnLoad: true, diff --git a/frontend/js/Components/Editor/EditorComponent.js b/frontend/js/Components/Editor/EditorComponent.js @@ -1,12 +1,12 @@ /** - * @class PartDB2.EditorComponent + * @class PartKeepr.EditorComponent * <p>The EditorComponent encapsulates an editing workflow. In general, we have four actions * for each object: create, update, delete, view. These actions stay exactly the same for each * distinct object.</p> * <p>The EditorComponent is a border layout, which has a grid and a form.</p> * @todo Document the editor system a bit better */ -Ext.define('PartDB2.EditorComponent', { +Ext.define('PartKeepr.EditorComponent', { extend: 'Ext.panel.Panel', alias: 'widget.EditorComponent', layout: 'border', diff --git a/frontend/js/Components/Editor/EditorGrid.js b/frontend/js/Components/Editor/EditorGrid.js @@ -6,7 +6,7 @@ * - Search field * - Paging Toolbar */ -Ext.define('PartDB2.EditorGrid', { +Ext.define('PartKeepr.EditorGrid', { extend: 'Ext.grid.Panel', alias: 'widget.EditorGrid', diff --git a/frontend/js/Components/Footprint/FootprintEditor.js b/frontend/js/Components/Footprint/FootprintEditor.js @@ -1,5 +1,5 @@ -Ext.define('PartDB2.FootprintEditor', { - extend: 'PartDB2.Editor', +Ext.define('PartKeepr.FootprintEditor', { + extend: 'PartKeepr.Editor', alias: 'widget.FootprintEditor', items: [{ xtype: 'textfield', @@ -7,5 +7,5 @@ Ext.define('PartDB2.FootprintEditor', { fieldLabel: i18n("Footprint") }], saveText: i18n("Save Footprint"), - model: 'PartDB2.Footprint' + model: 'PartKeepr.Footprint' }); \ No newline at end of file diff --git a/frontend/js/Components/Footprint/FootprintEditorComponent.js b/frontend/js/Components/Footprint/FootprintEditorComponent.js @@ -1,8 +1,8 @@ -Ext.define('PartDB2.FootprintEditorComponent', { - extend: 'PartDB2.EditorComponent', +Ext.define('PartKeepr.FootprintEditorComponent', { + extend: 'PartKeepr.EditorComponent', alias: 'widget.FootprintEditorComponent', - gridClass: 'PartDB2.FootprintGrid', - editorClass: 'PartDB2.FootprintEditor', + gridClass: 'PartKeepr.FootprintGrid', + editorClass: 'PartKeepr.FootprintEditor', newItemText: i18n("New Footprint"), initComponent: function () { this.createStore({ diff --git a/frontend/js/Components/Footprint/FootprintGrid.js b/frontend/js/Components/Footprint/FootprintGrid.js @@ -1,5 +1,5 @@ -Ext.define('PartDB2.FootprintGrid', { - extend: 'PartDB2.EditorGrid', +Ext.define('PartKeepr.FootprintGrid', { + extend: 'PartKeepr.EditorGrid', alias: 'widget.FootprintGrid', columns: [ {header: i18n("Footprint"), dataIndex: 'footprint', flex: 1} diff --git a/frontend/js/Components/Manufacturer/ManufacturerEditor.js b/frontend/js/Components/Manufacturer/ManufacturerEditor.js @@ -1,8 +1,8 @@ -Ext.define('PartDB2.ManufacturerEditor', { - extend: 'PartDB2.Editor', +Ext.define('PartKeepr.ManufacturerEditor', { + extend: 'PartKeepr.Editor', alias: 'widget.ManufacturerEditor', saveText: i18n("Save Manufacturer"), - model: 'PartDB2.Manufacturer', + model: 'PartKeepr.Manufacturer', labelWidth: 150, initComponent: function () { this.on("startEdit", Ext.bind(this.onEditStart, this)); @@ -110,7 +110,7 @@ Ext.define('PartDB2.ManufacturerEditor', { }); }, uploadImage: function () { - var j = Ext.create("PartDB2.FileUploadDialog", { imageUpload: true }); + var j = Ext.create("PartKeepr.FileUploadDialog", { imageUpload: true }); j.on("fileUploaded", Ext.bind(this.onFileUploaded, this)); j.show(); }, diff --git a/frontend/js/Components/Manufacturer/ManufacturerEditorComponent.js b/frontend/js/Components/Manufacturer/ManufacturerEditorComponent.js @@ -1,8 +1,8 @@ -Ext.define('PartDB2.ManufacturerEditorComponent', { - extend: 'PartDB2.EditorComponent', +Ext.define('PartKeepr.ManufacturerEditorComponent', { + extend: 'PartKeepr.EditorComponent', alias: 'widget.ManufacturerEditorComponent', - gridClass: 'PartDB2.ManufacturerGrid', - editorClass: 'PartDB2.ManufacturerEditor', + gridClass: 'PartKeepr.ManufacturerGrid', + editorClass: 'PartKeepr.ManufacturerEditor', newItemText: i18n("New Manufacturer"), initComponent: function () { this.createStore({ diff --git a/frontend/js/Components/Manufacturer/ManufacturerGrid.js b/frontend/js/Components/Manufacturer/ManufacturerGrid.js @@ -1,5 +1,5 @@ -Ext.define('PartDB2.ManufacturerGrid', { - extend: 'PartDB2.EditorGrid', +Ext.define('PartKeepr.ManufacturerGrid', { + extend: 'PartKeepr.EditorGrid', alias: 'widget.ManufacturerGrid', columns: [ {header: i18n("Manufacturer"), dataIndex: 'name', flex: 1} diff --git a/frontend/js/Components/Menu.js b/frontend/js/Components/Menu.js @@ -1,4 +1,4 @@ -Ext.define('PartDB2.Menu', { +Ext.define('PartKeepr.Menu', { extend: 'Ext.toolbar.Toolbar', items: [{ diff --git a/frontend/js/Components/MenuBar.js b/frontend/js/Components/MenuBar.js @@ -1,4 +1,4 @@ -Ext.define('PartDB2.MenuBar', { +Ext.define('PartKeepr.MenuBar', { extend: 'Ext.toolbar.Toolbar', initComponent: function () { @@ -46,70 +46,70 @@ Ext.define('PartDB2.MenuBar', { this.callParent(); }, showStatistics: function () { - var j = Ext.create("PartDB2.CurrentStatisticsDialog"); + var j = Ext.create("PartKeepr.CurrentStatisticsDialog"); j.show(); }, editStorageLocations: function () { - var j = Ext.create("PartDB2.StorageLocationEditorComponent", { + var j = Ext.create("PartKeepr.StorageLocationEditorComponent", { title: i18n("Storage Locations"), closable: true }); - PartDB2.getApplication().addItem(j); + PartKeepr.getApplication().addItem(j); j.show(); }, editUnits: function () { - var j = Ext.create("PartDB2.UnitEditorComponent", { + var j = Ext.create("PartKeepr.UnitEditorComponent", { title: i18n("Units"), closable: true }); - PartDB2.getApplication().addItem(j); + PartKeepr.getApplication().addItem(j); j.show(); }, editManufacturers: function () { - var j = Ext.create("PartDB2.ManufacturerEditorComponent", { + var j = Ext.create("PartKeepr.ManufacturerEditorComponent", { title: i18n("Manufacturers"), closable: true }); - PartDB2.getApplication().addItem(j); + PartKeepr.getApplication().addItem(j); j.show(); }, editFootprints: function () { - var j = Ext.create("PartDB2.FootprintEditorComponent", { + var j = Ext.create("PartKeepr.FootprintEditorComponent", { title: i18n("Footprints"), closable: true }); - PartDB2.getApplication().addItem(j); + PartKeepr.getApplication().addItem(j); j.show(); }, editDistributors: function () { - var j = Ext.create("PartDB2.DistributorEditorComponent", { + var j = Ext.create("PartKeepr.DistributorEditorComponent", { title: i18n("Distributors"), closable: true }); - PartDB2.getApplication().addItem(j); + PartKeepr.getApplication().addItem(j); j.show(); }, editUsers: function () { - var j = Ext.create("PartDB2.UserEditorComponent", { + var j = Ext.create("PartKeepr.UserEditorComponent", { title: i18n("Users"), closable: true }); - PartDB2.getApplication().addItem(j); + PartKeepr.getApplication().addItem(j); j.show(); }, editPartUnits: function () { - var j = Ext.create("PartDB2.PartUnitEditorComponent", { + var j = Ext.create("PartKeepr.PartUnitEditorComponent", { title: i18n("Part Units"), closable: true }); - PartDB2.getApplication().addItem(j); + PartKeepr.getApplication().addItem(j); j.show(); } }); diff --git a/frontend/js/Components/MessageLog.js b/frontend/js/Components/MessageLog.js @@ -1,4 +1,4 @@ -Ext.define('PartDB2.MessageLog', { +Ext.define('PartKeepr.MessageLog', { extend: 'Ext.grid.Panel', store: { model: "Message" diff --git a/frontend/js/Components/Part/PartDisplay.js b/frontend/js/Components/Part/PartDisplay.js @@ -1,8 +1,8 @@ /** - * @class PartDB2.PartDisplay + * @class PartKeepr.PartDisplay * <p>This component displays information about a specific part.</p> */ -Ext.define('PartDB2.PartDisplay', { +Ext.define('PartKeepr.PartDisplay', { extend: 'Ext.panel.Panel', bodyCls: 'partdisplay', @@ -112,14 +112,14 @@ Ext.define('PartDB2.PartDisplay', { * Prompt the user for the stock level he wishes to add. */ addPartPrompt: function () { - var j = new PartDB2.PartStockWindow(); + var j = new PartKeepr.PartStockWindow(); j.addStock(this.addPartHandler, this); }, /** * Callback after the "add stock" dialog is complete. */ addPartHandler: function (quantity, price) { - var call = new PartDB2.ServiceCall( + var call = new PartKeepr.ServiceCall( "Part", "addStock"); call.setParameter("stock", quantity); @@ -132,7 +132,7 @@ Ext.define('PartDB2.PartDisplay', { * Prompts the user for the stock level to decrease for the item. */ deletePartPrompt: function () { - var j = new PartDB2.PartStockWindow(); + var j = new PartKeepr.PartStockWindow(); j.removeStock(this.deletePartHandler, this); //Ext.Msg.prompt(i18n("Remove Stock"), i18n("Amount"), this.deletePartHandler, this); }, @@ -140,7 +140,7 @@ Ext.define('PartDB2.PartDisplay', { * Callback after the "delete stock" dialog is complete. */ deletePartHandler: function (quantity) { - var call = new PartDB2.ServiceCall( + var call = new PartKeepr.ServiceCall( "Part", "deleteStock"); call.setParameter("stock", quantity); @@ -158,11 +158,11 @@ Ext.define('PartDB2.PartDisplay', { * Load the part from the database. */ loadPart: function (id) { - var call = new PartDB2.ServiceCall( + var call = new PartKeepr.ServiceCall( "Part", "getPart"); call.setParameter("part", id); - call.setLoadMessage('$[de.RaumZeitLabor.PartDB2.CategoryEditor.loadCategories]'); + call.setLoadMessage('$[de.RaumZeitLabor.PartKeepr.CategoryEditor.loadCategories]'); call.setHandler(Ext.bind(this.onPartLoaded, this)); call.doCall(); }, diff --git a/frontend/js/Components/Part/PartDistributorGrid.js b/frontend/js/Components/Part/PartDistributorGrid.js @@ -1,4 +1,4 @@ -Ext.define('PartDB2.PartDistributorGrid', { +Ext.define('PartKeepr.PartDistributorGrid', { extend: 'Ext.grid.Panel', alias: 'widget.PartDistributorGrid', border: false, @@ -80,7 +80,7 @@ Ext.define('PartDB2.PartDistributorGrid', { onEdit: function (data) { var id = data.record.get("distributor_id"); - var rec = PartDB2.getApplication().getDistributorStore().findRecord("id", id); + var rec = PartKeepr.getApplication().getDistributorStore().findRecord("id", id); if (rec) { data.record.set("distributor_name", rec.get("name")); @@ -89,7 +89,7 @@ Ext.define('PartDB2.PartDistributorGrid', { onAddClick: function () { this.editing.cancelEdit(); - var rec = new PartDB2.PartDistributor({ + var rec = new PartKeepr.PartDistributor({ packagingUnit: 1 }); diff --git a/frontend/js/Components/Part/PartEditor.js b/frontend/js/Components/Part/PartEditor.js @@ -1,7 +1,7 @@ -Ext.define('PartDB2.PartEditor', { - extend: 'PartDB2.Editor', +Ext.define('PartKeepr.PartEditor', { + extend: 'PartKeepr.Editor', border: false, - model: 'PartDB2.Part', + model: 'PartKeepr.Part', mode: 'add', layout: 'fit', bodyStyle: 'background:#DFE8F6;', @@ -42,17 +42,17 @@ Ext.define('PartDB2.PartEditor', { name: 'comment' }]; - this.partDistributorGrid = Ext.create("PartDB2.PartDistributorGrid", { + this.partDistributorGrid = Ext.create("PartKeepr.PartDistributorGrid", { title: i18n("Distributors"), layout: 'fit' }); - this.partManufacturerGrid = Ext.create("PartDB2.PartManufacturerGrid", { + this.partManufacturerGrid = Ext.create("PartKeepr.PartManufacturerGrid", { title: i18n("Manufacturers"), layout: 'fit' }); - this.partParameterGrid = Ext.create("PartDB2.PartParameterGrid", { + this.partParameterGrid = Ext.create("PartKeepr.PartParameterGrid", { title: i18n("Parameters"), layout: 'fit' }); @@ -91,7 +91,7 @@ Ext.define('PartDB2.PartEditor', { return; } - var call = new PartDB2.ServiceCall( + var call = new PartKeepr.ServiceCall( "Part", "addOrUpdatePart"); @@ -102,21 +102,21 @@ Ext.define('PartDB2.PartEditor', { var values = this.getForm().getFieldValues(); values.distributorChanges = { - "inserts": PartDB2.serializeRecords(this.partDistributorGrid.getStore().getNewRecords()), - "updates": PartDB2.serializeRecords(this.partDistributorGrid.getStore().getUpdatedRecords()), - "removals": PartDB2.serializeRecords(this.partDistributorGrid.getStore().getRemovedRecords()) + "inserts": PartKeepr.serializeRecords(this.partDistributorGrid.getStore().getNewRecords()), + "updates": PartKeepr.serializeRecords(this.partDistributorGrid.getStore().getUpdatedRecords()), + "removals": PartKeepr.serializeRecords(this.partDistributorGrid.getStore().getRemovedRecords()) }; values.manufacturerChanges = { - "inserts": PartDB2.serializeRecords(this.partManufacturerGrid.getStore().getNewRecords()), - "updates": PartDB2.serializeRecords(this.partManufacturerGrid.getStore().getUpdatedRecords()), - "removals": PartDB2.serializeRecords(this.partManufacturerGrid.getStore().getRemovedRecords()) + "inserts": PartKeepr.serializeRecords(this.partManufacturerGrid.getStore().getNewRecords()), + "updates": PartKeepr.serializeRecords(this.partManufacturerGrid.getStore().getUpdatedRecords()), + "removals": PartKeepr.serializeRecords(this.partManufacturerGrid.getStore().getRemovedRecords()) }; values.parameterChanges = { - "inserts": PartDB2.serializeRecords(this.partParameterGrid.getStore().getNewRecords()), - "updates": PartDB2.serializeRecords(this.partParameterGrid.getStore().getUpdatedRecords()), - "removals": PartDB2.serializeRecords(this.partParameterGrid.getStore().getRemovedRecords()) + "inserts": PartKeepr.serializeRecords(this.partParameterGrid.getStore().getNewRecords()), + "updates": PartKeepr.serializeRecords(this.partParameterGrid.getStore().getUpdatedRecords()), + "removals": PartKeepr.serializeRecords(this.partParameterGrid.getStore().getRemovedRecords()) }; call.setParameters(values); call.setHandler(Ext.bind(this.onPartSave, this)); diff --git a/frontend/js/Components/Part/PartEditorWindow.js b/frontend/js/Components/Part/PartEditorWindow.js @@ -1,4 +1,4 @@ -Ext.define('PartDB2.PartEditorWindow', { +Ext.define('PartKeepr.PartEditorWindow', { extend: 'Ext.window.Window', constrainHeader: true, width: 600, @@ -8,7 +8,7 @@ Ext.define('PartDB2.PartEditorWindow', { layout: 'fit', title: i18n("Add Part"), initComponent: function () { - this.editor = Ext.create("PartDB2.PartEditor", { + this.editor = Ext.create("PartKeepr.PartEditor", { border: false }); this.items = [ this.editor ]; diff --git a/frontend/js/Components/Part/PartFilterPanel.js b/frontend/js/Components/Part/PartFilterPanel.js @@ -1,4 +1,4 @@ -Ext.define('PartDB2.PartFilterPanel', { +Ext.define('PartKeepr.PartFilterPanel', { extend: 'Ext.form.Panel', alias: 'widget.PartFilterPanel', bodyPadding: '10px', @@ -88,7 +88,7 @@ Ext.define('PartDB2.PartFilterPanel', { createFilterFields: function () { // Create the storage location filter field - this.storageLocationFilter = Ext.create("PartDB2.StorageLocationComboBox", { + this.storageLocationFilter = Ext.create("PartKeepr.StorageLocationComboBox", { fieldLabel: i18n("Storage Location"), forceSelection: true }); diff --git a/frontend/js/Components/Part/PartManufacturerGrid.js b/frontend/js/Components/Part/PartManufacturerGrid.js @@ -1,4 +1,4 @@ -Ext.define('PartDB2.PartManufacturerGrid', { +Ext.define('PartKeepr.PartManufacturerGrid', { extend: 'Ext.grid.Panel', alias: 'widget.PartManufacturerGrid', border: false, @@ -70,7 +70,7 @@ Ext.define('PartDB2.PartManufacturerGrid', { onEdit: function (data) { var id = data.record.get("manufacturer_id"); - var rec = PartDB2.getApplication().getManufacturerStore().findRecord("id", id); + var rec = PartKeepr.getApplication().getManufacturerStore().findRecord("id", id); if (rec) { data.record.set("manufacturer_name", rec.get("name")); @@ -79,7 +79,7 @@ Ext.define('PartDB2.PartManufacturerGrid', { onAddClick: function () { this.editing.cancelEdit(); - var rec = new PartDB2.PartManufacturer({ + var rec = new PartKeepr.PartManufacturer({ packagingUnit: 1 }); diff --git a/frontend/js/Components/Part/PartParameterGrid.js b/frontend/js/Components/Part/PartParameterGrid.js @@ -1,4 +1,4 @@ -Ext.define('PartDB2.PartParameterGrid', { +Ext.define('PartKeepr.PartParameterGrid', { extend: 'Ext.grid.Panel', alias: 'widget.PartParameterGrid', border: false, @@ -63,7 +63,7 @@ Ext.define('PartDB2.PartParameterGrid', { renderer: function (val,p,rec) { if (!Ext.isObject(val)) { return ""; } - var foundRec = PartDB2.getApplication().getUnitStore().findRecord("id", rec.get("unit_id")); + var foundRec = PartKeepr.getApplication().getUnitStore().findRecord("id", rec.get("unit_id")); if (foundRec) { return val.value + " "+val.symbol + foundRec.get("symbol"); @@ -82,7 +82,7 @@ Ext.define('PartDB2.PartParameterGrid', { flex: 0.2, dataIndex: 'unit_id', renderer: function (val,p,rec) { - var foundRec = PartDB2.getApplication().getUnitStore().findRecord("id", val); + var foundRec = PartKeepr.getApplication().getUnitStore().findRecord("id", val); if (foundRec) { return foundRec.get("name"); @@ -113,7 +113,7 @@ Ext.define('PartDB2.PartParameterGrid', { onAddClick: function () { this.editing.cancelEdit(); - var rec = new PartDB2.PartParameter({ + var rec = new PartKeepr.PartParameter({ }); @@ -135,7 +135,7 @@ Ext.define('PartDB2.PartParameterGrid', { var edit = this.editing.getEditor(editor.record, header); if (editor.field == "prefixedValue") { - var unit = PartDB2.getApplication().getUnitStore().getById(editor.record.get("unit_id")); + var unit = PartKeepr.getApplication().getUnitStore().getById(editor.record.get("unit_id")); if (unit) { edit.field.setStore(unit.prefixes()); } diff --git a/frontend/js/Components/Part/PartStockHistory.js b/frontend/js/Components/Part/PartStockHistory.js @@ -1,4 +1,4 @@ -Ext.define('PartDB2.PartStockHistory', { +Ext.define('PartKeepr.PartStockHistory', { extend: 'Ext.grid.Panel', alias: 'widget.PartStockHistory', @@ -33,7 +33,7 @@ Ext.define('PartDB2.PartStockHistory', { } } ], - model: 'PartDB2.StockEntry', + model: 'PartKeepr.StockEntry', initComponent: function () { var config = { autoLoad: false, diff --git a/frontend/js/Components/Part/PartStockWindow.js b/frontend/js/Components/Part/PartStockWindow.js @@ -3,7 +3,7 @@ * for a specific part. Logic and service calls are not contained in this window, * and need to be implemented from the caller. */ -Ext.define('PartDB2.PartStockWindow', { +Ext.define('PartKeepr.PartStockWindow', { extend: 'Ext.window.Window', // Configurations diff --git a/frontend/js/Components/Part/PartsGrid.js b/frontend/js/Components/Part/PartsGrid.js @@ -2,8 +2,8 @@ * This class is the main part list grid. * */ -Ext.define('PartDB2.PartsGrid', { - extend: 'PartDB2.EditorGrid', +Ext.define('PartKeepr.PartsGrid', { + extend: 'PartKeepr.EditorGrid', alias: 'widget.PartsGrid', // We want to display the texts for the add/delete buttons @@ -18,7 +18,7 @@ Ext.define('PartDB2.PartsGrid', { this.callParent(); // Create the filter panel - this.filterPanel = Ext.create("PartDB2.PartFilterPanel", { + this.filterPanel = Ext.create("PartKeepr.PartFilterPanel", { dock: 'bottom', title: i18n("Filter"), height: 200, diff --git a/frontend/js/Components/Part/PartsManager.js b/frontend/js/Components/Part/PartsManager.js @@ -1,10 +1,10 @@ /** - * @class PartDB2.PartManager + * @class PartKeepr.PartManager * @todo Document the editor system a bit better * * The part manager encapsulates the category tree, the part display grid and the part detail view. */ -Ext.define('PartDB2.PartManager', { +Ext.define('PartKeepr.PartManager', { extend: 'Ext.panel.Panel', alias: 'widget.PartManager', layout: 'border', @@ -22,7 +22,7 @@ Ext.define('PartDB2.PartManager', { }); // Create the tree - this.tree = Ext.create("PartDB2.CategoryEditorTree", { + this.tree = Ext.create("PartKeepr.CategoryEditorTree", { region: 'west', split: true, width: 300, // @todo Make this configurable @@ -37,11 +37,11 @@ Ext.define('PartDB2.PartManager', { }, this)); // Create the detail panel - this.detail = Ext.create("PartDB2.PartDisplay", { title: i18n("Part Details") }); + this.detail = Ext.create("PartKeepr.PartDisplay", { title: i18n("Part Details") }); this.detail.on("editPart", this.onEditPart, this); // Create the grid - this.grid = Ext.create("PartDB2.PartsGrid", { region: 'center', layout: 'fit', store: this.getStore()}); + this.grid = Ext.create("PartKeepr.PartsGrid", { region: 'center', layout: 'fit', store: this.getStore()}); // Create the grid listeners this.grid.on("itemSelect", this.onItemSelect, this); @@ -52,7 +52,7 @@ Ext.define('PartDB2.PartManager', { this.detail.on("partChanged", function () { this.grid.getStore().load(); }, this); // Create the stock level panel - this.stockLevel = Ext.create("PartDB2.PartStockHistory", { title: "Stock History"}); + this.stockLevel = Ext.create("PartKeepr.PartStockHistory", { title: "Stock History"}); this.detailPanel = Ext.create("Ext.tab.Panel", { hidden: true, @@ -88,7 +88,7 @@ Ext.define('PartDB2.PartManager', { var r = this.grid.getSelectionModel().getLastSelected(); if (btn == "yes") { - var call = new PartDB2.ServiceCall( + var call = new PartKeepr.ServiceCall( "Part", "deletePart"); @@ -104,11 +104,11 @@ Ext.define('PartDB2.PartManager', { * Creates a new, empty part editor window */ onItemAdd: function () { - var j = Ext.create("PartDB2.PartEditorWindow"); + var j = Ext.create("PartKeepr.PartEditorWindow"); var defaults = {}; - var defaultPartUnit = PartDB2.getApplication().getPartUnitStore().find("default", true); + var defaultPartUnit = PartKeepr.getApplication().getPartUnitStore().find("default", true); defaults.partUnit_id = defaultPartUnit; defaults.category_id = this.grid.currentCategory; @@ -126,7 +126,7 @@ Ext.define('PartDB2.PartManager', { * Called when a part was loaded. Displays the part in the editor window. */ onPartLoaded: function (f,g) { - var j = Ext.create("PartDB2.PartEditorWindow"); + var j = Ext.create("PartKeepr.PartEditorWindow"); j.applyRecord(f); j.show(); }, @@ -145,7 +145,7 @@ Ext.define('PartDB2.PartManager', { * @param {Function} handler The callback to call when the part was loaded */ loadPart: function (id, handler) { - var call = new PartDB2.ServiceCall( + var call = new PartKeepr.ServiceCall( "Part", "getPart"); call.setParameter("part", id); diff --git a/frontend/js/Components/PartUnit/PartUnitEditor.js b/frontend/js/Components/PartUnit/PartUnitEditor.js @@ -1,5 +1,5 @@ -Ext.define('PartDB2.PartUnitEditor', { - extend: 'PartDB2.Editor', +Ext.define('PartKeepr.PartUnitEditor', { + extend: 'PartKeepr.Editor', alias: 'widget.PartUnitEditor', items: [{ xtype: 'textfield', @@ -11,5 +11,5 @@ Ext.define('PartDB2.PartUnitEditor', { fieldLabel: i18n("Short Name") }], saveText: i18n("Save Part Unit"), - model: 'PartDB2.PartUnit' + model: 'PartKeepr.PartUnit' }); diff --git a/frontend/js/Components/PartUnit/PartUnitEditorComponent.js b/frontend/js/Components/PartUnit/PartUnitEditorComponent.js @@ -1,8 +1,8 @@ -Ext.define('PartDB2.PartUnitEditorComponent', { - extend: 'PartDB2.EditorComponent', +Ext.define('PartKeepr.PartUnitEditorComponent', { + extend: 'PartKeepr.EditorComponent', alias: 'widget.PartUnitEditorComponent', - gridClass: 'PartDB2.PartUnitGrid', - editorClass: 'PartDB2.PartUnitEditor', + gridClass: 'PartKeepr.PartUnitGrid', + editorClass: 'PartKeepr.PartUnitEditor', newItemText: i18n("New Part Unit"), deleteMessage: i18n("Do you really wish to delete the part unit'%s'?"), deleteTitle: i18n("Delete Part Unit"), diff --git a/frontend/js/Components/PartUnit/PartUnitGrid.js b/frontend/js/Components/PartUnit/PartUnitGrid.js @@ -1,5 +1,5 @@ -Ext.define('PartDB2.PartUnitGrid', { - extend: 'PartDB2.EditorGrid', +Ext.define('PartKeepr.PartUnitGrid', { + extend: 'PartKeepr.EditorGrid', alias: 'widget.PartUnitGrid', columns: [ {header: i18n("Part Unit"), dataIndex: 'name', flex: 1}, @@ -33,7 +33,7 @@ Ext.define('PartDB2.PartUnitGrid', { onDefaultClick: function () { var r = this.getSelectionModel().getLastSelected(); - var call = new PartDB2.ServiceCall( + var call = new PartKeepr.ServiceCall( "PartUnit", "setDefault"); diff --git a/frontend/js/Components/Statistics/CurrentStatisticsDialog.js b/frontend/js/Components/Statistics/CurrentStatisticsDialog.js @@ -1,4 +1,4 @@ -Ext.define('PartDB2.CurrentStatisticsDialog', { +Ext.define('PartKeepr.CurrentStatisticsDialog', { extend: 'Ext.window.Window', width: 400, height: 250, @@ -79,7 +79,7 @@ Ext.define('PartDB2.CurrentStatisticsDialog', { this.loadStats(); }, loadStats: function () { - var call = new PartDB2.ServiceCall( + var call = new PartKeepr.ServiceCall( "Statistic", "getCurrentStats"); diff --git a/frontend/js/Components/Statusbar.js b/frontend/js/Components/Statusbar.js @@ -1,4 +1,4 @@ -Ext.define('PartDB2.Statusbar', { +Ext.define('PartKeepr.Statusbar', { extend: 'Ext.ux.StatusBar', defaultText: i18n("Ready."), @@ -7,8 +7,8 @@ Ext.define('PartDB2.Statusbar', { autoClear: 3000, initComponent: function () { - this.connectionButton = new PartDB2.ConnectionButton(); - this.timeDisplay = new PartDB2.TimeDisplay(); + this.connectionButton = new PartKeepr.ConnectionButton(); + this.timeDisplay = new PartKeepr.TimeDisplay(); this.currentUserDisplay = Ext.create("Ext.toolbar.TextItem"); this.currentUserDisplay.setText(i18n("Not logged in")); @@ -17,7 +17,7 @@ Ext.define('PartDB2.Statusbar', { icon: 'resources/silkicons/application_osx_terminal.png', cls: 'x-btn-icon', handler: function () { - PartDB2.getApplication().toggleMessageLog(); + PartKeepr.getApplication().toggleMessageLog(); } }); diff --git a/frontend/js/Components/StorageLocation/StorageLocationEditor.js b/frontend/js/Components/StorageLocation/StorageLocationEditor.js @@ -1,5 +1,5 @@ -Ext.define('PartDB2.StorageLocationEditor', { - extend: 'PartDB2.Editor', +Ext.define('PartKeepr.StorageLocationEditor', { + extend: 'PartKeepr.Editor', alias: 'widget.StorageLocationEditor', items: [{ xtype: 'textfield', @@ -7,5 +7,5 @@ Ext.define('PartDB2.StorageLocationEditor', { fieldLabel: i18n("Storage Location") }], saveText: i18n("Save Storage Location"), - model: 'PartDB2.StorageLocation' + model: 'PartKeepr.StorageLocation' }); \ No newline at end of file diff --git a/frontend/js/Components/StorageLocation/StorageLocationEditorComponent.js b/frontend/js/Components/StorageLocation/StorageLocationEditorComponent.js @@ -1,8 +1,8 @@ -Ext.define('PartDB2.StorageLocationEditorComponent', { - extend: 'PartDB2.EditorComponent', +Ext.define('PartKeepr.StorageLocationEditorComponent', { + extend: 'PartKeepr.EditorComponent', alias: 'widget.StorageLocationEditorComponent', - gridClass: 'PartDB2.StorageLocationGrid', - editorClass: 'PartDB2.StorageLocationEditor', + gridClass: 'PartKeepr.StorageLocationGrid', + editorClass: 'PartKeepr.StorageLocationEditor', newItemText: i18n("New Storage Location"), initComponent: function () { this.createStore({ diff --git a/frontend/js/Components/StorageLocation/StorageLocationGrid.js b/frontend/js/Components/StorageLocation/StorageLocationGrid.js @@ -1,5 +1,5 @@ -Ext.define('PartDB2.StorageLocationGrid', { - extend: 'PartDB2.EditorGrid', +Ext.define('PartKeepr.StorageLocationGrid', { + extend: 'PartKeepr.EditorGrid', alias: 'widget.StorageLocationGrid', columns: [ {header: i18n("Storage Location"), dataIndex: 'name', flex: 1} diff --git a/frontend/js/Components/TimeDisplay.js b/frontend/js/Components/TimeDisplay.js @@ -1,4 +1,4 @@ -Ext.define('PartDB2.TimeDisplay', { +Ext.define('PartKeepr.TimeDisplay', { extend: 'Ext.Toolbar.TextItem', el: null, dt: null, diff --git a/frontend/js/Components/Unit/UnitEditor.js b/frontend/js/Components/Unit/UnitEditor.js @@ -1,8 +1,8 @@ -Ext.define('PartDB2.UnitEditor', { - extend: 'PartDB2.Editor', +Ext.define('PartKeepr.UnitEditor', { + extend: 'PartKeepr.Editor', alias: 'widget.UnitEditor', saveText: i18n("Save Unit"), - model: 'PartDB2.Unit', + model: 'PartKeepr.Unit', initComponent: function () { var sm = Ext.create('Ext.selection.CheckboxModel',{ @@ -10,7 +10,7 @@ Ext.define('PartDB2.UnitEditor', { }); this.gridPanel = Ext.create("Ext.grid.Panel", { - store: PartDB2.getApplication().getSiPrefixStore(), + store: PartKeepr.getApplication().getSiPrefixStore(), selModel: sm, columnLines: true, columns: [ @@ -45,7 +45,7 @@ Ext.define('PartDB2.UnitEditor', { var records = this.record.prefixes().getRange(); var toSelect = []; - var pfxStore = PartDB2.getApplication().getSiPrefixStore(); + var pfxStore = PartKeepr.getApplication().getSiPrefixStore(); for (var i=0;i<records.length;i++) { toSelect.push(pfxStore.getAt(pfxStore.find("id", records[i].get("id")))); @@ -62,7 +62,7 @@ Ext.define('PartDB2.UnitEditor', { records.push(selection[i].get("id")); } - var call = new PartDB2.ServiceCall("Unit", "setUnitPrefixes"); + var call = new PartKeepr.ServiceCall("Unit", "setUnitPrefixes"); call.setParameter("prefixes", records); call.setParameter("id", this.record.get("id")); call.doCall(); diff --git a/frontend/js/Components/Unit/UnitEditorComponent.js b/frontend/js/Components/Unit/UnitEditorComponent.js @@ -1,8 +1,8 @@ -Ext.define('PartDB2.UnitEditorComponent', { - extend: 'PartDB2.EditorComponent', +Ext.define('PartKeepr.UnitEditorComponent', { + extend: 'PartKeepr.EditorComponent', alias: 'widget.UnitEditorComponent', - gridClass: 'PartDB2.UnitGrid', - editorClass: 'PartDB2.UnitEditor', + gridClass: 'PartKeepr.UnitGrid', + editorClass: 'PartKeepr.UnitEditor', newItemText: i18n("New Unit"), deleteMessage: i18n("Do you really wish to delete the unit'%s'?"), deleteTitle: i18n("Delete Unit"), diff --git a/frontend/js/Components/Unit/UnitGrid.js b/frontend/js/Components/Unit/UnitGrid.js @@ -1,5 +1,5 @@ -Ext.define('PartDB2.UnitGrid', { - extend: 'PartDB2.EditorGrid', +Ext.define('PartKeepr.UnitGrid', { + extend: 'PartKeepr.EditorGrid', alias: 'widget.UnitGrid', columns: [ {header: i18n("Unit"), dataIndex: 'name', flex: 1}, diff --git a/frontend/js/Components/User/UserEditor.js b/frontend/js/Components/User/UserEditor.js @@ -1,5 +1,5 @@ -Ext.define('PartDB2.UserEditor', { - extend: 'PartDB2.Editor', +Ext.define('PartKeepr.UserEditor', { + extend: 'PartKeepr.Editor', alias: 'widget.UserEditor', items: [{ xtype: 'textfield', @@ -12,5 +12,5 @@ Ext.define('PartDB2.UserEditor', { fieldLabel: i18n("Password") }], saveText: i18n("Save User"), - model: 'PartDB2.User' + model: 'PartKeepr.User' }); diff --git a/frontend/js/Components/User/UserEditorComponent.js b/frontend/js/Components/User/UserEditorComponent.js @@ -1,8 +1,8 @@ -Ext.define('PartDB2.UserEditorComponent', { - extend: 'PartDB2.EditorComponent', +Ext.define('PartKeepr.UserEditorComponent', { + extend: 'PartKeepr.EditorComponent', alias: 'widget.UserEditorComponent', - gridClass: 'PartDB2.UserGrid', - editorClass: 'PartDB2.UserEditor', + gridClass: 'PartKeepr.UserGrid', + editorClass: 'PartKeepr.UserEditor', newItemText: i18n("New User"), deleteMessage: i18n("Do you really wish to delete the user '%s'?"), deleteTitle: i18n("Delete User"), diff --git a/frontend/js/Components/User/UserGrid.js b/frontend/js/Components/User/UserGrid.js @@ -1,5 +1,5 @@ -Ext.define('PartDB2.UserGrid', { - extend: 'PartDB2.EditorGrid', +Ext.define('PartKeepr.UserGrid', { + extend: 'PartKeepr.EditorGrid', alias: 'widget.UserGrid', columns: [ {header: i18n("User"), dataIndex: 'username', flex: 1} diff --git a/frontend/js/Components/Widgets/CategoryComboBox.js b/frontend/js/Components/Widgets/CategoryComboBox.js @@ -1,4 +1,4 @@ -Ext.define("PartDB2.CategoryComboBox",{ +Ext.define("PartKeepr.CategoryComboBox",{ extend:"Ext.form.field.Picker", alias: 'widget.CategoryComboBox', requires:["Ext.tree.Panel"], @@ -20,7 +20,7 @@ Ext.define("PartDB2.CategoryComboBox",{ createPicker: function(){ var self = this; - self.picker = new PartDB2.CategoryTree({ + self.picker = new PartKeepr.CategoryTree({ height:290, floating: true, focusOnToFront: false, diff --git a/frontend/js/Components/Widgets/DistributorComboBox.js b/frontend/js/Components/Widgets/DistributorComboBox.js @@ -1,4 +1,4 @@ -Ext.define("PartDB2.DistributorComboBox",{ +Ext.define("PartKeepr.DistributorComboBox",{ extend:"Ext.form.field.ComboBox", alias: 'widget.DistributorComboBox', displayField: 'name', @@ -9,7 +9,7 @@ Ext.define("PartDB2.DistributorComboBox",{ forceSelection: true, editable: false, initComponent: function () { - this.store = PartDB2.getApplication().getDistributorStore(); + this.store = PartKeepr.getApplication().getDistributorStore(); /* Workaround to remember the value when loading */ this.store.on("beforeload", function () { diff --git a/frontend/js/Components/Widgets/FootprintComboBox.js b/frontend/js/Components/Widgets/FootprintComboBox.js @@ -1,4 +1,4 @@ -Ext.define("PartDB2.FootprintComboBox",{ +Ext.define("PartKeepr.FootprintComboBox",{ extend:"Ext.form.field.ComboBox", alias: 'widget.FootprintComboBox', displayField: 'footprint', @@ -8,7 +8,7 @@ Ext.define("PartDB2.FootprintComboBox",{ triggerAction: 'all', initComponent: function () { - this.store = PartDB2.getApplication().getFootprintStore(); + this.store = PartKeepr.getApplication().getFootprintStore(); /* Workaround to remember the value when loading */ this.store.on("beforeload", function () { diff --git a/frontend/js/Components/Widgets/ManufacturerComboBox.js b/frontend/js/Components/Widgets/ManufacturerComboBox.js @@ -1,4 +1,4 @@ -Ext.define("PartDB2.ManufacturerComboBox",{ +Ext.define("PartKeepr.ManufacturerComboBox",{ extend:"Ext.form.field.ComboBox", alias: 'widget.ManufacturerComboBox', displayField: 'name', @@ -9,7 +9,7 @@ Ext.define("PartDB2.ManufacturerComboBox",{ forceSelection: true, editable: false, initComponent: function () { - this.store = PartDB2.getApplication().getManufacturerStore(); + this.store = PartKeepr.getApplication().getManufacturerStore(); /* Workaround to remember the value when loading */ this.store.on("beforeload", function () { diff --git a/frontend/js/Components/Widgets/PartParameterComboBox.js b/frontend/js/Components/Widgets/PartParameterComboBox.js @@ -1,4 +1,4 @@ -Ext.define("PartDB2.PartParameterComboBox",{ +Ext.define("PartKeepr.PartParameterComboBox",{ extend:"Ext.form.field.ComboBox", alias: 'widget.PartParameterComboBox', displayField: 'name', @@ -10,13 +10,13 @@ Ext.define("PartDB2.PartParameterComboBox",{ forceSelection: false, editable: true, initComponent: function () { - //this.store = PartDB2.getApplication().getPartUnitStore(); + //this.store = PartKeepr.getApplication().getPartUnitStore(); this.store = Ext.create("Ext.data.Store", { fields: [{ name: 'name' }], proxy: { type: 'ajax', - url: PartDB2.getBasePath() + "/Part/getPartParameterNames", + url: PartKeepr.getBasePath() + "/Part/getPartParameterNames", reader: { type: 'json', root: 'response.data' diff --git a/frontend/js/Components/Widgets/PartUnitComboBox.js b/frontend/js/Components/Widgets/PartUnitComboBox.js @@ -1,4 +1,4 @@ -Ext.define("PartDB2.PartUnitComboBox",{ +Ext.define("PartKeepr.PartUnitComboBox",{ extend:"Ext.form.field.ComboBox", alias: 'widget.PartUnitComboBox', displayField: 'name', @@ -9,7 +9,7 @@ Ext.define("PartDB2.PartUnitComboBox",{ forceSelection: true, editable: false, initComponent: function () { - this.store = PartDB2.getApplication().getPartUnitStore(); + this.store = PartKeepr.getApplication().getPartUnitStore(); /* Workaround to remember the value when loading */ this.store.on("beforeload", function () { diff --git a/frontend/js/Components/Widgets/SiUnitField.js b/frontend/js/Components/Widgets/SiUnitField.js @@ -11,7 +11,7 @@ * } * */ -Ext.define("PartDB2.SiUnitField",{ +Ext.define("PartKeepr.SiUnitField",{ extend:"Ext.form.field.Picker", alias: 'widget.SiUnitField', @@ -98,7 +98,7 @@ Ext.define("PartDB2.SiUnitField",{ if (me.disableKeyFilter !== true) { allowed = me.baseChars + ''; - var store = PartDB2.getApplication().getSiPrefixStore(); + var store = PartKeepr.getApplication().getSiPrefixStore(); for (var i=0;i<store.count();i++) { allowed += store.getAt(i).get("symbol"); @@ -138,7 +138,7 @@ Ext.define("PartDB2.SiUnitField",{ return this.store; } - return PartDB2.getApplication().getSiPrefixStore(); + return PartKeepr.getApplication().getSiPrefixStore(); }, setStore: function (store) { if (this.picker) { @@ -155,7 +155,7 @@ Ext.define("PartDB2.SiUnitField",{ '</div>', '</tpl>'); - var tmp = Ext.create('PartDB2.SiUnitList', { + var tmp = Ext.create('PartKeepr.SiUnitList', { store: this.getStore(), singleSelect: true, ownerCt: this.ownerCt, @@ -339,7 +339,7 @@ Ext.define("PartDB2.SiUnitField",{ } }, findSiPrefix: function (value) { - var store = PartDB2.getApplication().getSiPrefixStore(); + var store = PartKeepr.getApplication().getSiPrefixStore(); var symbol; for (var i=0;i<store.count();i++) { @@ -364,7 +364,7 @@ Ext.define("PartDB2.SiUnitField",{ }, setValue: function (v) { if (Ext.isObject(v)) { - this.siPrefix = PartDB2.getApplication().getSiPrefixStore().getById(v.siprefix_id); + this.siPrefix = PartKeepr.getApplication().getSiPrefixStore().getById(v.siprefix_id); return this.callParent([v.value]); } else { @@ -374,7 +374,7 @@ Ext.define("PartDB2.SiUnitField",{ processRawValue: function (value) { var prefix; - value = PartDB2.getApplication().convertMicroToMu(value); + value = PartKeepr.getApplication().convertMicroToMu(value); var siPrefix = this.findSiPrefix(value); diff --git a/frontend/js/Components/Widgets/SiUnitList.js b/frontend/js/Components/Widgets/SiUnitList.js @@ -1,4 +1,4 @@ -Ext.define('PartDB2.SiUnitList', { +Ext.define('PartKeepr.SiUnitList', { extend: 'Ext.view.BoundList', alias: 'widget.siunitlist', getInnerTpl: function(displayField) { diff --git a/frontend/js/Components/Widgets/StorageLocationComboBox.js b/frontend/js/Components/Widgets/StorageLocationComboBox.js @@ -1,4 +1,4 @@ -Ext.define("PartDB2.StorageLocationComboBox",{ +Ext.define("PartKeepr.StorageLocationComboBox",{ extend:"Ext.form.field.ComboBox", alias: 'widget.StorageLocationComboBox', displayField: 'name', @@ -8,7 +8,7 @@ Ext.define("PartDB2.StorageLocationComboBox",{ triggerAction: 'all', initComponent: function () { - this.store = PartDB2.getApplication().getStorageLocationStore(); + this.store = PartKeepr.getApplication().getStorageLocationStore(); /* Workaround to remember the value when loading */ this.store.on("beforeload", function () { diff --git a/frontend/js/Components/Widgets/UnitComboBox.js b/frontend/js/Components/Widgets/UnitComboBox.js @@ -1,4 +1,4 @@ -Ext.define("PartDB2.UnitComboBox",{ +Ext.define("PartKeepr.UnitComboBox",{ extend:"Ext.form.field.ComboBox", alias: 'widget.UnitComboBox', displayField: 'name', @@ -9,7 +9,7 @@ Ext.define("PartDB2.UnitComboBox",{ forceSelection: true, editable: true, initComponent: function () { - this.store = PartDB2.getApplication().getUnitStore(); + this.store = PartKeepr.getApplication().getUnitStore(); /* Workaround to remember the value when loading */ this.store.on("beforeload", function () { diff --git a/frontend/js/Dialogs/Auth/LoginDialog.js b/frontend/js/Dialogs/Auth/LoginDialog.js @@ -1,6 +1,6 @@ -Ext.define('PartDB2.LoginDialog', { +Ext.define('PartKeepr.LoginDialog', { extend: 'Ext.Window', - title: i18n("PartDB2: Login"), + title: i18n("PartKeepr: Login"), loginField: null, width: 400, @@ -59,7 +59,7 @@ Ext.define('PartDB2.LoginDialog', { this.callParent(arguments); }, login: function () { - var call = new PartDB2.ServiceCall("Auth", "login"); + var call = new PartKeepr.ServiceCall("Auth", "login"); call.setParameter("username", this.loginField.getValue()); call.setParameter("password", md5(this.passwordField.getValue())); @@ -69,26 +69,26 @@ Ext.define('PartDB2.LoginDialog', { call.doCall(); }, onLogin: function (obj) { - PartDB2.getApplication().setSession(obj.sessionid); - PartDB2.getApplication().setUsername(obj.username); + PartKeepr.getApplication().setSession(obj.sessionid); + PartKeepr.getApplication().setUsername(obj.username); if (!obj.admin) { Ext.getCmp("edit-users").hide(); } - PartDB2.getApplication().createGlobalStores(); + PartKeepr.getApplication().createGlobalStores(); - PartDB2.getApplication().reloadStores(); + PartKeepr.getApplication().reloadStores(); - var j = Ext.create("PartDB2.PartManager", { + var j = Ext.create("PartKeepr.PartManager", { title: i18n("Part Manager"), closable: false }); - PartDB2.getApplication().addItem(j); + PartKeepr.getApplication().addItem(j); j.show(); - PartDB2.log(i18n("Logged in as")+" "+obj.username); + PartKeepr.log(i18n("Logged in as")+" "+obj.username); this.close(); } diff --git a/frontend/js/Dialogs/ExceptionWindow.js b/frontend/js/Dialogs/ExceptionWindow.js @@ -1,4 +1,4 @@ -Ext.define('PartDB2.ExceptionWindow', { +Ext.define('PartKeepr.ExceptionWindow', { extend: 'Ext.window.Window', autoScroll: true, resizable: true, diff --git a/frontend/js/Dialogs/FileUploadDialog.js b/frontend/js/Dialogs/FileUploadDialog.js @@ -1,4 +1,4 @@ -Ext.define('PartDB2.FileUploadDialog', { +Ext.define('PartKeepr.FileUploadDialog', { extend: 'Ext.window.Window', title: i18n("File Upload"), @@ -19,7 +19,7 @@ Ext.define('PartDB2.FileUploadDialog', { url: 'rest.php/TempImage', params: { call: "upload", - session: PartDB2.getApplication().getSession() + session: PartKeepr.getApplication().getSession() }, success: Ext.bind(function(fp, o) { this.fireEvent("fileUploaded", o.result.response.id); @@ -62,7 +62,7 @@ Ext.define('PartDB2.FileUploadDialog', { anchor: '100%', buttonText: this.uploadButtonText },{ - html: sprintf(i18n("Maximum upload size: %s"), PartDB2.bytesToSize(PartDB2.getMaxUploadSize())), + html: sprintf(i18n("Maximum upload size: %s"), PartKeepr.bytesToSize(PartKeepr.getMaxUploadSize())), border: false }], @@ -85,7 +85,7 @@ Ext.define('PartDB2.FileUploadDialog', { autoScroll: true, target: this.fileFormatButton.getEl(), closable: true, - html: implode("<br>", PartDB2.getAvailableImageFormats()), + html: implode("<br>", PartKeepr.getAvailableImageFormats()), autoHide: false }); } diff --git a/frontend/js/Models/Category.js b/frontend/js/Models/Category.js @@ -1,4 +1,4 @@ -PartDB2.Category = Ext.define("Category", { +PartKeepr.Category = Ext.define("Category", { extend: "Ext.data.Model", fields: [ { name: 'id', type: 'int' }, @@ -6,7 +6,7 @@ PartDB2.Category = Ext.define("Category", { { name: 'description', type: 'string' }, { name: 'parent', type: 'int' } ], - proxy: PartDB2.getRESTProxy("Category"), + proxy: PartKeepr.getRESTProxy("Category"), getName: function () { return this.get("name"); } diff --git a/frontend/js/Models/Distributor.js b/frontend/js/Models/Distributor.js @@ -1,4 +1,4 @@ -PartDB2.Distributor = Ext.define("Distributor", { +PartKeepr.Distributor = Ext.define("Distributor", { extend: "Ext.data.Model", fields: [ { id: 'id', name: 'id', type: 'int' }, @@ -8,7 +8,7 @@ PartDB2.Distributor = Ext.define("Distributor", { { name: 'address', type: 'string'}, { name: 'email', type: 'string'} ], - proxy: PartDB2.getRESTProxy("Distributor"), + proxy: PartKeepr.getRESTProxy("Distributor"), getName: function () { return this.get("name"); } diff --git a/frontend/js/Models/Footprint.js b/frontend/js/Models/Footprint.js @@ -1,10 +1,10 @@ -PartDB2.Footprint = Ext.define("Footprint", { +PartKeepr.Footprint = Ext.define("Footprint", { extend: "Ext.data.Model", fields: [ { id: 'id', name: 'id', type: 'int' }, { name: 'footprint', type: 'string'} ], - proxy: PartDB2.getRESTProxy("Footprint"), + proxy: PartKeepr.getRESTProxy("Footprint"), getName: function () { return this.get("footprint"); } diff --git a/frontend/js/Models/Manufacturer.js b/frontend/js/Models/Manufacturer.js @@ -1,4 +1,4 @@ -PartDB2.Manufacturer = Ext.define("Manufacturer", { +PartKeepr.Manufacturer = Ext.define("Manufacturer", { extend: "Ext.data.Model", fields: [ { id: 'id', name: 'id', type: 'int' }, @@ -9,7 +9,7 @@ PartDB2.Manufacturer = Ext.define("Manufacturer", { { name: 'email', type: 'string'} ], hasMany: {model: 'ManufacturerICLogo', name: 'iclogos'}, - proxy: PartDB2.getRESTProxy("Manufacturer"), + proxy: PartKeepr.getRESTProxy("Manufacturer"), getName: function () { return this.get("name"); } diff --git a/frontend/js/Models/ManufacturerICLogo.js b/frontend/js/Models/ManufacturerICLogo.js @@ -1,4 +1,4 @@ -PartDB2.ManufacturerICLogo = Ext.define("ManufacturerICLogo", { +PartKeepr.ManufacturerICLogo = Ext.define("ManufacturerICLogo", { extend: "Ext.data.Model", fields: [ { id: 'id', name: 'id', type: 'int' }, @@ -7,5 +7,5 @@ PartDB2.ManufacturerICLogo = Ext.define("ManufacturerICLogo", { { name: 'tmp_id', type: 'int' } ], belongsTo: { type: 'belongsTo', model: 'Manufacturer', primaryKey: 'id', foreignKey: 'manufacturer_id'}, - proxy: PartDB2.getRESTProxy("ManufacturerICLogo") + proxy: PartKeepr.getRESTProxy("ManufacturerICLogo") }); \ No newline at end of file diff --git a/frontend/js/Models/Message.js b/frontend/js/Models/Message.js @@ -1,4 +1,4 @@ -PartDB2.Message = Ext.define("Message", { +PartKeepr.Message = Ext.define("Message", { extend: "Ext.data.Model", fields: [ { name: 'message', type: 'string' }, diff --git a/frontend/js/Models/Part.js b/frontend/js/Models/Part.js @@ -1,4 +1,4 @@ -PartDB2.Part = Ext.define("Part", { +PartKeepr.Part = Ext.define("Part", { extend: "Ext.data.Model", fields: [ { id: 'id', name: 'id', type: 'int' }, @@ -37,7 +37,7 @@ PartDB2.Part = Ext.define("Part", { { model: 'Category', primaryKey: 'id', foreignKey: 'category_id'} ], hasMany: { model: 'PartDistributor', name: 'distributors'}, - proxy: PartDB2.getRESTProxy("Part"), + proxy: PartKeepr.getRESTProxy("Part"), getName: function () { return this.get("name"); } diff --git a/frontend/js/Models/PartDistributor.js b/frontend/js/Models/PartDistributor.js @@ -1,4 +1,4 @@ -PartDB2.PartDistributor = Ext.define("PartDistributor", { +PartKeepr.PartDistributor = Ext.define("PartDistributor", { extend: "Ext.data.Model", fields: [ { id: 'id', name: 'id', type: 'int' }, @@ -11,5 +11,5 @@ PartDB2.PartDistributor = Ext.define("PartDistributor", { ], belongsTo: { type: 'belongsTo', model: 'Part', primaryKey: 'id', foreignKey: 'part_id'}, belongsTo: { type: 'belongsTo', model: 'Distributor', primaryKey: 'id', foreignKey: 'distributor_id'}, - proxy: PartDB2.getRESTProxy("PartDistributor") + proxy: PartKeepr.getRESTProxy("PartDistributor") }); \ No newline at end of file diff --git a/frontend/js/Models/PartManufacturer.js b/frontend/js/Models/PartManufacturer.js @@ -1,4 +1,4 @@ -PartDB2.PartManufacturer = Ext.define("PartManufacturer", { +PartKeepr.PartManufacturer = Ext.define("PartManufacturer", { extend: "Ext.data.Model", fields: [ { id: 'id', name: 'id', type: 'int' }, @@ -10,5 +10,5 @@ PartDB2.PartManufacturer = Ext.define("PartManufacturer", { ], belongsTo: { type: 'belongsTo', model: 'Part', primaryKey: 'id', foreignKey: 'part_id'}, belongsTo: { type: 'belongsTo', model: 'Manufacturer', primaryKey: 'id', foreignKey: 'manufacturer_id'}, - proxy: PartDB2.getRESTProxy("PartManufacturer") + proxy: PartKeepr.getRESTProxy("PartManufacturer") }); diff --git a/frontend/js/Models/PartParameter.js b/frontend/js/Models/PartParameter.js @@ -1,4 +1,4 @@ -PartDB2.PartParameter = Ext.define("PartParameter", { +PartKeepr.PartParameter = Ext.define("PartParameter", { extend: "Ext.data.Model", fields: [ { id: 'id', name: 'id', type: 'int' }, @@ -10,5 +10,5 @@ PartDB2.PartParameter = Ext.define("PartParameter", { { name: 'value', type: 'float' }, { name: 'prefixedValue' } ], - proxy: PartDB2.getRESTProxy("PartParameter") + proxy: PartKeepr.getRESTProxy("PartParameter") }); diff --git a/frontend/js/Models/PartUnit.js b/frontend/js/Models/PartUnit.js @@ -1,4 +1,4 @@ -PartDB2.PartUnit = Ext.define("PartUnit", { +PartKeepr.PartUnit = Ext.define("PartUnit", { extend: "Ext.data.Model", fields: [ { id: 'id', name: 'id', type: 'int' }, @@ -6,7 +6,7 @@ PartDB2.PartUnit = Ext.define("PartUnit", { { name: 'shortName', type: 'string'}, { name: 'default', type: 'bool'} ], - proxy: PartDB2.getRESTProxy("PartUnit"), + proxy: PartKeepr.getRESTProxy("PartUnit"), getName: function () { return this.get("name"); } diff --git a/frontend/js/Models/SiPrefix.js b/frontend/js/Models/SiPrefix.js @@ -1,4 +1,4 @@ -PartDB2.SiPrefix = Ext.define("SiPrefix", { +PartKeepr.SiPrefix = Ext.define("SiPrefix", { extend: "Ext.data.Model", fields: [ { id: 'id', name: 'id', type: 'int' }, @@ -6,5 +6,5 @@ PartDB2.SiPrefix = Ext.define("SiPrefix", { { name: 'symbol', type: 'string'}, { name: 'power', type: 'int'} ], - proxy: PartDB2.getRESTProxy("SiPrefix") + proxy: PartKeepr.getRESTProxy("SiPrefix") }); \ No newline at end of file diff --git a/frontend/js/Models/StockEntry.js b/frontend/js/Models/StockEntry.js @@ -1,4 +1,4 @@ -PartDB2.StockEntry = Ext.define("StockEntry", { +PartKeepr.StockEntry = Ext.define("StockEntry", { extend: "Ext.data.Model", fields: [ { id: 'id', name: 'id', type: 'int' }, @@ -8,5 +8,5 @@ PartDB2.StockEntry = Ext.define("StockEntry", { { name: 'direction', type: 'string'}, { name: 'price', type: 'float'} ], - proxy: PartDB2.getRESTProxy("Stock") + proxy: PartKeepr.getRESTProxy("Stock") }); \ No newline at end of file diff --git a/frontend/js/Models/StorageLocation.js b/frontend/js/Models/StorageLocation.js @@ -1,10 +1,10 @@ -PartDB2.StorageLocation = Ext.define("StorageLocation", { +PartKeepr.StorageLocation = Ext.define("StorageLocation", { extend: "Ext.data.Model", fields: [ { id: 'id', name: 'id', type: 'int' }, { name: 'name', type: 'string'} ], - proxy: PartDB2.getRESTProxy("StorageLocation"), + proxy: PartKeepr.getRESTProxy("StorageLocation"), getName: function () { return this.get("name"); } diff --git a/frontend/js/Models/Unit.js b/frontend/js/Models/Unit.js @@ -1,4 +1,4 @@ -PartDB2.Unit = Ext.define("Unit", { +PartKeepr.Unit = Ext.define("Unit", { extend: "Ext.data.Model", fields: [ { id: 'id', name: 'id', type: 'int' }, @@ -6,7 +6,7 @@ PartDB2.Unit = Ext.define("Unit", { { name: 'symbol', type: 'string'} ], hasMany: { model: 'SiPrefix', name: 'prefixes'}, - proxy: PartDB2.getRESTProxy("Unit"), + proxy: PartKeepr.getRESTProxy("Unit"), getName: function () { return this.get("name"); } diff --git a/frontend/js/Models/User.js b/frontend/js/Models/User.js @@ -1,10 +1,10 @@ -PartDB2.User = Ext.define("User", { +PartKeepr.User = Ext.define("User", { extend: "Ext.data.Model", fields: [ { id: 'id', name: 'id', type: 'int' }, { name: 'username', type: 'string'} ], - proxy: PartDB2.getRESTProxy("User"), + proxy: PartKeepr.getRESTProxy("User"), getName: function () { return this.get("username"); } diff --git a/frontend/js/PartDB2.js b/frontend/js/PartDB2.js @@ -1,333 +0,0 @@ -Ext.namespace('PartDB2'); - -Ext.Loader.setPath({ - 'PartDB2': 'js' -}); - -PartDB2.application = null; - -Ext.application({ - name: 'PartDB2', - launch: function() { - Ext.setLocale('en_US'); - - this.createLayout(); - - PartDB2.application = this; - - var o = new PartDB2.LoginDialog(); - o.show(); - - - Ext.QuickTips.init(); - }, - createGlobalStores: function () { - this.storageLocationStore = Ext.create("Ext.data.Store", - { - model: 'StorageLocation', - pageSize: -1, - autoLoad: false - }); - - this.footprintStore = Ext.create("Ext.data.Store", - { - model: 'Footprint', - pageSize: -1, - autoLoad: false - }); - - this.siPrefixStore = Ext.create("Ext.data.Store", - { - model: 'SiPrefix', - pageSize: -1, - autoLoad: true - }); - - this.distributorStore = Ext.create("Ext.data.Store", - { - model: 'Distributor', - pageSize: -1, - autoLoad: false - }); - - this.manufacturerStore = Ext.create("Ext.data.Store", - { - model: 'Manufacturer', - pageSize: -1, - autoLoad: false - }); - - this.partUnitStore = Ext.create("Ext.data.Store", - { - model: 'PartUnit', - pageSize: -1, - autoLoad: false - }); - - this.unitStore = Ext.create("Ext.data.Store", - { - model: 'Unit', - pageSize: -1, - autoLoad: false - }); - }, - getUnitStore: function () { - return this.unitStore; - }, - getPartUnitStore: function () { - return this.partUnitStore; - }, - getStorageLocationStore: function () { - return this.storageLocationStore; - }, - getFootprintStore: function () { - return this.footprintStore; - }, - getManufacturerStore: function () { - return this.manufacturerStore; - }, - getDistributorStore: function () { - return this.distributorStore; - }, - getSiPrefixStore: function () { - return this.siPrefixStore; - }, - /** - * Converts the Character "micro" (µ, available on german keyboards via AltGr+m) to the Character "Mu" (μ). - * - * The standard for Si-Prefixes defines that the "Mu"-character should be used instead of the "micro" character. - * - * Wikipedia Entry for the "Micro" Si Prefix: http://en.wikipedia.org/wiki/Micro- - * - */ - convertMicroToMu: function (value) { - /** - * Since the Si-Prefix for "micro" is μ, but keyboard have "µ" on it - * (note: both chars might look identical, depending on your font), we need - * to convert "µ" (on the keyboard, Unicode U+00B5) to the Mu (U+03BC). - */ - - return str_replace("µ", "μ", value); - }, - /** - * Reload all global stores each 100 seconds. - * - * @todo In the future, it would be nice to trigger a specific - * store reload when something happens. Example: - * - * If the user pulls down the storage location combo box, - * reload it. - * - * YES, this is becoming nasty. We have now 6 stores, each - * reloading every minute. This NEEDS to be fixed soon! - * - */ - reloadStores: function () { - this.storageLocationStore.load(); - this.footprintStore.load(); - this.manufacturerStore.load(); - this.distributorStore.load(); - this.partUnitStore.load(); - this.unitStore.load(); - Ext.defer(PartDB2.getApplication().reloadStores, 100000, this); - }, - createLayout: function () { - - this.statusBar = Ext.create("PartDB2.Statusbar"); - - this.messageLog = this.createMessageLog(); - - this.centerPanel = Ext.create("Ext.tab.Panel", { - xtype: 'tabpanel', - region: 'center', - bodyStyle: 'background:#DFE8F6' - - }); - - this.menuBar = Ext.create("PartDB2.MenuBar"); - - Ext.create('Ext.container.Viewport', { - layout: 'fit', - items: [{ - xtype: 'panel', - layout: 'border', - items: [ - this.centerPanel, - this.messageLog - ], - bbar: this.statusBar, - tbar: this.menuBar - }] - - }); - }, - addItem: function (item) { - this.centerPanel.add(item); - }, - createMessageLog: function () { - return Ext.create("PartDB2.MessageLog", { - height: 200, - hidden: true, - split: true, - title: i18n("Message Log"), - titleCollapse: true, - collapsible: true, - region: 'south', - listeners: { - beforecollapse: Ext.bind( - function (obj) { - this.hideMessageLog(); - return false; - }, - this) - } - }); - }, - log: function (message) { - this.logMessage(message, "none"); - }, - logMessage: function (message, severity) { - if (message != i18n("Ready.")) { - var r = Ext.ModelManager.create({ - message: message, - severity: severity, - date: new Date() - }, 'Message'); - - this.messageLog.getStore().add(r); - } - }, - hideMessageLog: function () { - this.messageLog.hide(); - }, - showMessageLog: function () { - this.messageLog.show(); - }, - toggleMessageLog: function () { - if (this.messageLog.isHidden()) { - this.showMessageLog(); - } else { - this.hideMessageLog(); - } - - }, - getStatusbar: function () { - return this.statusBar; - }, - getSession: function () { - return this.session; - }, - setSession: function (session) { - this.session = session; - - this.getStatusbar().getConnectionButton().setConnected(); - }, - setUsername: function (username) { - this.username = username; - - this.getStatusbar().setCurrentUser(username); - } -}); - -/** - * <p>This static method returns a REST object definition for use with any models.</p> - * <p>It automatically sets the session (if available) and the prefix for the given REST service.</p> - * @param {string} service The REST service to call. Only use the base name, e.g. "Footprint" instead of "FootprintService". - * @return {Object} The RESTProxy definition -*/ -PartDB2.getRESTProxy = function (service) { - var obj = { - batchActions: false, - url: PartDB2.getBasePath()+ '/'+service, - listeners: { - exception: function (proxy, response, operation) { - try { - var data = Ext.decode(response.responseText); - - var j = new PartDB2.ExceptionWindow(); - j.showException(data.exception); - } catch (ex) { - var exception = { - message: i18n("Critical Error"), - detail: i18n("The server returned a response which we were not able to interpret."), - exception: "", - backtrace: response.responseText - }; - - - var jj = new PartDB2.ExceptionWindow(); - jj.showException(exception); - - - } - } - }, - reader: { - type: 'json', - root: 'response.data', - successProperty: "success", - messageProperty: 'message', - totalProperty : 'response.totalCount' - }, - writer: { - type: 'json' - } - - }; - //Ext.data.AjaxProxy.superclass.constructor.apply(this, arguments); - return new Ext.data.proxy.Rest(obj); -}; - -PartDB2.getSession = function () { - alert("This should not be called."); - return "hli2ong0ktnise68p9f5nu6nk1"; -}; - -PartDB2.log = function (message) { - PartDB2.getApplication().log(message); -}; - -/** - * <p>This static method returns the instance of the application.</p> - * @return {Object} The application -*/ -PartDB2.getApplication = function () { - return PartDB2.application; -}; - -PartDB2.getBasePath = function () { - return "rest.php"; -}; - -PartDB2.setMaxUploadSize = function (size) { - PartDB2.maxUploadSize = size; -}; - -PartDB2.getMaxUploadSize = function () { - return PartDB2.maxUploadSize; -}; - -PartDB2.bytesToSize = function (bytes) { - var sizes = ['Bytes', 'KB', 'MB', 'GB', 'TB']; - if (bytes === 0) return 'n/a'; - var i = parseInt(Math.floor(Math.log(bytes) / Math.log(1024)),10); - return Math.round(bytes / Math.pow(1024, i), 2) + ' ' + sizes[i]; -}; - -PartDB2.setAvailableImageFormats = function (formats) { - PartDB2.imageFormats = formats; -}; - -PartDB2.getAvailableImageFormats = function () { - return PartDB2.imageFormats; -}; - -PartDB2.serializeRecords = function (records) { - var finalData = []; - - for (var i=0;i<records.length;i++) { - finalData.push(records[i].data); - } - - return finalData; -};- \ No newline at end of file diff --git a/frontend/js/PartKeepr.js b/frontend/js/PartKeepr.js @@ -0,0 +1,333 @@ +Ext.namespace('PartKeepr'); + +Ext.Loader.setPath({ + 'PartKeepr': 'js' +}); + +PartKeepr.application = null; + +Ext.application({ + name: 'PartKeepr', + launch: function() { + Ext.setLocale('en_US'); + + this.createLayout(); + + PartKeepr.application = this; + + var o = new PartKeepr.LoginDialog(); + o.show(); + + + Ext.QuickTips.init(); + }, + createGlobalStores: function () { + this.storageLocationStore = Ext.create("Ext.data.Store", + { + model: 'StorageLocation', + pageSize: -1, + autoLoad: false + }); + + this.footprintStore = Ext.create("Ext.data.Store", + { + model: 'Footprint', + pageSize: -1, + autoLoad: false + }); + + this.siPrefixStore = Ext.create("Ext.data.Store", + { + model: 'SiPrefix', + pageSize: -1, + autoLoad: true + }); + + this.distributorStore = Ext.create("Ext.data.Store", + { + model: 'Distributor', + pageSize: -1, + autoLoad: false + }); + + this.manufacturerStore = Ext.create("Ext.data.Store", + { + model: 'Manufacturer', + pageSize: -1, + autoLoad: false + }); + + this.partUnitStore = Ext.create("Ext.data.Store", + { + model: 'PartUnit', + pageSize: -1, + autoLoad: false + }); + + this.unitStore = Ext.create("Ext.data.Store", + { + model: 'Unit', + pageSize: -1, + autoLoad: false + }); + }, + getUnitStore: function () { + return this.unitStore; + }, + getPartUnitStore: function () { + return this.partUnitStore; + }, + getStorageLocationStore: function () { + return this.storageLocationStore; + }, + getFootprintStore: function () { + return this.footprintStore; + }, + getManufacturerStore: function () { + return this.manufacturerStore; + }, + getDistributorStore: function () { + return this.distributorStore; + }, + getSiPrefixStore: function () { + return this.siPrefixStore; + }, + /** + * Converts the Character "micro" (µ, available on german keyboards via AltGr+m) to the Character "Mu" (μ). + * + * The standard for Si-Prefixes defines that the "Mu"-character should be used instead of the "micro" character. + * + * Wikipedia Entry for the "Micro" Si Prefix: http://en.wikipedia.org/wiki/Micro- + * + */ + convertMicroToMu: function (value) { + /** + * Since the Si-Prefix for "micro" is μ, but keyboard have "µ" on it + * (note: both chars might look identical, depending on your font), we need + * to convert "µ" (on the keyboard, Unicode U+00B5) to the Mu (U+03BC). + */ + + return str_replace("µ", "μ", value); + }, + /** + * Reload all global stores each 100 seconds. + * + * @todo In the future, it would be nice to trigger a specific + * store reload when something happens. Example: + * + * If the user pulls down the storage location combo box, + * reload it. + * + * YES, this is becoming nasty. We have now 6 stores, each + * reloading every minute. This NEEDS to be fixed soon! + * + */ + reloadStores: function () { + this.storageLocationStore.load(); + this.footprintStore.load(); + this.manufacturerStore.load(); + this.distributorStore.load(); + this.partUnitStore.load(); + this.unitStore.load(); + Ext.defer(PartKeepr.getApplication().reloadStores, 100000, this); + }, + createLayout: function () { + + this.statusBar = Ext.create("PartKeepr.Statusbar"); + + this.messageLog = this.createMessageLog(); + + this.centerPanel = Ext.create("Ext.tab.Panel", { + xtype: 'tabpanel', + region: 'center', + bodyStyle: 'background:#DFE8F6' + + }); + + this.menuBar = Ext.create("PartKeepr.MenuBar"); + + Ext.create('Ext.container.Viewport', { + layout: 'fit', + items: [{ + xtype: 'panel', + layout: 'border', + items: [ + this.centerPanel, + this.messageLog + ], + bbar: this.statusBar, + tbar: this.menuBar + }] + + }); + }, + addItem: function (item) { + this.centerPanel.add(item); + }, + createMessageLog: function () { + return Ext.create("PartKeepr.MessageLog", { + height: 200, + hidden: true, + split: true, + title: i18n("Message Log"), + titleCollapse: true, + collapsible: true, + region: 'south', + listeners: { + beforecollapse: Ext.bind( + function (obj) { + this.hideMessageLog(); + return false; + }, + this) + } + }); + }, + log: function (message) { + this.logMessage(message, "none"); + }, + logMessage: function (message, severity) { + if (message != i18n("Ready.")) { + var r = Ext.ModelManager.create({ + message: message, + severity: severity, + date: new Date() + }, 'Message'); + + this.messageLog.getStore().add(r); + } + }, + hideMessageLog: function () { + this.messageLog.hide(); + }, + showMessageLog: function () { + this.messageLog.show(); + }, + toggleMessageLog: function () { + if (this.messageLog.isHidden()) { + this.showMessageLog(); + } else { + this.hideMessageLog(); + } + + }, + getStatusbar: function () { + return this.statusBar; + }, + getSession: function () { + return this.session; + }, + setSession: function (session) { + this.session = session; + + this.getStatusbar().getConnectionButton().setConnected(); + }, + setUsername: function (username) { + this.username = username; + + this.getStatusbar().setCurrentUser(username); + } +}); + +/** + * <p>This static method returns a REST object definition for use with any models.</p> + * <p>It automatically sets the session (if available) and the prefix for the given REST service.</p> + * @param {string} service The REST service to call. Only use the base name, e.g. "Footprint" instead of "FootprintService". + * @return {Object} The RESTProxy definition +*/ +PartKeepr.getRESTProxy = function (service) { + var obj = { + batchActions: false, + url: PartKeepr.getBasePath()+ '/'+service, + listeners: { + exception: function (proxy, response, operation) { + try { + var data = Ext.decode(response.responseText); + + var j = new PartKeepr.ExceptionWindow(); + j.showException(data.exception); + } catch (ex) { + var exception = { + message: i18n("Critical Error"), + detail: i18n("The server returned a response which we were not able to interpret."), + exception: "", + backtrace: response.responseText + }; + + + var jj = new PartKeepr.ExceptionWindow(); + jj.showException(exception); + + + } + } + }, + reader: { + type: 'json', + root: 'response.data', + successProperty: "success", + messageProperty: 'message', + totalProperty : 'response.totalCount' + }, + writer: { + type: 'json' + } + + }; + //Ext.data.AjaxProxy.superclass.constructor.apply(this, arguments); + return new Ext.data.proxy.Rest(obj); +}; + +PartKeepr.getSession = function () { + alert("This should not be called."); + return "hli2ong0ktnise68p9f5nu6nk1"; +}; + +PartKeepr.log = function (message) { + PartKeepr.getApplication().log(message); +}; + +/** + * <p>This static method returns the instance of the application.</p> + * @return {Object} The application +*/ +PartKeepr.getApplication = function () { + return PartKeepr.application; +}; + +PartKeepr.getBasePath = function () { + return "rest.php"; +}; + +PartKeepr.setMaxUploadSize = function (size) { + PartKeepr.maxUploadSize = size; +}; + +PartKeepr.getMaxUploadSize = function () { + return PartKeepr.maxUploadSize; +}; + +PartKeepr.bytesToSize = function (bytes) { + var sizes = ['Bytes', 'KB', 'MB', 'GB', 'TB']; + if (bytes === 0) return 'n/a'; + var i = parseInt(Math.floor(Math.log(bytes) / Math.log(1024)),10); + return Math.round(bytes / Math.pow(1024, i), 2) + ' ' + sizes[i]; +}; + +PartKeepr.setAvailableImageFormats = function (formats) { + PartKeepr.imageFormats = formats; +}; + +PartKeepr.getAvailableImageFormats = function () { + return PartKeepr.imageFormats; +}; + +PartKeepr.serializeRecords = function (records) { + var finalData = []; + + for (var i=0;i<records.length;i++) { + finalData.push(records[i].data); + } + + return finalData; +};+ \ No newline at end of file diff --git a/frontend/js/Util/ServiceCall.js b/frontend/js/Util/ServiceCall.js @@ -1,4 +1,4 @@ -Ext.define('PartDB2.ServiceCall', { +Ext.define('PartKeepr.ServiceCall', { extend: 'Ext.util.Observable', service: null, @@ -48,7 +48,7 @@ Ext.define('PartDB2.ServiceCall', { }, doCall: function () { /* Update the status bar to indicate that the call is in progress. */ - PartDB2.getApplication().getStatusbar().startLoad(this.loadMessage); + PartKeepr.getApplication().getStatusbar().startLoad(this.loadMessage); var callDefinition = Ext.encode(this.parameters); @@ -58,11 +58,11 @@ Ext.define('PartDB2.ServiceCall', { }; if (!this.anonymous) { - headers.session = PartDB2.getApplication().getSession(); + headers.session = PartKeepr.getApplication().getSession(); } Ext.Ajax.request({ - url: PartDB2.getBasePath() + '/' + this.service + "/"+this.call, + url: PartKeepr.getBasePath() + '/' + this.service + "/"+this.call, success: Ext.bind(this.onSuccess, this), failure: Ext.bind(this.onError, this), method: "POST", @@ -71,7 +71,7 @@ Ext.define('PartDB2.ServiceCall', { }); }, onSuccess: function (responseObj) { - PartDB2.getApplication().getStatusbar().endLoad(); + PartKeepr.getApplication().getStatusbar().endLoad(); try { var response = Ext.decode(responseObj.responseText); @@ -84,7 +84,7 @@ Ext.define('PartDB2.ServiceCall', { }; - var j = new PartDB2.ExceptionWindow(); + var j = new PartKeepr.ExceptionWindow(); j.showException(exception); return; } @@ -93,7 +93,7 @@ Ext.define('PartDB2.ServiceCall', { /* Check the status */ if (response.status == "error") { this.displayError(response.exception); - PartDB2.getApplication().getStatusbar().setStatus({ + PartKeepr.getApplication().getStatusbar().setStatus({ text: this.getErrorMessage(response.exception), iconCls: 'x-status-error', clear: { @@ -107,7 +107,7 @@ Ext.define('PartDB2.ServiceCall', { /* Check the status */ if (response.status == "systemerror") { this.displaySystemError(response); - PartDB2.getApplication().getStatusbar().setStatus({ + PartKeepr.getApplication().getStatusbar().setStatus({ text: this.getErrorMessage(response), iconCls: 'x-status-error', clear: { @@ -130,7 +130,7 @@ Ext.define('PartDB2.ServiceCall', { try { var data = Ext.decode(response.responseText); - var j = new PartDB2.ExceptionWindow(); + var j = new PartKeepr.ExceptionWindow(); j.showException(data.exception); } catch (ex) { var exception = { @@ -141,13 +141,13 @@ Ext.define('PartDB2.ServiceCall', { }; - var jj = new PartDB2.ExceptionWindow(); + var jj = new PartKeepr.ExceptionWindow(); jj.showException(exception); } - PartDB2.getApplication().getStatusbar().endLoad(); + PartKeepr.getApplication().getStatusbar().endLoad(); }, displayError: function (obj) { diff --git a/frontend/js/bugfixes.js b/frontend/js/bugfixes.js @@ -27,8 +27,8 @@ Ext.override(Ext.data.Connection, { options.headers = {}; } - if (PartDB2.getApplication() !== null) { - session = PartDB2.getApplication().getSession(); + if (PartKeepr.getApplication() !== null) { + session = PartKeepr.getApplication().getSession(); if (session !== null) { options.headers.session = session; } diff --git a/frontend/js/org.jerrymouse.util.locale/locales/de_DE.js b/frontend/js/org.jerrymouse.util.locale/locales/de_DE.js @@ -28,29 +28,29 @@ locales.de_DE = { /* Status Bar */ "org.jerrymouse.components.Statusbar.Ready": "Bereit.", - "de.RaumZeitLabor.PartDB2.save": "Speichern", - "de.RaumZeitLabor.PartDB2.cancel": "Abbrechen", + "de.RaumZeitLabor.PartKeepr.save": "Speichern", + "de.RaumZeitLabor.PartKeepr.cancel": "Abbrechen", /* Footprints */ - "de.RaumZeitLabor.PartDB2.FootPrintManager.manage": "Footprints verwalten", - "de.RaumZeitLabor.PartDB2.FootPrintManager.add": "Footprint erzeugen", - "de.RaumZeitLabor.PartDB2.FootPrintManager.delete": "Footprint löschen", - "de.RaumZeitLabor.PartDB2.FootPrintManager.reload": "Footprints neu laden", - "de.RaumZeitLabor.PartDB2.FootPrintManager.loading": "Footprints werden geladen...", - "de.RaumZeitLabor.PartDB2.FootPrintManager.footprint": "Footprint", - "de.RaumZeitLabor.PartDB2.FootPrintManager.addFootprintDialogTitle": "Footprint erzeugen", - "de.RaumZeitLabor.PartDB2.FootPrintManager.addFootprintDialogMessage":"Name des Footprints:", - "de.RaumZeitLabor.PartDB2.FootPrintManager.addFootprint": "Footprint wird erzeugt...", - "de.RaumZeitLabor.PartDB2.FootPrintManager.deleteFootprintDialogTitle": "Footprint löschen", - "de.RaumZeitLabor.PartDB2.FootPrintManager.deleteFootprintDialogMessage":"Den Footprint %s wirklich löschen?", - "de.RaumZeitLabor.PartDB2.FootPrintManager.deleteFootprint": "Footprint wird gelöscht...", - "de.RaumZeitLabor.PartDB2.FootPrintManager.loadFootprint": "Footprint wird geladen...", + "de.RaumZeitLabor.PartKeepr.FootPrintManager.manage": "Footprints verwalten", + "de.RaumZeitLabor.PartKeepr.FootPrintManager.add": "Footprint erzeugen", + "de.RaumZeitLabor.PartKeepr.FootPrintManager.delete": "Footprint löschen", + "de.RaumZeitLabor.PartKeepr.FootPrintManager.reload": "Footprints neu laden", + "de.RaumZeitLabor.PartKeepr.FootPrintManager.loading": "Footprints werden geladen...", + "de.RaumZeitLabor.PartKeepr.FootPrintManager.footprint": "Footprint", + "de.RaumZeitLabor.PartKeepr.FootPrintManager.addFootprintDialogTitle": "Footprint erzeugen", + "de.RaumZeitLabor.PartKeepr.FootPrintManager.addFootprintDialogMessage":"Name des Footprints:", + "de.RaumZeitLabor.PartKeepr.FootPrintManager.addFootprint": "Footprint wird erzeugt...", + "de.RaumZeitLabor.PartKeepr.FootPrintManager.deleteFootprintDialogTitle": "Footprint löschen", + "de.RaumZeitLabor.PartKeepr.FootPrintManager.deleteFootprintDialogMessage":"Den Footprint %s wirklich löschen?", + "de.RaumZeitLabor.PartKeepr.FootPrintManager.deleteFootprint": "Footprint wird gelöscht...", + "de.RaumZeitLabor.PartKeepr.FootPrintManager.loadFootprint": "Footprint wird geladen...", /* Category Editor */ - "de.RaumZeitLabor.PartDB2.CategoryEditor.categoryName": "Kategoriename", - "de.RaumZeitLabor.PartDB2.CategoryEditor.categoryDescription": "Beschreibung", - "de.RaumZeitLabor.PartDB2.CategoryEditor.parentCategory": "Übergeordnete Kategorie", - "de.RaumZeitLabor.PartDB2.CategoryEditor.loadCategor": "Kategorie wird geladen...", - "de.RaumZeitLabor.PartDB2.CategoryEditor.saveCategory": "Kategorie wird gespeichert..." + "de.RaumZeitLabor.PartKeepr.CategoryEditor.categoryName": "Kategoriename", + "de.RaumZeitLabor.PartKeepr.CategoryEditor.categoryDescription": "Beschreibung", + "de.RaumZeitLabor.PartKeepr.CategoryEditor.parentCategory": "Übergeordnete Kategorie", + "de.RaumZeitLabor.PartKeepr.CategoryEditor.loadCategor": "Kategorie wird geladen...", + "de.RaumZeitLabor.PartKeepr.CategoryEditor.saveCategory": "Kategorie wird gespeichert..." }; \ No newline at end of file diff --git a/frontend/js/org.jerrymouse.util.locale/locales/en_US.js b/frontend/js/org.jerrymouse.util.locale/locales/en_US.js @@ -30,53 +30,53 @@ locales.en_US = { /* Status Bar */ "org.jerrymouse.components.Statusbar.Ready": "Ready.", - "de.RaumZeitLabor.PartDB2.save": "Save", - "de.RaumZeitLabor.PartDB2.cancel": "Cancel", + "de.RaumZeitLabor.PartKeepr.save": "Save", + "de.RaumZeitLabor.PartKeepr.cancel": "Cancel", /* Footprints */ - "de.RaumZeitLabor.PartDB2.FootPrintManager.manage": "Manage Footprints", - "de.RaumZeitLabor.PartDB2.FootPrintManager.add": "Add Footprint", - "de.RaumZeitLabor.PartDB2.FootPrintManager.delete": "Delete Footprint", - "de.RaumZeitLabor.PartDB2.FootPrintManager.reload": "Reload Footprints", - "de.RaumZeitLabor.PartDB2.FootPrintManager.loading": "Loading Footprints...", - "de.RaumZeitLabor.PartDB2.FootPrintManager.footprint": "Footprint", - "de.RaumZeitLabor.PartDB2.FootPrintManager.addFootprintDialogTitle": "Add Footprint", - "de.RaumZeitLabor.PartDB2.FootPrintManager.addFootprintDialogMessage":"Footprint Name:", - "de.RaumZeitLabor.PartDB2.FootPrintManager.addFootprint": "Creating Footprint...", - "de.RaumZeitLabor.PartDB2.FootPrintManager.deleteFootprintDialogTitle": "Delete Footprint", - "de.RaumZeitLabor.PartDB2.FootPrintManager.deleteFootprintDialogMessage":"Really delete Footprint %s?", - "de.RaumZeitLabor.PartDB2.FootPrintManager.deleteFootprint": "Deleting Footprint...", - "de.RaumZeitLabor.PartDB2.FootPrintManager.loadFootprint": "Loading Footprint...", + "de.RaumZeitLabor.PartKeepr.FootPrintManager.manage": "Manage Footprints", + "de.RaumZeitLabor.PartKeepr.FootPrintManager.add": "Add Footprint", + "de.RaumZeitLabor.PartKeepr.FootPrintManager.delete": "Delete Footprint", + "de.RaumZeitLabor.PartKeepr.FootPrintManager.reload": "Reload Footprints", + "de.RaumZeitLabor.PartKeepr.FootPrintManager.loading": "Loading Footprints...", + "de.RaumZeitLabor.PartKeepr.FootPrintManager.footprint": "Footprint", + "de.RaumZeitLabor.PartKeepr.FootPrintManager.addFootprintDialogTitle": "Add Footprint", + "de.RaumZeitLabor.PartKeepr.FootPrintManager.addFootprintDialogMessage":"Footprint Name:", + "de.RaumZeitLabor.PartKeepr.FootPrintManager.addFootprint": "Creating Footprint...", + "de.RaumZeitLabor.PartKeepr.FootPrintManager.deleteFootprintDialogTitle": "Delete Footprint", + "de.RaumZeitLabor.PartKeepr.FootPrintManager.deleteFootprintDialogMessage":"Really delete Footprint %s?", + "de.RaumZeitLabor.PartKeepr.FootPrintManager.deleteFootprint": "Deleting Footprint...", + "de.RaumZeitLabor.PartKeepr.FootPrintManager.loadFootprint": "Loading Footprint...", /* Category Editor */ - "de.RaumZeitLabor.PartDB2.CategoryEditor.categoryName": "Category Name", - "de.RaumZeitLabor.PartDB2.CategoryEditor.categoryDescription": "Description", - "de.RaumZeitLabor.PartDB2.CategoryEditor.parentCategory": "Parent Category", - "de.RaumZeitLabor.PartDB2.CategoryEditor.loadCategor": "Loading Category...", - "de.RaumZeitLabor.PartDB2.CategoryEditor.saveCategory": "Saving Category...", + "de.RaumZeitLabor.PartKeepr.CategoryEditor.categoryName": "Category Name", + "de.RaumZeitLabor.PartKeepr.CategoryEditor.categoryDescription": "Description", + "de.RaumZeitLabor.PartKeepr.CategoryEditor.parentCategory": "Parent Category", + "de.RaumZeitLabor.PartKeepr.CategoryEditor.loadCategor": "Loading Category...", + "de.RaumZeitLabor.PartKeepr.CategoryEditor.saveCategory": "Saving Category...", /* Storage Locations */ - "de.RaumZeitLabor.PartDB2.StorageLocationManager.manage": "Manage Storage Locations", - "de.RaumZeitLabor.PartDB2.StorageLocationManager.name": "Storage Location Name", - "de.RaumZeitLabor.PartDB2.StorageLocationManager.add": "Add Storage Location", - "de.RaumZeitLabor.PartDB2.StorageLocationManager.delete": "Delete Storage Location", - "de.RaumZeitLabor.PartDB2.StorageLocationManager.deleteStorageLocationDialogTitle": "Delete Storage Location", - "de.RaumZeitLabor.PartDB2.StorageLocationManager.deleteStorageLocationDialogMessage": "Do you really wish to delete the selected storage location?", - "de.RaumZeitLabor.PartDB2.StorageLocationManager.addStorageLocationDialogTitle": "Add a new storage location", - "de.RaumZeitLabor.PartDB2.StorageLocationManager.addStorageLocationDialogMessage": "Enter the name of the new storage location:", - "de.RaumZeitLabor.PartDB2.StorageLocationManager.name": "Name", + "de.RaumZeitLabor.PartKeepr.StorageLocationManager.manage": "Manage Storage Locations", + "de.RaumZeitLabor.PartKeepr.StorageLocationManager.name": "Storage Location Name", + "de.RaumZeitLabor.PartKeepr.StorageLocationManager.add": "Add Storage Location", + "de.RaumZeitLabor.PartKeepr.StorageLocationManager.delete": "Delete Storage Location", + "de.RaumZeitLabor.PartKeepr.StorageLocationManager.deleteStorageLocationDialogTitle": "Delete Storage Location", + "de.RaumZeitLabor.PartKeepr.StorageLocationManager.deleteStorageLocationDialogMessage": "Do you really wish to delete the selected storage location?", + "de.RaumZeitLabor.PartKeepr.StorageLocationManager.addStorageLocationDialogTitle": "Add a new storage location", + "de.RaumZeitLabor.PartKeepr.StorageLocationManager.addStorageLocationDialogMessage": "Enter the name of the new storage location:", + "de.RaumZeitLabor.PartKeepr.StorageLocationManager.name": "Name", /* Manufacturers */ - "de.RaumZeitLabor.PartDB2.ManufacturerManager.manage": "Manage Manufacturers", - "de.RaumZeitLabor.PartDB2.ManufacturerManager.name": "Manufacturer Name", - "de.RaumZeitLabor.PartDB2.ManufacturerManager.add": "Add Manufacturer", - "de.RaumZeitLabor.PartDB2.ManufacturerManager.delete": "Delete Manufacturer", - "de.RaumZeitLabor.PartDB2.ManufacturerManager.deleteManufacturerDialogTitle": "Delete Manufacturer", - "de.RaumZeitLabor.PartDB2.ManufacturerManager.deleteManufacturerDialogMessage": "Do you really wish to delete the selected manufacturer?", - "de.RaumZeitLabor.PartDB2.ManufacturerManager.addManufacturerDialogTitle": "Add a new manufacturer", - "de.RaumZeitLabor.PartDB2.ManufacturerManager.addManufacturerDialogMessage": "Enter the name of the new manufacturer:", - "de.RaumZeitLabor.PartDB2.ManufacturerManager.name": "Name", + "de.RaumZeitLabor.PartKeepr.ManufacturerManager.manage": "Manage Manufacturers", + "de.RaumZeitLabor.PartKeepr.ManufacturerManager.name": "Manufacturer Name", + "de.RaumZeitLabor.PartKeepr.ManufacturerManager.add": "Add Manufacturer", + "de.RaumZeitLabor.PartKeepr.ManufacturerManager.delete": "Delete Manufacturer", + "de.RaumZeitLabor.PartKeepr.ManufacturerManager.deleteManufacturerDialogTitle": "Delete Manufacturer", + "de.RaumZeitLabor.PartKeepr.ManufacturerManager.deleteManufacturerDialogMessage": "Do you really wish to delete the selected manufacturer?", + "de.RaumZeitLabor.PartKeepr.ManufacturerManager.addManufacturerDialogTitle": "Add a new manufacturer", + "de.RaumZeitLabor.PartKeepr.ManufacturerManager.addManufacturerDialogMessage": "Enter the name of the new manufacturer:", + "de.RaumZeitLabor.PartKeepr.ManufacturerManager.name": "Name", /* Parts */ - "de.RaumZeitLabor.PartDB2.PartsManager.manage": "Manage Parts" + "de.RaumZeitLabor.PartKeepr.PartsManager.manage": "Manage Parts" }; diff --git a/frontend/rest.php b/frontend/rest.php @@ -1,12 +1,12 @@ <?php -namespace de\RaumZeitLabor\PartDB2\Frontend; +namespace de\RaumZeitLabor\PartKeepr\Frontend; declare(encoding = 'UTF-8'); -use de\RaumZeitLabor\PartDB2\PartDB2, - de\RaumZeitLabor\PartDB2\Service\ServiceManager; +use de\RaumZeitLabor\PartKeepr\PartKeepr, + de\RaumZeitLabor\PartKeepr\Service\ServiceManager; -include("../src/de/RaumZeitLabor/PartDB2/PartDB2.php"); -PartDB2::initialize(""); +include("../src/de/RaumZeitLabor/PartKeepr/PartKeepr.php"); +PartKeepr::initialize(""); /** * This script dispatches the request to the ServiceManager. @@ -35,7 +35,7 @@ PartDB2::initialize(""); * rest.php/Part * * /Part specifies that you wish to call the Part service. The service manager automatically extends the short "Part" - * name to the class de\RaumZeitLabor\PartDB2\Part\PartService. + * name to the class de\RaumZeitLabor\PartKeepr\Part\PartService. * * REST * ==== @@ -52,7 +52,7 @@ try { echo json_encode($response); -} catch (\de\RaumZeitLabor\PartDB2\Util\SerializableException $e) { +} catch (\de\RaumZeitLabor\PartKeepr\Util\SerializableException $e) { header('HTTP/1.0 400 Exception', false, 400); $response = array(); $response["status"] = "error"; diff --git a/frontend/service.php b/frontend/service.php @@ -1,13 +1,13 @@ <?php -namespace de\RaumZeitLabor\PartDB2\Frontend; +namespace de\RaumZeitLabor\PartKeepr\Frontend; declare(encoding = 'UTF-8'); -use de\RaumZeitLabor\PartDB2\Service\ServiceManager; -use de\RaumZeitLabor\PartDB2\PartDB2; +use de\RaumZeitLabor\PartKeepr\Service\ServiceManager; +use de\RaumZeitLabor\PartKeepr\PartKeepr; -include("../src/de/RaumZeitLabor/PartDB2/PartDB2.php"); +include("../src/de/RaumZeitLabor/PartKeepr/PartKeepr.php"); -PartDB2::initialize(""); +PartKeepr::initialize(""); try { $request = $_REQUEST; @@ -19,7 +19,7 @@ try { echo json_encode($response); -} catch (de\RaumZeitLabor\PartDB2\Util\SerializableException $e) { +} catch (de\RaumZeitLabor\PartKeepr\Util\SerializableException $e) { $response = array(); $response["status"] = "error"; $response["exception"] = $e->serialize(); diff --git a/frontend/upload.php b/frontend/upload.php @@ -1,15 +1,15 @@ <?php -namespace de\RaumZeitLabor\PartDB2\Frontend; +namespace de\RaumZeitLabor\PartKeepr\Frontend; declare(encoding = 'UTF-8'); -use de\RaumZeitLabor\PartDB2\PartDB2; -use de\RaumZeitLabor\PartDB2\Image\Image; -use de\RaumZeitLabor\PartDB2\Manufacturer\ManufacturerICLogo; -use de\RaumZeitLabor\PartDB2\Manufacturer\Manufacturer; +use de\RaumZeitLabor\PartKeepr\PartKeepr; +use de\RaumZeitLabor\PartKeepr\Image\Image; +use de\RaumZeitLabor\PartKeepr\Manufacturer\ManufacturerICLogo; +use de\RaumZeitLabor\PartKeepr\Manufacturer\Manufacturer; -include("../src/de/RaumZeitLabor/PartDB2/PartDB2.php"); +include("../src/de/RaumZeitLabor/PartKeepr/PartKeepr.php"); -PartDB2::initialize(""); +PartKeepr::initialize(""); $keys = array_keys($_FILES); @@ -25,8 +25,8 @@ switch ($_REQUEST["uploadMode"]) { $image = new ManufacturerICLogo(); $image->setManufacturer($manufacturer); $image->replace($file); - PartDB2::getEM()->persist($image); - PartDB2::getEM()->flush(); + PartKeepr::getEM()->persist($image); + PartKeepr::getEM()->flush(); } break; diff --git a/setup/tests/PDOTest.php b/setup/tests/PDOTest.php @@ -1,5 +1,5 @@ <?php -namespace de\RaumZeitLabor\PartDB2\setup\tests; +namespace de\RaumZeitLabor\PartKeepr\setup\tests; declare(encoding = 'UTF-8'); class PDOTest extends \PHPUnit_Framework_TestCase { diff --git a/setup/tests/SOAPTest.php b/setup/tests/SOAPTest.php @@ -1,5 +1,5 @@ <?php -namespace de\RaumZeitLabor\PartDB2\setup\tests; +namespace de\RaumZeitLabor\PartKeepr\setup\tests; declare(encoding = 'UTF-8'); class SOAPTest extends \PHPUnit_Framework_TestCase { diff --git a/src/de/RaumZeitLabor/PartDB2/Auth/AuthManager.php b/src/de/RaumZeitLabor/PartDB2/Auth/AuthManager.php @@ -1,13 +0,0 @@ -<?php -namespace de\RaumZeitLabor\PartDB2\Auth; - -use de\RaumZeitLabor\PartDB2\Util\Singleton; - -class AuthManager extends Singleton { - public function login () { - - } - - -} -?>- \ No newline at end of file diff --git a/src/de/RaumZeitLabor/PartDB2/Auth/AuthService.php b/src/de/RaumZeitLabor/PartDB2/Auth/AuthService.php @@ -1,36 +0,0 @@ -<?php -namespace de\raumzeitlabor\PartDB2\Auth; -declare(encoding = 'UTF-8'); - -use de\RaumZeitLabor\PartDB2\Service\AnonService, - de\RaumZeitLabor\PartDB2\Auth\User, - de\RaumZeitLabor\PartDB2\Auth\UserManager, - de\RaumZeitLabor\PartDB2\Session\SessionManager; - -class AuthService extends AnonService { - public function login () { - $this->requireParameter("username"); - $this->requireParameter("password"); - - /* Build a temporary user */ - $user = new User; - $user->setRawUsername($this->getParameter("username")); - $user->setHashedPassword($this->getParameter("password")); - - $authenticatedUser = UserManager::getInstance()->authenticate($user); - - if ($authenticatedUser !== false) { - /* Start Session */ - $session = SessionManager::getInstance()->startSession($authenticatedUser); - - return array("sessionid" => $session->getSessionID(), "username" => $this->getParameter("username"), "admin" => $session->getUser()->isAdmin()); - } else { - throw new InvalidLoginDataException(); - } - - - } - - -} -?>- \ No newline at end of file diff --git a/src/de/RaumZeitLabor/PartDB2/Auth/Exceptions/InvalidLoginDataException.php b/src/de/RaumZeitLabor/PartDB2/Auth/Exceptions/InvalidLoginDataException.php @@ -1,12 +0,0 @@ -<?php -namespace de\RaumZeitLabor\PartDB2\Auth\Exceptions; - -use de\RaumZeitLabor\PartDB2\Util\SerializableException, - de\RaumZeitLabor\PartDB2\PartDB2; - -class InvalidLoginDataException extends SerializableException { - public function __construct () { - parent::__construct(PartDB2::i18n("Username or Password wrong.")); - } -} -?>- \ No newline at end of file diff --git a/src/de/RaumZeitLabor/PartDB2/Auth/Exceptions/UserAlreadyExistsException.php b/src/de/RaumZeitLabor/PartDB2/Auth/Exceptions/UserAlreadyExistsException.php @@ -1,12 +0,0 @@ -<?php -namespace de\RaumZeitLabor\PartDB2\Auth\Exceptions; - -use de\RaumZeitLabor\PartDB2\Util\SerializableException, - de\RaumZeitLabor\PartDB2\PartDB2; - -class UserAlreadyExistsException extends SerializableException { - public function __construct () { - parent::__construct(PartDB2::i18n("User already exists.")); - } -} -?>- \ No newline at end of file diff --git a/src/de/RaumZeitLabor/PartDB2/Auth/Exceptions/UserDoesNotExistException.php b/src/de/RaumZeitLabor/PartDB2/Auth/Exceptions/UserDoesNotExistException.php @@ -1,12 +0,0 @@ -<?php -namespace de\RaumZeitLabor\PartDB2\Auth\Exceptions; - -use de\RaumZeitLabor\PartDB2\Util\SerializableException, - de\RaumZeitLabor\PartDB2\PartDB2; - -class UserDoesNotExistException extends SerializableException { - public function __construct () { - parent::__construct(PartDB2::i18n("The given user doesn't exist. Maybe the user was already deleted.")); - } -} -?>- \ No newline at end of file diff --git a/src/de/RaumZeitLabor/PartDB2/Auth/User.php b/src/de/RaumZeitLabor/PartDB2/Auth/User.php @@ -1,183 +0,0 @@ -<?php -namespace de\RaumZeitLabor\PartDB2\Auth; -declare(encoding = 'UTF-8'); - -/** @Entity */ - -class User { - /** - * @Id @Column(type="integer") - * @GeneratedValue(strategy="AUTO") - * @var unknown_type - */ - private $id; - - /** @Column(length=50,unique=true) */ - private $username; - - /** @Column(length=32) */ - private $password; - - /** @Column(type="boolean") */ - private $admin; - - - /** - * Creates a new user object. - * - * @param string $username The username to set (optional) - * @param string $password The password to set (optional) - */ - public function __construct ($username = null, $password = null) { - if ($username !== null) { - $this->setUsername($username); - } - - if ($password !== null) { - $this->setPassword($password); - } - - $this->setAdmin(false); - } - /** - * Sets the username. - * - * Forces the username to have - * lowercase a-z characters. - * - * Replaces space with an underscore. - * - * @param string $username The username to set. Applies automatic username modification. - * @return nothing - */ - public function setUsername ($username) { - $username = strtolower($username); - - - preg_match_all("/[a-z\s]+/", $username, $out); - $username = implode('', $out[0]); - - $username = str_replace(" ", "_", $username); - - $this->username = $username; - - } - - /** - * Sets the raw username, without replacing any special chars. - * - * This method should only be used for building a temporary user - * for login checks. - * - * @param string $username The raw username - * @return nothing - */ - public function setRawUsername ($username) { - $this->username = $username; - } - - /** - * Returns the username. - * @param none - * @return string The username - */ - public function getUsername () { - return $this->username; - } - - /** - * Sets the admin flag - * @param boolean $bAdmin True if the user is an admin, false otherwise - */ - public function setAdmin ($bAdmin) { - $this->admin = (boolean)$bAdmin; - } - - /** - * Returns the admin flag - * @return boolean True if the user is an admin - */ - public function isAdmin () { - return $this->admin; - } - - /** - * Sets the user's password. Automatically - * applies md5 hashing. - * - * @param string $password - */ - public function setPassword ($password) { - $this->setHashedPassword(md5($password)); - } - - /** - * Returns the user's md5-hashed password. - * @param none - * @return string The md5-hashed password - */ - public function getHashedPassword () { - return $this->password; - } - - /** - * Sets the user's password. Expects a hash - * and does not apply md5 hasing. - * - * @param string $hashedPassword - */ - public function setHashedPassword ($hashedPassword) { - $this->password = $hashedPassword; - } - - /** - * Compares the given un-hashed password with the - * object's hashed password. - * - * - * @param string $password The unhashed password - * @return boolean true if the passwords match, false otherwise - */ - public function comparePassword ($password) { - return $this->compareHashedPassword(md5($password)); - } - - /** - * Compares the given hashed password with the object's - * hashed password. - * - * @param string $hashedPassword The md5-hashed password - * @return boolean true if the passwords match, false otherwise - */ - public function compareHashedPassword ($hashedPassword) { - if ($hashedPassword == $this->password) { - return true; - } else { - return false; - } - } - - /** - * Returns the ID of this object. - * @param none - * @return int The ID of this object - */ - public function getId () { - return $this->id; - } - - /** - * Serializes the user object and returns it as array, suitable - * to process via json_encode. - * @param none - * @return array An array containing the object information - */ - public function serialize () { - return array( - "id" => $this->getId(), - "username" => $this->getUsername() - ); - } - -} -?>- \ No newline at end of file diff --git a/src/de/RaumZeitLabor/PartDB2/Auth/UserManager.php b/src/de/RaumZeitLabor/PartDB2/Auth/UserManager.php @@ -1,57 +0,0 @@ -<?php -namespace de\raumzeitlabor\PartDB2\Auth; -declare(encoding = 'UTF-8'); - -use de\RaumZeitLabor\PartDB2\Util\Singleton, - de\RaumZeitLabor\PartDB2\Auth\User, - de\RaumZeitLabor\PartDB2\PartDB2, - de\RaumZeitLabor\PartDB2\Auth\Exceptions\UserAlreadyExistsException, - de\RaumZeitLabor\PartDB2\Auth\Exceptions\UserDoesNotExistException, - de\RaumZeitLabor\PartDB2\Auth\Exceptions\InvalidLoginDataException; - -class UserManager extends Singleton { - - public function createUser (User $user) { - if ($this->userExists($user)) { - throw new UserAlreadyExistsException($user->getUsername()); - } - - PartDB2::getEM()->persist($user); - } - - public function userExists (User $user) { - $user = PartDB2::getEM()->find("de\RaumZeitLabor\PartDB2\Auth\User", $user->getUsername()); - - if ($user === null) { - return false; - } else { - return true; - } - } - - public function deleteUser (User $user) { - if (!$this->userExists($user)) { - throw new UserDoesNotExistException($user->getUsername()); - } - PartDB2::getEM()->remove($user); - } - - public function authenticate (User $user) { - $result = PartDB2::getEM() - ->getRepository("de\RaumZeitLabor\PartDB2\Auth\User") - ->findOneBy( - array( - "username" => $user->getUsername(), - "password" => $user->getHashedPassword() - ) - ); - - if ($result == null) { - throw new InvalidLoginDataException(); - } else { - return $result; - } - } - -} -?>- \ No newline at end of file diff --git a/src/de/RaumZeitLabor/PartDB2/Auth/UserManagerService.php b/src/de/RaumZeitLabor/PartDB2/Auth/UserManagerService.php @@ -1,20 +0,0 @@ -<?php -namespace de\raumzeitlabor\PartDB2\Auth; -declare(encoding = 'UTF-8'); - -use de\RaumZeitLabor\PartDB2\Service\Service; -use de\RaumZeitLabor\PartDB2\Auth\UserManager; - -class UserManagerService extends Service { - public function createUser () { - $this->requireParameter("username"); - $this->requireParameter("password"); - - $user = new User(); - $user->setUsername($this->getParameter("username")); - $user->setHashedPassword($this->getParameter("password")); - - UserManager::getInstance()->createUser($user); - } -} -?>- \ No newline at end of file diff --git a/src/de/RaumZeitLabor/PartDB2/Category/Category.php b/src/de/RaumZeitLabor/PartDB2/Category/Category.php @@ -1,71 +0,0 @@ -<?php -namespace de\RaumZeitLabor\PartDB2\Category; -declare(encoding = 'UTF-8'); - -use DoctrineExtensions\NestedSet\Node; - -/** @Entity @Table(indexes={@index(name="lft", columns={"lft"}),@index(name="rgt", columns={"rgt"})}) */ -class Category implements Node { - /** @Id @Column(type="integer") - * @GeneratedValue(strategy="AUTO") - */ - private $id; - - /** - * @Column(type="integer") - */ - private $lft; - - /** - * @Column(type="integer") - */ - private $rgt; - - /** @Column(length=128) */ - private $name; - - /** @Column(length=32768) */ - private $description; - - private $parent; - - public function setName ($name) { - $this->name = $name; - } - - public function setParent ($id) { - $this->parent = $id; - } - - public function getParent () { - return $this->parent; - } - - public function setDescription ($description) { - $this->description = $description; - } - - - public function getName () { - return $this->name; - } - public function getId() { return $this->id; } - - public function getLeftValue() { return $this->lft; } - public function setLeftValue($lft) { $this->lft = $lft; } - - public function getRightValue() { return $this->rgt; } - public function setRightValue($rgt) { $this->rgt = $rgt; } - - public function serialize () { - return array( - "id" => $this->id, - "name" => $this->name, - "description" => $this->description - - ); - } - - public function __toString () {} -} -?>- \ No newline at end of file diff --git a/src/de/RaumZeitLabor/PartDB2/Category/CategoryManager.php b/src/de/RaumZeitLabor/PartDB2/Category/CategoryManager.php @@ -1,137 +0,0 @@ -<?php -namespace de\raumzeitlabor\PartDB2\Category; -declare(encoding = 'UTF-8'); - -use de\RaumZeitLabor\PartDB2\Util\Singleton, - de\RaumZeitLabor\PartDB2\Category\Category, - de\RaumZeitLabor\PartDB2\Util\SerializableException, - de\RaumZeitLabor\PartDB2\Category\Exceptions\CategoryNotFoundException, - de\RaumZeitLabor\PartDB2\PartDB2; -use DoctrineExtensions\NestedSet\Manager; -use DoctrineExtensions\NestedSet\Config; -use DoctrineExtensions\NestedSet\NodeWrapper; - -class CategoryManager extends Singleton { - private $nodeManager; - - public function getNodeManager () { - if (!$this->nodeManager) { - $config = new Config(PartDB2::getEM(), 'de\RaumZeitLabor\PartDB2\Category\Category'); - - $this->nodeManager = new Manager($config); - } - - return $this->nodeManager; - } - - public function getChildNodes ($id) { - $category = $this->getCategory($id); - - $aData = array(); - - foreach ($category->getDescendants() as $cat) { - $aData[] = $cat->getNode()->getId(); - } - return $aData; - } - - public function getAllCategories () { - return $this->getNodeManager()->fetchTree(1); - } - - - public function ensureRootExists () { - /* Check if the root node exists */ - $rootNode = $this->getNodeManager()->fetchTree(1); - - if ($rootNode === null) { - $this->createRootNode(); - } - } - - public function getRootNode () { - return $this->getNodeManager()->fetchTree(1); - } - - public function createRootNode () { - $rootNode = new Category(); - $rootNode->setName("Root Category"); - $rootNode->setDescription(""); - - $this->getNodeManager()->createRoot($rootNode); - } - - public function addCategory (Category $category) { - $parent = $category->getParent(); - - if ($parent == 0) { - $parent = $this->getRootNode(); - - } else { - $parent = PartDB2::getEM()->find("de\RaumZeitLabor\PartDB2\Category\Category", $parent); - - $parent = new NodeWrapper($parent, $this->getNodeManager()); - } - - return $parent->addChild($category); - - - } - - public function deleteCategory ($id) { - $category = PartDB2::getEM()->find("de\RaumZeitLabor\PartDB2\Category\Category", $id); - - - if ($category) { - try { - $category = new NodeWrapper($category, $this->getNodeManager()); - - if ($category->hasChildren()) { - $exception = new SerializableException(sprintf(PartDB2::i18n("Category '%s' contains other categories."), $category->getNode()->getName())); - $exception->setDetail(sprintf(PartDB2::i18n("You tried to delete the category '%s', but it still contains other categories. Please move the categories or delete them first."), $category->getNode()->getName())); - - throw $exception; - } - $category->delete(); - } catch (\PDOException $e) { - if ($e->getCode() == "23000") { - $exception = new SerializableException(sprintf(PartDB2::i18n("Category '%s' contains parts."), $category->getNode()->getName())); - $exception->setDetail(sprintf(PartDB2::i18n("You tried to delete the category '%s', but it still contains parts. Please move the parts to another category."), $category->getNode()->getName())); - - throw $exception; - } - } - - } else { - throw new CategoryNotFoundException; - } - } - - public function saveCategory ($category) { - PartDB2::getEM()->persist($category); - } - - public function getCategory ($id) { - $category = PartDB2::getEM()->find("de\RaumZeitLabor\PartDB2\Category\Category", $id); - - - - if ($category) { - $category = new NodeWrapper($category, $this->getNodeManager()); - - return $category; - } else { - throw new CategoryNotFoundException; - } - } - - /** - * Returns the overall category count currently existing. - * @return int The amount of categories in the database - */ - public function getCategoryCount () { - $dql = "SELECT COUNT(c.id) FROM de\RaumZeitLabor\PartDB2\Category\Category c"; - - return PartDB2::getEM()->createQuery($dql)->getSingleScalarResult(); - } -}- \ No newline at end of file diff --git a/src/de/RaumZeitLabor/PartDB2/Category/CategoryService.php b/src/de/RaumZeitLabor/PartDB2/Category/CategoryService.php @@ -1,119 +0,0 @@ -<?php -namespace de\RaumZeitLabor\PartDB2\Category; -declare(encoding = 'UTF-8'); - -use de\RaumZeitLabor\PartDB2\Service\Service; -use de\RaumZeitLabor\PartDB2\Category\CategoryManager; -use DoctrineExtensions\NestedSet\NodeWrapper; - - -class CategoryService extends Service { - - public function getCategories () { - $categories = CategoryManager::getInstance()->getAllCategories( - $this->getParameter("parent", 0)); - - return $this->serializeTree($categories); - } - - public function moveCategory () { - $this->requireParameter("category"); - $this->requireParameter("target"); - - $category = CategoryManager::getInstance()->getCategory($this->getParameter("category")); - - if (intval($this->getParameter("target", 0)) !== 0) { - - $parent = CategoryManager::getInstance()->getCategory($this->getParameter("target")); - - $category->moveAsLastChildOf($parent); - - } - } - - public function deleteCategory () { - $this->requireParameter("id"); - - CategoryManager::getInstance()->deleteCategory($this->getParameter("id")); - - return array("id" => $this->getParameter("id")); - } - - public function update () { - $this->requireParameter("id"); - $this->requireParameter("name"); - - $category = CategoryManager::getInstance()->getCategory($this->getParameter("id")); - - $category->getNode()->setName($this->getParameter("name")); - $category->getNode()->setDescription($this->getParameter("description", "")); - - CategoryManager::getInstance()->saveCategory($category->getNode()); - - return array("data" => $this->serializeCategory($category)); - } - - public function create () { - $this->requireParameter("name"); - $this->requireParameter("parent"); - - $category = new Category; - $category->setName($this->getParameter("name")); - $category->setDescription($this->getParameter("description", "")); - $category->setParent($this->getParameter("parent")); - - $category = CategoryManager::getInstance()->addCategory($category); - - return array("data" => $this->serializeCategory($category)); - } - - // Old stuff below - - public function getCategory () { - $this->requireParameter("id"); - - $category = CategoryManager::getInstance()->getCategory($this->getParameter("id")); - - return $this->serializeCategory($category); - - } - - private function serializeCategory ($category) { - $data = $category->getNode()->serialize(); - - if ($category->getParent() !== null) { - $data["parent"] = $category->getParent()->getNode()->getId(); - $data["parentName"] = $category->getParent()->getNode()->getName(); - } - - return $data; - } - - public function getAllCategories () { - return $this->serializeTree(CategoryManager::getInstance()->getAllCategories()); - } - - public function serializeTree (NodeWrapper $node = null) { - if ($node == null) { - throw new \Exception("Node must not be null!"); - } - - $aData = $node->getNode()->serialize(); - - $aData["children"] = array(); - - if (count($node->getChildren()) == 0) { - $aData["leaf"] = true; - } else { - $aData["expanded"] = true; - } - - foreach ($node->getChildren() as $child) { - $aData["children"][] = $this->serializeTree($child); - - } - - return $aData; - } -} -?>- \ No newline at end of file diff --git a/src/de/RaumZeitLabor/PartDB2/Category/Exceptions/CategoryNotFoundException.php b/src/de/RaumZeitLabor/PartDB2/Category/Exceptions/CategoryNotFoundException.php @@ -1,12 +0,0 @@ -<?php -namespace de\RaumZeitLabor\PartDB2\Category\Exceptions; - -use de\RaumZeitLabor\PartDB2\Util\SerializableException, - de\RaumZeitLabor\PartDB2\PartDB2; - -class CategoryNotFoundException extends SerializableException { - public function __construct () { - parent::__construct(PartDB2::i18n("Category not found.")); - } -} -?>- \ No newline at end of file diff --git a/src/de/RaumZeitLabor/PartDB2/Distributor/Distributor.php b/src/de/RaumZeitLabor/PartDB2/Distributor/Distributor.php @@ -1,133 +0,0 @@ -<?php -namespace de\RaumZeitLabor\PartDB2\Distributor; -declare(encoding = 'UTF-8'); - -use de\RaumZeitLabor\PartDB2\PartDB2; - -/** @Entity **/ -class Distributor { - - /** - * @Id @Column(type="integer") - * @GeneratedValue(strategy="AUTO") - * @var unknown_type - */ - private $id; - - /** - * @Column(type="string",unique=true) - */ - private $name; - - /** - * @Column(type="string",nullable=true) - */ - private $address; - - /** - * @Column(type="string",nullable=true) - */ - private $url; - - /** - * @Column(type="string",nullable=true) - */ - private $phone; - - /** - * @Column(type="string",nullable=true) - */ - private $fax; - - /** - * @Column(type="string",nullable=true) - */ - private $email; - - /** - * @Column(type="string",nullable=true) - */ - private $comment; - - public function __construct () { - } - public function setName ($name) { - $this->name = $name; - } - - public function getName () { - return $this->name; - } - - public function setAddress ($address) { - $this->address = $address; - } - - public function getAddress () { - return $this->address; - } - - public function setPhone ($phone) { - $this->phone = $phone; - } - - public function getPhone () { - return $this->phone; - } - - public function setFax ($fax) { - $this->fax = $fax; - } - - public function getFax ($fax) { - return $this->fax; - } - - - public function setComment ($comment) { - $this->comment = $comment; - } - - public function getComment () { - return $this->comment; - } - - public function setEmail ($email) { - $this->email = $email; - } - - public function getEmail () { - return $this->email; - } - - public function setURL ($url) { - $this->url = $url; - } - - public function getURL () { - return $this->url; - } - - public function getICLogos () { - return $this->icLogos; - } - - public function getId () { - return $this->id; - } - - public function serialize () { - return array( - "id" => $this->getId(), - "name" => $this->getName(), - "url" => $this->getURL(), - "address" => $this->getAddress(), - "email" => $this->getEmail(), - "comment" => $this->getComment() - ); - } - - public static function loadById ($id) { - return PartDB2::getEM()->find(get_called_class(), $id); - } -}- \ No newline at end of file diff --git a/src/de/RaumZeitLabor/PartDB2/Distributor/DistributorManager.php b/src/de/RaumZeitLabor/PartDB2/Distributor/DistributorManager.php @@ -1,73 +0,0 @@ -<?php -namespace de\RaumZeitLabor\PartDB2\Distributor; -declare(encoding = 'UTF-8'); - -use de\RaumZeitLabor\PartDB2\Util\Singleton, - de\RaumZeitLabor\PartDB2\Distributor\Distributor, - de\RaumZeitLabor\PartDB2\PartDB2, - de\RaumZeitLabor\PartDB2\Category\CategoryManager, - de\RaumZeitLabor\PartDB2\Distributor\Exceptions\DistributorNotFoundException; - -class DistributorManager extends Singleton { - public function getDistributors ($start = 0, $limit = 10, $sort = "name", $dir = "asc", $filter = "") { - - $qb = PartDB2::getEM()->createQueryBuilder(); - $qb->select("st.id, st.name, st.url, st.email, st.comment, st.address")->from("de\RaumZeitLabor\PartDB2\Distributor\Distributor","st"); - - if ($filter != "") { - $qb = $qb->where("st.name LIKE :filter"); - $qb->setParameter("filter", "%".$filter."%"); - } - - if ($limit > -1) { - $qb->setMaxResults($limit); - $qb->setFirstResult($start); - } - - $qb->orderBy("st.".$sort, $dir); - - $query = $qb->getQuery(); - - $result = $query->getResult(); - - $totalQueryBuilder = PartDB2::getEM()->createQueryBuilder(); - $totalQueryBuilder->select("COUNT(st.id)")->from("de\RaumZeitLabor\PartDB2\Distributor\Distributor","st"); - - - - if ($filter != "") { - $totalQueryBuilder = $totalQueryBuilder->where("st.name LIKE :filter"); - $totalQueryBuilder->setParameter("filter", "%".$filter."%"); - } - - $totalQuery = $totalQueryBuilder->getQuery(); - - return array("data" => $result, "totalCount" => $totalQuery->getSingleScalarResult()); - } - - public function getDistributor ($id) { - $distributor = PartDB2::getEM()->find("de\RaumZeitLabor\PartDB2\Distributor\Distributor", $id); - - if ($distributor) { - return $distributor; - } else { - throw new DistributorNotFoundException(); - } - } - - public function addDistributor ($name) { - $distributor = new Distributor(); - $distributor->setName($name); - - PartDB2::getEM()->persist($distributor); - PartDB2::getEM()->flush(); - - return $distributor; - } - public function deleteDistributor ($id) { - $distributor = $this->getDistributor($id); - - PartDB2::getEM()->remove($distributor); - PartDB2::getEM()->flush(); - } -}- \ No newline at end of file diff --git a/src/de/RaumZeitLabor/PartDB2/Distributor/DistributorService.php b/src/de/RaumZeitLabor/PartDB2/Distributor/DistributorService.php @@ -1,141 +0,0 @@ -<?php -namespace de\RaumZeitLabor\PartDB2\Distributor; -use de\RaumZeitLabor\PartDB2\Service\RestfulService; - -declare(encoding = 'UTF-8'); - -use de\RaumZeitLabor\PartDB2\Service\Service; -use de\RaumZeitLabor\PartDB2\Part\PartManager, - de\RaumZeitLabor\PartDB2\Stock\StockEntry, - de\RaumZeitLabor\PartDB2\PartDB2, - de\RaumZeitLabor\PartDB2\Session\SessionManager; - -class DistributorService extends Service implements RestfulService { - public function get () { - if ($this->hasParameter("id")) { - return DistributorManager::getInstance()->getDistributor($this->getParameter("id"))->serialize(); - } else { - if ($this->hasParameter("sort")) { - $tmp = json_decode($this->getParameter("sort"), true); - - $aSortParams = $tmp[0]; - } else { - $aSortParams = array( - "property" => "name", - "direction" => "ASC"); - } - return DistributorManager::getInstance()->getDistributors( - $this->getParameter("start", $this->getParameter("start", 0)), - $this->getParameter("limit", $this->getParameter("limit", 25)), - $this->getParameter("sortby", $aSortParams["property"]), - $this->getParameter("dir", $aSortParams["direction"]), - $this->getParameter("query", "")); - } - } - - public function create () { - $this->requireParameter("name"); - - $distributor = new Distributor; - - $this->setDistributorData($distributor); - - PartDB2::getEM()->persist($distributor); - PartDB2::getEM()->flush(); - - return array("data" => $distributor->serialize()); - } - - private function setDistributorData (Distributor $distributor) { - $distributor->setName($this->getParameter("name")); - $distributor->setComment($this->getParameter("comment", "")); - $distributor->setAddress($this->getParameter("address", "")); - $distributor->setURL($this->getParameter("url", "")); - $distributor->setEmail($this->getParameter("email", "")); - } - - public function update () { - $this->requireParameter("id"); - $this->requireParameter("name"); - $distributor = DistributorManager::getInstance()->getDistributor($this->getParameter("id")); - - $this->setDistributorData($distributor); - PartDB2::getEM()->flush(); - - return array("data" => $distributor->serialize()); - - } - - public function destroy () { - $this->requireParameter("id"); - - DistributorManager::getInstance()->deleteDistributor($this->getParameter("id")); - - return array("data" => null); - } - - - // Old stuff below - public function getDistributors() { - return DistributorManager::getInstance()->getDistributors( - $this->getParameter("start", 0), - $this->getParameter("limit", 10), - $this->getParameter("sortby", "name"), - $this->getParameter("dir", "asc"), - $this->getParameter("filter", "")); - } - - public function addDistributor () { - $this->requireParameter("name"); - - DistributorManager::getInstance()->addDistributor($this->getParameter("name")); - } - - public function deleteDistributor () { - $this->requireParameter("id"); - - DistributorManager::getInstance()->deleteDistributor($this->getParameter("id")); - } - - public function deleteDistributorLogo () { - $this->requireParameter("id"); - - $logo = DistributorICLogo::loadById($this->getParameter("id")); - - PartDB2::getEM()->remove($logo); - PartDB2::getEM()->flush(); - } - - public function getDistributorLogos () { - $this->requireParameter("id"); - $distributor = DistributorManager::getInstance()->getDistributor($this->getParameter("id")); - - $aData = array(); - - foreach ($distributor->getICLogos() as $logo) { - $aData[] = array("id" => $logo->getId()); - } - - return array("logos" => $aData); - - } - - public function getDistributor () { - $this->requireParameter("id"); - - return DistributorManager::getInstance()->getDistributor($this->getParameter("id"))->serialize(); - } - - public function saveDistributor () { - $this->requireParameter("id"); - $this->requireParameter("name"); - - $Distributor = DistributorManager::getInstance()->getDistributor($this->getParameter("id")); - - $Distributor->setName($this->getParameter("name")); - - PartDB2::getEM()->flush(); - - return $Distributor->serialize(); - } -}- \ No newline at end of file diff --git a/src/de/RaumZeitLabor/PartDB2/Footprint/Exceptions/FootprintNotFoundException.php b/src/de/RaumZeitLabor/PartDB2/Footprint/Exceptions/FootprintNotFoundException.php @@ -1,12 +0,0 @@ -<?php -namespace de\RaumZeitLabor\PartDB2\Footprint\Exceptions; - -use de\RaumZeitLabor\PartDB2\Util\SerializableException, - de\RaumZeitLabor\PartDB2\PartDB2; - -class FootprintNotFoundException extends SerializableException { - public function __construct () { - parent::__construct(PartDB2::i18n("Footprint not found.")); - } -} -?>- \ No newline at end of file diff --git a/src/de/RaumZeitLabor/PartDB2/Footprint/Footprint.php b/src/de/RaumZeitLabor/PartDB2/Footprint/Footprint.php @@ -1,32 +0,0 @@ -<?php -namespace de\RaumZeitLabor\PartDB2\Footprint; -declare(encoding = 'UTF-8'); - -/** @Entity */ - -class Footprint { - /** @Id @Column(type="integer") - * @GeneratedValue(strategy="AUTO") - */ - private $id; - - /** @Column(length=64,unique=true) */ - private $footprint; - - public function setFootprint ($footprint) { - $this->footprint = $footprint; - } - - public function getId () { - return $this->id; - } - - public function getFootprint () { - return $this->footprint; - } - - public function serialize () { - return array("id" => $this->id, "footprint" => $this->footprint); - } -} -?>- \ No newline at end of file diff --git a/src/de/RaumZeitLabor/PartDB2/Footprint/FootprintManager.php b/src/de/RaumZeitLabor/PartDB2/Footprint/FootprintManager.php @@ -1,115 +0,0 @@ -<?php -namespace de\raumzeitlabor\PartDB2\Footprint; -declare(encoding = 'UTF-8'); - -use de\RaumZeitLabor\PartDB2\Util\Singleton, - de\RaumZeitLabor\PartDB2\Util\SerializableException, - de\RaumZeitLabor\PartDB2\Footprint\Footprint, - de\RaumZeitLabor\PartDB2\PartDB2, - de\RaumZeitLabor\PartDB2\Footprint\Exceptions\FootprintNotFoundException; - -class FootprintManager extends Singleton { - public function getFootprints ($start = 0, $limit = 10, $sort = "footprint", $dir = "asc", $filter = "") { - - $qb = PartDB2::getEM()->createQueryBuilder(); - $qb->select("f.id, f.footprint")->from("de\RaumZeitLabor\PartDB2\Footprint\Footprint","f"); - - if ($filter != "") { - $qb = $qb->where("f.footprint LIKE :filter"); - $qb->setParameter("filter", "%".$filter."%"); - } - - if ($limit > -1) { - $qb->setMaxResults($limit); - $qb->setFirstResult($start); - } - - $qb->orderBy("f.".$sort, $dir); - - $query = $qb->getQuery(); - - $result = $query->getResult(); - - $totalQueryBuilder = PartDB2::getEM()->createQueryBuilder(); - $totalQueryBuilder->select("COUNT(f.id)")->from("de\RaumZeitLabor\PartDB2\Footprint\Footprint","f"); - - - - if ($filter != "") { - $totalQueryBuilder = $totalQueryBuilder->where("f.footprint LIKE :filter"); - $totalQueryBuilder->setParameter("filter", "%".$filter."%"); - } - - $totalQuery = $totalQueryBuilder->getQuery(); - - return array("data" => $result, "totalCount" => $totalQuery->getSingleScalarResult()); - } - - public function addFootprint ($footprint) { - $fp = new Footprint(); - $fp->setFootprint($footprint); - - // @todo Port the UniqueEntityValidator from Symfony2 to here. - try { - PartDB2::getEM()->persist($fp); - PartDB2::getEM()->flush(); - } catch (\PDOException $e) { - if ($e->getCode() == "23000") { - $exception = new SerializableException(sprintf(PartDB2::i18n("Footprint %s already exists!"), $footprint)); - $exception->setDetail(sprintf(PartDB2::i18n("You tried to add the footprint %s, but a footprint with the same name already exists."), $footprint)); - - throw $exception; - } else { - throw $e; - } - } - - return $fp; - } - - public function deleteFootprint ($id) { - $footprint = PartDB2::getEM()->find("de\RaumZeitLabor\PartDB2\Footprint\Footprint", $id); - - if ($footprint) { - try { - PartDB2::getEM()->remove($footprint); - PartDB2::getEM()->flush(); - } catch (\PDOException $e) { - if ($e->getCode() == "23000") { - $exception = new SerializableException(sprintf(PartDB2::i18n("Footprint %s is in use by some parts!"), $footprint->getFootprint())); - $exception->setDetail(sprintf(PartDB2::i18n("You tried to delete the footprint %s, but there are parts which use this footprint."), $footprint->getFootprint())); - - throw $exception; - } - } - - } else { - throw new FootprintNotFoundException; - } - } - - public function getOrCreateFootprint ($footprint) { - if (is_int($footprint)) { - try { - return $this->getFootprint($footprint); - } catch (FootprintNotFoundException $e) {} - } - - $fp = new Footprint(); - $fp->setFootprint($footprint); - - PartDB2::getEM()->persist($fp); - - return $fp; - } - - public function getFootprint ($id) { - $footprint = PartDB2::getEM()->find("de\RaumZeitLabor\PartDB2\Footprint\Footprint", $id); - - if ($footprint) { - return $footprint; - } else { - throw new FootprintNotFoundException; - } - } -}- \ No newline at end of file diff --git a/src/de/RaumZeitLabor/PartDB2/Footprint/FootprintService.php b/src/de/RaumZeitLabor/PartDB2/Footprint/FootprintService.php @@ -1,102 +0,0 @@ -<?php -namespace de\raumzeitlabor\PartDB2\Footprint; -declare(encoding = 'UTF-8'); - -use de\RaumZeitLabor\PartDB2\Service\Service, - de\RaumZeitLabor\PartDB2\Service\RestfulService, - de\RaumZeitLabor\PartDB2\PartDB2, - de\RaumZeitLabor\PartDB2\Footprint\FootprintManager; - -class FootprintService extends Service implements RestfulService { - public function get () { - if ($this->hasParameter("id")) { - return FootprintManager::getInstance()->getFootprint($this->getParameter("id"))->serialize(); - } else { - if ($this->hasParameter("sort")) { - $tmp = json_decode($this->getParameter("sort"), true); - - $aSortParams = $tmp[0]; - } else { - $aSortParams = array( - "property" => "footprint", - "direction" => "ASC"); - } - return FootprintManager::getInstance()->getFootprints( - $this->getParameter("start", $this->getParameter("start", 0)), - $this->getParameter("limit", $this->getParameter("limit", 25)), - $this->getParameter("sortby", $aSortParams["property"]), - $this->getParameter("dir", $aSortParams["direction"]), - $this->getParameter("query", "")); - } - } - - public function create () { - $this->requireParameter("footprint"); - - $fp = FootprintManager::getInstance()->addFootprint($this->getParameter("footprint")); - - return array("data" => $fp->serialize()); - } - - public function update () { - $this->requireParameter("id"); - $this->requireParameter("footprint"); - $footprint = FootprintManager::getInstance()->getFootprint($this->getParameter("id")); - $footprint->setFootprint($this->getParameter("footprint")); - - PartDB2::getEM()->flush(); - - return array("data" => $footprint->serialize()); - - } - - public function destroy () { - $this->requireParameter("id"); - - FootprintManager::getInstance()->deleteFootprint($this->getParameter("id")); - - return array("data" => null); - } - - /* Old stuff below */ - public function getFootprints () { - return FootprintManager::getInstance()->getFootprints( - $this->getParameter("start", 0), - $this->getParameter("limit", 10), - $this->getParameter("sortby", "footprint"), - $this->getParameter("dir", "asc"), - $this->getParameter("filter", "")); - } - - public function addFootprint () { - $this->requireParameter("footprint"); - - - } - - public function deleteFootprint () { - $this->requireParameter("id"); - - FootprintManager::getInstance()->deleteFootprint($this->getParameter("id")); - } - - public function getFootprint () { - $this->requireParameter("id"); - - return $this->get($this->getParameter("id")); - } - - public function saveFootprint () { - $this->requireParameter("id"); - $this->requireParameter("footprint"); - - $footprint = FootprintManager::getInstance()->getFootprint($this->getParameter("id")); - - $footprint->setFootprint($this->getParameter("footprint")); - - PartDB2::getEM()->flush(); - - return $footprint->serialize(); - } -} -?>- \ No newline at end of file diff --git a/src/de/RaumZeitLabor/PartDB2/Image/CachedImage.php b/src/de/RaumZeitLabor/PartDB2/Image/CachedImage.php @@ -1,78 +0,0 @@ -<?php -namespace de\RaumZeitLabor\PartDB2\Image; -declare(encoding = 'UTF-8'); - -use de\RaumZeitLabor\PartDB2\PartDB2; - -/** - * @Entity - */ -class CachedImage { - /** - * Specifies the ID of the cached image. - * - * @var integer - * @Id - * @Column(type="integer") - * @GeneratedValue(strategy="AUTO") - **/ - private $id; - - /** - * Specifies the ID of the original image - * - * @var integer - * @Column(type="integer") - */ - private $originalId; - - /** - * Specifies the type of the original image. - * - * @var string - * @Column(type="string") - **/ - private $originalType; - - /** - * The cache filename of the image - * - * @var string - * @Column(type="string") - */ - private $cacheFile; - - public function __construct (Image $image, $cacheFile) { - $this->originalId = (int)$image->getId(); - $this->originalType = $image->getType(); - $this->cacheFile = $cacheFile; - } - - public function getCacheFile () { - return $this->cacheFile; - } - - public static function invalidate (Image $image) { - $qb = PartDB2::getEM()->createQueryBuilder(); - $qb->select(array("c")) - ->from('de\RaumZeitLabor\PartDB2\Image\CachedImage', 'c') - ->where("c.originalId = :id") - ->andWhere("c.originalType = :type") - ->setParameter("id", $image->getId()) - ->setParameter("type", $image->getType()); - - $query = $qb->getQuery(); - - $bImagesRemoved = false; - - foreach ($query->getResult() as $file) { - unlink($file->getCacheFile()); - PartDB2::getEM()->remove($file); - $bImagesRemoved = true; - } - - if ($bImagesRemoved) { - PartDB2::getEM()->flush(); - } - } -}- \ No newline at end of file diff --git a/src/de/RaumZeitLabor/PartDB2/Image/Exceptions/InvalidImageTypeException.php b/src/de/RaumZeitLabor/PartDB2/Image/Exceptions/InvalidImageTypeException.php @@ -1,8 +0,0 @@ -<?php -namespace de\RaumZeitLabor\PartDB2\Image\Exceptions; - -class InvalidImageTypeException extends \Exception { - public function __construct ($type) { - parent::__construct("The image type $type is unknown."); - } -}- \ No newline at end of file diff --git a/src/de/RaumZeitLabor/PartDB2/Image/Image.php b/src/de/RaumZeitLabor/PartDB2/Image/Image.php @@ -1,241 +0,0 @@ -<?php -namespace de\RaumZeitLabor\PartDB2\Image; -declare(encoding = 'UTF-8'); - -use de\RaumZeitLabor\PartDB2\PartDB2, - de\RaumZeitLabor\PartDB2\Util\Configuration, - de\RaumZeitLabor\PartDB2\Image\Exceptions\InvalidImageTypeException; - -/** - * @MappedSuperclass - */ -abstract class Image { - /** - * Specifies the ID of the image. - * - * @var integer - * @Id - * @Column(type="integer") - * @GeneratedValue(strategy="AUTO") - **/ - protected $id; - - /** - * Specifies the type of the image. - * - * @var string - * @Column(type="string") - **/ - private $type; - - /** - * The unique filename of the image - * - * @var string - * @Column(type="string") - */ - private $filename; - - const IMAGE_ICLOGO = "iclogo"; - const IMAGE_TEMP = "temp"; - - /** - * Constructs a new image object. - * - * @param string $type The type for the image, one of the IMAGE_ constants. - */ - public function __construct ($type) { - $this->setType($type); - $this->filename = PartDB2::createGUIDv4(); - } - - /** - * Sets the type of the image. Once the type is set, - * it may not be changed later. - * - * @param string $type The type for the image, one of the IMAGE_ constants. - * @throws InvalidImageTypeException - */ - protected function setType ($type) { - switch ($type) { - case Image::IMAGE_ICLOGO: - case Image::IMAGE_TEMP: - $this->type = $type; - break; - default: - throw new InvalidImageTypeException($type); - } - } - - /** - * Replaces the current image with a new image. - * - * Automatically converts from one format to PNG, - * which is the default when dealing with images - * on the platform. - * - * @param string $path The path to the original image - */ - public function replace ($path) { - $this->ensureImagePathExists(); - - copy($path, $this->getImageFilename()); - - CachedImage::invalidate($this); - } - - /** - * Returns the full image filename including path. - * This is the image where all scale operations take place on. - * - * @param none - * @return string The full image filename including path. - */ - public function getImageFilename () { - return $this->getImagePath().$this->filename.".png"; - } - - public function getImageFilenameWithoutSuffix () { - return $this->filename; - } - - /** - * Returns the ID of the image. - * @param none - * @return integer The ID of the image - */ - public function getId () { - return $this->id; - } - - /** - * Returns the type of the image - * @param none - * @return string The type of the image - */ - public function getType () { - return $this->type; - } - - /** - * Returns the path to the image. May be overridden by - * subclasses. - * - * @param none - * @return string The path to the image - */ - public function getImagePath () { - return Configuration::getOption("partdb2.images.path").$this->getType()."/"; - } - - /** - * Ensures that the image path exists. This function - * is called every time an image is processed. - * It is maybe a bit overhead, but saves headaches later when - * introducing new types. - * - * @param none - * @return nothing - */ - public function ensureImagePathExists () { - if (!is_dir($this->getImagePath())) { - mkdir($this->getImagePath(), 0777, true); - } - } - - public function scaleTo ($w, $h) { - $this->ensureCachedirExists(); - - $outputFile = Configuration::getOption("partdb2.images.cache").md5($this->getImageFilename().$w."x".$h).".png"; - - if (file_exists($outputFile)) { - return $outputFile; - } - $image = new \Imagick(); - $image->readImage($this->getImageFilename()); - $image->adaptiveResizeImage($w, $h); - $image->writeImage($outputFile); - - $cachedImage = new CachedImage($this, $outputFile); - PartDB2::getEM()->persist($cachedImage); - - return $outputFile; - } - - public function fitWithinExact ($w, $h) { - $this->ensureCachedirExists(); - - $outputFile = Configuration::getOption("partdb2.images.cache").md5($this->getImageFilename().$w."x".$h."fwe").".png"; - - if (file_exists($outputFile)) { - return $outputFile; - } - $image = new \Imagick(); - $image->readImage($this->getImageFilename()); - - $sourceAspectRatio = $image->getImageWidth() / $image->getImageHeight(); - $targetAspectRatio = $w / $h; - - $filter = \Imagick::FILTER_UNDEFINED; - $blur = 1; - - if ($sourceAspectRatio < $targetAspectRatio) { - $image->resizeImage($w, $w / $sourceAspectRatio, $filter, $blur); - } else { - $image->resizeImage($h * $sourceAspectRatio, $h, $filter, $blur); - } - - $offsetX = intval(($image->getImageWidth() - $w)/2); - $offsetY = intval(($image->getImageHeight() - $h)/2); - - $image = $image->getImageRegion($w, $h, $offsetX, $offsetY); - - $image->writeImage($outputFile); - - $cachedImage = new CachedImage($this, $outputFile); - PartDB2::getEM()->persist($cachedImage); - - return $outputFile; - } - - public function fitWithin ($w, $h) { - $this->ensureCachedirExists(); - - $outputFile = Configuration::getOption("partdb2.images.cache").md5($this->getImageFilename().$w."x".$h."fw").".png"; - - if (file_exists($outputFile)) { - return $outputFile; - } - $image = new \Imagick(); - $image->readImage($this->getImageFilename()); - - $sourceAspectRatio = $image->getImageWidth() / $image->getImageHeight(); - $targetAspectRatio = $w / $h; - - $filter = \Imagick::FILTER_UNDEFINED; - $blur = 1; - - if ($sourceAspectRatio < $targetAspectRatio) { - $image->resizeImage($h * $sourceAspectRatio, $h, $filter, $blur); - } else { - $image->resizeImage($w, $w / $sourceAspectRatio, $filter, $blur); - } - - $image->writeImage($outputFile); - - $cachedImage = new CachedImage($this, $outputFile); - PartDB2::getEM()->persist($cachedImage); - - return $outputFile; - } - - public function ensureCachedirExists () { - if (!is_dir(Configuration::getOption("partdb2.images.cache"))) { - mkdir(Configuration::getOption("partdb2.images.cache"), 0777, true); - } - } - - public static function loadById ($id) { - return PartDB2::getEM()->find(get_called_class(), $id); - } -}- \ No newline at end of file diff --git a/src/de/RaumZeitLabor/PartDB2/Image/TempImage.php b/src/de/RaumZeitLabor/PartDB2/Image/TempImage.php @@ -1,17 +0,0 @@ -<?php -namespace de\RaumZeitLabor\PartDB2\Image; -declare(encoding = 'UTF-8'); - -use de\RaumZeitLabor\PartDB2\Image\Exceptions\InvalidImageTypeException, - de\RaumZeitLabor\PartDB2\Util\Configuration, - de\RaumZeitLabor\PartDB2\Image\Image, - de\RaumZeitLabor\PartDB2\PartDB2; - -/** - * @Entity - */ -class TempImage extends Image { - public function __construct () { - parent::__construct(Image::IMAGE_TEMP); - } -}- \ No newline at end of file diff --git a/src/de/RaumZeitLabor/PartDB2/Manufacturer/Manufacturer.php b/src/de/RaumZeitLabor/PartDB2/Manufacturer/Manufacturer.php @@ -1,138 +0,0 @@ -<?php -namespace de\RaumZeitLabor\PartDB2\Manufacturer; -declare(encoding = 'UTF-8'); - -use de\RaumZeitLabor\PartDB2\PartDB2; - -/** @Entity **/ -class Manufacturer { - - /** - * @Id @Column(type="integer") - * @GeneratedValue(strategy="AUTO") - * @var unknown_type - */ - private $id; - - /** - * @Column(type="string",unique=true) - */ - private $name; - - /** - * @Column(type="string",nullable=true) - */ - private $address; - - /** - * @Column(type="string",nullable=true) - */ - private $url; - - /** - * @Column(type="string",nullable=true) - */ - private $email; - - /** - * @Column(type="string",nullable=true) - */ - private $comment; - - /** - * @Column(type="string",nullable=true) - */ - private $phone; - - /** - * @Column(type="string",nullable=true) - */ - private $fax; - - /** - * @OneToMany(targetEntity="de\RaumZeitLabor\PartDB2\Manufacturer\ManufacturerICLogo",mappedBy="manufacturer",cascade={"persist", "remove"}) - */ - private $icLogos; - - public function __construct () { - $this->icLogos = new \Doctrine\Common\Collections\ArrayCollection(); - } - public function setName ($name) { - $this->name = $name; - } - - public function getName () { - return $this->name; - } - - public function setPhone ($phone) { - $this->phone = $phone; - } - - public function getPhone () { - return $this->phone; - } - - public function setFax ($fax) { - $this->fax = $fax; - } - - public function getFax ($fax) { - return $this->fax; - } - - public function setAddress ($address) { - $this->address = $address; - } - - public function getAddress () { - return $this->address; - } - - public function setComment ($comment) { - $this->comment = $comment; - } - - public function getComment () { - return $this->comment; - } - - public function setEmail ($email) { - $this->email = $email; - } - - public function getEmail () { - return $this->email; - } - - public function setURL ($url) { - $this->url = $url; - } - - public function getURL () { - return $this->url; - } - - public function getICLogos () { - return $this->icLogos; - } - - public function getId () { - return $this->id; - } - - public function serialize () { - return array( - "id" => $this->getId(), - "name" => $this->getName(), - "url" => $this->getURL(), - "address" => $this->getAddress(), - "email" => $this->getEmail(), - "comment" => $this->getComment() - ); - } - - public static function loadById ($id) { - return PartDB2::getEM()->find(get_called_class(), $id); - } -}- \ No newline at end of file diff --git a/src/de/RaumZeitLabor/PartDB2/Manufacturer/ManufacturerICLogo.php b/src/de/RaumZeitLabor/PartDB2/Manufacturer/ManufacturerICLogo.php @@ -1,25 +0,0 @@ -<?php -namespace de\RaumZeitLabor\PartDB2\Manufacturer; -declare(encoding = 'UTF-8'); - -use de\RaumZeitLabor\PartDB2\Image\Image; - -/** @Entity **/ -class ManufacturerICLogo extends Image { - /** - * @ManyToOne(targetEntity="de\RaumZeitLabor\PartDB2\Manufacturer\Manufacturer") - */ - private $manufacturer = null; - - public function __construct () { - parent::__construct(Image::IMAGE_ICLOGO); - } - - public function setManufacturer (Manufacturer $manufacturer) { - $this->manufacturer = $manufacturer; - } - - public function serialize () { - return array("id" => $this->id, "manufacturer_id" => $this->manufacturer->getId()); - } -}- \ No newline at end of file diff --git a/src/de/RaumZeitLabor/PartDB2/Manufacturer/ManufacturerManager.php b/src/de/RaumZeitLabor/PartDB2/Manufacturer/ManufacturerManager.php @@ -1,73 +0,0 @@ -<?php -namespace de\RaumZeitLabor\PartDB2\Manufacturer; -declare(encoding = 'UTF-8'); - -use de\RaumZeitLabor\PartDB2\Util\Singleton, - de\RaumZeitLabor\PartDB2\Manufacturer\Manufacturer, - de\RaumZeitLabor\PartDB2\PartDB2, - de\RaumZeitLabor\PartDB2\Category\CategoryManager, - de\RaumZeitLabor\PartDB2\Manufacturer\Exceptions\ManufacturerNotFoundException; - -class ManufacturerManager extends Singleton { - public function getManufacturers ($start = 0, $limit = 10, $sort = "name", $dir = "asc", $filter = "") { - - $qb = PartDB2::getEM()->createQueryBuilder(); - $qb->select("st.id, st.name, st.url, st.email, st.comment, st.address")->from("de\RaumZeitLabor\PartDB2\Manufacturer\Manufacturer","st"); - - if ($filter != "") { - $qb = $qb->where("st.name LIKE :filter"); - $qb->setParameter("filter", "%".$filter."%"); - } - - if ($limit > -1) { - $qb->setMaxResults($limit); - $qb->setFirstResult($start); - } - - $qb->orderBy("st.".$sort, $dir); - - $query = $qb->getQuery(); - - $result = $query->getResult(); - - $totalQueryBuilder = PartDB2::getEM()->createQueryBuilder(); - $totalQueryBuilder->select("COUNT(st.id)")->from("de\RaumZeitLabor\PartDB2\Manufacturer\Manufacturer","st"); - - - - if ($filter != "") { - $totalQueryBuilder = $totalQueryBuilder->where("st.name LIKE :filter"); - $totalQueryBuilder->setParameter("filter", "%".$filter."%"); - } - - $totalQuery = $totalQueryBuilder->getQuery(); - - return array("data" => $result, "totalCount" => $totalQuery->getSingleScalarResult()); - } - - public function getManufacturer ($id) { - $manufacturer = PartDB2::getEM()->find("de\RaumZeitLabor\PartDB2\Manufacturer\Manufacturer", $id); - - if ($manufacturer) { - return $manufacturer; - } else { - throw new ManufacturerNotFoundException(); - } - } - - public function addManufacturer ($name) { - $manufacturer = new Manufacturer(); - $manufacturer->setName($name); - - PartDB2::getEM()->persist($manufacturer); - PartDB2::getEM()->flush(); - - return $manufacturer; - } - public function deleteManufacturer ($id) { - $manufacturer = $this->getManufacturer($id); - - PartDB2::getEM()->remove($manufacturer); - PartDB2::getEM()->flush(); - } -}- \ No newline at end of file diff --git a/src/de/RaumZeitLabor/PartDB2/Manufacturer/ManufacturerService.php b/src/de/RaumZeitLabor/PartDB2/Manufacturer/ManufacturerService.php @@ -1,141 +0,0 @@ -<?php -namespace de\RaumZeitLabor\PartDB2\Manufacturer; -use de\RaumZeitLabor\PartDB2\Service\RestfulService; - -declare(encoding = 'UTF-8'); - -use de\RaumZeitLabor\PartDB2\Service\Service; -use de\RaumZeitLabor\PartDB2\Part\PartManager, - de\RaumZeitLabor\PartDB2\Stock\StockEntry, - de\RaumZeitLabor\PartDB2\PartDB2, - de\RaumZeitLabor\PartDB2\Session\SessionManager; - -class ManufacturerService extends Service implements RestfulService { - public function get () { - if ($this->hasParameter("id")) { - return ManufacturerManager::getInstance()->getManufacturer($this->getParameter("id"))->serialize(); - } else { - if ($this->hasParameter("sort")) { - $tmp = json_decode($this->getParameter("sort"), true); - - $aSortParams = $tmp[0]; - } else { - $aSortParams = array( - "property" => "name", - "direction" => "ASC"); - } - return ManufacturerManager::getInstance()->getManufacturers( - $this->getParameter("start", $this->getParameter("start", 0)), - $this->getParameter("limit", $this->getParameter("limit", 25)), - $this->getParameter("sortby", $aSortParams["property"]), - $this->getParameter("dir", $aSortParams["direction"]), - $this->getParameter("query", "")); - } - } - - public function create () { - $this->requireParameter("name"); - - $manufacturer = new Manufacturer; - - $this->setManufacturerData($manufacturer); - - PartDB2::getEM()->persist($manufacturer); - PartDB2::getEM()->flush(); - - return array("data" => $manufacturer->serialize()); - } - - private function setManufacturerData (Manufacturer $manufacturer) { - $manufacturer->setName($this->getParameter("name")); - $manufacturer->setComment($this->getParameter("comment", "")); - $manufacturer->setAddress($this->getParameter("address", "")); - $manufacturer->setURL($this->getParameter("url", "")); - $manufacturer->setEmail($this->getParameter("email", "")); - } - - public function update () { - $this->requireParameter("id"); - $this->requireParameter("name"); - $manufacturer = ManufacturerManager::getInstance()->getManufacturer($this->getParameter("id")); - - $this->setManufacturerData($manufacturer); - PartDB2::getEM()->flush(); - - return array("data" => $manufacturer->serialize()); - - } - - public function destroy () { - $this->requireParameter("id"); - - ManufacturerManager::getInstance()->deleteManufacturer($this->getParameter("id")); - - return array("data" => null); - } - - - // Old stuff below - public function getManufacturers() { - return ManufacturerManager::getInstance()->getManufacturers( - $this->getParameter("start", 0), - $this->getParameter("limit", 10), - $this->getParameter("sortby", "name"), - $this->getParameter("dir", "asc"), - $this->getParameter("filter", "")); - } - - public function addManufacturer () { - $this->requireParameter("name"); - - ManufacturerManager::getInstance()->addManufacturer($this->getParameter("name")); - } - - public function deleteManufacturer () { - $this->requireParameter("id"); - - ManufacturerManager::getInstance()->deleteManufacturer($this->getParameter("id")); - } - - public function deleteManufacturerLogo () { - $this->requireParameter("id"); - - $logo = ManufacturerICLogo::loadById($this->getParameter("id")); - - PartDB2::getEM()->remove($logo); - PartDB2::getEM()->flush(); - } - - public function getManufacturerLogos () { - $this->requireParameter("id"); - $manufacturer = ManufacturerManager::getInstance()->getManufacturer($this->getParameter("id")); - - $aData = array(); - - foreach ($manufacturer->getICLogos() as $logo) { - $aData[] = array("id" => $logo->getId()); - } - - return array("logos" => $aData); - - } - - public function getManufacturer () { - $this->requireParameter("id"); - - return ManufacturerManager::getInstance()->getManufacturer($this->getParameter("id"))->serialize(); - } - - public function saveManufacturer () { - $this->requireParameter("id"); - $this->requireParameter("name"); - - $Manufacturer = ManufacturerManager::getInstance()->getManufacturer($this->getParameter("id")); - - $Manufacturer->setName($this->getParameter("name")); - - PartDB2::getEM()->flush(); - - return $Manufacturer->serialize(); - } -}- \ No newline at end of file diff --git a/src/de/RaumZeitLabor/PartDB2/ManufacturerICLogo/ManufacturerICLogoManager.php b/src/de/RaumZeitLabor/PartDB2/ManufacturerICLogo/ManufacturerICLogoManager.php @@ -1,74 +0,0 @@ -<?php -namespace de\RaumZeitLabor\PartDB2\ManufacturerICLogo; -declare(encoding = 'UTF-8'); - -use de\RaumZeitLabor\PartDB2\Util\Singleton, - de\RaumZeitLabor\PartDB2\Manufacturer\Manufacturer, - de\RaumZeitLabor\PartDB2\PartDB2, - de\RaumZeitLabor\PartDB2\Manufacturer\Exceptions\ManufacturerNotFoundException; - -class ManufacturerICLogoManager extends Singleton { - public function getManufacturerICLogos ($start = 0, $limit = 10, $sort = "name", $dir = "asc", $filter = "") { - - $qb = PartDB2::getEM()->createQueryBuilder(); - $qb->select("st.id, maf.id AS manufacturer_id")->from("de\RaumZeitLabor\PartDB2\Manufacturer\ManufacturerICLogo","st") - ->leftJoin('st.manufacturer', "maf"); - - if ($filter != "") { - $manufacturer = Manufacturer::loadById($filter); - $qb = $qb->where("st.manufacturer = :manufacturer"); - $qb->setParameter("manufacturer", $manufacturer); - } - - if ($limit > -1) { - $qb->setMaxResults($limit); - $qb->setFirstResult($start); - } - - $qb->orderBy("st.".$sort, $dir); - - $query = $qb->getQuery(); - - $result = $query->getResult(); - - $totalQueryBuilder = PartDB2::getEM()->createQueryBuilder(); - $totalQueryBuilder->select("COUNT(st.id)")->from("de\RaumZeitLabor\PartDB2\Manufacturer\ManufacturerICLogo","st"); - - - - if ($filter != "") { - $totalQueryBuilder = $totalQueryBuilder->where("st.manufacturer = :manufacturer"); - $totalQueryBuilder->setParameter("manufacturer", $manufacturer); - } - - $totalQuery = $totalQueryBuilder->getQuery(); - - return array("data" => $result, "totalCount" => $totalQuery->getSingleScalarResult()); - } - - public function getManufacturerICLogo ($id) { - $manufacturer = PartDB2::getEM()->find("de\RaumZeitLabor\PartDB2\Manufacturer\ManufacturerICLogo", $id); - - if ($manufacturer) { - return $manufacturer; - } else { - throw new ManufacturerNotFoundException(); - } - } - - public function addManufacturerICLogo ($name) { - $manufacturer = new ManufacturerICLogo(); - $manufacturer->setName($name); - - PartDB2::getEM()->persist($manufacturer); - PartDB2::getEM()->flush(); - - return $manufacturer; - } - public function deleteManufacturer ($id) { - $manufacturer = $this->getManufacturer($id); - - PartDB2::getEM()->remove($manufacturer); - PartDB2::getEM()->flush(); - } -}- \ No newline at end of file diff --git a/src/de/RaumZeitLabor/PartDB2/ManufacturerICLogo/ManufacturerICLogoService.php b/src/de/RaumZeitLabor/PartDB2/ManufacturerICLogo/ManufacturerICLogoService.php @@ -1,88 +0,0 @@ -<?php -namespace de\RaumZeitLabor\PartDB2\ManufacturerICLogo; -use de\RaumZeitLabor\PartDB2\Manufacturer\ManufacturerICLogo; - -use de\RaumZeitLabor\PartDB2\Image\TempImage; - -use de\RaumZeitLabor\PartDB2\Service\RestfulService; - -declare(encoding = 'UTF-8'); - -use de\RaumZeitLabor\PartDB2\Service\Service; -use de\RaumZeitLabor\PartDB2\PartDB2, - de\RaumZeitLabor\PartDB2\Manufacturer\Manufacturer, - de\RaumZeitLabor\PartDB2\Session\SessionManager; - -class ManufacturerICLogoService extends Service implements RestfulService { - public function get () { - if ($this->hasParameter("id")) { - return ManufacturerICLogoManager::getInstance()->getManufacturerICLogo($this->getParameter("id"))->serialize(); - } else { - if ($this->hasParameter("sort")) { - $tmp = json_decode($this->getParameter("sort"), true); - - $aSortParams = $tmp[0]; - } else { - $aSortParams = array( - "property" => "id", - "direction" => "ASC"); - } - - $filter = ""; - - if ($this->hasParameter("filter")) { - $tmp = json_decode($this->getParameter("filter"), true); - - foreach ($tmp as $item) { - if (array_key_exists("property", $item)) { - if ($item["property"] == "manufacturer_id") { - if (array_key_exists("value", $item)) { - $filter = $item["value"]; - } - } - } - } - } - return ManufacturerICLogoManager::getInstance()->getManufacturerICLogos( - $this->getParameter("start", $this->getParameter("start", 0)), - $this->getParameter("limit", $this->getParameter("limit", 25)), - $this->getParameter("sortby", $aSortParams["property"]), - $this->getParameter("dir", $aSortParams["direction"]), - $filter); - } - } - - public function create () { - $this->requireParameter("tmp_id"); - $this->requireParameter("manufacturer_id"); - - $tmpImage = TempImage::loadById($this->getParameter("tmp_id")); - - $image = new ManufacturerICLogo(); - - $manufacturer = Manufacturer::loadById($this->getParameter("manufacturer_id")); - - $image->setManufacturer($manufacturer); - $image->replace($tmpImage->getImageFilename()); - PartDB2::getEM()->persist($image); - PartDB2::getEM()->flush(); - - return $image->serialize(); - } - - public function update () { - - } - - public function destroy () { - $this->requireParameter("id"); - - $logo = ManufacturerICLogo::loadById($this->getParameter("id")); - - PartDB2::getEM()->remove($logo); - PartDB2::getEM()->flush(); - - return array("data" => null); - } - -}- \ No newline at end of file diff --git a/src/de/RaumZeitLabor/PartDB2/Part/Part.php b/src/de/RaumZeitLabor/PartDB2/Part/Part.php @@ -1,224 +0,0 @@ -<?php -namespace de\RaumZeitLabor\PartDB2\Part; -declare(encoding = 'UTF-8'); - -use de\RaumZeitLabor\PartDB2\PartDB2, - de\RaumZeitLabor\PartDB2\Util\Exceptions\OutOfRangeException; - - -/** @Entity **/ -class Part { - - /** - * @Id @Column(type="integer") - * @GeneratedValue(strategy="AUTO") - * @var integer - */ - private $id; - - /** - * @ManyToOne(targetEntity="de\RaumZeitLabor\PartDB2\Category\Category") - */ - private $category; - - /** - * @Column - */ - private $name; - - /** - * @ManyToOne(targetEntity="de\RaumZeitLabor\PartDB2\Footprint\Footprint") - */ - private $footprint; - - /** - * @ManyToOne(targetEntity="de\RaumZeitLabor\PartDB2\Part\PartUnit") - */ - private $partUnit; - - /** - * @ManyToOne(targetEntity="de\RaumZeitLabor\PartDB2\StorageLocation\StorageLocation") - */ - private $storageLocation; - - /** - * @OneToMany(targetEntity="de\RaumZeitLabor\PartDB2\Part\PartManufacturer",mappedBy="part",cascade={"persist", "remove"}) - */ - private $manufacturers; - - /** - * @OneToMany(targetEntity="de\RaumZeitLabor\PartDB2\Part\PartDistributor",mappedBy="part",cascade={"persist", "remove"}) - */ - private $distributors; - - /** - * @Column(type="text") - */ - private $comment; - - /** - * The stock level. Note that this is a cached value. - * @Column(type="integer") - */ - private $stockLevel = 0; - - /** - * @Column(type="integer") - */ - private $minStockLevel; - - /** - * The average price for the part. Note that this is a cached value. - * - * @Column(type="decimal",precision=5, scale=2,nullable=true) - * @var float - */ - private $averagePrice = null; - - /** - * @OneToMany(targetEntity="de\RaumZeitLabor\PartDB2\Stock\StockEntry",mappedBy="part",cascade={"persist", "remove"}) - * @var ArrayCollection - */ - private $stockLevels; - - /** - * @OneToMany(targetEntity="de\RaumZeitLabor\PartDB2\PartParameter\PartParameter",mappedBy="part",cascade={"persist", "remove"}) - * @var ArrayCollection - */ - private $parameters; - - public function __construct () { - $this->distributors = new \Doctrine\Common\Collections\ArrayCollection(); - $this->manufacturers = new \Doctrine\Common\Collections\ArrayCollection(); - $this->parameters = new \Doctrine\Common\Collections\ArrayCollection(); - } - - public function getName () { - return $this->name; - } - - /** - * Sets the part unit - * - * @param PartUnit $partUnit The part unit object to set - * @return nothing - */ - public function setPartUnit (PartUnit $partUnit) { - $this->partUnit = $partUnit; - } - - /** - * Returns the part unit - * - * @param none - * @return PartUnit The part unit object - */ - public function getPartUnit () { - return $this->partUnit; - } - - public function setAveragePrice ($price) { - $this->averagePrice = $price; - } - - public function updateStockLevel () { - $this->stockLevel = $this->getStockLevel(); - } - - public function setMinStockLevel ($minStockLevel) { - $minStockLevel = intval($minStockLevel); - - if ($minStockLevel < 0) { - $exception = new OutOfRangeException(PartDB2::i18n("Minimum Stock Level is out of range")); - $exception->setDetail(PartDB2::i18n("The minimum stock level must be 0 or higher")); - throw $exception; - } - $this->minStockLevel = $minStockLevel; - } - - public function setCategory (\de\RaumZeitLabor\PartDB2\Category\Category $category) { - $this->category = $category; - } - - public function setStorageLocation (\de\RaumZeitLabor\PartDB2\StorageLocation\StorageLocation $storageLocation) { - $this->storageLocation = $storageLocation; - } - - public function setName ($name) { - $this->name = $name; - } - - public function setFootprint (\de\RaumZeitLabor\PartDB2\Footprint\Footprint $footprint = null) { - $this->footprint = $footprint; - } - - public function setComment ($comment) { - $this->comment = $comment; - } - - public function getDistributors () { - return $this->distributors; - } - - public function getManufacturers () { - return $this->manufacturers; - } - - /** - * Returns the parameters assigned to this part - * @return array An array of PartParameter objects - */ - public function getParameters () { - return $this->parameters; - } - - public function getStockLevel () { - $query = PartDB2::getEM()->createQuery("SELECT SUM(s.stockLevel) FROM de\RaumZeitLabor\PartDB2\Stock\StockEntry s WHERE s.part = :part"); - $query->setParameter("part", $this); - - return $query->getSingleScalarResult(); - - } - - public function getId () { - return $this->id; - } - - public function serialize () { - $aManufacturers = array(); - - foreach ($this->getManufacturers() as $manufacturer) { - $aManufacturers[] = $manufacturer->serialize(); - } - - $aDistributors = array(); - - foreach ($this->getDistributors() as $distributor) { - $aDistributors[] = $distributor->serialize(); - } - - $aParameters = array(); - foreach ($this->getParameters() as $parameter) { - $aParameters[] = $parameter->serialize(); - } - - return array( - "id" => $this->id, - "name" => $this->name, - "comment" => $this->comment, - "stockLevel" => $this->getStockLevel(), - "footprint_id" => is_object($this->footprint) ? $this->footprint->getId() : null, - "minStockLevel" => $this->minStockLevel, - "storageLocation_id" => is_object($this->storageLocation) ? $this->storageLocation->getId() : null, - "storageLocationName" => is_object($this->storageLocation) ? $this->storageLocation->getName() : null, - "category_id" => is_object($this->category) ? $this->category->getId() : null, - "partUnit_id" => is_object($this->partUnit) ? $this->getPartUnit()->getId() : null, - "partUnit_name" => is_object($this->partUnit) ? $this->getPartUnit()->getId() : PartDB2::i18n("Pieces"), - "partUnit_shortName" => is_object($this->partUnit) ? $this->getPartUnit()->getId() : "", - "manufacturers" => $aManufacturers, - "distributors" => $aDistributors, - "parameters" => $aParameters - - ); - } -}- \ No newline at end of file diff --git a/src/de/RaumZeitLabor/PartDB2/Part/PartDistributor.php b/src/de/RaumZeitLabor/PartDB2/Part/PartDistributor.php @@ -1,113 +0,0 @@ -<?php -namespace de\RaumZeitLabor\PartDB2\Part; -declare(encoding = 'UTF-8'); - -use de\RaumZeitLabor\PartDB2\PartDB2, - de\RaumZeitLabor\PartDB2\Distributor\Distributor; - -/** @Entity **/ -class PartDistributor { - /** - * @Id @Column(type="integer") - * @GeneratedValue(strategy="AUTO") - * @var unknown_type - */ - private $id; - - /** - * @ManyToOne(targetEntity="de\RaumZeitLabor\PartDB2\Part\Part") - */ - private $part; - - /** - * @ManyToOne(targetEntity="de\RaumZeitLabor\PartDB2\Distributor\Distributor") - */ - private $distributor; - - /** - * @Column(type="string",nullable=true) - * Enter description here ... - * @var unknown_type - */ - private $orderNumber; - - /** - * @Column(type="integer") - * @var integer - * - * Defines the packaging unit when ordering a part. - */ - private $packagingUnit; - - public function __construct (Part $part, Distributor $distributor) { - $this->setPart($part); - $this->setDistributor($distributor); - $this->setPackagingUnit(1); - } - - /** - * Sets the packaging unit for a specific distributor. - * - * For example, some distributors only sell resistors in packs of 100, so you can't order just one. We use the - * packagingUnit to calculate how many pieces will be delivered once ordered. So if your stock level falls below - * the minimum (example: you would need to order 10 resistors), we suggest that you only order one resistor pack - * instead of 10. - * - * @param int $packagingUnit The amount of items in one package - * @throws \de\RaumZeitLabor\PartDB2\Part\OutOfRangeException When the packaging unit is less than 1 - */ - public function setPackagingUnit ($packagingUnit) { - $packagingUnit = intval($packagingUnit); - - if ($packagingUnit < 1) { - $exception = new OutOfRangeException(PartDB2::i18n("Packaging Unit is out of range")); - $exception->setDetail(PartDB2::i18n("The packaging unit must be 1 or higher")); - throw $exception; - } - - $this->packagingUnit = $packagingUnit; - } - - public function getPackagingUnit () { - return $this->packagingUnit; - } - - public function setPart (Part $part) { - $this->part = $part; - } - - public function getPart () { - return $this->part; - } - - public function setDistributor (Distributor $distributor) { - $this->distributor = $distributor; - } - - public function getDistributor () { - return $this->distributor; - } - - public function setOrderNumber ($orderNumber) { - $this->orderNumber = $orderNumber; - } - - public function getOrderNumber () { - return $this->orderNumber; - } - - public function getId () { - return $this->id; - } - - public function serialize () { - return array( - "id" => $this->getId(), - "orderNumber" => $this->getOrderNumber(), - "distributor_id" => $this->getDistributor()->getId(), - "distributor_name" => $this->getDistributor()->getName(), - "part_id" => $this->getPart()->getId(), - "part_name" => $this->getPart()->getName(), - "packagingUnit" => $this->getPackagingUnit()); - } -}- \ No newline at end of file diff --git a/src/de/RaumZeitLabor/PartDB2/Part/PartManager.php b/src/de/RaumZeitLabor/PartDB2/Part/PartManager.php @@ -1,375 +0,0 @@ -<?php -namespace de\raumzeitlabor\PartDB2\Part; -use de\RaumZeitLabor\PartDB2\PartParameter\PartParameter; - -use de\RaumZeitLabor\PartDB2\Unit\Unit; -use de\RaumZeitLabor\PartDB2\SiPrefix\SiPrefix; - -use de\RaumZeitLabor\PartDB2\Part\PartDistributor; -use de\RaumZeitLabor\PartDB2\Part\PartManufacturer; - -use de\RaumZeitLabor\PartDB2\StorageLocation\StorageLocation; - -use de\RaumZeitLabor\PartDB2\StorageLocation\StorageLocationManager; - -use de\RaumZeitLabor\PartDB2\Part\Part; -use de\RaumZeitLabor\PartDB2\PartUnit\PartUnitManager; -use de\RaumZeitLabor\PartDB2\Distributor\Distributor; -use de\RaumZeitLabor\PartDB2\Manufacturer\Manufacturer; -use de\RaumZeitLabor\PartDB2\Footprint\FootprintManager; -use de\RaumZeitLabor\PartDB2\Session\SessionManager; -use de\RaumZeitLabor\PartDB2\Stock\StockEntry; - -declare(encoding = 'UTF-8'); - -use de\RaumZeitLabor\PartDB2\Util\Singleton, - de\RaumZeitLabor\PartDB2\Footprint\Footprint, - de\RaumZeitLabor\PartDB2\PartDB2, - de\RaumZeitLabor\PartDB2\Category\CategoryManager, - de\RaumZeitLabor\PartDB2\Manufacturer\ManufacturerManager, - de\RaumZeitLabor\PartDB2\Footprint\Exceptions\FootprintNotFoundException; - -class PartManager extends Singleton { - public function getParts ($start = 0, $limit = 10, $sort = "name", $dir = "asc", $filter = "", $category = 0, $categoryScope = "all", $stockMode = "all", $withoutPrice = false, $storageLocation = "") { - - $qb = PartDB2::getEM()->createQueryBuilder(); - $qb->select("COUNT(p.id)")->from("de\RaumZeitLabor\PartDB2\Part\Part","p") - ->join("p.storageLocation", "st") - ->leftJoin("p.footprint", "f") - ->join("p.category", "c") - ->leftJoin("p.partUnit", "pu"); - - $qb->where("1=1"); - if ($filter != "") { - $qb = $qb->where("p.name LIKE :filter"); - $qb->setParameter("filter", "%".$filter."%"); - } - - if ($storageLocation != "") { - $qb->andWhere("st.name = :storageLocation"); - $qb->setParameter("storageLocation", $storageLocation); - } - - switch ($sort) { - case "storageLocationName": - $orderBy = "st.name"; - break; - case "footprintName": - $orderBy = "f.footprint"; - break; - default; - $orderBy = "p.".$sort; - break; - } - $qb->orderBy($orderBy, $dir); - - - $category = intval($category); - - - - if ($category !== 0) { - /* Fetch all children */ - if ($categoryScope == "selected") { - $qb->andWhere("p.category = :category"); - $qb->setParameter("category", $category); - } else { - $childs = CategoryManager::getInstance()->getChildNodes($category); - $childs[] = $category; - $qb->andWhere("p.category IN (".implode(",", $childs).")"); - } - } - - switch ($stockMode) { - case "all": - break; - case "zero": - $qb->andWhere("p.stockLevel = 0"); - break; - case "nonzero": - $qb->andWhere("p.stockLevel > 0"); - break; - case "below": - $qb->andWhere("p.stockLevel < p.minStockLevel"); - break; - } - - if ($withoutPrice === true || $withoutPrice === "true") { - $qb->andWhere("p.averagePrice IS NULL"); - } - - $totalQuery = $qb->getQuery(); - - - - - $qb->select("p.averagePrice, p.name, p.id, p.stockLevel, p.minStockLevel, p.comment, st.id AS storageLocation_id, st.name as storageLocationName, f.id AS footprint_id, f.footprint AS footprintName, c.id AS category_id, c.name AS categoryName, pu.name AS partUnit, pu.is_default AS partUnitDefault"); - - if ($limit > -1) { - $qb->setMaxResults($limit); - $qb->setFirstResult($start); - } - - $query = $qb->getQuery(); - - $result = $query->getArrayResult(); - - - - return array("data" => $result, "totalCount" => $totalQuery->getSingleScalarResult()); - } - - public function addOrUpdatePart ($aParameters) { - - if (!array_key_exists("quantity", $aParameters)) { - $aParameters["quantity"] = 0; - } - - if ($aParameters["part"] !== null) { - try { - $part = $this->getPart($aParameters["part"]); - } catch (\Exception $e) { - $part = new Part(); - $user = SessionManager::getCurrentSession()->getUser(); - - $stock = new StockEntry($part, $aParameters["quantity"], $user); - PartDB2::getEM()->persist($stock); - } - } else { - $part = new Part(); - - $user = SessionManager::getCurrentSession()->getUser(); - - $stock = new StockEntry($part, $aParameters["quantity"], $user); - PartDB2::getEM()->persist($stock); - } - - if (array_key_exists("name", $aParameters)) { - $part->setName($aParameters["name"]); - } - - if (array_key_exists("minstock", $aParameters)) { - $part->setMinStockLevel($aParameters["minstock"]); - } - - if (array_key_exists("comment", $aParameters)) { - $part->setComment($aParameters["comment"]); - } - - if (array_key_exists("footprint", $aParameters)) { - - if ($aParameters["footprint"] === null) { - $part->setFootprint(null); - } else { - $footprint = FootprintManager::getInstance()->getOrCreateFootprint($aParameters["footprint"]); - $part->setFootprint($footprint); - } - } - - if (array_key_exists("storagelocation", $aParameters)) { - $storageLocation = StorageLocationManager::getInstance()->getOrCreateStorageLocation($aParameters["storagelocation"]); - $part->setStorageLocation($storageLocation); - } - - if (array_key_exists("category", $aParameters)) { - $category = CategoryManager::getInstance()->getCategory($aParameters["category"]); - $part->setCategory($category->getNode()); - } - - /* Process linked changes */ - if (array_key_exists("distributorChanges", $aParameters)) { - if (is_array($aParameters["distributorChanges"])) { - $this->processDistributorChanges($part, $aParameters["distributorChanges"]); - } - } - - if (array_key_exists("manufacturerChanges", $aParameters)) { - if (is_array($aParameters["manufacturerChanges"])) { - $this->processManufacturerChanges($part, $aParameters["manufacturerChanges"]); - } - } - - if (array_key_exists("parameterChanges", $aParameters)) { - if (is_array($aParameters["parameterChanges"])) { - $this->processParameterChanges($part, $aParameters["parameterChanges"]); - } - } - - if (array_key_exists("partUnit", $aParameters)) { - if ($aParameters["partUnit"] === null || $aParameters["partUnit"] === 0) { - $part->setPartUnit(null); - } else { - $part->setPartUnit(PartUnitManager::getInstance()->getPartUnit($aParameters["partUnit"])); - } - } - - - PartDB2::getEM()->persist($part); - PartDB2::getEM()->flush(); - - } - - private function processParameterChanges (Part $part, Array $data) { - if (array_key_exists("updates", $data)) { - foreach ($data["updates"] as $record) { - foreach ($part->getParameters() as $partParameter) { - if ($partParameter->getId() == $record["id"]) { - $partParameter->setName($record["name"]); - $partParameter->setDescription($record["description"]); - $partParameter->setValue($record["value"]); - $partParameter->setSiPrefix(SiPrefix::loadById($record["siprefix_id"])); - $partParameter->setUnit(Unit::loadById($record["unit_id"])); - break; - } - } - } - } - - if (array_key_exists("removals", $data)) { - foreach ($data["removals"] as $record) { - foreach ($part->getParameters() as $partParameter) { - if ($partParameter->getId() == $record["id"]) { - PartDB2::getEM()->remove($partParameter); - $part->getParameters()->removeElement($partParameter); - break; - } - } - } - } - - if (array_key_exists("inserts", $data)) { - foreach ($data["inserts"] as $record) { - $partParameter = new PartParameter(); - $partParameter->setPart($part); - - $partParameter->setName($record["name"]); - $partParameter->setDescription($record["description"]); - $partParameter->setValue($record["value"]); - $partParameter->setSiPrefix(SiPrefix::loadById($record["siprefix_id"])); - $partParameter->setUnit(Unit::loadById($record["unit_id"])); - - $part->getParameters()->add($partParameter); - } - } - } - - private function processDistributorChanges (Part $part, Array $data) { - if (array_key_exists("updates", $data)) { - foreach ($data["updates"] as $record) { - foreach ($part->getDistributors() as $partDistributor) { - if ($partDistributor->getId() == $record["id"]) { - $partDistributor->setOrderNumber($record["orderNumber"]); - $partDistributor->setDistributor(Distributor::loadById($record["distributor_id"])); - $partDistributor->setPackagingUnit($record["packagingUnit"]); - break; - } - } - } - } - - if (array_key_exists("removals", $data)) { - foreach ($data["removals"] as $record) { - foreach ($part->getDistributors() as $partDistributor) { - if ($partDistributor->getId() == $record["id"]) { - PartDB2::getEM()->remove($partDistributor); - $part->getDistributors()->removeElement($partDistributor); - break; - } - } - } - } - - if (array_key_exists("inserts", $data)) { - foreach ($data["inserts"] as $record) { - $distributor = new PartDistributor($part, Distributor::loadById($record["distributor_id"])); - $distributor->setOrderNumber($record["orderNumber"]); - $distributor->setPackagingUnit($record["packagingUnit"]); - - $part->getDistributors()->add($distributor); - } - } - } - - private function processManufacturerChanges (Part $part, Array $data) { - if (array_key_exists("updates", $data)) { - foreach ($data["updates"] as $record) { - foreach ($part->getManufacturers() as $partManufacturer) { - if ($partManufacturer->getId() == $record["id"]) { - $partManufacturer->setPartNumber($record["partNumber"]); - $partManufacturer->setManufacturer(Manufacturer::loadById($record["manufacturer_id"])); - break; - } - } - } - } - - if (array_key_exists("removals", $data)) { - foreach ($data["removals"] as $record) { - foreach ($part->getManufacturers() as $partManufacturer) { - if ($partManufacturer->getId() == $record["id"]) { - PartDB2::getEM()->remove($partManufacturer); - $part->getManufacturers()->removeElement($partManufacturer); - break; - } - } - } - } - - if (array_key_exists("inserts", $data)) { - foreach ($data["inserts"] as $record) { - $manufacturer = new PartManufacturer($part, Manufacturer::loadById($record["manufacturer_id"])); - $manufacturer->setPartNumber($record["partNumber"]); - - $part->getManufacturers()->add($manufacturer); - } - } - } - - public function deletePart ($id) { - $part = PartManager::getInstance()->getPart($id); - - PartDB2::getEM()->remove($part); - PartDB2::getEM()->flush(); - } - - public function getPart ($id) { - $part = PartDB2::getEM()->find("de\RaumZeitLabor\PartDB2\Part\Part", $id); - - return $part; - } - - /** - * Returns the overall part count currently existing. - * @param boolean $withPrice Only consider parts with a price - * @return int The amount of parts in the database - */ - public function getPartCount ($withPrice = false) { - $dql = "SELECT COUNT(p.id) FROM de\RaumZeitLabor\PartDB2\Part\Part p"; - - if ($withPrice === true) { - $dql .= " WHERE p.averagePrice IS NOT NULL"; - } - - return PartDB2::getEM()->createQuery($dql)->getSingleScalarResult(); - } - - /** - * Returns the total price for all parts. Only parts with a price are calculated. - * @return float The total price - */ - public function getTotalPrice () { - $dql = "SELECT SUM(p.averagePrice * p.stockLevel) FROM de\RaumZeitLabor\PartDB2\Part\Part p"; - - return PartDB2::getEM()->createQuery($dql)->getSingleScalarResult(); - } - - /** - * Returns the average price for all parts. Only parts with a price are calculated. - * @return float The average price - */ - public function getAveragePrice () { - $dql = "SELECT AVG(p.averagePrice) FROM de\RaumZeitLabor\PartDB2\Part\Part p"; - - return PartDB2::getEM()->createQuery($dql)->getSingleScalarResult(); - } -}- \ No newline at end of file diff --git a/src/de/RaumZeitLabor/PartDB2/Part/PartManufacturer.php b/src/de/RaumZeitLabor/PartDB2/Part/PartManufacturer.php @@ -1,82 +0,0 @@ -<?php -namespace de\RaumZeitLabor\PartDB2\Part; -declare(encoding = 'UTF-8'); - -use de\RaumZeitLabor\PartDB2\PartDB2, - de\RaumZeitLabor\PartDB2\Manufacturer\Manufacturer; - -/** @Entity **/ -class PartManufacturer { - /** - * @Id @Column(type="integer") - * @GeneratedValue(strategy="AUTO") - * @var unknown_type - */ - private $id; - - /** - * @ManyToOne(targetEntity="de\RaumZeitLabor\PartDB2\Part\Part") - */ - private $part; - - /** - * @ManyToOne(targetEntity="de\RaumZeitLabor\PartDB2\Manufacturer\Manufacturer") - */ - private $manufacturer; - - /** - * @Column(type="string",nullable=true) - * Enter description here ... - * @var unknown_type - */ - private $partNumber; - - public function __construct (Part $part, Manufacturer $manufacturer) { - $this->setPart($part); - $this->setManufacturer($manufacturer); - } - - public function setPart (Part $part) { - $this->part = $part; - } - - public function getPart () { - return $this->part; - } - - public function setManufacturer (Manufacturer $manufacturer) { - $this->manufacturer = $manufacturer; - } - - public function getManufacturer () { - return $this->manufacturer; - } - - public function setPartNumber ($partNumber) { - $this->partNumber = $partNumber; - } - - public function getPartNumber () { - return $this->partNumber; - } - - public function getId () { - return $this->id; - } - - /** - * Returns the data of this object in a serialized form. - * @return array The result array - */ - public function serialize () { - return array( - "id" => $this->getId(), - "partNumber" => $this->getPartNumber(), - "manufacturer_id" => $this->getManufacturer()->getId(), - "manufacturer_name" => $this->getManufacturer()->getName(), - "part_id" => $this->getPart()->getId(), - "part_name" => $this->getPart()->getName()); - } - - -}- \ No newline at end of file diff --git a/src/de/RaumZeitLabor/PartDB2/Part/PartService.php b/src/de/RaumZeitLabor/PartDB2/Part/PartService.php @@ -1,181 +0,0 @@ -<?php -namespace de\raumzeitlabor\PartDB2\Part; -use de\RaumZeitLabor\PartDB2\Service\RestfulService; - -declare(encoding = 'UTF-8'); - -use de\RaumZeitLabor\PartDB2\Service\Service; -use de\RaumZeitLabor\PartDB2\Part\PartManager, - de\RaumZeitLabor\PartDB2\Stock\StockEntry, - de\RaumZeitLabor\PartDB2\PartDB2, - de\RaumZeitLabor\PartDB2\Session\SessionManager; - -class PartService extends Service implements RestfulService { - public function get () { - if ($this->hasParameter("id")) { - return PartManager::getInstance()->getPart($this->getParameter("id"))->serialize(); - } else { - if ($this->hasParameter("sort")) { - $tmp = json_decode($this->getParameter("sort"), true); - - $aSortParams = $tmp[0]; - } else { - $aSortParams = array( - "property" => "name", - "direction" => "ASC"); - } - return PartManager::getInstance()->getParts( - $this->getParameter("start", $this->getParameter("start", 0)), - $this->getParameter("limit", $this->getParameter("limit", 25)), - $this->getParameter("sortby", $aSortParams["property"]), - $this->getParameter("dir", $aSortParams["direction"]), - $this->getParameter("query", ""), - $this->getParameter("category", 0), - $this->getParameter("categoryScope", "all"), - $this->getParameter("stockMode", "all"), - $this->getParameter("withoutPrice", false), - $this->getParameter("storageLocation", "")); - } - } - - public function create () { - throw new \Exception("Not yet implemented"); - } - - public function update () { - throw new \Exception("Not yet implemented"); - } - - public function destroy () { - throw new \Exception("Not yet implemented"); - } - - public function getPartParameterNames () { - $dql = "SELECT pp.name FROM de\RaumZeitLabor\PartDB2\PartParameter\PartParameter pp GROUP BY pp.name"; - $query = PartDB2::getEM()->createQuery($dql); - - return array("data" => $query->getArrayResult()); - } - - // Old stuff below - public function getParts () { - $aParameters = array( - "start" => $this->getParameter("start", 0), - "limit" => $this->getParameter("limit", 15), - "sort" => $this->getParameter("sort", "name"), - "dir" => $this->getParameter("dir", "asc"), - "filter" => $this->getParameter("filter", ""), - "category" => $this->getParameter("category", 0), - "stockmode" => $this->getParameter("stockmode", "all") - ); - return PartManager::getInstance()->getParts($aParameters); - } - - public function addStock () { - $part = PartManager::getInstance()->getPart($this->getParameter("part")); - - $user = SessionManager::getCurrentSession()->getUser(); - - $stock = new StockEntry($part, intval($this->getParameter("stock")), $user); - - $price = floatval($this->getParameter("price")); - - if ($price != 0) { - $stock->setPrice($price); - } - - PartDB2::getEM()->persist($stock); - PartDB2::getEM()->flush(); - - $part->updateStockLevel(); - - PartDB2::getEM()->flush(); - - return true; - } - - public function addOrUpdatePart () { - $aParameters = array(); - - $aParameters["part"] = $this->getParameter("part", null); - - if ($this->hasParameter("name")) { - $aParameters["name"] = $this->getParameter("name"); - } - - if ($this->hasParameter("minStockLevel")) { - $aParameters["minstock"] = $this->getParameter("minStockLevel"); - } - - if ($this->hasParameter("storageLocation_id")) { - $aParameters["storagelocation"] = $this->getParameter("storageLocation_id"); - } - - if ($this->hasParameter("category_id")) { - $aParameters["category"] = $this->getParameter("category_id"); - } - - if ($this->hasParameter("footprint_id")) { - $aParameters["footprint"] = $this->getParameter("footprint_id"); - } - - if ($this->hasParameter("comment")) { - $aParameters["comment"] = $this->getParameter("comment"); - } - - if ($this->hasParameter("quantity")) { - $aParameters["quantity"] = $this->getParameter("quantity"); - } - - if ($this->hasParameter("distributorChanges")) { - $aParameters["distributorChanges"] = $this->getParameter("distributorChanges"); - } - - if ($this->hasParameter("manufacturerChanges")) { - $aParameters["manufacturerChanges"] = $this->getParameter("manufacturerChanges"); - } - - if ($this->hasParameter("parameterChanges")) { - $aParameters["parameterChanges"] = $this->getParameter("parameterChanges"); - } - - if ($this->hasParameter("partUnit_id")) { - $aParameters["partUnit"] = $this->getParameter("partUnit_id"); - } - - PartManager::getInstance()->addOrUpdatePart($aParameters); - - return true; - } - - public function deleteStock () { - $part = PartManager::getInstance()->getPart($this->getParameter("part")); - - $user = SessionManager::getCurrentSession()->getUser(); - - $stock = new StockEntry($part, 0-intval($this->getParameter("stock")), $user); - - PartDB2::getEM()->persist($stock); - PartDB2::getEM()->flush(); - - $part->updateStockLevel(); - - PartDB2::getEM()->flush(); - - return true; - } - - public function getPart () { - $part = PartManager::getInstance()->getPart($this->getParameter("part")); - - return $this->serializePart($part); - } - - public function deletePart () { - PartManager::getInstance()->deletePart($this->getParameter("part")); - } - - private function serializePart ($part) { - return $part->serialize(); - } -}- \ No newline at end of file diff --git a/src/de/RaumZeitLabor/PartDB2/Part/PartUnit.php b/src/de/RaumZeitLabor/PartDB2/Part/PartUnit.php @@ -1,134 +0,0 @@ -<?php -namespace de\RaumZeitLabor\PartDB2\Part; -declare(encoding = 'UTF-8'); - -use de\RaumZeitLabor\PartDB2\PartDB2, - de\RaumZeitLabor\PartDB2\Util\Exceptions\OutOfRangeException; - - -/** @Entity **/ -class PartUnit { - /** - * @Id @Column(type="integer") - * @GeneratedValue(strategy="AUTO") - * @var int - */ - private $id; - - /** - * Defines the name of the unit - * @Column - * @var string - */ - private $name; - - /** - * Defines the short name of the unit - * @Column - * @var string - */ - private $shortName; - - /** - * Defines if the unit is default or not. - * - * @Column(type="boolean") - * @var boolean - */ - private $is_default; - - /** - * @OneToMany(targetEntity="de\RaumZeitLabor\PartDB2\Part\Part",mappedBy="partUnit") - */ - private $parts; - - - /** - * Creates a new part unit. - * - * Sets the default to false. - */ - public function __construct () { - $this->setDefault(false); - } - - /** - * Sets the name for this unit - * @param string $name The name for this unit - * @return nothing - */ - public function setName ($name) { - $this->name = $name; - } - - /** - * Returns the name for this unit - * @param none - * @return string The name for this unit - */ - public function getName () { - return $this->name; - } - - /** - * Sets the short name for this unit. - * - * Short names are used for list views (e.g. if your unit name is "metres", your short name could be "m") - * @param string $shortName The short name - * @return nothing - */ - public function setShortName ($shortName) { - $this->shortName = $shortName; - } - - /** - * Returns the short name for this unit - * @param none - * @return string The short name for this unit - */ - public function getShortName () { - return $this->shortName; - } - - /** - * Returns the ID for this object. - * @param none - * @return int The ID for this object - */ - public function getId () { - return $this->id; - } - - /** - * Defines if the unit is default or not. - * @param boolean $default True if the unit is default, false otherwise - */ - public function setDefault ($default) { - $this->is_default = (bool)$default; - } - - /** - * Returns if the unit is default or not - * @param none - * @return boolean True if the unit is default, false for not - */ - public function getDefault () { - return $this->is_default; - } - - /** - * Serializes the object and returns it as array, suitable - * to process via json_encode. - * @param none - * @return array An array containing the object information - */ - public function serialize () { - return array( - "id" => $this->getId(), - "name" => $this->getName(), - "shortName" => $this->getShortName(), - "default" => $this->getDefault() - ); - } -} - - \ No newline at end of file diff --git a/src/de/RaumZeitLabor/PartDB2/PartDB2.php b/src/de/RaumZeitLabor/PartDB2/PartDB2.php @@ -1,223 +0,0 @@ -<?php -namespace de\RaumZeitLabor\PartDB2; - -use Doctrine\Common\ClassLoader, - Doctrine\ORM\Configuration, - Doctrine\ORM\EntityManager, - de\RaumZeitLabor\PartDB2\Util\Configuration as PartDB2Configuration; - - - -class PartDB2 { - /** - * - * Contains the doctrine entity manager. - * @var Doctrine\ORM\EntityManager - */ - private static $entityManager = null; - - /** - * Initializes the PartDB2 system - * - * You *need* to call this method before doing anything else. - * - * An environment is used to load a different configuration file. - * Usually, you don't need to pass anything here. - * - * @param $environment string The environment to use, null otherwise. - * @return nothing - */ - public static function initialize ($environment = null) { - self::initializeClassLoaders(); - self::initializeConfig($environment); - self::initializeDoctrine(); - } - - /** - * Initializes the doctrine class loader and sets up the - * directories. - * - * @param none - * @return nothing - */ - public static function initializeClassLoaders() { - require_once 'Doctrine/Common/ClassLoader.php'; - - - $classLoader = new ClassLoader('de\RaumZeitLabor\PartDB2', dirname(dirname(dirname(__DIR__)))); - $classLoader->register(); // register on SPL autoload stack - - $classLoader = new ClassLoader('Doctrine\ORM'); - $classLoader->register(); // register on SPL autoload stack - - $classLoader = new ClassLoader('Doctrine\DBAL'); - $classLoader->register(); // register on SPL autoload stack - - $classLoader = new ClassLoader('Doctrine\Common'); - $classLoader->register(); // register on SPL autoload stack - - $classLoader = new ClassLoader('Symfony', 'Doctrine'); - $classLoader->register(); // register on SPL autoload stack - - $classLoader = new ClassLoader("DoctrineExtensions\NestedSet", dirname(dirname(dirname(dirname(__DIR__)))) ."/3rdparty/doctrine2-nestedset/lib"); - $classLoader->register(); - } - - - /** - * Initializes the configuration for a given environment. - * - * An environment is used to load a different configuration file. - * - * Usually, you don't need to pass anything here. - * - * - * @param $environment string The environment to use, null otherwise. - * @return nothing - */ - public static function initializeConfig ($environment = null) { - if ($environment != null) { - include(dirname(dirname(dirname(dirname(__DIR__))))."/config-$environment.php"); - } else { - include(dirname(dirname(dirname(dirname(__DIR__))))."/config.php"); - } - - } - /** - * Initializes the doctrine framework and - * sets all required configuration options. - * - * @param none - * @return nothing - */ - public static function initializeDoctrine () { - - - $config = new Configuration; - - $driverImpl = $config->newDefaultAnnotationDriver( - array(__DIR__) - //array(__DIR__."/Session") - - ); - $config->setMetadataDriverImpl($driverImpl); - - $connectionOptions = array( - 'driver' => PartDB2Configuration::getOption("partdb2.database.driver","pdo_mysql"), - 'dbname' => PartDB2Configuration::getOption("partdb2.database.dbname", "partdb2"), - 'user' => PartDB2Configuration::getOption("partdb2.database.username", "partdb2"), - 'password' => PartDB2Configuration::getOption("partdb2.database.password", "partdb2"), - 'host' => PartDB2Configuration::getOption("partdb2.database.hostname", "localhost") - ); - - $cache = new \Doctrine\Common\Cache\ApcCache(); - $config->setMetadataCacheImpl($cache); - - $config->setQueryCacheImpl($cache); - - //$logger = new \Doctrine\DBAL\Logging\EchoSQLLogger(); - //$config->setSQLLogger($logger); - - /* @todo what's up with this proxy stuff? */ - // Proxy configuration - $config->setProxyDir(dirname(dirname(dirname(__DIR__))) . '/Proxies'); - $config->setProxyNamespace('Proxies'); - $config->setEntityNamespaces(self::getEntityClasses()); - $config->setAutoGenerateProxyClasses(false); - - $logger = new \Doctrine\DBAL\Logging\EchoSQLLogger(); - //$config->setSQLLogger($logger); - - self::$entityManager = EntityManager::create($connectionOptions, $config); - } - - /** - * Returns the EntityManager. Shortcut for getEntityManager(). - * @param none - * @return Doctrine\ORM\EntityManager The EntityManager - */ - public static function getEM () { - return self::getEntityManager(); - } - - /** - * Returns the EntityManager. - * @param none - * @return Doctrine\ORM\EntityManager The EntityManager - */ - public static function getEntityManager () { - if (!self::$entityManager instanceof EntityManager) { - throw new Exception("No EntityManager found. Make sure you called initializeDoctrine() or initialize()."); - } - return self::$entityManager; - } - - public static function getClassMetaData () { - $classes = self::getEntityClasses(); - - $aClasses = array(); - - foreach ($classes as $class) { - $aClasses[] = PartDB2::getEM()->getClassMetadata($class); - } - - return $aClasses; - } - - public static function getEntityClasses () { - return array( - 'de\RaumZeitLabor\PartDB2\Auth\User', - 'de\RaumZeitLabor\PartDB2\Session\Session', - 'de\RaumZeitLabor\PartDB2\Footprint\Footprint', - 'de\RaumZeitLabor\PartDB2\Category\Category', - 'de\RaumZeitLabor\PartDB2\Part\Part', - 'de\RaumZeitLabor\PartDB2\Part\PartUnit', - 'de\RaumZeitLabor\PartDB2\Part\PartManufacturer', - 'de\RaumZeitLabor\PartDB2\Part\PartDistributor', - 'de\RaumZeitLabor\PartDB2\StorageLocation\StorageLocation', - 'de\RaumZeitLabor\PartDB2\Stock\StockEntry', - 'de\RaumZeitLabor\PartDB2\Manufacturer\Manufacturer', - 'de\RaumZeitLabor\PartDB2\Distributor\Distributor', - 'de\RaumZeitLabor\PartDB2\Image\Image', - 'de\RaumZeitLabor\PartDB2\Image\CachedImage', - 'de\RaumZeitLabor\PartDB2\Image\TempImage', - 'de\RaumZeitLabor\PartDB2\Manufacturer\ManufacturerICLogo', - 'de\RaumZeitLabor\PartDB2\Statistic\StatisticSnapshot', - 'de\RaumZeitLabor\PartDB2\Statistic\StatisticSnapshotUnit', - 'de\RaumZeitLabor\PartDB2\SiPrefix\SiPrefix', - 'de\RaumZeitLabor\PartDB2\Unit\Unit', - 'de\RaumZeitLabor\PartDB2\PartParameter\PartParameter' - ); - } - - /** - *@todo stub - */ - public static function i18n ($string) { - return $string; - } - - public static function createGUIDv4() { - return sprintf('%04x%04x-%04x-%04x-%04x-%04x%04x%04x', - - // 32 bits for "time_low" - mt_rand(0, 0xffff), mt_rand(0, 0xffff), - - // 16 bits for "time_mid" - mt_rand(0, 0xffff), - - // 16 bits for "time_hi_and_version", - // four most significant bits holds version number 4 - mt_rand(0, 0x0fff) | 0x4000, - - // 16 bits, 8 bits for "clk_seq_hi_res", - // 8 bits for "clk_seq_low", - // two most significant bits holds zero and one for variant DCE1.1 - mt_rand(0, 0x3fff) | 0x8000, - - // 48 bits for "node" - mt_rand(0, 0xffff), mt_rand(0, 0xffff), mt_rand(0, 0xffff) - ); - } -} -?>- \ No newline at end of file diff --git a/src/de/RaumZeitLabor/PartDB2/PartDistributor/PartDistributorManager.php b/src/de/RaumZeitLabor/PartDB2/PartDistributor/PartDistributorManager.php @@ -1,75 +0,0 @@ -<?php -namespace de\RaumZeitLabor\PartDB2\PartDistributor; -declare(encoding = 'UTF-8'); - -use de\RaumZeitLabor\PartDB2\Util\Singleton, - de\RaumZeitLabor\PartDB2\Manufacturer\Manufacturer, - de\RaumZeitLabor\PartDB2\PartDB2, - de\RaumZeitLabor\PartDB2\Manufacturer\Exceptions\ManufacturerNotFoundException; - -class PartDistributorManager extends Singleton { - public function getPartDistributors ($start = 0, $limit = 10, $sort = "name", $dir = "asc", $filter = "") { - - $qb = PartDB2::getEM()->createQueryBuilder(); - $qb->select("pd.orderNumber, part.id AS part_id, dist.id AS distributor_id")->from("de\RaumZeitLabor\PartDB2\Part\PartDistributor","pd") - ->leftJoin('pd.distributor', "dist") - ->leftJoin("pd.part", "part"); - - /*if ($filter != "") { - $manufacturer = Manufacturer::loadById($filter); - $qb = $qb->where("st.manufacturer = :manufacturer"); - $qb->setParameter("manufacturer", $manufacturer); - }*/ - - if ($limit > -1) { - $qb->setMaxResults($limit); - $qb->setFirstResult($start); - } - - $qb->orderBy("pd.".$sort, $dir); - - $query = $qb->getQuery(); - - $result = $query->getResult(); - - $totalQueryBuilder = PartDB2::getEM()->createQueryBuilder(); - $totalQueryBuilder->select("COUNT(pd.id)")->from("de\RaumZeitLabor\PartDB2\Part\PartDistributor","pd"); - - - /* - if ($filter != "") { - $totalQueryBuilder = $totalQueryBuilder->where("st.manufacturer = :manufacturer"); - $totalQueryBuilder->setParameter("manufacturer", $manufacturer); - }*/ - - $totalQuery = $totalQueryBuilder->getQuery(); - - return array("data" => $result, "totalCount" => $totalQuery->getSingleScalarResult()); - } - - public function getPartDistributor ($id) { - $partDistributor = PartDB2::getEM()->find("de\RaumZeitLabor\PartDB2\Part\PartDistributor", $id); - - if ($partDistributor) { - return $partDistributor; - } else { - throw new PartDistributorNotFoundException(); - } - } - - public function addPartDistributor ($orderNumber) { - $partDistributor = new PartDistributor(); - $partDistributor->setName($orderNumber); - - PartDB2::getEM()->persist($partDistributor); - PartDB2::getEM()->flush(); - - return $partDistributor; - } - public function deletePartDistributor ($id) { - $manufacturer = $this->getManufacturer($id); - - PartDB2::getEM()->remove($manufacturer); - PartDB2::getEM()->flush(); - } -}- \ No newline at end of file diff --git a/src/de/RaumZeitLabor/PartDB2/PartDistributor/PartDistributorService.php b/src/de/RaumZeitLabor/PartDB2/PartDistributor/PartDistributorService.php @@ -1,88 +0,0 @@ -<?php -namespace de\RaumZeitLabor\PartDB2\ManufacturerICLogo; -use de\RaumZeitLabor\PartDB2\Manufacturer\ManufacturerICLogo; - -use de\RaumZeitLabor\PartDB2\Image\TempImage; - -use de\RaumZeitLabor\PartDB2\Service\RestfulService; - -declare(encoding = 'UTF-8'); - -use de\RaumZeitLabor\PartDB2\Service\Service; -use de\RaumZeitLabor\PartDB2\PartDB2, - de\RaumZeitLabor\PartDB2\Manufacturer\Manufacturer, - de\RaumZeitLabor\PartDB2\Session\SessionManager; - -class PartDistributorService extends Service implements RestfulService { - public function get () { - if ($this->hasParameter("id")) { - return PartDistributorManager::getInstance()->getManufacturerICLogo($this->getParameter("id"))->serialize(); - } else { - if ($this->hasParameter("sort")) { - $tmp = json_decode($this->getParameter("sort"), true); - - $aSortParams = $tmp[0]; - } else { - $aSortParams = array( - "property" => "id", - "direction" => "ASC"); - } - - $filter = ""; - - if ($this->hasParameter("filter")) { - $tmp = json_decode($this->getParameter("filter"), true); - - foreach ($tmp as $item) { - if (array_key_exists("property", $item)) { - if ($item["property"] == "manufacturer_id") { - if (array_key_exists("value", $item)) { - $filter = $item["value"]; - } - } - } - } - } - return ManufacturerICLogoManager::getInstance()->getManufacturerICLogos( - $this->getParameter("start", $this->getParameter("start", 0)), - $this->getParameter("limit", $this->getParameter("limit", 25)), - $this->getParameter("sortby", $aSortParams["property"]), - $this->getParameter("dir", $aSortParams["direction"]), - $filter); - } - } - - public function create () { - $this->requireParameter("tmp_id"); - $this->requireParameter("manufacturer_id"); - - $tmpImage = TempImage::loadById($this->getParameter("tmp_id")); - - $image = new ManufacturerICLogo(); - - $manufacturer = Manufacturer::loadById($this->getParameter("manufacturer_id")); - - $image->setManufacturer($manufacturer); - $image->replace($tmpImage->getImageFilename()); - PartDB2::getEM()->persist($image); - PartDB2::getEM()->flush(); - - return $image->serialize(); - } - - public function update () { - - } - - public function destroy () { - $this->requireParameter("id"); - - $logo = ManufacturerICLogo::loadById($this->getParameter("id")); - - PartDB2::getEM()->remove($logo); - PartDB2::getEM()->flush(); - - return array("data" => null); - } - -}- \ No newline at end of file diff --git a/src/de/RaumZeitLabor/PartDB2/PartParameter/PartParameter.php b/src/de/RaumZeitLabor/PartDB2/PartParameter/PartParameter.php @@ -1,221 +0,0 @@ -<?php -namespace de\RaumZeitLabor\PartDB2\PartParameter; -declare(encoding = 'UTF-8'); - -use de\RaumZeitLabor\PartDB2\PartDB2, - de\RaumZeitLabor\PartDB2\Util\Exceptions\OutOfRangeException, - de\RaumZeitLabor\PartDB2\Unit\Unit, - de\RaumZeitLabor\PartDB2\Part\Part, - de\RaumZeitLabor\PartDB2\SiPrefix\SiPrefix; - - -/** - * This object represents a parameter. Each parameter can have an unit (defined by the class "Unit") associated with - * a numeric value. - * - * @Entity @HasLifecycleCallbacks - **/ -class PartParameter { - /** - * @Id @Column(type="integer") - * @GeneratedValue(strategy="AUTO") - * @var integer - */ - private $id; - - /** - * @ManyToOne(targetEntity="de\RaumZeitLabor\PartDB2\Part\Part") - * The part this parameter is bound to - * @var Part - */ - private $part; - - /** - * The name of the parameter (e.g. Resistance, Voltage) - * @Column(type="string") - * @var string - */ - private $name; - - /** - * A description for this parameter - * @Column(type="string") - * @var string - */ - private $description; - - /** - * The unit for this type. May be null. - * - * @ManyToOne(targetEntity="de\RaumZeitLabor\PartDB2\Unit\Unit") - * @var Unit - */ - private $unit; - - /** - * The value of the unit. Together with the prefix, it becomes the actual value. - * - * Example: If you have 10µ, the value field will contain "10", the prefix object is linked to the SiPrefix - * representing "µ" and the rawValue field will contain 0.000001 - * @Column(type="float") - * @var float - */ - private $value; - - /** - * The SiPrefix of the unit - * @ManyToOne(targetEntity="de\RaumZeitLabor\PartDB2\SiPrefix\SiPrefix") - * @var object - */ - private $siPrefix; - - /** - * The raw value of the unit. - * @Column(type="float") - * @var float - */ - private $rawValue; - - /** - * Sets the name for this parameter - * @param string $name The name - */ - public function setName ($name) { - $this->name = $name; - } - - /** - * Returns the name for this parameter - * @return string The name for this parameter - */ - public function getName () { - return $this->name; - } - - /** - * Sets the description for this parameter - * @param string $description The description - */ - public function setDescription ($description) { - $this->description = $description; - } - - /** - * Returns the description - * @return string The description - */ - public function getDescription () { - return $this->description; - } - - /** - * Sets the unit - * @param Unit $unit The unit to set - */ - public function setUnit (Unit $unit = null) { - $this->unit = $unit; - } - - /** - * Returns the unit - * @return Unit the unit - */ - public function getUnit () { - return $this->unit; - } - - /** - * Sets the part - * @param Part $part The part to set - */ - public function setPart (Part $part) { - $this->part = $part; - } - - /** - * Returns the part - * @return Part the part - */ - public function getPart () { - return $this->part; - } - - /** - * Sets the value - * @param float $value The value to set - */ - public function setValue ($value) { - $this->value = $value; - - $this->recalculateRawValue(); - } - - /** - * Returns the value - * @return float The value - */ - public function getValue () { - return $this->value; - } - - /** - * Sets the si prefix for this parameter - * @param SiPrefix $prefix The prefix to set, or null - */ - public function setSiPrefix (SiPrefix $prefix = null) { - $this->siPrefix = $prefix; - - $this->recalculateRawValue(); - } - - /** - * Returns the si prefix for this parameter - * @return SiPrefix the si prefix or null - */ - public function getSiPrefix () { - return $this->siPrefix; - } - - /** - * Returns the ID for this object. - * @param none - * @return int The ID for this object - */ - public function getId () { - return $this->id; - } - - private function recalculateRawValue () { - if (is_object($this->getSiPrefix())) { - $power = $this->getSiPrefix()->getPower(); - } else { - $power = 0; - } - - $this->rawValue = $this->getValue() * pow(10, $power); - } - - /** - * Returns the data of this object in a serialized form. - * @return array The result array - */ - public function serialize () { - return array( - "id" => $this->getId(), - "name" => $this->getName(), - "description" => $this->getDescription(), - "value" => $this->getValue(), - "part_id" => $this->getPart()->getId(), - "siprefix_id" => is_object($this->getSiPrefix()) ? $this->getSiPrefix()->getId() : null, - "prefixedValue" => array( - /* We duplicate most data because of strange ExtJS stuff... */ - "value" => $this->getValue(), - "power" => is_object($this->getSiPrefix()) ? $this->getSiPrefix()->getPower() : 0, - "symbol" => is_object($this->getSiPrefix()) ? $this->getSiPrefix()->getSymbol() : "", - "siprefix_id" => is_object($this->getSiPrefix()) ? $this->getSiPrefix()->getId() : null - ), - "unit_id" => is_object($this->getUnit()) ? $this->getUnit()->getId() : null - ); - } -} - - \ No newline at end of file diff --git a/src/de/RaumZeitLabor/PartDB2/PartUnit/PartUnitManager.php b/src/de/RaumZeitLabor/PartDB2/PartUnit/PartUnitManager.php @@ -1,96 +0,0 @@ -<?php -namespace de\RaumZeitLabor\PartDB2\PartUnit; -declare(encoding = 'UTF-8'); - -use de\RaumZeitLabor\PartDB2\Util\Singleton, - de\RaumZeitLabor\PartDB2\Part\PartUnit, - de\RaumZeitLabor\PartDB2\PartDB2, - de\RaumZeitLabor\PartDB2\Category\CategoryManager, - de\RaumZeitLabor\PartDB2\PartUnit\Exceptions\PartUnitNotFoundException; - -class PartUnitManager extends Singleton { - public function getPartUnits ($start = 0, $limit = 10, $sort = "name", $dir = "asc", $filter = "") { - - $qb = PartDB2::getEM()->createQueryBuilder(); - $qb->select("st.id, st.name, st.shortName, st.is_default AS default")->from("de\RaumZeitLabor\PartDB2\Part\PartUnit","st"); - - if ($filter != "") { - $qb = $qb->where("st.name LIKE :filter"); - $qb->setParameter("filter", "%".$filter."%"); - } - - if ($limit > -1) { - $qb->setMaxResults($limit); - $qb->setFirstResult($start); - } - - $qb->orderBy("st.".$sort, $dir); - - $query = $qb->getQuery(); - - $result = $query->getResult(); - - foreach ($result as $key => $row) { - foreach ($row as $rowkey => $column) { - if ($rowkey == "default") { - if ($column == 0) { - $result[$key][$rowkey] = false; - } else { - $result[$key][$rowkey] = true; - } - } - } - } - - $totalQueryBuilder = PartDB2::getEM()->createQueryBuilder(); - $totalQueryBuilder->select("COUNT(st.id)")->from("de\RaumZeitLabor\PartDB2\Part\PartUnit","st"); - - - - if ($filter != "") { - $totalQueryBuilder = $totalQueryBuilder->where("st.name LIKE :filter"); - $totalQueryBuilder->setParameter("filter", "%".$filter."%"); - } - - $totalQuery = $totalQueryBuilder->getQuery(); - - return array("data" => $result, "totalCount" => $totalQuery->getSingleScalarResult()); - } - - public function getPartUnit ($id) { - $partUnit = PartDB2::getEM()->find("de\RaumZeitLabor\PartDB2\Part\PartUnit", $id); - - if ($partUnit) { - return $partUnit; - } else { - throw new PartUnitNotFoundException(); - } - } - - public function deletePartUnit ($id) { - $partUnit = $this->getPartUnit($id); - - PartDB2::getEM()->remove($partUnit); - PartDB2::getEM()->flush(); - } - - public function setDefaultPartUnit ($id) { - PartDB2::getEM()->beginTransaction(); - - $dql = 'UPDATE de\RaumZeitLabor\PartDB2\Part\PartUnit pu SET pu.is_default = 1 WHERE pu.id = :id'; - PartDB2::getEM()->createQuery($dql)->setParameter("id", $id)->execute(); - - $dql = 'UPDATE de\RaumZeitLabor\PartDB2\Part\PartUnit pu SET pu.is_default = 0 WHERE pu.id != :id'; - PartDB2::getEM()->createQuery($dql)->setParameter("id", $id)->execute(); - - PartDB2::getEM()->commit(); - } - - public function getUnitCounts () { - $dql = 'SELECT SUM(p.stockLevel) AS stockLevel, pu FROM de\RaumZeitLabor\PartDB2\Part\PartUnit pu LEFT JOIN pu.parts p GROUP BY pu.id'; - - $result = PartDB2::getEM()->createQuery($dql)->getResult(); - - return $result; - } -}- \ No newline at end of file diff --git a/src/de/RaumZeitLabor/PartDB2/PartUnit/PartUnitService.php b/src/de/RaumZeitLabor/PartDB2/PartUnit/PartUnitService.php @@ -1,81 +0,0 @@ -<?php -namespace de\RaumZeitLabor\PartDB2\PartUnit; -use de\RaumZeitLabor\PartDB2\Service\RestfulService; - -declare(encoding = 'UTF-8'); - -use de\RaumZeitLabor\PartDB2\Service\Service; -use de\RaumZeitLabor\PartDB2\PartDB2, - de\RaumZeitLabor\PartDB2\Part\PartUnit, - de\RaumZeitLabor\PartDB2\Session\SessionManager; - -class PartUnitService extends Service implements RestfulService { - public function get () { - if ($this->hasParameter("id")) { - return PartUnitManager::getInstance()->getPartUnit($this->getParameter("id"))->serialize(); - } else { - if ($this->hasParameter("sort")) { - $tmp = json_decode($this->getParameter("sort"), true); - - $aSortParams = $tmp[0]; - } else { - $aSortParams = array( - "property" => "name", - "direction" => "ASC"); - } - return PartUnitManager::getInstance()->getPartUnits( - $this->getParameter("start", $this->getParameter("start", 0)), - $this->getParameter("limit", $this->getParameter("limit", 25)), - $this->getParameter("sortby", $aSortParams["property"]), - $this->getParameter("dir", $aSortParams["direction"]), - $this->getParameter("query", "")); - } - } - - public function create () { - $this->requireParameter("name"); - - $partUnit = new PartUnit; - - $this->setPartUnitData($partUnit); - - PartDB2::getEM()->persist($partUnit); - PartDB2::getEM()->flush(); - - return array("data" => $partUnit->serialize()); - } - - private function setPartUnitData (PartUnit $partUnit) { - $partUnit->setName($this->getParameter("name")); - $partUnit->setShortName($this->getParameter("shortName","")); - } - - public function update () { - $this->requireParameter("id"); - $this->requireParameter("name"); - - $partUnit = PartUnitManager::getInstance()->getPartUnit($this->getParameter("id")); - - $this->setPartUnitData($partUnit); - PartDB2::getEM()->flush(); - - return array("data" => $partUnit->serialize()); - - } - - public function destroy () { - $this->requireParameter("id"); - - PartUnitManager::getInstance()->deletePartUnit($this->getParameter("id")); - - return array("data" => null); - } - - public function setDefault () { - $this->requireParameter("id"); - - $partUnit = PartUnitManager::getInstance()->setDefaultPartUnit($this->getParameter("id")); - - return array("data" => null); - } -}- \ No newline at end of file diff --git a/src/de/RaumZeitLabor/PartDB2/REST/ApplicationController.php b/src/de/RaumZeitLabor/PartDB2/REST/ApplicationController.php @@ -1,42 +0,0 @@ -<?php -namespace de\RaumZeitLabor\PartDB2\REST; - -// Class taken over from the Sencha example -class ApplicationController { - public $request, $id, $params; - - /** - * dispatch - * Dispatch request to appropriate controller-action by convention according to the HTTP method. - */ - public function dispatch($request) { - $this->request = $request; - $this->id = $request->id; - $this->params = $request->params; - - if ($request->isRestful()) { - return $this->dispatchRestful(); - } - if ($request->action) { - return $this->{$request->action}(); - } - } - - protected function dispatchRestful() { - switch ($this->request->method) { - case 'GET': - return $this->view(); - break; - case 'POST': - return $this->create(); - break; - case 'PUT': - return $this->update(); - break; - case 'DELETE': - return $this->destroy(); - break; - } - } -} - diff --git a/src/de/RaumZeitLabor/PartDB2/REST/Model.php b/src/de/RaumZeitLabor/PartDB2/REST/Model.php @@ -1,71 +0,0 @@ -<?php -namespace de\RaumZeitLabor\PartDB2\REST; - -// Class taken over from the Sencha example -class Model { - public $id, $attributes; - static function create($params) { - $obj = new self(get_object_vars($params)); - $obj->save(); - return $obj; - } - static function find($id) { - global $dbh; - $found = null; - foreach ($dbh->rs() as $rec) { - if ($rec['id'] == $id) { - $found = new self($rec); - break; - } - } - return $found; - } - static function update($id, $params) { - global $dbh; - $rec = self::find($id); - - if ($rec == null) { - return $rec; - } - $rs = $dbh->rs(); - - foreach ($rs as $idx => $row) { - if ($row['id'] == $id) { - $rec->attributes = array_merge($rec->attributes, get_object_vars($params)); - $dbh->update($idx, $rec->attributes); - break; - } - } - return $rec; - } - static function destroy($id) { - global $dbh; - $rec = null; - $rs = $dbh->rs(); - foreach ($rs as $idx => $row) { - if ($row['id'] == $id) { - $rec = new self($dbh->destroy($idx)); - break; - } - } - return $rec; - } - static function all() { - global $dbh; - return $dbh->rs(); - } - - public function __construct($params) { - $this->id = isset($params['id']) ? $params['id'] : null; - $this->attributes = $params; - } - public function save() { - global $dbh; - $this->attributes['id'] = $dbh->pk(); - $dbh->insert($this->attributes); - } - public function to_hash() { - return $this->attributes; - } -} - diff --git a/src/de/RaumZeitLabor/PartDB2/REST/Request.php b/src/de/RaumZeitLabor/PartDB2/REST/Request.php @@ -1,115 +0,0 @@ -<?php -namespace de\RaumZeitLabor\PartDB2\REST; - -// Class taken over from the Sencha example -class Request { - public $restful, $method, $controller, $action, $id, $params; - - public function __construct($params) { - $this->restful = (isset($params["restful"])) ? $params["restful"] : false; - $this->method = $_SERVER["REQUEST_METHOD"]; - $this->parseRequest(); - } - public function isRestful() { - return $this->restful; - } - - public function getMethod () { - return $this->method; - } - - public function getParams () { - if ($this->params === null) { - $this->params = array(); - } - - if ($this->id !== null) { - $this->params["id"] = $this->id; - } - - $this->params = array_merge($_REQUEST, $this->params); - return $this->params; - } - - public function getService () { - if ($this->controller == "") { - $this->controller = $_REQUEST["service"]; - } - - $serviceName = $this->controller."Service"; - $namespace = 'de\RaumZeitLabor\PartDB2\\'; - $cat = $this->controller . "\\"; - $fullName= $namespace . $cat . $serviceName; - - $class = new $fullName($this->getParams()); - - return $class; - } - - public function getAction () { - return $this->action; - } - - protected function parseRequest() { - if ($this->method == 'PUT') { // <-- Have to jump through hoops to get PUT data - $raw = ''; - $httpContent = fopen('php://input', 'r'); - while ($kb = fread($httpContent, 1024)) { - $raw .= $kb; - } - fclose($httpContent); - $params = array(); - parse_str($raw, $params); - - if (isset($params['data'])) { - $this->params = json_decode($params['data'], true); - } else { - $params = json_decode($raw, true); - $this->params = $params; - } - } else { - // grab JSON data if there... - $this->params = (isset($_REQUEST['data'])) ? json_decode($_REQUEST['data'], true) : null; - - if (isset($_REQUEST['data'])) { - $this->params = json_decode($_REQUEST['data'], true); - } else { - $raw = ''; - $httpContent = fopen('php://input', 'r'); - while ($kb = fread($httpContent, 1024)) { - $raw .= $kb; - } - $params = json_decode($raw, true); - if ($params) { - $this->params = $params; - } - } - - } - // Quickndirty PATH_INFO parser - if (isset($_SERVER["PATH_INFO"])){ - $cai = '/^\/([A-Za-z]+\w)\/([A-Za-z]+\w)\/([0-9]+)$/'; // /controller/action/id - $ca = '/^\/([A-Za-z]+\w)\/([A-Za-z]+)$/'; // /controller/action - $ci = '/^\/([A-Za-z]+\w)\/([0-9]+)$/'; // /controller/id - $c = '/^\/([A-Za-z]+\w)$/'; // /controller - $i = '/^\/([0-9]+)$/'; // /id - $matches = array(); - if (preg_match($cai, $_SERVER["PATH_INFO"], $matches)) { - $this->controller = $matches[1]; - $this->action = $matches[2]; - $this->id = $matches[3]; - } else if (preg_match($ca, $_SERVER["PATH_INFO"], $matches)) { - $this->controller = $matches[1]; - $this->action = $matches[2]; - } else if (preg_match($ci, $_SERVER["PATH_INFO"], $matches)) { - $this->controller = $matches[1]; - $this->id = $matches[2]; - } else if (preg_match($c, $_SERVER["PATH_INFO"], $matches)) { - $this->controller = $matches[1]; - } else if (preg_match($i, $_SERVER["PATH_INFO"], $matches)) { - $this->id = $matches[1]; - } - } - } -} - diff --git a/src/de/RaumZeitLabor/PartDB2/REST/Response.php b/src/de/RaumZeitLabor/PartDB2/REST/Response.php @@ -1,21 +0,0 @@ -<?php -namespace de\RaumZeitLabor\PartDB2\REST; - -// Class taken over from the Sencha example -class Response { - public $success, $data, $message, $errors, $tid, $trace; - - public function __construct($params = array()) { - $this->success = isset($params["success"]) ? $params["success"] : false; - $this->message = isset($params["message"]) ? $params["message"] : ''; - $this->data = isset($params["data"]) ? $params["data"] : array(); - } - - public function to_json() { - return json_encode(array( - 'success' => $this->success, - 'message' => $this->message, - 'data' => $this->data - )); - } -} diff --git a/src/de/RaumZeitLabor/PartDB2/Service/AdminService.php b/src/de/RaumZeitLabor/PartDB2/Service/AdminService.php @@ -1,17 +0,0 @@ -<?php -namespace de\RaumZeitLabor\PartDB2\Service; -use de\RaumZeitLabor\PartDB2\Session\SessionManager; - -declare(encoding = 'UTF-8'); - -class AdminService extends Service { - public function mayCall ($call) { - if (SessionManager::getCurrentSession()->getUser()->isAdmin()) { - return true; - } else { - return false; - } - } -} - -?>- \ No newline at end of file diff --git a/src/de/RaumZeitLabor/PartDB2/Service/AnonService.php b/src/de/RaumZeitLabor/PartDB2/Service/AnonService.php @@ -1,9 +0,0 @@ -<?php -namespace de\RaumZeitLabor\PartDB2\Service; -declare(encoding = 'UTF-8'); - -class AnonService extends Service { - -} - -?>- \ No newline at end of file diff --git a/src/de/RaumZeitLabor/PartDB2/Service/Exceptions/ServiceException.php b/src/de/RaumZeitLabor/PartDB2/Service/Exceptions/ServiceException.php @@ -1,9 +0,0 @@ -<?php -namespace de\RaumZeitLabor\PartDB2\Service\Exceptions; -declare(encoding = 'UTF-8'); - -use de\RaumZeitLabor\PartDB2\Util\SerializableException; - -class ServiceException extends SerializableException {} - -?>- \ No newline at end of file diff --git a/src/de/RaumZeitLabor/PartDB2/Service/RestfulService.php b/src/de/RaumZeitLabor/PartDB2/Service/RestfulService.php @@ -1,10 +0,0 @@ -<?php -namespace de\RaumZeitLabor\PartDB2\Service; -declare(encoding = 'UTF-8'); - -interface RestfulService { - public function get (); - public function create (); - public function update (); - public function destroy (); -}- \ No newline at end of file diff --git a/src/de/RaumZeitLabor/PartDB2/Service/Service.php b/src/de/RaumZeitLabor/PartDB2/Service/Service.php @@ -1,68 +0,0 @@ -<?php -namespace de\RaumZeitLabor\PartDB2\Service; -use de\RaumZeitLabor\PartDB2\Session\Session; - -declare(encoding = 'UTF-8'); - -use de\RaumZeitLabor\PartDB2\Session\SessionManager, - de\RaumZeitLabor\PartDB2\Service\Exceptions\ServiceException; - -class Service { - private $params; - - public function __construct (Array $params) { - $this->params = $params; - } - - public function mayCall ($call) { - if (SessionManager::getCurrentSession()->getUser() === null) { - return false; - } else { - /* @todo: Implement permission checking */ - return true; - } - - - } - - protected function requireParameter ($name) { - if (!$this->hasParameter($name)) { - throw new ServiceException(sprintf("Parameter %s is required.", $name)); - } - } - - public function getParameter ($name, $default = null) { - if (!$this->hasParameter($name)) { - return $default; - } else { - return $this->params[$name]; - } - } - - public function hasParameter ($name) { - if (array_key_exists($name, $this->params)) { - return true; - } else { - return false; - } - } - - public function hasHeader ($name) { - $targetName = "HTTP_".strtoupper($name); - - return array_key_exists($targetName, $_SERVER); - } - - public function getHeader ($name) { - $targetName = "HTTP_".strtoupper($name); - - if (array_key_exists($targetName, $_SERVER)) { - return $_SERVER[$targetName]; - } else { - throw new \Exception("Header ".$targetName." not found"); - } - } -} - - -?>- \ No newline at end of file diff --git a/src/de/RaumZeitLabor/PartDB2/Service/ServiceManager.php b/src/de/RaumZeitLabor/PartDB2/Service/ServiceManager.php @@ -1,85 +0,0 @@ -<?php -namespace de\RaumZeitLabor\PartDB2\Service; -use de\RaumZeitLabor\PartDB2\Session\SessionManager; - -declare(encoding = 'UTF-8'); - -use de\RaumZeitLabor\PartDB2\Service\Exceptions\ServiceException, - de\RaumZeitLabor\PartDB2\PartDB2, - de\RaumZeitLabor\PartDB2\REST\Request; - -class ServiceManager { - - public static function call () { - - $request = new Request(array('restful' => true)); - $service = $request->getService(); - - //print_r($request->action); - - if ($service->hasHeader("call")) { - $call = $service->getHeader("call"); - } elseif (array_key_exists("call", $_REQUEST) && $_REQUEST["call"] != "") { - $call = $_REQUEST["call"]; - } elseif ($request->action != "") { - $call = $request->action; - } else { - switch (strtoupper($request->getMethod())) { - case "POST": - $call = "create"; - break; - case "GET": - $call = "get"; - break; - case "PUT": - $call = "update"; - break; - case "DELETE": - $call = "destroy"; - break; - default: - $call = $request->getMethod(); - break; - } - } - - $allowCall = true; - - if (!is_subclass_of($service, "de\\RaumZeitLabor\\PartDB2\\Service\\AnonService")) { - - $session = null; - if ($service->hasHeader("session")) { - $sessionid = $service->getHeader("session"); - } - - if (array_key_exists("session", $_REQUEST) && $session === null) { - $sessionid = $_REQUEST["session"]; - } - if ($sessionid === null) - { - $session = SessionManager::getInstance()->startSession(); - throw new ServiceException("You called a non-anonymous service, but did not pass the 'session' parameter."); - } else { - $session = SessionManager::getInstance()->resumeSession($sessionid); - } - - if (!$service->mayCall($call)) { - $allowCall = false; - } - } - - if (!$allowCall) { - throw new ServiceException("Permission denied"); - } - - $result = $service->$call(); - - PartDB2::getEM()->flush(); - - return $result; - - } - -} - -?>- \ No newline at end of file diff --git a/src/de/RaumZeitLabor/PartDB2/Session/Exceptions/SessionNotFoundException.php b/src/de/RaumZeitLabor/PartDB2/Session/Exceptions/SessionNotFoundException.php @@ -1,11 +0,0 @@ -<?php -namespace de\RaumZeitLabor\PartDB2\Session\Exceptions; -declare(encoding = 'UTF-8'); - -use de\RaumZeitLabor\PartDB2\Util\SerializableException; - -class SessionNotFoundException extends SerializableException { - public function __construct ($id) { - parent::__construct("The session with the id $id could not be found"); - } -}- \ No newline at end of file diff --git a/src/de/RaumZeitLabor/PartDB2/Session/Session.php b/src/de/RaumZeitLabor/PartDB2/Session/Session.php @@ -1,51 +0,0 @@ -<?php -namespace de\RaumZeitLabor\PartDB2\Session; -declare(encoding = 'UTF-8'); - -use de\RaumZeitLabor\PartDB2\Auth\User; - -/** @Entity */ -class Session { - - /** @Id @Column(type="integer") - * @GeneratedValue(strategy="AUTO") - */ - private $id; - - /** @Column(length=50) */ - private $sessionid; - - /** - * @ManyToOne(targetEntity="de\RaumZeitLabor\PartDB2\Auth\User") - */ - private $user; - - public function __construct () { - - } - - public function start () { - session_start(); - - $this->sessionid = session_id(); - } - - public function getSessionID () { - return $this->sessionid; - } - - public function resume () { - session_id($this->sessionid); - session_start(); - } - - public function getUser () { - return $this->user; - } - - public function setUser (User $user) { - $this->user = $user; - } - -} -?>- \ No newline at end of file diff --git a/src/de/RaumZeitLabor/PartDB2/Session/SessionManager.php b/src/de/RaumZeitLabor/PartDB2/Session/SessionManager.php @@ -1,59 +0,0 @@ -<?php -namespace de\RaumZeitLabor\PartDB2\Session; -declare(encoding = 'UTF-8'); - -use de\RaumZeitLabor\PartDB2\Util\Singleton, - de\RaumZeitLabor\PartDB2\Auth\User, - de\RaumZeitLabor\PartDB2\Session\Exceptions\SessionNotFoundException, - de\RaumZeitLabor\PartDB2\PartDB2; - -class SessionManager extends Singleton { - public static $currentSession = null; - - public static function getCurrentSession () { - return self::$currentSession; - } - - public function startSession (User $user = null) { - if (is_object($user)) { - try { - $query = PartDB2::getEM()->createQuery("SELECT s FROM de\\RaumZeitLabor\\PartDB2\\Session\\Session s WHERE s.user = :user"); - $query->setParameter("user", $user); - $query->execute(); - - $session = $query->getSingleResult(); - $session->resume(); - } catch (\Exception $e) { - $session = new Session; - $session->setUser($user); - $session->start(); - PartDB2::getEM()->persist($session); - } - } else { - $session = new Session; - $session->setUser($user); - $session->start(); - PartDB2::getEM()->persist($session); - } - - self::$currentSession = $session; - - return $session; - } - - public function resumeSession ($session) { - $query = PartDB2::getEM()->createQuery("SELECT s FROM de\\RaumZeitLabor\\PartDB2\\Session\\Session s WHERE s.sessionid = :session"); - $query->setParameter("session", $session); - $query->execute(); - try { - self::$currentSession = $query->getSingleResult(); - return self::$currentSession; - } catch (\Doctrine\ORM\NonUniqueResultException $e) { - throw new \Exception("Fatal error: Multiple sessions with id $session found."); - } catch (\Doctrine\ORM\NoResultException $e) { - throw new SessionNotFoundException($session); - } - - } -} -?>- \ No newline at end of file diff --git a/src/de/RaumZeitLabor/PartDB2/SiPrefix/SiPrefix.php b/src/de/RaumZeitLabor/PartDB2/SiPrefix/SiPrefix.php @@ -1,115 +0,0 @@ -<?php -namespace de\RaumZeitLabor\PartDB2\SiPrefix; -declare(encoding = 'UTF-8'); - -use de\RaumZeitLabor\PartDB2\PartDB2, - de\RaumZeitLabor\PartDB2\Util\Exceptions\OutOfRangeException; - - -/** @Entity **/ -class SiPrefix { - /** - * @Id @Column(type="integer") - * @GeneratedValue(strategy="AUTO") - * @var integer - */ - private $id; - - /** - * The prefix of the Si-Prefix (e.g. yotta, deca, deci, centi) - * @Column(type="string") - * @var string - */ - private $prefix; - - /** - * The symbol of the Si-Prefix (e.g. m, M, G) - * @Column(type="string",length=2) - * @var string - */ - private $symbol; - - /** - * The power of the Si-Prefix (e.g. milli = 10^-3) - * @Column(type="integer") - * @var int - */ - private $power; - - /** - * Sets the prefix name. - * @param string $prefix - */ - public function setPrefix ($prefix) { - $this->prefix = $prefix; - } - - /** - * Returns the prefix name - * @return string The prefix name - */ - public function getPrefix () { - return $this->prefix; - } - - /** - * Sets the symbol for the prefix - * @param string $symbol The symbol - */ - public function setSymbol ($symbol) { - $this->symbol = $symbol; - } - - /** - * Returns the symbol for the prefix - * @return string The symbol - */ - public function getSymbol () { - return $this->symbol; - } - - /** - * Sets the power in a 10^n power (n=power) - * @param int $power The 10^power - */ - public function setPower ($power) { - $this->power = $power; - } - - /** - * Returns the power (10^n) - * @return int The power - */ - public function getPower () { - return $this->power; - } - - /** - * Returns the ID for this object. - * @param none - * @return int The ID for this object - */ - public function getId () { - return $this->id; - } - - /** - * Serializes the object into an array format. - * @return array the object in serialized format. - */ - public function serialize () { - return array( - "id" => $this->getId(), - "symbol" => $this->getSymbol(), - "prefix" => $this->getPrefix(), - "power" => $this->getPower()); - } - - /** - * Loads a prefix by ID - * @param int $id The ID to load - */ - public static function loadById ($id) { - return PartDB2::getEM()->find(get_called_class(), $id); - } -}- \ No newline at end of file diff --git a/src/de/RaumZeitLabor/PartDB2/SiPrefix/SiPrefixService.php b/src/de/RaumZeitLabor/PartDB2/SiPrefix/SiPrefixService.php @@ -1,29 +0,0 @@ -<?php -namespace de\RaumZeitLabor\PartDB2\SiPrefix; -use de\RaumZeitLabor\PartDB2\Service\RestfulService; - -declare(encoding = 'UTF-8'); - -use de\RaumZeitLabor\PartDB2\Service\Service; -use de\RaumZeitLabor\PartDB2\PartDB2, - de\RaumZeitLabor\PartDB2\Session\SessionManager; - -class SiPrefixService extends Service implements RestfulService { - public function get () { - $query = PartDB2::getEM()->createQuery("SELECT si.id, si.prefix, si.symbol, si.power FROM de\RaumZeitLabor\PartDB2\SiPrefix\SiPrefix si"); - - return array("data" => $query->getArrayResult()); - } - - public function create () { - throw new \Exception("Not yet implemented"); - } - - public function update () { - throw new \Exception("Not yet implemented"); - } - - public function destroy () { - throw new \Exception("Not yet implemented"); - } -} diff --git a/src/de/RaumZeitLabor/PartDB2/Statistic/StatisticService.php b/src/de/RaumZeitLabor/PartDB2/Statistic/StatisticService.php @@ -1,37 +0,0 @@ -<?php -namespace de\RaumZeitLabor\PartDB2\Statistic; -declare(encoding = 'UTF-8'); - -use de\RaumZeitLabor\PartDB2\Service\Service; -use de\RaumZeitLabor\PartDB2\PartDB2, - de\RaumZeitLabor\PartDB2\Part\PartManager, - de\RaumZeitLabor\PartDB2\Category\CategoryManager, - de\RaumZeitLabor\PartDB2\PartUnit\PartUnitManager; - -class StatisticService extends Service { - public function getCurrentStats () { - - $aData = array(); - $aData["partCount"] = PartManager::getInstance()->getPartCount(); - $aData["categoryCount"] = CategoryManager::getInstance()->getCategoryCount(); - $aData["totalPrice"] = PartManager::getInstance()->getTotalPrice(); - $aData["averagePrice"] = PartManager::getInstance()->getAveragePrice(); - $aData["partsWithPrice"] = PartManager::getInstance()->getPartCount(true); - $aData["partsWithoutPrice"] = $aData["partCount"] - $aData["partsWithPrice"]; - - $result = PartUnitManager::getInstance()->getUnitCounts(); - - $aUnits = array(); - - foreach ($result as $row) { - $aUnits[] = array( - "name" => $row[0]->getName(), - "stockLevel" => $row["stockLevel"]); - } - - $aData["units"] = $aUnits; - - return $aData; - } - -}- \ No newline at end of file diff --git a/src/de/RaumZeitLabor/PartDB2/Statistic/StatisticSnapshot.php b/src/de/RaumZeitLabor/PartDB2/Statistic/StatisticSnapshot.php @@ -1,111 +0,0 @@ -<?php -namespace de\RaumZeitLabor\PartDB2\Statistic; -declare(encoding = 'UTF-8'); - -use de\RaumZeitLabor\PartDB2\PartDB2; - - -/** @Entity **/ -class StatisticSnapshot { - /** - * @Id @Column(type="integer") - * @GeneratedValue(strategy="AUTO") - * @var integer - */ - private $id; - - /** - * Defines the date when this snapshot has been taken - * @Column(type="datetime") - * @var DateTime - */ - private $dateTime; - - /** - * Defines the amount of different parts in the database - * @Column(type="integer") - * @var int - */ - private $parts; - - /** - * Defines the amount of categories - * @Column(type="integer") - * @var int - */ - private $categories; - - /** - * Holds all defined units in the database - * @OneToMany(targetEntity="de\RaumZeitLabor\PartDB2\Statistic\StatisticSnapshotUnit",mappedBy="statisticSnapshot",cascade={"persist", "remove"}) - */ - private $units; - - /** - * Creates a new statistic snapshot - */ - public function __construct () { - $this->units = new \Doctrine\Common\Collections\ArrayCollection(); - $this->setDateTime(new \DateTime()); - } - - /** - * Sets the date+time for the snapshot - * @param \DateTime $dateTime The date+time for the snapshot - */ - public function setDateTime (\DateTime $dateTime) { - $this->dateTime = $dateTime; - } - - /** - * Returns the date+time for the snapshot - * @return DateTime The date+time for the snapshot - */ - public function getDateTime () { - return $this->dateTime; - } - - /** - * Sets the amount of overall parts for the snapshot - * @param int $parts The amount of parts - */ - public function setParts ($parts) { - $this->parts = $parts; - } - - /** - * Returns the amount of overall parts for the snapshot - * @return int The amount of parts - */ - public function getParts () { - return $this->parts; - } - - /** - * Sets the amount of categories for the snapshot - * @param int $categories The amount of categories - */ - public function setCategories ($categories) { - $this->categories = $categories; - } - - /** - * Returns the amount of categories - * @return int The amount of categories - */ - public function getCategories () { - return $this->categories; - } - - /** - * Returns the ID of this snapshot - * @return int The ID of this snapshot - */ - public function getId () { - return $this->id; - } - - public function getUnits () { - return $this->units; - } -}- \ No newline at end of file diff --git a/src/de/RaumZeitLabor/PartDB2/Statistic/StatisticSnapshotManager.php b/src/de/RaumZeitLabor/PartDB2/Statistic/StatisticSnapshotManager.php @@ -1,33 +0,0 @@ -<?php -namespace de\RaumZeitLabor\PartDB2\Statistic; -declare(encoding = 'UTF-8'); - -use de\RaumZeitLabor\PartDB2\Util\Singleton, - de\RaumZeitLabor\PartDB2\Part\PartUnit, - de\RaumZeitLabor\PartDB2\Part\PartManager, - de\RaumZeitLabor\PartDB2\PartUnit\PartUnitManager, - de\RaumZeitLabor\PartDB2\PartDB2, - de\RaumZeitLabor\PartDB2\Category\CategoryManager, - de\RaumZeitLabor\PartDB2\PartUnit\Exceptions\PartUnitNotFoundException; - -class StatisticSnapshotManager extends Singleton { - public function createSnapshot () { - - $snapshot = new StatisticSnapshot(); - $snapshot->setParts(PartManager::getInstance()->getPartCount()); - $snapshot->setCategories(CategoryManager::getInstance()->getCategoryCount()); - - $result = PartUnitManager::getInstance()->getUnitCounts(); - - foreach ($result as $row) { - $snapshotUnit = new StatisticSnapshotUnit(); - $snapshotUnit->setPartUnit($row[0]); - $snapshotUnit->setStatisticSnapshot($snapshot); - $snapshotUnit->setStockLevel($row["stockLevel"]); - $snapshot->getUnits()->add($snapshotUnit); - } - - PartDB2::getEM()->persist($snapshot); - PartDB2::getEM()->flush(); - } -}- \ No newline at end of file diff --git a/src/de/RaumZeitLabor/PartDB2/Statistic/StatisticSnapshotUnit.php b/src/de/RaumZeitLabor/PartDB2/Statistic/StatisticSnapshotUnit.php @@ -1,98 +0,0 @@ -<?php -namespace de\RaumZeitLabor\PartDB2\Statistic; - -use de\RaumZeitLabor\PartDB2\Statistic\StatisticSnapshot; -use de\RaumZeitLabor\PartDB2\Part\PartUnit; - -declare(encoding = 'UTF-8'); - -use de\RaumZeitLabor\PartDB2\PartDB2; - - -/** @Entity **/ -class StatisticSnapshotUnit { - /** - * @Id @Column(type="integer") - * @GeneratedValue(strategy="AUTO") - * @var integer - */ - private $id; - - /** - * @ManyToOne(targetEntity="de\RaumZeitLabor\PartDB2\Statistic\StatisticSnapshot") - * The statistic snapshot this entity belongs to - * @var StatisticSnapshot - */ - private $statisticSnapshot; - - /** - * @ManyToOne(targetEntity="de\RaumZeitLabor\PartDB2\Part\PartUnit") - * The statistic snapshot this entity belongs to - * @var StatisticSnapshot - */ - private $partUnit; - - /** - * The stockLevel for the unit - * @Column(type="integer") - * @var int - */ - private $stockLevel; - - /** - * Sets the statistic snapshot this entity belongs to - * @param StatisticSnapshot $snapshot The snapshot - */ - public function setStatisticSnapshot (StatisticSnapshot $snapshot) { - $this->statisticSnapshot = $snapshot; - } - - /** - * Returns the snapshot this entity belongs to - * @return StatisticSnapshot The snapshot - */ - public function getStatisticSnapshot () { - return $this->statisticSnapshot; - } - - /** - * - * Sets the part unit for this entity - * @param PartUnit $unit The part unit - */ - public function setPartUnit (PartUnit $unit) { - $this->partUnit = $unit; - } - - /** - * Returns the part unit for this entity - * @return PartUnit The part unit - */ - public function getPartUnit () { - return $this->partUnit; - } - - /** - * Returns the ID of this statistic snapshot unit - * @return int The ID - */ - public function getId () { - return $this->id; - } - - /** - * Sets the stock level for this unit snapshot - * @param int $stockLevel - */ - public function setStockLevel ($stockLevel) { - $this->stockLevel = $stockLevel; - } - - /** - * Returns the stock level for this unit snapshot - * @return int The stock level - */ - public function getStockLevel () { - return $this->stockLevel; - } -}- \ No newline at end of file diff --git a/src/de/RaumZeitLabor/PartDB2/Stock/StockEntry.php b/src/de/RaumZeitLabor/PartDB2/Stock/StockEntry.php @@ -1,192 +0,0 @@ -<?php -namespace de\RaumZeitLabor\PartDB2\Stock; -declare(encoding = 'UTF-8'); - -use de\RaumZeitLabor\PartDB2\Part\Part; -use de\RaumZeitLabor\PartDB2\Auth\User; -use de\RaumZeitLabor\PartDB2\PartDB2; - -/** @Entity @HasLifecycleCallbacks **/ -class StockEntry { - - /** - * @Id @Column(type="integer") - * @GeneratedValue(strategy="AUTO") - * @var unknown_type - */ - private $id; - - /** - * @Column(type="integer") - */ - private $stockLevel; - - /** - * @ManyToOne(targetEntity="de\RaumZeitLabor\PartDB2\Part\Part") - */ - private $part; - - /** - * @ManyToOne(targetEntity="de\RaumZeitLabor\PartDB2\Auth\User") - */ - private $user; - - /** - * @Column(type="decimal",precision=5, scale=2,nullable=true) - * @var float - */ - private $price; - - /** - * @Column(type="datetime") - * @var DateTime - */ - private $dateTime; - - /** - * Creates a new stock entry. A stock entry tracks how many parts - * were the stockLevel is the amount of items added/removed, - * by which user and how much the user paid for it (for adding parts only!) - * - * @param Part $part The part which was added/removed - * @param int $stockLevel The stock level. Positive value means added parts, negative values means removed parts. - * @param User $user The user who removed/added parts - */ - public function __construct (Part $part, $stockLevel, User $user = null) { - $this->setPart($part); - $this->setStockLevel($stockLevel); - $this->setUser($user); - $this->setDateTime(new \DateTime()); - } - - - /** - * Sets the date+time - * @param \DateTime $dateTime The date+time - */ - private function setDateTime (\DateTime $dateTime) { - $this->dateTime = $dateTime; - } - - /** - * Returns the date+time when the record was created. - * @return \DateTime The date+time when the record was created - */ - public function getDateTime () { - return $this->dateTime; - } - - /** - * Sets the price for the item stored. - * - * Please note that the price is for a single item only, and can be null. - * @param float $price The price to set - */ - public function setPrice ($price) { - $this->price = $price; - } - - /** - * Returns the price for this entry. The price is for a single item only. - * - * @return float The price for this entry. - */ - public function getPrice () { - return $this->price; - } - - /** - * Sets the stock level for this entry. - * - * Negative values means part removal, positive values means part adding. - * @param int $stockLevel The stock level - */ - public function setStockLevel($stockLevel) { - $this->stockLevel = $stockLevel; - } - - /** - * Returns the stock level for this entry. - * @return int The stock level - */ - public function getStockLevel () { - return $this->stockLevel; - } - - /** - * Sets the part assigned to this entry. - * @param Part $part The part to set - */ - public function setPart (Part $part) { - $this->part = $part; - } - - /** - * Sets the user assigned to this entry. - * @param User $user The user The user to set - */ - public function setUser (User $user = null) { - $this->user = $user; - } - - /** - * Returns the user for this entry - * @return User the user - */ - public function getUser () { - return $this->user; - } - - /** - * Returns the ID for this entity. - * @return int The ID - */ - public function getId () { - return $this->id; - } - - /** - * If the stock level is negative, we can't have a price. - * @PrePersist - */ - public function checkPrice () { - if ($this->getStockLevel() < 0 && $this->getPrice() !== null) { - $this->setPrice(null); - } - } - - /** - * Updates the stock leve for a part - * @PostPersist - */ - public function postPersist () { - $this->updateStockLevel(); - $this->updatePrice(); - } - - - public function updateStockLevel () { - $query = PartDB2::getEM()->createQuery("SELECT SUM(se.stockLevel) FROM de\RaumZeitLabor\PartDB2\Stock\StockEntry se WHERE se.part = :part"); - $query->setParameter("part", $this->part); - $val = $query->getSingleScalarResult(); - - $query = PartDB2::getEM()->createQuery('UPDATE de\RaumZeitLabor\PartDB2\Part\Part p SET p.stockLevel = :val WHERE p = :part'); - $query->setParameter("val", $val); - $query->setParameter("part", $this->part); - $query->execute(); - } - - /** - * Updates the average price for a part - */ - public function updatePrice () { - $query = PartDB2::getEM()->createQuery("SELECT SUM(se.price*se.stockLevel) / SUM(se.stockLevel) FROM de\RaumZeitLabor\PartDB2\Stock\StockEntry se WHERE se.part = :part AND se.stockLevel > 0"); - $query->setParameter("part", $this->part); - $val = $query->getSingleScalarResult(); - - $query = PartDB2::getEM()->createQuery('UPDATE de\RaumZeitLabor\PartDB2\Part\Part p SET p.averagePrice = :val WHERE p = :part'); - $query->setParameter("val", $val); - $query->setParameter("part", $this->part); - $query->execute(); - } -}- \ No newline at end of file diff --git a/src/de/RaumZeitLabor/PartDB2/Stock/StockService.php b/src/de/RaumZeitLabor/PartDB2/Stock/StockService.php @@ -1,51 +0,0 @@ -<?php -namespace de\raumzeitlabor\PartDB2\Stock; - -declare(encoding = 'UTF-8'); - -use de\RaumZeitLabor\PartDB2\Stock\StockEntry, - de\RaumZeitLabor\PartDB2\PartDB2, - de\RaumZeitLabor\PartDB2\Service\RestfulService, - de\RaumZeitLabor\PartDB2\Service\Service;; - - -class StockService extends Service implements RestfulService { - public function get () { - $qb = PartDB2::getEM()->createQueryBuilder(); - - $qb->select("se")->from("de\RaumZeitLabor\PartDB2\Stock\StockEntry","se") - ->where("se.part = :part") - ->orderBy("se.dateTime", "DESC") - ->setParameter("part", $this->getParameter("item")); - - $results = $qb->getQuery()->getResult(); - - $aData = array(); - - foreach ($results as $result) { - $aData[] = array( - "username" => is_object($result->getUser()) ? $result->getUser()->getUsername() : PartDB2::i18n("Unknown User"), - "amount" => abs($result->getStockLevel()), - "datetime" => $result->getDateTime()->format("Y-m-d H:i:s"), - "id" => $result->getId(), - "direction" => ($result->getStockLevel() < 0) ? "out" : "in", - "price" => $result->getPrice() - ); - } - - - return array("data" => $aData); - } - - public function create () { - throw new \Exception("Not yet implemented"); - } - - public function update () { - throw new \Exception("Not yet implemented"); - } - - public function destroy () { - throw new \Exception("Not yet implemented"); - } -}- \ No newline at end of file diff --git a/src/de/RaumZeitLabor/PartDB2/StorageLocation/Exceptions/StorageLocationNotFoundException.php b/src/de/RaumZeitLabor/PartDB2/StorageLocation/Exceptions/StorageLocationNotFoundException.php @@ -1,12 +0,0 @@ -<?php -namespace de\RaumZeitLabor\PartDB2\StorageLocation\Exceptions; - -use de\RaumZeitLabor\PartDB2\Util\SerializableException, - de\RaumZeitLabor\PartDB2\PartDB2; - -class StorageLocationNotFoundException extends SerializableException { - public function __construct () { - parent::__construct(PartDB2::i18n("Storage Location not found.")); - } -} -?>- \ No newline at end of file diff --git a/src/de/RaumZeitLabor/PartDB2/StorageLocation/StorageLocation.php b/src/de/RaumZeitLabor/PartDB2/StorageLocation/StorageLocation.php @@ -1,34 +0,0 @@ -<?php -namespace de\RaumZeitLabor\PartDB2\StorageLocation; -declare(encoding = 'UTF-8'); - -/** @Entity **/ -class StorageLocation { - - /** - * @Id @Column(type="integer") - * @GeneratedValue(strategy="AUTO") - * @var unknown_type - */ - private $id; - - /** - * @Column(type="string",unique=true) - */ - private $name; - - public function setName ($name) { - $this->name = $name; - } - - public function getName () { - return $this->name; - } - public function getId () { - return $this->id; - } - - public function serialize () { - return array("id" => $this->id, "name" => $this->name); - } -}- \ No newline at end of file diff --git a/src/de/RaumZeitLabor/PartDB2/StorageLocation/StorageLocationManager.php b/src/de/RaumZeitLabor/PartDB2/StorageLocation/StorageLocationManager.php @@ -1,88 +0,0 @@ -<?php -namespace de\RaumZeitLabor\PartDB2\StorageLocation; -declare(encoding = 'UTF-8'); - -use de\RaumZeitLabor\PartDB2\Util\Singleton, - de\RaumZeitLabor\PartDB2\StorageLocation\StorageLocation, - de\RaumZeitLabor\PartDB2\PartDB2, - de\RaumZeitLabor\PartDB2\Category\CategoryManager, - de\RaumZeitLabor\PartDB2\StorageLocation\Exceptions\StorageLocationNotFoundException; - -class StorageLocationManager extends Singleton { - public function getStorageLocations ($start = 0, $limit = 10, $sort = "footprint", $dir = "asc", $filter = "") { - - $qb = PartDB2::getEM()->createQueryBuilder(); - $qb->select("st.id, st.name")->from("de\RaumZeitLabor\PartDB2\StorageLocation\StorageLocation","st"); - - if ($filter != "") { - $qb = $qb->where("st.name LIKE :filter"); - $qb->setParameter("filter", "%".$filter."%"); - } - - if ($limit > -1) { - $qb->setMaxResults($limit); - $qb->setFirstResult($start); - } - - $qb->orderBy("st.".$sort, $dir); - - $query = $qb->getQuery(); - - $result = $query->getResult(); - - $totalQueryBuilder = PartDB2::getEM()->createQueryBuilder(); - $totalQueryBuilder->select("COUNT(st.id)")->from("de\RaumZeitLabor\PartDB2\StorageLocation\StorageLocation","st"); - - - - if ($filter != "") { - $totalQueryBuilder = $totalQueryBuilder->where("st.name LIKE :filter"); - $totalQueryBuilder->setParameter("filter", "%".$filter."%"); - } - - $totalQuery = $totalQueryBuilder->getQuery(); - - return array("data" => $result, "start" => $start, "totalCount" => $totalQuery->getSingleScalarResult()); - } - - public function getStorageLocation ($id) { - $storageLocation = PartDB2::getEM()->find("de\RaumZeitLabor\PartDB2\StorageLocation\StorageLocation", $id); - - if ($storageLocation) { - return $storageLocation; - } else { - throw new StorageLocationNotFoundException(); - } - } - - public function addStorageLocation ($name) { - $storageLocation = new StorageLocation(); - $storageLocation->setName($name); - - PartDB2::getEM()->persist($storageLocation); - PartDB2::getEM()->flush(); - - return $storageLocation; - } - public function deleteStorageLocation ($id) { - $storageLocation = $this->getStorageLocation($id); - - PartDB2::getEM()->remove($storageLocation); - PartDB2::getEM()->flush(); - } - - public function getOrCreateStorageLocation ($storageLocation) { - if (is_int($storageLocation)) { - try { - return $this->getStorageLocation($storageLocation); - } catch (StorageLocationNotFoundException $e) {} - } - - $sl = new StorageLocation(); - $sl->setName($storageLocation); - - PartDB2::getEM()->persist($sl); - - return $sl; - } -}- \ No newline at end of file diff --git a/src/de/RaumZeitLabor/PartDB2/StorageLocation/StorageLocationService.php b/src/de/RaumZeitLabor/PartDB2/StorageLocation/StorageLocationService.php @@ -1,105 +0,0 @@ -<?php -namespace de\RaumZeitLabor\PartDB2\StorageLocation; -use de\RaumZeitLabor\PartDB2\Service\RestfulService; - -declare(encoding = 'UTF-8'); - -use de\RaumZeitLabor\PartDB2\Service\Service; -use de\RaumZeitLabor\PartDB2\Part\PartManager, - de\RaumZeitLabor\PartDB2\Stock\StockEntry, - de\RaumZeitLabor\PartDB2\PartDB2, - de\RaumZeitLabor\PartDB2\Session\SessionManager; - -class StorageLocationService extends Service implements RestfulService { - - public function get () { - if ($this->hasParameter("id")) { - return StorageLocationManager::getInstance()->getStorageLocation($this->getParameter("id"))->serialize(); - } else { - if ($this->hasParameter("sort")) { - $tmp = json_decode($this->getParameter("sort"), true); - - $aSortParams = $tmp[0]; - } else { - $aSortParams = array( - "property" => "name", - "direction" => "ASC"); - } - return StorageLocationManager::getInstance()->getStorageLocations( - $this->getParameter("start", $this->getParameter("start", 0)), - $this->getParameter("limit", $this->getParameter("limit", 25)), - $this->getParameter("sortby", $aSortParams["property"]), - $this->getParameter("dir", $aSortParams["direction"]), - $this->getParameter("query", "")); - } - } - - public function create () { - $this->requireParameter("name"); - - $sl = StorageLocationManager::getInstance()->addStorageLocation($this->getParameter("name")); - - return array("data" => $sl->serialize()); - } - - public function update () { - $this->requireParameter("id"); - $this->requireParameter("name"); - $storageLocation = StorageLocationManager::getInstance()->getStorageLocation($this->getParameter("id")); - $storageLocation->setName($this->getParameter("name")); - - PartDB2::getEM()->flush(); - - return array("data" => $storageLocation->serialize()); - - } - - public function destroy () { - $this->requireParameter("id"); - - StorageLocationManager::getInstance()->deleteStorageLocation($this->getParameter("id")); - - return array("data" => null); - } - - // Old Stuff below - public function getStorageLocations() { - return StorageLocationManager::getInstance()->getStorageLocations( - $this->getParameter("start", 0), - $this->getParameter("limit", 10), - $this->getParameter("sortby", "name"), - $this->getParameter("dir", "asc"), - $this->getParameter("filter", "")); - } - - public function addStorageLocation () { - $this->requireParameter("name"); - - StorageLocationManager::getInstance()->addStorageLocation($this->getParameter("name")); - } - - public function deleteStorageLocation () { - $this->requireParameter("id"); - - StorageLocationManager::getInstance()->deleteStorageLocation($this->getParameter("id")); - } - - public function getStorageLocation () { - $this->requireParameter("id"); - - return StorageLocationManager::getInstance()->getStorageLocation($this->getParameter("id"))->serialize(); - } - - public function saveStorageLocation () { - $this->requireParameter("id"); - $this->requireParameter("name"); - - $storageLocation = StorageLocationManager::getInstance()->getStorageLocation($this->getParameter("id")); - - $storageLocation->setName($this->getParameter("name")); - - PartDB2::getEM()->flush(); - - return $storageLocation->serialize(); - } -}- \ No newline at end of file diff --git a/src/de/RaumZeitLabor/PartDB2/TempImage/TempImageService.php b/src/de/RaumZeitLabor/PartDB2/TempImage/TempImageService.php @@ -1,22 +0,0 @@ -<?php -namespace de\RaumZeitLabor\PartDB2\TempImage; - -use de\RaumZeitLabor\PartDB2\Service\Service; -use de\RaumZeitLabor\PartDB2\Image\TempImage; -use de\RaumZeitLabor\PartDB2\PartDB2; - -class TempImageService extends Service { - - public function upload () { - $image = new TempImage(); - - $file = $_FILES['userfile']['tmp_name']; - - $image->replace($file); - PartDB2::getEM()->persist($image); - PartDB2::getEM()->flush(); - - return array("id" => $image->getId()); - } -} - - \ No newline at end of file diff --git a/src/de/RaumZeitLabor/PartDB2/Unit/Unit.php b/src/de/RaumZeitLabor/PartDB2/Unit/Unit.php @@ -1,111 +0,0 @@ -<?php -namespace de\RaumZeitLabor\PartDB2\Unit; -declare(encoding = 'UTF-8'); - -use de\RaumZeitLabor\PartDB2\PartDB2, - de\RaumZeitLabor\PartDB2\Util\Exceptions\OutOfRangeException, - de\RaumZeitLabor\PartDB2\SiPrefix\SiPrefix; - - -/** - * This object represents an unit. Units can be: Volt, Hertz etc. - * - * @Entity - **/ -class Unit { - /** - * @Id @Column(type="integer") - * @GeneratedValue(strategy="AUTO") - * @var integer - */ - private $id; - - /** - * The name of the unit (e.g. Volts, Ampere, Farad, Metres) - * @Column(type="string") - * @var string - */ - private $name; - - /** - * The symbol of the unit (e.g. V, A, F, m) - * @Column(type="string") - * @var string - */ - private $symbol; - - /** - * Defines the allowed SiPrefixes for this parameter unit - * @ManyToMany(targetEntity="de\RaumZeitLabor\PartDB2\SiPrefix\SiPrefix") - * @JoinTable(name="UnitSiPrefixes", - * joinColumns={@JoinColumn(name="unit_id", referencedColumnName="id")}, - * inverseJoinColumns={@JoinColumn(name="siprefix_id", referencedColumnName="id")} - * ) - * @var ArrayCollection - */ - private $prefixes; - - /** - * Creates a new Unit. - */ - public function __construct () { - $this->prefixes = new \Doctrine\Common\Collections\ArrayCollection(); - } - - /** - * Sets the name for this unit - * @param string $name the name for this unit - */ - public function setName ($name) { - $this->name = $name; - } - - /** - * Returns the name for this unit - * @return string The unit name - */ - public function getName () { - return $this->name; - } - - /** - * Sets the symbol for this unit - * @param string $symbol The symbol - */ - public function setSymbol ($symbol) { - $this->symbol = $symbol; - } - - /** - * Returns the symbol for this unit - * @return string The symbol - */ - public function getSymbol () { - return $this->symbol; - } - - /** - * Returns the si-prefix list for this unit - * @return array An array of SiPrefix objects - */ - public function getPrefixes () { - return $this->prefixes; - } - - /** - * Returns the ID for this object. - * @param none - * @return int The ID for this object - */ - public function getId () { - return $this->id; - } - - /** - * Loads a unit by ID - * @param int $id The ID to load - */ - public static function loadById ($id) { - return PartDB2::getEM()->find(get_called_class(), $id); - } -}- \ No newline at end of file diff --git a/src/de/RaumZeitLabor/PartDB2/Unit/UnitManager.php b/src/de/RaumZeitLabor/PartDB2/Unit/UnitManager.php @@ -1,80 +0,0 @@ -<?php -namespace de\RaumZeitLabor\PartDB2\Unit; -declare(encoding = 'UTF-8'); - -use de\RaumZeitLabor\PartDB2\Util\Singleton, - de\RaumZeitLabor\PartDB2\PartDB2, - de\RaumZeitLabor\PartDB2\Unit\Exceptions\UnitNotFoundException; - -class UnitManager extends Singleton { - public function getUnits ($start = 0, $limit = 10, $sort = "name", $dir = "asc", $filter = "") { - - $qb = PartDB2::getEM()->createQueryBuilder(); - $qb->select("u.id, u.name, u.symbol")->from("de\RaumZeitLabor\PartDB2\Unit\Unit","u"); - - if ($filter != "") { - $qb = $qb->where("u.name LIKE :filter"); - $qb->setParameter("filter", "%".$filter."%"); - } - - if ($limit > -1) { - $qb->setMaxResults($limit); - $qb->setFirstResult($start); - } - - $qb->orderBy("u.".$sort, $dir); - - $query = $qb->getQuery(); - - $result = $query->getResult(); - - $totalQueryBuilder = PartDB2::getEM()->createQueryBuilder(); - $totalQueryBuilder->select("COUNT(u.id)")->from("de\RaumZeitLabor\PartDB2\Unit\Unit","u"); - - - - if ($filter != "") { - $totalQueryBuilder = $totalQueryBuilder->where("u.name LIKE :filter"); - $totalQueryBuilder->setParameter("filter", "%".$filter."%"); - } - - $totalQuery = $totalQueryBuilder->getQuery(); - - foreach ($result as $key => $value) { - $result[$key]["prefixes"] = $this->getSiPrefixes($value["id"]); - } - - return array("data" => $result, "totalCount" => $totalQuery->getSingleScalarResult()); - } - - public function getSiPrefixes ($id) { - $unit = UnitManager::getInstance()->getUnit($id); - - $aData = array(); - - foreach ($unit->getPrefixes() as $prefix) { - $aData[] = $prefix->serialize(); - } - - return array("response" => array("totalCount" => count($aData), "data" => $aData)); - } - - public function getUnit ($id) { - $unit = PartDB2::getEM()->find("de\RaumZeitLabor\PartDB2\Unit\Unit", $id); - - if ($unit) { - return $unit; - } else { - throw new UnitNotFoundException(); - } - } - - public function deleteUnit ($id) { - $unit = $this->getUnit($id); - - PartDB2::getEM()->remove($unit); - PartDB2::getEM()->flush(); - } - - -}- \ No newline at end of file diff --git a/src/de/RaumZeitLabor/PartDB2/Unit/UnitService.php b/src/de/RaumZeitLabor/PartDB2/Unit/UnitService.php @@ -1,91 +0,0 @@ -<?php -namespace de\RaumZeitLabor\PartDB2\Unit; -use de\RaumZeitLabor\PartDB2\Service\RestfulService; - -declare(encoding = 'UTF-8'); - -use de\RaumZeitLabor\PartDB2\Service\Service; -use de\RaumZeitLabor\PartDB2\PartDB2, - de\RaumZeitLabor\PartDB2\Part\PartUnit, - de\RaumZeitLabor\PartDB2\SiPrefix\SiPrefix, - de\RaumZeitLabor\PartDB2\Session\SessionManager; - -class UnitService extends Service implements RestfulService { - public function get () { - if ($this->hasParameter("id")) { - return UnitManager::getInstance()->getUnit($this->getParameter("id"))->serialize(); - } else { - if ($this->hasParameter("sort")) { - $tmp = json_decode($this->getParameter("sort"), true); - - $aSortParams = $tmp[0]; - } else { - $aSortParams = array( - "property" => "name", - "direction" => "ASC"); - } - return UnitManager::getInstance()->getUnits( - $this->getParameter("start", $this->getParameter("start", 0)), - $this->getParameter("limit", $this->getParameter("limit", 25)), - $this->getParameter("sortby", $aSortParams["property"]), - $this->getParameter("dir", $aSortParams["direction"]), - $this->getParameter("query", "")); - } - } - - public function setUnitPrefixes () { - $this->requireParameter("id"); - - $unit = UnitManager::getInstance()->getUnit($this->getParameter("id")); - - $prefixes = $unit->getPrefixes(); - - $prefixes->clear(); - - foreach ($this->getParameter("prefixes") as $prefix) { - $prefix = SiPrefix::loadById($prefix); - $prefixes->add($prefix); - } - - } - - public function create () { - $this->requireParameter("name"); - - $unit = new Unit; - - $this->setUnitData($unit); - - PartDB2::getEM()->persist($unit); - PartDB2::getEM()->flush(); - - return array("data" => $unit->serialize()); - } - - private function setUnitData (Unit $unit) { - $unit->setName($this->getParameter("name")); - $unit->setSymbol($this->getParameter("symbol")); - } - - public function update () { - $this->requireParameter("id"); - $this->requireParameter("name"); - - $unit = UnitManager::getInstance()->getUnit($this->getParameter("id")); - - $this->setUnitData($unit); - PartDB2::getEM()->flush(); - - return array("data" => $unit->serialize()); - - } - - public function destroy () { - $this->requireParameter("id"); - - UnitManager::getInstance()->deleteUnit($this->getParameter("id")); - - return array("data" => null); - } - -}- \ No newline at end of file diff --git a/src/de/RaumZeitLabor/PartDB2/User/UserManager.php b/src/de/RaumZeitLabor/PartDB2/User/UserManager.php @@ -1,64 +0,0 @@ -<?php -namespace de\RaumZeitLabor\PartDB2\User; -declare(encoding = 'UTF-8'); - -use de\RaumZeitLabor\PartDB2\Util\Singleton, - de\RaumZeitLabor\PartDB2\Auth\User, - de\RaumZeitLabor\PartDB2\PartDB2, - de\RaumZeitLabor\PartDB2\Category\CategoryManager, - de\RaumZeitLabor\PartDB2\User\Exceptions\UserNotFoundException; - -class UserManager extends Singleton { - public function getUsers ($start = 0, $limit = 10, $sort = "name", $dir = "asc", $filter = "") { - - $qb = PartDB2::getEM()->createQueryBuilder(); - $qb->select("st.id, st.username")->from("de\RaumZeitLabor\PartDB2\Auth\User","st"); - - if ($filter != "") { - $qb = $qb->where("st.username LIKE :filter"); - $qb->setParameter("filter", "%".$filter."%"); - } - - if ($limit > -1) { - $qb->setMaxResults($limit); - $qb->setFirstResult($start); - } - - $qb->orderBy("st.".$sort, $dir); - - $query = $qb->getQuery(); - - $result = $query->getResult(); - - $totalQueryBuilder = PartDB2::getEM()->createQueryBuilder(); - $totalQueryBuilder->select("COUNT(st.id)")->from("de\RaumZeitLabor\PartDB2\Auth\User","st"); - - - - if ($filter != "") { - $totalQueryBuilder = $totalQueryBuilder->where("st.name LIKE :filter"); - $totalQueryBuilder->setParameter("filter", "%".$filter."%"); - } - - $totalQuery = $totalQueryBuilder->getQuery(); - - return array("data" => $result, "totalCount" => $totalQuery->getSingleScalarResult()); - } - - public function getUser ($id) { - $user = PartDB2::getEM()->find("de\RaumZeitLabor\PartDB2\Auth\User", $id); - - if ($user) { - return $user; - } else { - throw new UserNotFoundException(); - } - } - - public function deleteUser ($id) { - $user = $this->getUser($id); - - PartDB2::getEM()->remove($user); - PartDB2::getEM()->flush(); - } -}- \ No newline at end of file diff --git a/src/de/RaumZeitLabor/PartDB2/User/UserService.php b/src/de/RaumZeitLabor/PartDB2/User/UserService.php @@ -1,77 +0,0 @@ -<?php -namespace de\RaumZeitLabor\PartDB2\User; -use de\RaumZeitLabor\PartDB2\Service\RestfulService; - -declare(encoding = 'UTF-8'); - -use de\RaumZeitLabor\PartDB2\Service\AdminService; -use de\RaumZeitLabor\PartDB2\PartDB2, - de\RaumZeitLabor\PartDB2\Auth\User, - de\RaumZeitLabor\PartDB2\Session\SessionManager; - -class UserService extends AdminService implements RestfulService { - public function get () { - if ($this->hasParameter("id")) { - return UserManager::getInstance()->getUser($this->getParameter("id"))->serialize(); - } else { - if ($this->hasParameter("sort")) { - $tmp = json_decode($this->getParameter("sort"), true); - - $aSortParams = $tmp[0]; - } else { - $aSortParams = array( - "property" => "username", - "direction" => "ASC"); - } - return UserManager::getInstance()->getUsers( - $this->getParameter("start", $this->getParameter("start", 0)), - $this->getParameter("limit", $this->getParameter("limit", 25)), - $this->getParameter("sortby", $aSortParams["property"]), - $this->getParameter("dir", $aSortParams["direction"]), - $this->getParameter("query", "")); - } - } - - public function create () { - $this->requireParameter("username"); - - $user = new User; - - $this->setUserData($user); - - PartDB2::getEM()->persist($user); - PartDB2::getEM()->flush(); - - return array("data" => $user->serialize()); - } - - private function setUserData (User $user) { - $user->setUsername($this->getParameter("username")); - - if ($this->hasParameter("password") && $this->getParameter("password") !== "") { - $user->setHashedPassword($this->getParameter("password")); - } else { - $user->setHashedPassword(""); - } - } - - public function update () { - $this->requireParameter("id"); - $this->requireParameter("username"); - $user = UserManager::getInstance()->getUser($this->getParameter("id")); - - $this->setUserData($user); - PartDB2::getEM()->flush(); - - return array("data" => $user->serialize()); - - } - - public function destroy () { - $this->requireParameter("id"); - - UserManager::getInstance()->deleteUser($this->getParameter("id")); - - return array("data" => null); - } -}- \ No newline at end of file diff --git a/src/de/RaumZeitLabor/PartDB2/Util/Configuration.php b/src/de/RaumZeitLabor/PartDB2/Util/Configuration.php @@ -1,43 +0,0 @@ -<?php -namespace de\RaumZeitLabor\PartDB2\Util; - -/** - * This class manages simple key -> value configurations within the system. - * - * This allows the user to configure certain aspects of the system in a central place. - * - * The convention is to use a dotted format, for example: - * - * flipbeat.cms.layoutrenderer - * - * @author felicitus - */ -class Configuration { - private static $options = array(); - - /** - * Sets the option to value. - * - * @param string $option The option to set - * @param string $value The value to set - */ - public static function setOption ($option, $value) { - Configuration::$options[$option] = $value; - } - - /** - * Returns the value of an option. The developer - * may additionally specify a default value, which - * is returned when no option was found. - * - * @param string $option The option to return - * @param string $default The default value if the option was not found - */ - public static function getOption ($option, $default = false) { - if (!array_key_exists($option, Configuration::$options)) { - return $default; - } - return Configuration::$options[$option]; - } -} -?>- \ No newline at end of file diff --git a/src/de/RaumZeitLabor/PartDB2/Util/Exceptions/OutOfRangeException.php b/src/de/RaumZeitLabor/PartDB2/Util/Exceptions/OutOfRangeException.php @@ -1,7 +0,0 @@ -<?php -namespace de\RaumZeitLabor\PartDB2\Util\Exceptions; -declare(encoding = 'UTF-8'); - -use de\RaumZeitLabor\PartDB2\Util\SerializableException; - -class OutOfRangeException extends SerializableException {} diff --git a/src/de/RaumZeitLabor/PartDB2/Util/SerializableException.php b/src/de/RaumZeitLabor/PartDB2/Util/SerializableException.php @@ -1,58 +0,0 @@ -<?php -namespace de\RaumZeitLabor\PartDB2\Util; - -class SerializableException extends \Exception { - protected $detailMessage = "No detail message has been entered."; - - /* @todo: stub */ - public function getDetail () { - return $this->detailMessage; - } - - public function setDetail ($message) { - $this->detailMessage = $message; - } - - public function serialize () { - return array( - "message" => $this->getMessage(), - "detail" => $this->getDetail(), - "exception" => get_class($this) - //"backtrace" => $this->getFormattedTrace() - ); - } - - public function getFormattedTrace () { - $items = $this->getTrace(); - - $message = ""; - - $args = array(); - - foreach ($items as $id => $item) { - foreach ($item["args"] as $item) { - switch (gettype($item)) { - case "object": - if (method_exists($item, "__toString")) { - $args[] = get_class($item) . "(".$item->__toString().")"; - } else { - $args[] = get_class($item); - } - case "array": - $args[] = "array"; - break; - default: - $args[] = $item; - break; - } - } - - $message .= $item["file"].":".$item["line"]."\n"; - $message .= $item["function"] ."(".implode(",", $args).")"."\n\n"; - } - - return $message; - } - -} -?>- \ No newline at end of file diff --git a/src/de/RaumZeitLabor/PartDB2/Util/Singleton.php b/src/de/RaumZeitLabor/PartDB2/Util/Singleton.php @@ -1,20 +0,0 @@ -<?php -namespace de\RaumZeitLabor\PartDB2\Util; - -abstract class Singleton { - static $instance = null; - - private function __construct () { - - } - - public static function getInstance () { - if (!static::$instance instanceof static) { - static::$instance = new static; - } - - return static::$instance; - } -} - -?>- \ No newline at end of file diff --git a/src/de/RaumZeitLabor/PartDB2/Util/UtilService.php b/src/de/RaumZeitLabor/PartDB2/Util/UtilService.php @@ -1,14 +0,0 @@ -<?php -namespace de\raumzeitlabor\PartDB2\Util; -declare(encoding = 'UTF-8'); - -use de\RaumZeitLabor\PartDB2\Service\AnonService; - -class UtilService extends AnonService { - public function clearCache () { - apc_clear_cache(); - apc_clear_cache("user"); - - return array("status" => "ok"); - } -}- \ No newline at end of file diff --git a/src/de/RaumZeitLabor/PartKeepr/Auth/AuthManager.php b/src/de/RaumZeitLabor/PartKeepr/Auth/AuthManager.php @@ -0,0 +1,13 @@ +<?php +namespace de\RaumZeitLabor\PartKeepr\Auth; + +use de\RaumZeitLabor\PartKeepr\Util\Singleton; + +class AuthManager extends Singleton { + public function login () { + + } + + +} +?>+ \ No newline at end of file diff --git a/src/de/RaumZeitLabor/PartKeepr/Auth/AuthService.php b/src/de/RaumZeitLabor/PartKeepr/Auth/AuthService.php @@ -0,0 +1,36 @@ +<?php +namespace de\raumzeitlabor\PartKeepr\Auth; +declare(encoding = 'UTF-8'); + +use de\RaumZeitLabor\PartKeepr\Service\AnonService, + de\RaumZeitLabor\PartKeepr\Auth\User, + de\RaumZeitLabor\PartKeepr\Auth\UserManager, + de\RaumZeitLabor\PartKeepr\Session\SessionManager; + +class AuthService extends AnonService { + public function login () { + $this->requireParameter("username"); + $this->requireParameter("password"); + + /* Build a temporary user */ + $user = new User; + $user->setRawUsername($this->getParameter("username")); + $user->setHashedPassword($this->getParameter("password")); + + $authenticatedUser = UserManager::getInstance()->authenticate($user); + + if ($authenticatedUser !== false) { + /* Start Session */ + $session = SessionManager::getInstance()->startSession($authenticatedUser); + + return array("sessionid" => $session->getSessionID(), "username" => $this->getParameter("username"), "admin" => $session->getUser()->isAdmin()); + } else { + throw new InvalidLoginDataException(); + } + + + } + + +} +?>+ \ No newline at end of file diff --git a/src/de/RaumZeitLabor/PartKeepr/Auth/Exceptions/InvalidLoginDataException.php b/src/de/RaumZeitLabor/PartKeepr/Auth/Exceptions/InvalidLoginDataException.php @@ -0,0 +1,12 @@ +<?php +namespace de\RaumZeitLabor\PartKeepr\Auth\Exceptions; + +use de\RaumZeitLabor\PartKeepr\Util\SerializableException, + de\RaumZeitLabor\PartKeepr\PartKeepr; + +class InvalidLoginDataException extends SerializableException { + public function __construct () { + parent::__construct(PartKeepr::i18n("Username or Password wrong.")); + } +} +?>+ \ No newline at end of file diff --git a/src/de/RaumZeitLabor/PartKeepr/Auth/Exceptions/UserAlreadyExistsException.php b/src/de/RaumZeitLabor/PartKeepr/Auth/Exceptions/UserAlreadyExistsException.php @@ -0,0 +1,12 @@ +<?php +namespace de\RaumZeitLabor\PartKeepr\Auth\Exceptions; + +use de\RaumZeitLabor\PartKeepr\Util\SerializableException, + de\RaumZeitLabor\PartKeepr\PartKeepr; + +class UserAlreadyExistsException extends SerializableException { + public function __construct () { + parent::__construct(PartKeepr::i18n("User already exists.")); + } +} +?>+ \ No newline at end of file diff --git a/src/de/RaumZeitLabor/PartKeepr/Auth/Exceptions/UserDoesNotExistException.php b/src/de/RaumZeitLabor/PartKeepr/Auth/Exceptions/UserDoesNotExistException.php @@ -0,0 +1,12 @@ +<?php +namespace de\RaumZeitLabor\PartKeepr\Auth\Exceptions; + +use de\RaumZeitLabor\PartKeepr\Util\SerializableException, + de\RaumZeitLabor\PartKeepr\PartKeepr; + +class UserDoesNotExistException extends SerializableException { + public function __construct () { + parent::__construct(PartKeepr::i18n("The given user doesn't exist. Maybe the user was already deleted.")); + } +} +?>+ \ No newline at end of file diff --git a/src/de/RaumZeitLabor/PartKeepr/Auth/User.php b/src/de/RaumZeitLabor/PartKeepr/Auth/User.php @@ -0,0 +1,183 @@ +<?php +namespace de\RaumZeitLabor\PartKeepr\Auth; +declare(encoding = 'UTF-8'); + +/** @Entity */ + +class User { + /** + * @Id @Column(type="integer") + * @GeneratedValue(strategy="AUTO") + * @var unknown_type + */ + private $id; + + /** @Column(length=50,unique=true) */ + private $username; + + /** @Column(length=32) */ + private $password; + + /** @Column(type="boolean") */ + private $admin; + + + /** + * Creates a new user object. + * + * @param string $username The username to set (optional) + * @param string $password The password to set (optional) + */ + public function __construct ($username = null, $password = null) { + if ($username !== null) { + $this->setUsername($username); + } + + if ($password !== null) { + $this->setPassword($password); + } + + $this->setAdmin(false); + } + /** + * Sets the username. + * + * Forces the username to have + * lowercase a-z characters. + * + * Replaces space with an underscore. + * + * @param string $username The username to set. Applies automatic username modification. + * @return nothing + */ + public function setUsername ($username) { + $username = strtolower($username); + + + preg_match_all("/[a-z\s]+/", $username, $out); + $username = implode('', $out[0]); + + $username = str_replace(" ", "_", $username); + + $this->username = $username; + + } + + /** + * Sets the raw username, without replacing any special chars. + * + * This method should only be used for building a temporary user + * for login checks. + * + * @param string $username The raw username + * @return nothing + */ + public function setRawUsername ($username) { + $this->username = $username; + } + + /** + * Returns the username. + * @param none + * @return string The username + */ + public function getUsername () { + return $this->username; + } + + /** + * Sets the admin flag + * @param boolean $bAdmin True if the user is an admin, false otherwise + */ + public function setAdmin ($bAdmin) { + $this->admin = (boolean)$bAdmin; + } + + /** + * Returns the admin flag + * @return boolean True if the user is an admin + */ + public function isAdmin () { + return $this->admin; + } + + /** + * Sets the user's password. Automatically + * applies md5 hashing. + * + * @param string $password + */ + public function setPassword ($password) { + $this->setHashedPassword(md5($password)); + } + + /** + * Returns the user's md5-hashed password. + * @param none + * @return string The md5-hashed password + */ + public function getHashedPassword () { + return $this->password; + } + + /** + * Sets the user's password. Expects a hash + * and does not apply md5 hasing. + * + * @param string $hashedPassword + */ + public function setHashedPassword ($hashedPassword) { + $this->password = $hashedPassword; + } + + /** + * Compares the given un-hashed password with the + * object's hashed password. + * + * + * @param string $password The unhashed password + * @return boolean true if the passwords match, false otherwise + */ + public function comparePassword ($password) { + return $this->compareHashedPassword(md5($password)); + } + + /** + * Compares the given hashed password with the object's + * hashed password. + * + * @param string $hashedPassword The md5-hashed password + * @return boolean true if the passwords match, false otherwise + */ + public function compareHashedPassword ($hashedPassword) { + if ($hashedPassword == $this->password) { + return true; + } else { + return false; + } + } + + /** + * Returns the ID of this object. + * @param none + * @return int The ID of this object + */ + public function getId () { + return $this->id; + } + + /** + * Serializes the user object and returns it as array, suitable + * to process via json_encode. + * @param none + * @return array An array containing the object information + */ + public function serialize () { + return array( + "id" => $this->getId(), + "username" => $this->getUsername() + ); + } + +} +?>+ \ No newline at end of file diff --git a/src/de/RaumZeitLabor/PartKeepr/Auth/UserManager.php b/src/de/RaumZeitLabor/PartKeepr/Auth/UserManager.php @@ -0,0 +1,57 @@ +<?php +namespace de\raumzeitlabor\PartKeepr\Auth; +declare(encoding = 'UTF-8'); + +use de\RaumZeitLabor\PartKeepr\Util\Singleton, + de\RaumZeitLabor\PartKeepr\Auth\User, + de\RaumZeitLabor\PartKeepr\PartKeepr, + de\RaumZeitLabor\PartKeepr\Auth\Exceptions\UserAlreadyExistsException, + de\RaumZeitLabor\PartKeepr\Auth\Exceptions\UserDoesNotExistException, + de\RaumZeitLabor\PartKeepr\Auth\Exceptions\InvalidLoginDataException; + +class UserManager extends Singleton { + + public function createUser (User $user) { + if ($this->userExists($user)) { + throw new UserAlreadyExistsException($user->getUsername()); + } + + PartKeepr::getEM()->persist($user); + } + + public function userExists (User $user) { + $user = PartKeepr::getEM()->find("de\RaumZeitLabor\PartKeepr\Auth\User", $user->getUsername()); + + if ($user === null) { + return false; + } else { + return true; + } + } + + public function deleteUser (User $user) { + if (!$this->userExists($user)) { + throw new UserDoesNotExistException($user->getUsername()); + } + PartKeepr::getEM()->remove($user); + } + + public function authenticate (User $user) { + $result = PartKeepr::getEM() + ->getRepository("de\RaumZeitLabor\PartKeepr\Auth\User") + ->findOneBy( + array( + "username" => $user->getUsername(), + "password" => $user->getHashedPassword() + ) + ); + + if ($result == null) { + throw new InvalidLoginDataException(); + } else { + return $result; + } + } + +} +?>+ \ No newline at end of file diff --git a/src/de/RaumZeitLabor/PartKeepr/Auth/UserManagerService.php b/src/de/RaumZeitLabor/PartKeepr/Auth/UserManagerService.php @@ -0,0 +1,20 @@ +<?php +namespace de\raumzeitlabor\PartKeepr\Auth; +declare(encoding = 'UTF-8'); + +use de\RaumZeitLabor\PartKeepr\Service\Service; +use de\RaumZeitLabor\PartKeepr\Auth\UserManager; + +class UserManagerService extends Service { + public function createUser () { + $this->requireParameter("username"); + $this->requireParameter("password"); + + $user = new User(); + $user->setUsername($this->getParameter("username")); + $user->setHashedPassword($this->getParameter("password")); + + UserManager::getInstance()->createUser($user); + } +} +?>+ \ No newline at end of file diff --git a/src/de/RaumZeitLabor/PartKeepr/Category/Category.php b/src/de/RaumZeitLabor/PartKeepr/Category/Category.php @@ -0,0 +1,71 @@ +<?php +namespace de\RaumZeitLabor\PartKeepr\Category; +declare(encoding = 'UTF-8'); + +use DoctrineExtensions\NestedSet\Node; + +/** @Entity @Table(indexes={@index(name="lft", columns={"lft"}),@index(name="rgt", columns={"rgt"})}) */ +class Category implements Node { + /** @Id @Column(type="integer") + * @GeneratedValue(strategy="AUTO") + */ + private $id; + + /** + * @Column(type="integer") + */ + private $lft; + + /** + * @Column(type="integer") + */ + private $rgt; + + /** @Column(length=128) */ + private $name; + + /** @Column(length=32768) */ + private $description; + + private $parent; + + public function setName ($name) { + $this->name = $name; + } + + public function setParent ($id) { + $this->parent = $id; + } + + public function getParent () { + return $this->parent; + } + + public function setDescription ($description) { + $this->description = $description; + } + + + public function getName () { + return $this->name; + } + public function getId() { return $this->id; } + + public function getLeftValue() { return $this->lft; } + public function setLeftValue($lft) { $this->lft = $lft; } + + public function getRightValue() { return $this->rgt; } + public function setRightValue($rgt) { $this->rgt = $rgt; } + + public function serialize () { + return array( + "id" => $this->id, + "name" => $this->name, + "description" => $this->description + + ); + } + + public function __toString () {} +} +?>+ \ No newline at end of file diff --git a/src/de/RaumZeitLabor/PartKeepr/Category/CategoryManager.php b/src/de/RaumZeitLabor/PartKeepr/Category/CategoryManager.php @@ -0,0 +1,137 @@ +<?php +namespace de\raumzeitlabor\PartKeepr\Category; +declare(encoding = 'UTF-8'); + +use de\RaumZeitLabor\PartKeepr\Util\Singleton, + de\RaumZeitLabor\PartKeepr\Category\Category, + de\RaumZeitLabor\PartKeepr\Util\SerializableException, + de\RaumZeitLabor\PartKeepr\Category\Exceptions\CategoryNotFoundException, + de\RaumZeitLabor\PartKeepr\PartKeepr; +use DoctrineExtensions\NestedSet\Manager; +use DoctrineExtensions\NestedSet\Config; +use DoctrineExtensions\NestedSet\NodeWrapper; + +class CategoryManager extends Singleton { + private $nodeManager; + + public function getNodeManager () { + if (!$this->nodeManager) { + $config = new Config(PartKeepr::getEM(), 'de\RaumZeitLabor\PartKeepr\Category\Category'); + + $this->nodeManager = new Manager($config); + } + + return $this->nodeManager; + } + + public function getChildNodes ($id) { + $category = $this->getCategory($id); + + $aData = array(); + + foreach ($category->getDescendants() as $cat) { + $aData[] = $cat->getNode()->getId(); + } + return $aData; + } + + public function getAllCategories () { + return $this->getNodeManager()->fetchTree(1); + } + + + public function ensureRootExists () { + /* Check if the root node exists */ + $rootNode = $this->getNodeManager()->fetchTree(1); + + if ($rootNode === null) { + $this->createRootNode(); + } + } + + public function getRootNode () { + return $this->getNodeManager()->fetchTree(1); + } + + public function createRootNode () { + $rootNode = new Category(); + $rootNode->setName("Root Category"); + $rootNode->setDescription(""); + + $this->getNodeManager()->createRoot($rootNode); + } + + public function addCategory (Category $category) { + $parent = $category->getParent(); + + if ($parent == 0) { + $parent = $this->getRootNode(); + + } else { + $parent = PartKeepr::getEM()->find("de\RaumZeitLabor\PartKeepr\Category\Category", $parent); + + $parent = new NodeWrapper($parent, $this->getNodeManager()); + } + + return $parent->addChild($category); + + + } + + public function deleteCategory ($id) { + $category = PartKeepr::getEM()->find("de\RaumZeitLabor\PartKeepr\Category\Category", $id); + + + if ($category) { + try { + $category = new NodeWrapper($category, $this->getNodeManager()); + + if ($category->hasChildren()) { + $exception = new SerializableException(sprintf(PartKeepr::i18n("Category '%s' contains other categories."), $category->getNode()->getName())); + $exception->setDetail(sprintf(PartKeepr::i18n("You tried to delete the category '%s', but it still contains other categories. Please move the categories or delete them first."), $category->getNode()->getName())); + + throw $exception; + } + $category->delete(); + } catch (\PDOException $e) { + if ($e->getCode() == "23000") { + $exception = new SerializableException(sprintf(PartKeepr::i18n("Category '%s' contains parts."), $category->getNode()->getName())); + $exception->setDetail(sprintf(PartKeepr::i18n("You tried to delete the category '%s', but it still contains parts. Please move the parts to another category."), $category->getNode()->getName())); + + throw $exception; + } + } + + } else { + throw new CategoryNotFoundException; + } + } + + public function saveCategory ($category) { + PartKeepr::getEM()->persist($category); + } + + public function getCategory ($id) { + $category = PartKeepr::getEM()->find("de\RaumZeitLabor\PartKeepr\Category\Category", $id); + + + + if ($category) { + $category = new NodeWrapper($category, $this->getNodeManager()); + + return $category; + } else { + throw new CategoryNotFoundException; + } + } + + /** + * Returns the overall category count currently existing. + * @return int The amount of categories in the database + */ + public function getCategoryCount () { + $dql = "SELECT COUNT(c.id) FROM de\RaumZeitLabor\PartKeepr\Category\Category c"; + + return PartKeepr::getEM()->createQuery($dql)->getSingleScalarResult(); + } +}+ \ No newline at end of file diff --git a/src/de/RaumZeitLabor/PartKeepr/Category/CategoryService.php b/src/de/RaumZeitLabor/PartKeepr/Category/CategoryService.php @@ -0,0 +1,119 @@ +<?php +namespace de\RaumZeitLabor\PartKeepr\Category; +declare(encoding = 'UTF-8'); + +use de\RaumZeitLabor\PartKeepr\Service\Service; +use de\RaumZeitLabor\PartKeepr\Category\CategoryManager; +use DoctrineExtensions\NestedSet\NodeWrapper; + + +class CategoryService extends Service { + + public function getCategories () { + $categories = CategoryManager::getInstance()->getAllCategories( + $this->getParameter("parent", 0)); + + return $this->serializeTree($categories); + } + + public function moveCategory () { + $this->requireParameter("category"); + $this->requireParameter("target"); + + $category = CategoryManager::getInstance()->getCategory($this->getParameter("category")); + + if (intval($this->getParameter("target", 0)) !== 0) { + + $parent = CategoryManager::getInstance()->getCategory($this->getParameter("target")); + + $category->moveAsLastChildOf($parent); + + } + } + + public function deleteCategory () { + $this->requireParameter("id"); + + CategoryManager::getInstance()->deleteCategory($this->getParameter("id")); + + return array("id" => $this->getParameter("id")); + } + + public function update () { + $this->requireParameter("id"); + $this->requireParameter("name"); + + $category = CategoryManager::getInstance()->getCategory($this->getParameter("id")); + + $category->getNode()->setName($this->getParameter("name")); + $category->getNode()->setDescription($this->getParameter("description", "")); + + CategoryManager::getInstance()->saveCategory($category->getNode()); + + return array("data" => $this->serializeCategory($category)); + } + + public function create () { + $this->requireParameter("name"); + $this->requireParameter("parent"); + + $category = new Category; + $category->setName($this->getParameter("name")); + $category->setDescription($this->getParameter("description", "")); + $category->setParent($this->getParameter("parent")); + + $category = CategoryManager::getInstance()->addCategory($category); + + return array("data" => $this->serializeCategory($category)); + } + + // Old stuff below + + public function getCategory () { + $this->requireParameter("id"); + + $category = CategoryManager::getInstance()->getCategory($this->getParameter("id")); + + return $this->serializeCategory($category); + + } + + private function serializeCategory ($category) { + $data = $category->getNode()->serialize(); + + if ($category->getParent() !== null) { + $data["parent"] = $category->getParent()->getNode()->getId(); + $data["parentName"] = $category->getParent()->getNode()->getName(); + } + + return $data; + } + + public function getAllCategories () { + return $this->serializeTree(CategoryManager::getInstance()->getAllCategories()); + } + + public function serializeTree (NodeWrapper $node = null) { + if ($node == null) { + throw new \Exception("Node must not be null!"); + } + + $aData = $node->getNode()->serialize(); + + $aData["children"] = array(); + + if (count($node->getChildren()) == 0) { + $aData["leaf"] = true; + } else { + $aData["expanded"] = true; + } + + foreach ($node->getChildren() as $child) { + $aData["children"][] = $this->serializeTree($child); + + } + + return $aData; + } +} +?>+ \ No newline at end of file diff --git a/src/de/RaumZeitLabor/PartKeepr/Category/Exceptions/CategoryNotFoundException.php b/src/de/RaumZeitLabor/PartKeepr/Category/Exceptions/CategoryNotFoundException.php @@ -0,0 +1,12 @@ +<?php +namespace de\RaumZeitLabor\PartKeepr\Category\Exceptions; + +use de\RaumZeitLabor\PartKeepr\Util\SerializableException, + de\RaumZeitLabor\PartKeepr\PartKeepr; + +class CategoryNotFoundException extends SerializableException { + public function __construct () { + parent::__construct(PartKeepr::i18n("Category not found.")); + } +} +?>+ \ No newline at end of file diff --git a/src/de/RaumZeitLabor/PartKeepr/Distributor/Distributor.php b/src/de/RaumZeitLabor/PartKeepr/Distributor/Distributor.php @@ -0,0 +1,133 @@ +<?php +namespace de\RaumZeitLabor\PartKeepr\Distributor; +declare(encoding = 'UTF-8'); + +use de\RaumZeitLabor\PartKeepr\PartKeepr; + +/** @Entity **/ +class Distributor { + + /** + * @Id @Column(type="integer") + * @GeneratedValue(strategy="AUTO") + * @var unknown_type + */ + private $id; + + /** + * @Column(type="string",unique=true) + */ + private $name; + + /** + * @Column(type="string",nullable=true) + */ + private $address; + + /** + * @Column(type="string",nullable=true) + */ + private $url; + + /** + * @Column(type="string",nullable=true) + */ + private $phone; + + /** + * @Column(type="string",nullable=true) + */ + private $fax; + + /** + * @Column(type="string",nullable=true) + */ + private $email; + + /** + * @Column(type="string",nullable=true) + */ + private $comment; + + public function __construct () { + } + public function setName ($name) { + $this->name = $name; + } + + public function getName () { + return $this->name; + } + + public function setAddress ($address) { + $this->address = $address; + } + + public function getAddress () { + return $this->address; + } + + public function setPhone ($phone) { + $this->phone = $phone; + } + + public function getPhone () { + return $this->phone; + } + + public function setFax ($fax) { + $this->fax = $fax; + } + + public function getFax ($fax) { + return $this->fax; + } + + + public function setComment ($comment) { + $this->comment = $comment; + } + + public function getComment () { + return $this->comment; + } + + public function setEmail ($email) { + $this->email = $email; + } + + public function getEmail () { + return $this->email; + } + + public function setURL ($url) { + $this->url = $url; + } + + public function getURL () { + return $this->url; + } + + public function getICLogos () { + return $this->icLogos; + } + + public function getId () { + return $this->id; + } + + public function serialize () { + return array( + "id" => $this->getId(), + "name" => $this->getName(), + "url" => $this->getURL(), + "address" => $this->getAddress(), + "email" => $this->getEmail(), + "comment" => $this->getComment() + ); + } + + public static function loadById ($id) { + return PartKeepr::getEM()->find(get_called_class(), $id); + } +}+ \ No newline at end of file diff --git a/src/de/RaumZeitLabor/PartKeepr/Distributor/DistributorManager.php b/src/de/RaumZeitLabor/PartKeepr/Distributor/DistributorManager.php @@ -0,0 +1,73 @@ +<?php +namespace de\RaumZeitLabor\PartKeepr\Distributor; +declare(encoding = 'UTF-8'); + +use de\RaumZeitLabor\PartKeepr\Util\Singleton, + de\RaumZeitLabor\PartKeepr\Distributor\Distributor, + de\RaumZeitLabor\PartKeepr\PartKeepr, + de\RaumZeitLabor\PartKeepr\Category\CategoryManager, + de\RaumZeitLabor\PartKeepr\Distributor\Exceptions\DistributorNotFoundException; + +class DistributorManager extends Singleton { + public function getDistributors ($start = 0, $limit = 10, $sort = "name", $dir = "asc", $filter = "") { + + $qb = PartKeepr::getEM()->createQueryBuilder(); + $qb->select("st.id, st.name, st.url, st.email, st.comment, st.address")->from("de\RaumZeitLabor\PartKeepr\Distributor\Distributor","st"); + + if ($filter != "") { + $qb = $qb->where("st.name LIKE :filter"); + $qb->setParameter("filter", "%".$filter."%"); + } + + if ($limit > -1) { + $qb->setMaxResults($limit); + $qb->setFirstResult($start); + } + + $qb->orderBy("st.".$sort, $dir); + + $query = $qb->getQuery(); + + $result = $query->getResult(); + + $totalQueryBuilder = PartKeepr::getEM()->createQueryBuilder(); + $totalQueryBuilder->select("COUNT(st.id)")->from("de\RaumZeitLabor\PartKeepr\Distributor\Distributor","st"); + + + + if ($filter != "") { + $totalQueryBuilder = $totalQueryBuilder->where("st.name LIKE :filter"); + $totalQueryBuilder->setParameter("filter", "%".$filter."%"); + } + + $totalQuery = $totalQueryBuilder->getQuery(); + + return array("data" => $result, "totalCount" => $totalQuery->getSingleScalarResult()); + } + + public function getDistributor ($id) { + $distributor = PartKeepr::getEM()->find("de\RaumZeitLabor\PartKeepr\Distributor\Distributor", $id); + + if ($distributor) { + return $distributor; + } else { + throw new DistributorNotFoundException(); + } + } + + public function addDistributor ($name) { + $distributor = new Distributor(); + $distributor->setName($name); + + PartKeepr::getEM()->persist($distributor); + PartKeepr::getEM()->flush(); + + return $distributor; + } + public function deleteDistributor ($id) { + $distributor = $this->getDistributor($id); + + PartKeepr::getEM()->remove($distributor); + PartKeepr::getEM()->flush(); + } +}+ \ No newline at end of file diff --git a/src/de/RaumZeitLabor/PartKeepr/Distributor/DistributorService.php b/src/de/RaumZeitLabor/PartKeepr/Distributor/DistributorService.php @@ -0,0 +1,141 @@ +<?php +namespace de\RaumZeitLabor\PartKeepr\Distributor; +use de\RaumZeitLabor\PartKeepr\Service\RestfulService; + +declare(encoding = 'UTF-8'); + +use de\RaumZeitLabor\PartKeepr\Service\Service; +use de\RaumZeitLabor\PartKeepr\Part\PartManager, + de\RaumZeitLabor\PartKeepr\Stock\StockEntry, + de\RaumZeitLabor\PartKeepr\PartKeepr, + de\RaumZeitLabor\PartKeepr\Session\SessionManager; + +class DistributorService extends Service implements RestfulService { + public function get () { + if ($this->hasParameter("id")) { + return DistributorManager::getInstance()->getDistributor($this->getParameter("id"))->serialize(); + } else { + if ($this->hasParameter("sort")) { + $tmp = json_decode($this->getParameter("sort"), true); + + $aSortParams = $tmp[0]; + } else { + $aSortParams = array( + "property" => "name", + "direction" => "ASC"); + } + return DistributorManager::getInstance()->getDistributors( + $this->getParameter("start", $this->getParameter("start", 0)), + $this->getParameter("limit", $this->getParameter("limit", 25)), + $this->getParameter("sortby", $aSortParams["property"]), + $this->getParameter("dir", $aSortParams["direction"]), + $this->getParameter("query", "")); + } + } + + public function create () { + $this->requireParameter("name"); + + $distributor = new Distributor; + + $this->setDistributorData($distributor); + + PartKeepr::getEM()->persist($distributor); + PartKeepr::getEM()->flush(); + + return array("data" => $distributor->serialize()); + } + + private function setDistributorData (Distributor $distributor) { + $distributor->setName($this->getParameter("name")); + $distributor->setComment($this->getParameter("comment", "")); + $distributor->setAddress($this->getParameter("address", "")); + $distributor->setURL($this->getParameter("url", "")); + $distributor->setEmail($this->getParameter("email", "")); + } + + public function update () { + $this->requireParameter("id"); + $this->requireParameter("name"); + $distributor = DistributorManager::getInstance()->getDistributor($this->getParameter("id")); + + $this->setDistributorData($distributor); + PartKeepr::getEM()->flush(); + + return array("data" => $distributor->serialize()); + + } + + public function destroy () { + $this->requireParameter("id"); + + DistributorManager::getInstance()->deleteDistributor($this->getParameter("id")); + + return array("data" => null); + } + + + // Old stuff below + public function getDistributors() { + return DistributorManager::getInstance()->getDistributors( + $this->getParameter("start", 0), + $this->getParameter("limit", 10), + $this->getParameter("sortby", "name"), + $this->getParameter("dir", "asc"), + $this->getParameter("filter", "")); + } + + public function addDistributor () { + $this->requireParameter("name"); + + DistributorManager::getInstance()->addDistributor($this->getParameter("name")); + } + + public function deleteDistributor () { + $this->requireParameter("id"); + + DistributorManager::getInstance()->deleteDistributor($this->getParameter("id")); + } + + public function deleteDistributorLogo () { + $this->requireParameter("id"); + + $logo = DistributorICLogo::loadById($this->getParameter("id")); + + PartKeepr::getEM()->remove($logo); + PartKeepr::getEM()->flush(); + } + + public function getDistributorLogos () { + $this->requireParameter("id"); + $distributor = DistributorManager::getInstance()->getDistributor($this->getParameter("id")); + + $aData = array(); + + foreach ($distributor->getICLogos() as $logo) { + $aData[] = array("id" => $logo->getId()); + } + + return array("logos" => $aData); + + } + + public function getDistributor () { + $this->requireParameter("id"); + + return DistributorManager::getInstance()->getDistributor($this->getParameter("id"))->serialize(); + } + + public function saveDistributor () { + $this->requireParameter("id"); + $this->requireParameter("name"); + + $Distributor = DistributorManager::getInstance()->getDistributor($this->getParameter("id")); + + $Distributor->setName($this->getParameter("name")); + + PartKeepr::getEM()->flush(); + + return $Distributor->serialize(); + } +}+ \ No newline at end of file diff --git a/src/de/RaumZeitLabor/PartKeepr/Footprint/Exceptions/FootprintNotFoundException.php b/src/de/RaumZeitLabor/PartKeepr/Footprint/Exceptions/FootprintNotFoundException.php @@ -0,0 +1,12 @@ +<?php +namespace de\RaumZeitLabor\PartKeepr\Footprint\Exceptions; + +use de\RaumZeitLabor\PartKeepr\Util\SerializableException, + de\RaumZeitLabor\PartKeepr\PartKeepr; + +class FootprintNotFoundException extends SerializableException { + public function __construct () { + parent::__construct(PartKeepr::i18n("Footprint not found.")); + } +} +?>+ \ No newline at end of file diff --git a/src/de/RaumZeitLabor/PartKeepr/Footprint/Footprint.php b/src/de/RaumZeitLabor/PartKeepr/Footprint/Footprint.php @@ -0,0 +1,32 @@ +<?php +namespace de\RaumZeitLabor\PartKeepr\Footprint; +declare(encoding = 'UTF-8'); + +/** @Entity */ + +class Footprint { + /** @Id @Column(type="integer") + * @GeneratedValue(strategy="AUTO") + */ + private $id; + + /** @Column(length=64,unique=true) */ + private $footprint; + + public function setFootprint ($footprint) { + $this->footprint = $footprint; + } + + public function getId () { + return $this->id; + } + + public function getFootprint () { + return $this->footprint; + } + + public function serialize () { + return array("id" => $this->id, "footprint" => $this->footprint); + } +} +?>+ \ No newline at end of file diff --git a/src/de/RaumZeitLabor/PartKeepr/Footprint/FootprintManager.php b/src/de/RaumZeitLabor/PartKeepr/Footprint/FootprintManager.php @@ -0,0 +1,115 @@ +<?php +namespace de\raumzeitlabor\PartKeepr\Footprint; +declare(encoding = 'UTF-8'); + +use de\RaumZeitLabor\PartKeepr\Util\Singleton, + de\RaumZeitLabor\PartKeepr\Util\SerializableException, + de\RaumZeitLabor\PartKeepr\Footprint\Footprint, + de\RaumZeitLabor\PartKeepr\PartKeepr, + de\RaumZeitLabor\PartKeepr\Footprint\Exceptions\FootprintNotFoundException; + +class FootprintManager extends Singleton { + public function getFootprints ($start = 0, $limit = 10, $sort = "footprint", $dir = "asc", $filter = "") { + + $qb = PartKeepr::getEM()->createQueryBuilder(); + $qb->select("f.id, f.footprint")->from("de\RaumZeitLabor\PartKeepr\Footprint\Footprint","f"); + + if ($filter != "") { + $qb = $qb->where("f.footprint LIKE :filter"); + $qb->setParameter("filter", "%".$filter."%"); + } + + if ($limit > -1) { + $qb->setMaxResults($limit); + $qb->setFirstResult($start); + } + + $qb->orderBy("f.".$sort, $dir); + + $query = $qb->getQuery(); + + $result = $query->getResult(); + + $totalQueryBuilder = PartKeepr::getEM()->createQueryBuilder(); + $totalQueryBuilder->select("COUNT(f.id)")->from("de\RaumZeitLabor\PartKeepr\Footprint\Footprint","f"); + + + + if ($filter != "") { + $totalQueryBuilder = $totalQueryBuilder->where("f.footprint LIKE :filter"); + $totalQueryBuilder->setParameter("filter", "%".$filter."%"); + } + + $totalQuery = $totalQueryBuilder->getQuery(); + + return array("data" => $result, "totalCount" => $totalQuery->getSingleScalarResult()); + } + + public function addFootprint ($footprint) { + $fp = new Footprint(); + $fp->setFootprint($footprint); + + // @todo Port the UniqueEntityValidator from Symfony2 to here. + try { + PartKeepr::getEM()->persist($fp); + PartKeepr::getEM()->flush(); + } catch (\PDOException $e) { + if ($e->getCode() == "23000") { + $exception = new SerializableException(sprintf(PartKeepr::i18n("Footprint %s already exists!"), $footprint)); + $exception->setDetail(sprintf(PartKeepr::i18n("You tried to add the footprint %s, but a footprint with the same name already exists."), $footprint)); + + throw $exception; + } else { + throw $e; + } + } + + return $fp; + } + + public function deleteFootprint ($id) { + $footprint = PartKeepr::getEM()->find("de\RaumZeitLabor\PartKeepr\Footprint\Footprint", $id); + + if ($footprint) { + try { + PartKeepr::getEM()->remove($footprint); + PartKeepr::getEM()->flush(); + } catch (\PDOException $e) { + if ($e->getCode() == "23000") { + $exception = new SerializableException(sprintf(PartKeepr::i18n("Footprint %s is in use by some parts!"), $footprint->getFootprint())); + $exception->setDetail(sprintf(PartKeepr::i18n("You tried to delete the footprint %s, but there are parts which use this footprint."), $footprint->getFootprint())); + + throw $exception; + } + } + + } else { + throw new FootprintNotFoundException; + } + } + + public function getOrCreateFootprint ($footprint) { + if (is_int($footprint)) { + try { + return $this->getFootprint($footprint); + } catch (FootprintNotFoundException $e) {} + } + + $fp = new Footprint(); + $fp->setFootprint($footprint); + + PartKeepr::getEM()->persist($fp); + + return $fp; + } + + public function getFootprint ($id) { + $footprint = PartKeepr::getEM()->find("de\RaumZeitLabor\PartKeepr\Footprint\Footprint", $id); + + if ($footprint) { + return $footprint; + } else { + throw new FootprintNotFoundException; + } + } +}+ \ No newline at end of file diff --git a/src/de/RaumZeitLabor/PartKeepr/Footprint/FootprintService.php b/src/de/RaumZeitLabor/PartKeepr/Footprint/FootprintService.php @@ -0,0 +1,102 @@ +<?php +namespace de\raumzeitlabor\PartKeepr\Footprint; +declare(encoding = 'UTF-8'); + +use de\RaumZeitLabor\PartKeepr\Service\Service, + de\RaumZeitLabor\PartKeepr\Service\RestfulService, + de\RaumZeitLabor\PartKeepr\PartKeepr, + de\RaumZeitLabor\PartKeepr\Footprint\FootprintManager; + +class FootprintService extends Service implements RestfulService { + public function get () { + if ($this->hasParameter("id")) { + return FootprintManager::getInstance()->getFootprint($this->getParameter("id"))->serialize(); + } else { + if ($this->hasParameter("sort")) { + $tmp = json_decode($this->getParameter("sort"), true); + + $aSortParams = $tmp[0]; + } else { + $aSortParams = array( + "property" => "footprint", + "direction" => "ASC"); + } + return FootprintManager::getInstance()->getFootprints( + $this->getParameter("start", $this->getParameter("start", 0)), + $this->getParameter("limit", $this->getParameter("limit", 25)), + $this->getParameter("sortby", $aSortParams["property"]), + $this->getParameter("dir", $aSortParams["direction"]), + $this->getParameter("query", "")); + } + } + + public function create () { + $this->requireParameter("footprint"); + + $fp = FootprintManager::getInstance()->addFootprint($this->getParameter("footprint")); + + return array("data" => $fp->serialize()); + } + + public function update () { + $this->requireParameter("id"); + $this->requireParameter("footprint"); + $footprint = FootprintManager::getInstance()->getFootprint($this->getParameter("id")); + $footprint->setFootprint($this->getParameter("footprint")); + + PartKeepr::getEM()->flush(); + + return array("data" => $footprint->serialize()); + + } + + public function destroy () { + $this->requireParameter("id"); + + FootprintManager::getInstance()->deleteFootprint($this->getParameter("id")); + + return array("data" => null); + } + + /* Old stuff below */ + public function getFootprints () { + return FootprintManager::getInstance()->getFootprints( + $this->getParameter("start", 0), + $this->getParameter("limit", 10), + $this->getParameter("sortby", "footprint"), + $this->getParameter("dir", "asc"), + $this->getParameter("filter", "")); + } + + public function addFootprint () { + $this->requireParameter("footprint"); + + + } + + public function deleteFootprint () { + $this->requireParameter("id"); + + FootprintManager::getInstance()->deleteFootprint($this->getParameter("id")); + } + + public function getFootprint () { + $this->requireParameter("id"); + + return $this->get($this->getParameter("id")); + } + + public function saveFootprint () { + $this->requireParameter("id"); + $this->requireParameter("footprint"); + + $footprint = FootprintManager::getInstance()->getFootprint($this->getParameter("id")); + + $footprint->setFootprint($this->getParameter("footprint")); + + PartKeepr::getEM()->flush(); + + return $footprint->serialize(); + } +} +?>+ \ No newline at end of file diff --git a/src/de/RaumZeitLabor/PartKeepr/Image/CachedImage.php b/src/de/RaumZeitLabor/PartKeepr/Image/CachedImage.php @@ -0,0 +1,78 @@ +<?php +namespace de\RaumZeitLabor\PartKeepr\Image; +declare(encoding = 'UTF-8'); + +use de\RaumZeitLabor\PartKeepr\PartKeepr; + +/** + * @Entity + */ +class CachedImage { + /** + * Specifies the ID of the cached image. + * + * @var integer + * @Id + * @Column(type="integer") + * @GeneratedValue(strategy="AUTO") + **/ + private $id; + + /** + * Specifies the ID of the original image + * + * @var integer + * @Column(type="integer") + */ + private $originalId; + + /** + * Specifies the type of the original image. + * + * @var string + * @Column(type="string") + **/ + private $originalType; + + /** + * The cache filename of the image + * + * @var string + * @Column(type="string") + */ + private $cacheFile; + + public function __construct (Image $image, $cacheFile) { + $this->originalId = (int)$image->getId(); + $this->originalType = $image->getType(); + $this->cacheFile = $cacheFile; + } + + public function getCacheFile () { + return $this->cacheFile; + } + + public static function invalidate (Image $image) { + $qb = PartKeepr::getEM()->createQueryBuilder(); + $qb->select(array("c")) + ->from('de\RaumZeitLabor\PartKeepr\Image\CachedImage', 'c') + ->where("c.originalId = :id") + ->andWhere("c.originalType = :type") + ->setParameter("id", $image->getId()) + ->setParameter("type", $image->getType()); + + $query = $qb->getQuery(); + + $bImagesRemoved = false; + + foreach ($query->getResult() as $file) { + unlink($file->getCacheFile()); + PartKeepr::getEM()->remove($file); + $bImagesRemoved = true; + } + + if ($bImagesRemoved) { + PartKeepr::getEM()->flush(); + } + } +}+ \ No newline at end of file diff --git a/src/de/RaumZeitLabor/PartKeepr/Image/Exceptions/InvalidImageTypeException.php b/src/de/RaumZeitLabor/PartKeepr/Image/Exceptions/InvalidImageTypeException.php @@ -0,0 +1,8 @@ +<?php +namespace de\RaumZeitLabor\PartKeepr\Image\Exceptions; + +class InvalidImageTypeException extends \Exception { + public function __construct ($type) { + parent::__construct("The image type $type is unknown."); + } +}+ \ No newline at end of file diff --git a/src/de/RaumZeitLabor/PartKeepr/Image/Image.php b/src/de/RaumZeitLabor/PartKeepr/Image/Image.php @@ -0,0 +1,241 @@ +<?php +namespace de\RaumZeitLabor\PartKeepr\Image; +declare(encoding = 'UTF-8'); + +use de\RaumZeitLabor\PartKeepr\PartKeepr, + de\RaumZeitLabor\PartKeepr\Util\Configuration, + de\RaumZeitLabor\PartKeepr\Image\Exceptions\InvalidImageTypeException; + +/** + * @MappedSuperclass + */ +abstract class Image { + /** + * Specifies the ID of the image. + * + * @var integer + * @Id + * @Column(type="integer") + * @GeneratedValue(strategy="AUTO") + **/ + protected $id; + + /** + * Specifies the type of the image. + * + * @var string + * @Column(type="string") + **/ + private $type; + + /** + * The unique filename of the image + * + * @var string + * @Column(type="string") + */ + private $filename; + + const IMAGE_ICLOGO = "iclogo"; + const IMAGE_TEMP = "temp"; + + /** + * Constructs a new image object. + * + * @param string $type The type for the image, one of the IMAGE_ constants. + */ + public function __construct ($type) { + $this->setType($type); + $this->filename = PartKeepr::createGUIDv4(); + } + + /** + * Sets the type of the image. Once the type is set, + * it may not be changed later. + * + * @param string $type The type for the image, one of the IMAGE_ constants. + * @throws InvalidImageTypeException + */ + protected function setType ($type) { + switch ($type) { + case Image::IMAGE_ICLOGO: + case Image::IMAGE_TEMP: + $this->type = $type; + break; + default: + throw new InvalidImageTypeException($type); + } + } + + /** + * Replaces the current image with a new image. + * + * Automatically converts from one format to PNG, + * which is the default when dealing with images + * on the platform. + * + * @param string $path The path to the original image + */ + public function replace ($path) { + $this->ensureImagePathExists(); + + copy($path, $this->getImageFilename()); + + CachedImage::invalidate($this); + } + + /** + * Returns the full image filename including path. + * This is the image where all scale operations take place on. + * + * @param none + * @return string The full image filename including path. + */ + public function getImageFilename () { + return $this->getImagePath().$this->filename.".png"; + } + + public function getImageFilenameWithoutSuffix () { + return $this->filename; + } + + /** + * Returns the ID of the image. + * @param none + * @return integer The ID of the image + */ + public function getId () { + return $this->id; + } + + /** + * Returns the type of the image + * @param none + * @return string The type of the image + */ + public function getType () { + return $this->type; + } + + /** + * Returns the path to the image. May be overridden by + * subclasses. + * + * @param none + * @return string The path to the image + */ + public function getImagePath () { + return Configuration::getOption("partkeepr.images.path").$this->getType()."/"; + } + + /** + * Ensures that the image path exists. This function + * is called every time an image is processed. + * It is maybe a bit overhead, but saves headaches later when + * introducing new types. + * + * @param none + * @return nothing + */ + public function ensureImagePathExists () { + if (!is_dir($this->getImagePath())) { + mkdir($this->getImagePath(), 0777, true); + } + } + + public function scaleTo ($w, $h) { + $this->ensureCachedirExists(); + + $outputFile = Configuration::getOption("partkeepr.images.cache").md5($this->getImageFilename().$w."x".$h).".png"; + + if (file_exists($outputFile)) { + return $outputFile; + } + $image = new \Imagick(); + $image->readImage($this->getImageFilename()); + $image->adaptiveResizeImage($w, $h); + $image->writeImage($outputFile); + + $cachedImage = new CachedImage($this, $outputFile); + PartKeepr::getEM()->persist($cachedImage); + + return $outputFile; + } + + public function fitWithinExact ($w, $h) { + $this->ensureCachedirExists(); + + $outputFile = Configuration::getOption("partkeepr.images.cache").md5($this->getImageFilename().$w."x".$h."fwe").".png"; + + if (file_exists($outputFile)) { + return $outputFile; + } + $image = new \Imagick(); + $image->readImage($this->getImageFilename()); + + $sourceAspectRatio = $image->getImageWidth() / $image->getImageHeight(); + $targetAspectRatio = $w / $h; + + $filter = \Imagick::FILTER_UNDEFINED; + $blur = 1; + + if ($sourceAspectRatio < $targetAspectRatio) { + $image->resizeImage($w, $w / $sourceAspectRatio, $filter, $blur); + } else { + $image->resizeImage($h * $sourceAspectRatio, $h, $filter, $blur); + } + + $offsetX = intval(($image->getImageWidth() - $w)/2); + $offsetY = intval(($image->getImageHeight() - $h)/2); + + $image = $image->getImageRegion($w, $h, $offsetX, $offsetY); + + $image->writeImage($outputFile); + + $cachedImage = new CachedImage($this, $outputFile); + PartKeepr::getEM()->persist($cachedImage); + + return $outputFile; + } + + public function fitWithin ($w, $h) { + $this->ensureCachedirExists(); + + $outputFile = Configuration::getOption("partkeepr.images.cache").md5($this->getImageFilename().$w."x".$h."fw").".png"; + + if (file_exists($outputFile)) { + return $outputFile; + } + $image = new \Imagick(); + $image->readImage($this->getImageFilename()); + + $sourceAspectRatio = $image->getImageWidth() / $image->getImageHeight(); + $targetAspectRatio = $w / $h; + + $filter = \Imagick::FILTER_UNDEFINED; + $blur = 1; + + if ($sourceAspectRatio < $targetAspectRatio) { + $image->resizeImage($h * $sourceAspectRatio, $h, $filter, $blur); + } else { + $image->resizeImage($w, $w / $sourceAspectRatio, $filter, $blur); + } + + $image->writeImage($outputFile); + + $cachedImage = new CachedImage($this, $outputFile); + PartKeepr::getEM()->persist($cachedImage); + + return $outputFile; + } + + public function ensureCachedirExists () { + if (!is_dir(Configuration::getOption("partkeepr.images.cache"))) { + mkdir(Configuration::getOption("partkeepr.images.cache"), 0777, true); + } + } + + public static function loadById ($id) { + return PartKeepr::getEM()->find(get_called_class(), $id); + } +}+ \ No newline at end of file diff --git a/src/de/RaumZeitLabor/PartKeepr/Image/TempImage.php b/src/de/RaumZeitLabor/PartKeepr/Image/TempImage.php @@ -0,0 +1,17 @@ +<?php +namespace de\RaumZeitLabor\PartKeepr\Image; +declare(encoding = 'UTF-8'); + +use de\RaumZeitLabor\PartKeepr\Image\Exceptions\InvalidImageTypeException, + de\RaumZeitLabor\PartKeepr\Util\Configuration, + de\RaumZeitLabor\PartKeepr\Image\Image, + de\RaumZeitLabor\PartKeepr\PartKeepr; + +/** + * @Entity + */ +class TempImage extends Image { + public function __construct () { + parent::__construct(Image::IMAGE_TEMP); + } +}+ \ No newline at end of file diff --git a/src/de/RaumZeitLabor/PartKeepr/Manufacturer/Manufacturer.php b/src/de/RaumZeitLabor/PartKeepr/Manufacturer/Manufacturer.php @@ -0,0 +1,138 @@ +<?php +namespace de\RaumZeitLabor\PartKeepr\Manufacturer; +declare(encoding = 'UTF-8'); + +use de\RaumZeitLabor\PartKeepr\PartKeepr; + +/** @Entity **/ +class Manufacturer { + + /** + * @Id @Column(type="integer") + * @GeneratedValue(strategy="AUTO") + * @var unknown_type + */ + private $id; + + /** + * @Column(type="string",unique=true) + */ + private $name; + + /** + * @Column(type="string",nullable=true) + */ + private $address; + + /** + * @Column(type="string",nullable=true) + */ + private $url; + + /** + * @Column(type="string",nullable=true) + */ + private $email; + + /** + * @Column(type="string",nullable=true) + */ + private $comment; + + /** + * @Column(type="string",nullable=true) + */ + private $phone; + + /** + * @Column(type="string",nullable=true) + */ + private $fax; + + /** + * @OneToMany(targetEntity="de\RaumZeitLabor\PartKeepr\Manufacturer\ManufacturerICLogo",mappedBy="manufacturer",cascade={"persist", "remove"}) + */ + private $icLogos; + + public function __construct () { + $this->icLogos = new \Doctrine\Common\Collections\ArrayCollection(); + } + public function setName ($name) { + $this->name = $name; + } + + public function getName () { + return $this->name; + } + + public function setPhone ($phone) { + $this->phone = $phone; + } + + public function getPhone () { + return $this->phone; + } + + public function setFax ($fax) { + $this->fax = $fax; + } + + public function getFax ($fax) { + return $this->fax; + } + + public function setAddress ($address) { + $this->address = $address; + } + + public function getAddress () { + return $this->address; + } + + public function setComment ($comment) { + $this->comment = $comment; + } + + public function getComment () { + return $this->comment; + } + + public function setEmail ($email) { + $this->email = $email; + } + + public function getEmail () { + return $this->email; + } + + public function setURL ($url) { + $this->url = $url; + } + + public function getURL () { + return $this->url; + } + + public function getICLogos () { + return $this->icLogos; + } + + public function getId () { + return $this->id; + } + + public function serialize () { + return array( + "id" => $this->getId(), + "name" => $this->getName(), + "url" => $this->getURL(), + "address" => $this->getAddress(), + "email" => $this->getEmail(), + "comment" => $this->getComment() + ); + } + + public static function loadById ($id) { + return PartKeepr::getEM()->find(get_called_class(), $id); + } +}+ \ No newline at end of file diff --git a/src/de/RaumZeitLabor/PartKeepr/Manufacturer/ManufacturerICLogo.php b/src/de/RaumZeitLabor/PartKeepr/Manufacturer/ManufacturerICLogo.php @@ -0,0 +1,25 @@ +<?php +namespace de\RaumZeitLabor\PartKeepr\Manufacturer; +declare(encoding = 'UTF-8'); + +use de\RaumZeitLabor\PartKeepr\Image\Image; + +/** @Entity **/ +class ManufacturerICLogo extends Image { + /** + * @ManyToOne(targetEntity="de\RaumZeitLabor\PartKeepr\Manufacturer\Manufacturer") + */ + private $manufacturer = null; + + public function __construct () { + parent::__construct(Image::IMAGE_ICLOGO); + } + + public function setManufacturer (Manufacturer $manufacturer) { + $this->manufacturer = $manufacturer; + } + + public function serialize () { + return array("id" => $this->id, "manufacturer_id" => $this->manufacturer->getId()); + } +}+ \ No newline at end of file diff --git a/src/de/RaumZeitLabor/PartKeepr/Manufacturer/ManufacturerManager.php b/src/de/RaumZeitLabor/PartKeepr/Manufacturer/ManufacturerManager.php @@ -0,0 +1,73 @@ +<?php +namespace de\RaumZeitLabor\PartKeepr\Manufacturer; +declare(encoding = 'UTF-8'); + +use de\RaumZeitLabor\PartKeepr\Util\Singleton, + de\RaumZeitLabor\PartKeepr\Manufacturer\Manufacturer, + de\RaumZeitLabor\PartKeepr\PartKeepr, + de\RaumZeitLabor\PartKeepr\Category\CategoryManager, + de\RaumZeitLabor\PartKeepr\Manufacturer\Exceptions\ManufacturerNotFoundException; + +class ManufacturerManager extends Singleton { + public function getManufacturers ($start = 0, $limit = 10, $sort = "name", $dir = "asc", $filter = "") { + + $qb = PartKeepr::getEM()->createQueryBuilder(); + $qb->select("st.id, st.name, st.url, st.email, st.comment, st.address")->from("de\RaumZeitLabor\PartKeepr\Manufacturer\Manufacturer","st"); + + if ($filter != "") { + $qb = $qb->where("st.name LIKE :filter"); + $qb->setParameter("filter", "%".$filter."%"); + } + + if ($limit > -1) { + $qb->setMaxResults($limit); + $qb->setFirstResult($start); + } + + $qb->orderBy("st.".$sort, $dir); + + $query = $qb->getQuery(); + + $result = $query->getResult(); + + $totalQueryBuilder = PartKeepr::getEM()->createQueryBuilder(); + $totalQueryBuilder->select("COUNT(st.id)")->from("de\RaumZeitLabor\PartKeepr\Manufacturer\Manufacturer","st"); + + + + if ($filter != "") { + $totalQueryBuilder = $totalQueryBuilder->where("st.name LIKE :filter"); + $totalQueryBuilder->setParameter("filter", "%".$filter."%"); + } + + $totalQuery = $totalQueryBuilder->getQuery(); + + return array("data" => $result, "totalCount" => $totalQuery->getSingleScalarResult()); + } + + public function getManufacturer ($id) { + $manufacturer = PartKeepr::getEM()->find("de\RaumZeitLabor\PartKeepr\Manufacturer\Manufacturer", $id); + + if ($manufacturer) { + return $manufacturer; + } else { + throw new ManufacturerNotFoundException(); + } + } + + public function addManufacturer ($name) { + $manufacturer = new Manufacturer(); + $manufacturer->setName($name); + + PartKeepr::getEM()->persist($manufacturer); + PartKeepr::getEM()->flush(); + + return $manufacturer; + } + public function deleteManufacturer ($id) { + $manufacturer = $this->getManufacturer($id); + + PartKeepr::getEM()->remove($manufacturer); + PartKeepr::getEM()->flush(); + } +}+ \ No newline at end of file diff --git a/src/de/RaumZeitLabor/PartKeepr/Manufacturer/ManufacturerService.php b/src/de/RaumZeitLabor/PartKeepr/Manufacturer/ManufacturerService.php @@ -0,0 +1,141 @@ +<?php +namespace de\RaumZeitLabor\PartKeepr\Manufacturer; +use de\RaumZeitLabor\PartKeepr\Service\RestfulService; + +declare(encoding = 'UTF-8'); + +use de\RaumZeitLabor\PartKeepr\Service\Service; +use de\RaumZeitLabor\PartKeepr\Part\PartManager, + de\RaumZeitLabor\PartKeepr\Stock\StockEntry, + de\RaumZeitLabor\PartKeepr\PartKeepr, + de\RaumZeitLabor\PartKeepr\Session\SessionManager; + +class ManufacturerService extends Service implements RestfulService { + public function get () { + if ($this->hasParameter("id")) { + return ManufacturerManager::getInstance()->getManufacturer($this->getParameter("id"))->serialize(); + } else { + if ($this->hasParameter("sort")) { + $tmp = json_decode($this->getParameter("sort"), true); + + $aSortParams = $tmp[0]; + } else { + $aSortParams = array( + "property" => "name", + "direction" => "ASC"); + } + return ManufacturerManager::getInstance()->getManufacturers( + $this->getParameter("start", $this->getParameter("start", 0)), + $this->getParameter("limit", $this->getParameter("limit", 25)), + $this->getParameter("sortby", $aSortParams["property"]), + $this->getParameter("dir", $aSortParams["direction"]), + $this->getParameter("query", "")); + } + } + + public function create () { + $this->requireParameter("name"); + + $manufacturer = new Manufacturer; + + $this->setManufacturerData($manufacturer); + + PartKeepr::getEM()->persist($manufacturer); + PartKeepr::getEM()->flush(); + + return array("data" => $manufacturer->serialize()); + } + + private function setManufacturerData (Manufacturer $manufacturer) { + $manufacturer->setName($this->getParameter("name")); + $manufacturer->setComment($this->getParameter("comment", "")); + $manufacturer->setAddress($this->getParameter("address", "")); + $manufacturer->setURL($this->getParameter("url", "")); + $manufacturer->setEmail($this->getParameter("email", "")); + } + + public function update () { + $this->requireParameter("id"); + $this->requireParameter("name"); + $manufacturer = ManufacturerManager::getInstance()->getManufacturer($this->getParameter("id")); + + $this->setManufacturerData($manufacturer); + PartKeepr::getEM()->flush(); + + return array("data" => $manufacturer->serialize()); + + } + + public function destroy () { + $this->requireParameter("id"); + + ManufacturerManager::getInstance()->deleteManufacturer($this->getParameter("id")); + + return array("data" => null); + } + + + // Old stuff below + public function getManufacturers() { + return ManufacturerManager::getInstance()->getManufacturers( + $this->getParameter("start", 0), + $this->getParameter("limit", 10), + $this->getParameter("sortby", "name"), + $this->getParameter("dir", "asc"), + $this->getParameter("filter", "")); + } + + public function addManufacturer () { + $this->requireParameter("name"); + + ManufacturerManager::getInstance()->addManufacturer($this->getParameter("name")); + } + + public function deleteManufacturer () { + $this->requireParameter("id"); + + ManufacturerManager::getInstance()->deleteManufacturer($this->getParameter("id")); + } + + public function deleteManufacturerLogo () { + $this->requireParameter("id"); + + $logo = ManufacturerICLogo::loadById($this->getParameter("id")); + + PartKeepr::getEM()->remove($logo); + PartKeepr::getEM()->flush(); + } + + public function getManufacturerLogos () { + $this->requireParameter("id"); + $manufacturer = ManufacturerManager::getInstance()->getManufacturer($this->getParameter("id")); + + $aData = array(); + + foreach ($manufacturer->getICLogos() as $logo) { + $aData[] = array("id" => $logo->getId()); + } + + return array("logos" => $aData); + + } + + public function getManufacturer () { + $this->requireParameter("id"); + + return ManufacturerManager::getInstance()->getManufacturer($this->getParameter("id"))->serialize(); + } + + public function saveManufacturer () { + $this->requireParameter("id"); + $this->requireParameter("name"); + + $Manufacturer = ManufacturerManager::getInstance()->getManufacturer($this->getParameter("id")); + + $Manufacturer->setName($this->getParameter("name")); + + PartKeepr::getEM()->flush(); + + return $Manufacturer->serialize(); + } +}+ \ No newline at end of file diff --git a/src/de/RaumZeitLabor/PartKeepr/ManufacturerICLogo/ManufacturerICLogoManager.php b/src/de/RaumZeitLabor/PartKeepr/ManufacturerICLogo/ManufacturerICLogoManager.php @@ -0,0 +1,74 @@ +<?php +namespace de\RaumZeitLabor\PartKeepr\ManufacturerICLogo; +declare(encoding = 'UTF-8'); + +use de\RaumZeitLabor\PartKeepr\Util\Singleton, + de\RaumZeitLabor\PartKeepr\Manufacturer\Manufacturer, + de\RaumZeitLabor\PartKeepr\PartKeepr, + de\RaumZeitLabor\PartKeepr\Manufacturer\Exceptions\ManufacturerNotFoundException; + +class ManufacturerICLogoManager extends Singleton { + public function getManufacturerICLogos ($start = 0, $limit = 10, $sort = "name", $dir = "asc", $filter = "") { + + $qb = PartKeepr::getEM()->createQueryBuilder(); + $qb->select("st.id, maf.id AS manufacturer_id")->from("de\RaumZeitLabor\PartKeepr\Manufacturer\ManufacturerICLogo","st") + ->leftJoin('st.manufacturer', "maf"); + + if ($filter != "") { + $manufacturer = Manufacturer::loadById($filter); + $qb = $qb->where("st.manufacturer = :manufacturer"); + $qb->setParameter("manufacturer", $manufacturer); + } + + if ($limit > -1) { + $qb->setMaxResults($limit); + $qb->setFirstResult($start); + } + + $qb->orderBy("st.".$sort, $dir); + + $query = $qb->getQuery(); + + $result = $query->getResult(); + + $totalQueryBuilder = PartKeepr::getEM()->createQueryBuilder(); + $totalQueryBuilder->select("COUNT(st.id)")->from("de\RaumZeitLabor\PartKeepr\Manufacturer\ManufacturerICLogo","st"); + + + + if ($filter != "") { + $totalQueryBuilder = $totalQueryBuilder->where("st.manufacturer = :manufacturer"); + $totalQueryBuilder->setParameter("manufacturer", $manufacturer); + } + + $totalQuery = $totalQueryBuilder->getQuery(); + + return array("data" => $result, "totalCount" => $totalQuery->getSingleScalarResult()); + } + + public function getManufacturerICLogo ($id) { + $manufacturer = PartKeepr::getEM()->find("de\RaumZeitLabor\PartKeepr\Manufacturer\ManufacturerICLogo", $id); + + if ($manufacturer) { + return $manufacturer; + } else { + throw new ManufacturerNotFoundException(); + } + } + + public function addManufacturerICLogo ($name) { + $manufacturer = new ManufacturerICLogo(); + $manufacturer->setName($name); + + PartKeepr::getEM()->persist($manufacturer); + PartKeepr::getEM()->flush(); + + return $manufacturer; + } + public function deleteManufacturer ($id) { + $manufacturer = $this->getManufacturer($id); + + PartKeepr::getEM()->remove($manufacturer); + PartKeepr::getEM()->flush(); + } +}+ \ No newline at end of file diff --git a/src/de/RaumZeitLabor/PartKeepr/ManufacturerICLogo/ManufacturerICLogoService.php b/src/de/RaumZeitLabor/PartKeepr/ManufacturerICLogo/ManufacturerICLogoService.php @@ -0,0 +1,88 @@ +<?php +namespace de\RaumZeitLabor\PartKeepr\ManufacturerICLogo; +use de\RaumZeitLabor\PartKeepr\Manufacturer\ManufacturerICLogo; + +use de\RaumZeitLabor\PartKeepr\Image\TempImage; + +use de\RaumZeitLabor\PartKeepr\Service\RestfulService; + +declare(encoding = 'UTF-8'); + +use de\RaumZeitLabor\PartKeepr\Service\Service; +use de\RaumZeitLabor\PartKeepr\PartKeepr, + de\RaumZeitLabor\PartKeepr\Manufacturer\Manufacturer, + de\RaumZeitLabor\PartKeepr\Session\SessionManager; + +class ManufacturerICLogoService extends Service implements RestfulService { + public function get () { + if ($this->hasParameter("id")) { + return ManufacturerICLogoManager::getInstance()->getManufacturerICLogo($this->getParameter("id"))->serialize(); + } else { + if ($this->hasParameter("sort")) { + $tmp = json_decode($this->getParameter("sort"), true); + + $aSortParams = $tmp[0]; + } else { + $aSortParams = array( + "property" => "id", + "direction" => "ASC"); + } + + $filter = ""; + + if ($this->hasParameter("filter")) { + $tmp = json_decode($this->getParameter("filter"), true); + + foreach ($tmp as $item) { + if (array_key_exists("property", $item)) { + if ($item["property"] == "manufacturer_id") { + if (array_key_exists("value", $item)) { + $filter = $item["value"]; + } + } + } + } + } + return ManufacturerICLogoManager::getInstance()->getManufacturerICLogos( + $this->getParameter("start", $this->getParameter("start", 0)), + $this->getParameter("limit", $this->getParameter("limit", 25)), + $this->getParameter("sortby", $aSortParams["property"]), + $this->getParameter("dir", $aSortParams["direction"]), + $filter); + } + } + + public function create () { + $this->requireParameter("tmp_id"); + $this->requireParameter("manufacturer_id"); + + $tmpImage = TempImage::loadById($this->getParameter("tmp_id")); + + $image = new ManufacturerICLogo(); + + $manufacturer = Manufacturer::loadById($this->getParameter("manufacturer_id")); + + $image->setManufacturer($manufacturer); + $image->replace($tmpImage->getImageFilename()); + PartKeepr::getEM()->persist($image); + PartKeepr::getEM()->flush(); + + return $image->serialize(); + } + + public function update () { + + } + + public function destroy () { + $this->requireParameter("id"); + + $logo = ManufacturerICLogo::loadById($this->getParameter("id")); + + PartKeepr::getEM()->remove($logo); + PartKeepr::getEM()->flush(); + + return array("data" => null); + } + +}+ \ No newline at end of file diff --git a/src/de/RaumZeitLabor/PartKeepr/Part/Part.php b/src/de/RaumZeitLabor/PartKeepr/Part/Part.php @@ -0,0 +1,224 @@ +<?php +namespace de\RaumZeitLabor\PartKeepr\Part; +declare(encoding = 'UTF-8'); + +use de\RaumZeitLabor\PartKeepr\PartKeepr, + de\RaumZeitLabor\PartKeepr\Util\Exceptions\OutOfRangeException; + + +/** @Entity **/ +class Part { + + /** + * @Id @Column(type="integer") + * @GeneratedValue(strategy="AUTO") + * @var integer + */ + private $id; + + /** + * @ManyToOne(targetEntity="de\RaumZeitLabor\PartKeepr\Category\Category") + */ + private $category; + + /** + * @Column + */ + private $name; + + /** + * @ManyToOne(targetEntity="de\RaumZeitLabor\PartKeepr\Footprint\Footprint") + */ + private $footprint; + + /** + * @ManyToOne(targetEntity="de\RaumZeitLabor\PartKeepr\Part\PartUnit") + */ + private $partUnit; + + /** + * @ManyToOne(targetEntity="de\RaumZeitLabor\PartKeepr\StorageLocation\StorageLocation") + */ + private $storageLocation; + + /** + * @OneToMany(targetEntity="de\RaumZeitLabor\PartKeepr\Part\PartManufacturer",mappedBy="part",cascade={"persist", "remove"}) + */ + private $manufacturers; + + /** + * @OneToMany(targetEntity="de\RaumZeitLabor\PartKeepr\Part\PartDistributor",mappedBy="part",cascade={"persist", "remove"}) + */ + private $distributors; + + /** + * @Column(type="text") + */ + private $comment; + + /** + * The stock level. Note that this is a cached value. + * @Column(type="integer") + */ + private $stockLevel = 0; + + /** + * @Column(type="integer") + */ + private $minStockLevel; + + /** + * The average price for the part. Note that this is a cached value. + * + * @Column(type="decimal",precision=5, scale=2,nullable=true) + * @var float + */ + private $averagePrice = null; + + /** + * @OneToMany(targetEntity="de\RaumZeitLabor\PartKeepr\Stock\StockEntry",mappedBy="part",cascade={"persist", "remove"}) + * @var ArrayCollection + */ + private $stockLevels; + + /** + * @OneToMany(targetEntity="de\RaumZeitLabor\PartKeepr\PartParameter\PartParameter",mappedBy="part",cascade={"persist", "remove"}) + * @var ArrayCollection + */ + private $parameters; + + public function __construct () { + $this->distributors = new \Doctrine\Common\Collections\ArrayCollection(); + $this->manufacturers = new \Doctrine\Common\Collections\ArrayCollection(); + $this->parameters = new \Doctrine\Common\Collections\ArrayCollection(); + } + + public function getName () { + return $this->name; + } + + /** + * Sets the part unit + * + * @param PartUnit $partUnit The part unit object to set + * @return nothing + */ + public function setPartUnit (PartUnit $partUnit) { + $this->partUnit = $partUnit; + } + + /** + * Returns the part unit + * + * @param none + * @return PartUnit The part unit object + */ + public function getPartUnit () { + return $this->partUnit; + } + + public function setAveragePrice ($price) { + $this->averagePrice = $price; + } + + public function updateStockLevel () { + $this->stockLevel = $this->getStockLevel(); + } + + public function setMinStockLevel ($minStockLevel) { + $minStockLevel = intval($minStockLevel); + + if ($minStockLevel < 0) { + $exception = new OutOfRangeException(PartKeepr::i18n("Minimum Stock Level is out of range")); + $exception->setDetail(PartKeepr::i18n("The minimum stock level must be 0 or higher")); + throw $exception; + } + $this->minStockLevel = $minStockLevel; + } + + public function setCategory (\de\RaumZeitLabor\PartKeepr\Category\Category $category) { + $this->category = $category; + } + + public function setStorageLocation (\de\RaumZeitLabor\PartKeepr\StorageLocation\StorageLocation $storageLocation) { + $this->storageLocation = $storageLocation; + } + + public function setName ($name) { + $this->name = $name; + } + + public function setFootprint (\de\RaumZeitLabor\PartKeepr\Footprint\Footprint $footprint = null) { + $this->footprint = $footprint; + } + + public function setComment ($comment) { + $this->comment = $comment; + } + + public function getDistributors () { + return $this->distributors; + } + + public function getManufacturers () { + return $this->manufacturers; + } + + /** + * Returns the parameters assigned to this part + * @return array An array of PartParameter objects + */ + public function getParameters () { + return $this->parameters; + } + + public function getStockLevel () { + $query = PartKeepr::getEM()->createQuery("SELECT SUM(s.stockLevel) FROM de\RaumZeitLabor\PartKeepr\Stock\StockEntry s WHERE s.part = :part"); + $query->setParameter("part", $this); + + return $query->getSingleScalarResult(); + + } + + public function getId () { + return $this->id; + } + + public function serialize () { + $aManufacturers = array(); + + foreach ($this->getManufacturers() as $manufacturer) { + $aManufacturers[] = $manufacturer->serialize(); + } + + $aDistributors = array(); + + foreach ($this->getDistributors() as $distributor) { + $aDistributors[] = $distributor->serialize(); + } + + $aParameters = array(); + foreach ($this->getParameters() as $parameter) { + $aParameters[] = $parameter->serialize(); + } + + return array( + "id" => $this->id, + "name" => $this->name, + "comment" => $this->comment, + "stockLevel" => $this->getStockLevel(), + "footprint_id" => is_object($this->footprint) ? $this->footprint->getId() : null, + "minStockLevel" => $this->minStockLevel, + "storageLocation_id" => is_object($this->storageLocation) ? $this->storageLocation->getId() : null, + "storageLocationName" => is_object($this->storageLocation) ? $this->storageLocation->getName() : null, + "category_id" => is_object($this->category) ? $this->category->getId() : null, + "partUnit_id" => is_object($this->partUnit) ? $this->getPartUnit()->getId() : null, + "partUnit_name" => is_object($this->partUnit) ? $this->getPartUnit()->getId() : PartKeepr::i18n("Pieces"), + "partUnit_shortName" => is_object($this->partUnit) ? $this->getPartUnit()->getId() : "", + "manufacturers" => $aManufacturers, + "distributors" => $aDistributors, + "parameters" => $aParameters + + ); + } +}+ \ No newline at end of file diff --git a/src/de/RaumZeitLabor/PartKeepr/Part/PartDistributor.php b/src/de/RaumZeitLabor/PartKeepr/Part/PartDistributor.php @@ -0,0 +1,113 @@ +<?php +namespace de\RaumZeitLabor\PartKeepr\Part; +declare(encoding = 'UTF-8'); + +use de\RaumZeitLabor\PartKeepr\PartKeepr, + de\RaumZeitLabor\PartKeepr\Distributor\Distributor; + +/** @Entity **/ +class PartDistributor { + /** + * @Id @Column(type="integer") + * @GeneratedValue(strategy="AUTO") + * @var unknown_type + */ + private $id; + + /** + * @ManyToOne(targetEntity="de\RaumZeitLabor\PartKeepr\Part\Part") + */ + private $part; + + /** + * @ManyToOne(targetEntity="de\RaumZeitLabor\PartKeepr\Distributor\Distributor") + */ + private $distributor; + + /** + * @Column(type="string",nullable=true) + * Enter description here ... + * @var unknown_type + */ + private $orderNumber; + + /** + * @Column(type="integer") + * @var integer + * + * Defines the packaging unit when ordering a part. + */ + private $packagingUnit; + + public function __construct (Part $part, Distributor $distributor) { + $this->setPart($part); + $this->setDistributor($distributor); + $this->setPackagingUnit(1); + } + + /** + * Sets the packaging unit for a specific distributor. + * + * For example, some distributors only sell resistors in packs of 100, so you can't order just one. We use the + * packagingUnit to calculate how many pieces will be delivered once ordered. So if your stock level falls below + * the minimum (example: you would need to order 10 resistors), we suggest that you only order one resistor pack + * instead of 10. + * + * @param int $packagingUnit The amount of items in one package + * @throws \de\RaumZeitLabor\PartKeepr\Part\OutOfRangeException When the packaging unit is less than 1 + */ + public function setPackagingUnit ($packagingUnit) { + $packagingUnit = intval($packagingUnit); + + if ($packagingUnit < 1) { + $exception = new OutOfRangeException(PartKeepr::i18n("Packaging Unit is out of range")); + $exception->setDetail(PartKeepr::i18n("The packaging unit must be 1 or higher")); + throw $exception; + } + + $this->packagingUnit = $packagingUnit; + } + + public function getPackagingUnit () { + return $this->packagingUnit; + } + + public function setPart (Part $part) { + $this->part = $part; + } + + public function getPart () { + return $this->part; + } + + public function setDistributor (Distributor $distributor) { + $this->distributor = $distributor; + } + + public function getDistributor () { + return $this->distributor; + } + + public function setOrderNumber ($orderNumber) { + $this->orderNumber = $orderNumber; + } + + public function getOrderNumber () { + return $this->orderNumber; + } + + public function getId () { + return $this->id; + } + + public function serialize () { + return array( + "id" => $this->getId(), + "orderNumber" => $this->getOrderNumber(), + "distributor_id" => $this->getDistributor()->getId(), + "distributor_name" => $this->getDistributor()->getName(), + "part_id" => $this->getPart()->getId(), + "part_name" => $this->getPart()->getName(), + "packagingUnit" => $this->getPackagingUnit()); + } +}+ \ No newline at end of file diff --git a/src/de/RaumZeitLabor/PartKeepr/Part/PartManager.php b/src/de/RaumZeitLabor/PartKeepr/Part/PartManager.php @@ -0,0 +1,375 @@ +<?php +namespace de\raumzeitlabor\PartKeepr\Part; +use de\RaumZeitLabor\PartKeepr\PartParameter\PartParameter; + +use de\RaumZeitLabor\PartKeepr\Unit\Unit; +use de\RaumZeitLabor\PartKeepr\SiPrefix\SiPrefix; + +use de\RaumZeitLabor\PartKeepr\Part\PartDistributor; +use de\RaumZeitLabor\PartKeepr\Part\PartManufacturer; + +use de\RaumZeitLabor\PartKeepr\StorageLocation\StorageLocation; + +use de\RaumZeitLabor\PartKeepr\StorageLocation\StorageLocationManager; + +use de\RaumZeitLabor\PartKeepr\Part\Part; +use de\RaumZeitLabor\PartKeepr\PartUnit\PartUnitManager; +use de\RaumZeitLabor\PartKeepr\Distributor\Distributor; +use de\RaumZeitLabor\PartKeepr\Manufacturer\Manufacturer; +use de\RaumZeitLabor\PartKeepr\Footprint\FootprintManager; +use de\RaumZeitLabor\PartKeepr\Session\SessionManager; +use de\RaumZeitLabor\PartKeepr\Stock\StockEntry; + +declare(encoding = 'UTF-8'); + +use de\RaumZeitLabor\PartKeepr\Util\Singleton, + de\RaumZeitLabor\PartKeepr\Footprint\Footprint, + de\RaumZeitLabor\PartKeepr\PartKeepr, + de\RaumZeitLabor\PartKeepr\Category\CategoryManager, + de\RaumZeitLabor\PartKeepr\Manufacturer\ManufacturerManager, + de\RaumZeitLabor\PartKeepr\Footprint\Exceptions\FootprintNotFoundException; + +class PartManager extends Singleton { + public function getParts ($start = 0, $limit = 10, $sort = "name", $dir = "asc", $filter = "", $category = 0, $categoryScope = "all", $stockMode = "all", $withoutPrice = false, $storageLocation = "") { + + $qb = PartKeepr::getEM()->createQueryBuilder(); + $qb->select("COUNT(p.id)")->from("de\RaumZeitLabor\PartKeepr\Part\Part","p") + ->join("p.storageLocation", "st") + ->leftJoin("p.footprint", "f") + ->join("p.category", "c") + ->leftJoin("p.partUnit", "pu"); + + $qb->where("1=1"); + if ($filter != "") { + $qb = $qb->where("p.name LIKE :filter"); + $qb->setParameter("filter", "%".$filter."%"); + } + + if ($storageLocation != "") { + $qb->andWhere("st.name = :storageLocation"); + $qb->setParameter("storageLocation", $storageLocation); + } + + switch ($sort) { + case "storageLocationName": + $orderBy = "st.name"; + break; + case "footprintName": + $orderBy = "f.footprint"; + break; + default; + $orderBy = "p.".$sort; + break; + } + $qb->orderBy($orderBy, $dir); + + + $category = intval($category); + + + + if ($category !== 0) { + /* Fetch all children */ + if ($categoryScope == "selected") { + $qb->andWhere("p.category = :category"); + $qb->setParameter("category", $category); + } else { + $childs = CategoryManager::getInstance()->getChildNodes($category); + $childs[] = $category; + $qb->andWhere("p.category IN (".implode(",", $childs).")"); + } + } + + switch ($stockMode) { + case "all": + break; + case "zero": + $qb->andWhere("p.stockLevel = 0"); + break; + case "nonzero": + $qb->andWhere("p.stockLevel > 0"); + break; + case "below": + $qb->andWhere("p.stockLevel < p.minStockLevel"); + break; + } + + if ($withoutPrice === true || $withoutPrice === "true") { + $qb->andWhere("p.averagePrice IS NULL"); + } + + $totalQuery = $qb->getQuery(); + + + + + $qb->select("p.averagePrice, p.name, p.id, p.stockLevel, p.minStockLevel, p.comment, st.id AS storageLocation_id, st.name as storageLocationName, f.id AS footprint_id, f.footprint AS footprintName, c.id AS category_id, c.name AS categoryName, pu.name AS partUnit, pu.is_default AS partUnitDefault"); + + if ($limit > -1) { + $qb->setMaxResults($limit); + $qb->setFirstResult($start); + } + + $query = $qb->getQuery(); + + $result = $query->getArrayResult(); + + + + return array("data" => $result, "totalCount" => $totalQuery->getSingleScalarResult()); + } + + public function addOrUpdatePart ($aParameters) { + + if (!array_key_exists("quantity", $aParameters)) { + $aParameters["quantity"] = 0; + } + + if ($aParameters["part"] !== null) { + try { + $part = $this->getPart($aParameters["part"]); + } catch (\Exception $e) { + $part = new Part(); + $user = SessionManager::getCurrentSession()->getUser(); + + $stock = new StockEntry($part, $aParameters["quantity"], $user); + PartKeepr::getEM()->persist($stock); + } + } else { + $part = new Part(); + + $user = SessionManager::getCurrentSession()->getUser(); + + $stock = new StockEntry($part, $aParameters["quantity"], $user); + PartKeepr::getEM()->persist($stock); + } + + if (array_key_exists("name", $aParameters)) { + $part->setName($aParameters["name"]); + } + + if (array_key_exists("minstock", $aParameters)) { + $part->setMinStockLevel($aParameters["minstock"]); + } + + if (array_key_exists("comment", $aParameters)) { + $part->setComment($aParameters["comment"]); + } + + if (array_key_exists("footprint", $aParameters)) { + + if ($aParameters["footprint"] === null) { + $part->setFootprint(null); + } else { + $footprint = FootprintManager::getInstance()->getOrCreateFootprint($aParameters["footprint"]); + $part->setFootprint($footprint); + } + } + + if (array_key_exists("storagelocation", $aParameters)) { + $storageLocation = StorageLocationManager::getInstance()->getOrCreateStorageLocation($aParameters["storagelocation"]); + $part->setStorageLocation($storageLocation); + } + + if (array_key_exists("category", $aParameters)) { + $category = CategoryManager::getInstance()->getCategory($aParameters["category"]); + $part->setCategory($category->getNode()); + } + + /* Process linked changes */ + if (array_key_exists("distributorChanges", $aParameters)) { + if (is_array($aParameters["distributorChanges"])) { + $this->processDistributorChanges($part, $aParameters["distributorChanges"]); + } + } + + if (array_key_exists("manufacturerChanges", $aParameters)) { + if (is_array($aParameters["manufacturerChanges"])) { + $this->processManufacturerChanges($part, $aParameters["manufacturerChanges"]); + } + } + + if (array_key_exists("parameterChanges", $aParameters)) { + if (is_array($aParameters["parameterChanges"])) { + $this->processParameterChanges($part, $aParameters["parameterChanges"]); + } + } + + if (array_key_exists("partUnit", $aParameters)) { + if ($aParameters["partUnit"] === null || $aParameters["partUnit"] === 0) { + $part->setPartUnit(null); + } else { + $part->setPartUnit(PartUnitManager::getInstance()->getPartUnit($aParameters["partUnit"])); + } + } + + + PartKeepr::getEM()->persist($part); + PartKeepr::getEM()->flush(); + + } + + private function processParameterChanges (Part $part, Array $data) { + if (array_key_exists("updates", $data)) { + foreach ($data["updates"] as $record) { + foreach ($part->getParameters() as $partParameter) { + if ($partParameter->getId() == $record["id"]) { + $partParameter->setName($record["name"]); + $partParameter->setDescription($record["description"]); + $partParameter->setValue($record["value"]); + $partParameter->setSiPrefix(SiPrefix::loadById($record["siprefix_id"])); + $partParameter->setUnit(Unit::loadById($record["unit_id"])); + break; + } + } + } + } + + if (array_key_exists("removals", $data)) { + foreach ($data["removals"] as $record) { + foreach ($part->getParameters() as $partParameter) { + if ($partParameter->getId() == $record["id"]) { + PartKeepr::getEM()->remove($partParameter); + $part->getParameters()->removeElement($partParameter); + break; + } + } + } + } + + if (array_key_exists("inserts", $data)) { + foreach ($data["inserts"] as $record) { + $partParameter = new PartParameter(); + $partParameter->setPart($part); + + $partParameter->setName($record["name"]); + $partParameter->setDescription($record["description"]); + $partParameter->setValue($record["value"]); + $partParameter->setSiPrefix(SiPrefix::loadById($record["siprefix_id"])); + $partParameter->setUnit(Unit::loadById($record["unit_id"])); + + $part->getParameters()->add($partParameter); + } + } + } + + private function processDistributorChanges (Part $part, Array $data) { + if (array_key_exists("updates", $data)) { + foreach ($data["updates"] as $record) { + foreach ($part->getDistributors() as $partDistributor) { + if ($partDistributor->getId() == $record["id"]) { + $partDistributor->setOrderNumber($record["orderNumber"]); + $partDistributor->setDistributor(Distributor::loadById($record["distributor_id"])); + $partDistributor->setPackagingUnit($record["packagingUnit"]); + break; + } + } + } + } + + if (array_key_exists("removals", $data)) { + foreach ($data["removals"] as $record) { + foreach ($part->getDistributors() as $partDistributor) { + if ($partDistributor->getId() == $record["id"]) { + PartKeepr::getEM()->remove($partDistributor); + $part->getDistributors()->removeElement($partDistributor); + break; + } + } + } + } + + if (array_key_exists("inserts", $data)) { + foreach ($data["inserts"] as $record) { + $distributor = new PartDistributor($part, Distributor::loadById($record["distributor_id"])); + $distributor->setOrderNumber($record["orderNumber"]); + $distributor->setPackagingUnit($record["packagingUnit"]); + + $part->getDistributors()->add($distributor); + } + } + } + + private function processManufacturerChanges (Part $part, Array $data) { + if (array_key_exists("updates", $data)) { + foreach ($data["updates"] as $record) { + foreach ($part->getManufacturers() as $partManufacturer) { + if ($partManufacturer->getId() == $record["id"]) { + $partManufacturer->setPartNumber($record["partNumber"]); + $partManufacturer->setManufacturer(Manufacturer::loadById($record["manufacturer_id"])); + break; + } + } + } + } + + if (array_key_exists("removals", $data)) { + foreach ($data["removals"] as $record) { + foreach ($part->getManufacturers() as $partManufacturer) { + if ($partManufacturer->getId() == $record["id"]) { + PartKeepr::getEM()->remove($partManufacturer); + $part->getManufacturers()->removeElement($partManufacturer); + break; + } + } + } + } + + if (array_key_exists("inserts", $data)) { + foreach ($data["inserts"] as $record) { + $manufacturer = new PartManufacturer($part, Manufacturer::loadById($record["manufacturer_id"])); + $manufacturer->setPartNumber($record["partNumber"]); + + $part->getManufacturers()->add($manufacturer); + } + } + } + + public function deletePart ($id) { + $part = PartManager::getInstance()->getPart($id); + + PartKeepr::getEM()->remove($part); + PartKeepr::getEM()->flush(); + } + + public function getPart ($id) { + $part = PartKeepr::getEM()->find("de\RaumZeitLabor\PartKeepr\Part\Part", $id); + + return $part; + } + + /** + * Returns the overall part count currently existing. + * @param boolean $withPrice Only consider parts with a price + * @return int The amount of parts in the database + */ + public function getPartCount ($withPrice = false) { + $dql = "SELECT COUNT(p.id) FROM de\RaumZeitLabor\PartKeepr\Part\Part p"; + + if ($withPrice === true) { + $dql .= " WHERE p.averagePrice IS NOT NULL"; + } + + return PartKeepr::getEM()->createQuery($dql)->getSingleScalarResult(); + } + + /** + * Returns the total price for all parts. Only parts with a price are calculated. + * @return float The total price + */ + public function getTotalPrice () { + $dql = "SELECT SUM(p.averagePrice * p.stockLevel) FROM de\RaumZeitLabor\PartKeepr\Part\Part p"; + + return PartKeepr::getEM()->createQuery($dql)->getSingleScalarResult(); + } + + /** + * Returns the average price for all parts. Only parts with a price are calculated. + * @return float The average price + */ + public function getAveragePrice () { + $dql = "SELECT AVG(p.averagePrice) FROM de\RaumZeitLabor\PartKeepr\Part\Part p"; + + return PartKeepr::getEM()->createQuery($dql)->getSingleScalarResult(); + } +}+ \ No newline at end of file diff --git a/src/de/RaumZeitLabor/PartKeepr/Part/PartManufacturer.php b/src/de/RaumZeitLabor/PartKeepr/Part/PartManufacturer.php @@ -0,0 +1,82 @@ +<?php +namespace de\RaumZeitLabor\PartKeepr\Part; +declare(encoding = 'UTF-8'); + +use de\RaumZeitLabor\PartKeepr\PartKeepr, + de\RaumZeitLabor\PartKeepr\Manufacturer\Manufacturer; + +/** @Entity **/ +class PartManufacturer { + /** + * @Id @Column(type="integer") + * @GeneratedValue(strategy="AUTO") + * @var unknown_type + */ + private $id; + + /** + * @ManyToOne(targetEntity="de\RaumZeitLabor\PartKeepr\Part\Part") + */ + private $part; + + /** + * @ManyToOne(targetEntity="de\RaumZeitLabor\PartKeepr\Manufacturer\Manufacturer") + */ + private $manufacturer; + + /** + * @Column(type="string",nullable=true) + * Enter description here ... + * @var unknown_type + */ + private $partNumber; + + public function __construct (Part $part, Manufacturer $manufacturer) { + $this->setPart($part); + $this->setManufacturer($manufacturer); + } + + public function setPart (Part $part) { + $this->part = $part; + } + + public function getPart () { + return $this->part; + } + + public function setManufacturer (Manufacturer $manufacturer) { + $this->manufacturer = $manufacturer; + } + + public function getManufacturer () { + return $this->manufacturer; + } + + public function setPartNumber ($partNumber) { + $this->partNumber = $partNumber; + } + + public function getPartNumber () { + return $this->partNumber; + } + + public function getId () { + return $this->id; + } + + /** + * Returns the data of this object in a serialized form. + * @return array The result array + */ + public function serialize () { + return array( + "id" => $this->getId(), + "partNumber" => $this->getPartNumber(), + "manufacturer_id" => $this->getManufacturer()->getId(), + "manufacturer_name" => $this->getManufacturer()->getName(), + "part_id" => $this->getPart()->getId(), + "part_name" => $this->getPart()->getName()); + } + + +}+ \ No newline at end of file diff --git a/src/de/RaumZeitLabor/PartKeepr/Part/PartService.php b/src/de/RaumZeitLabor/PartKeepr/Part/PartService.php @@ -0,0 +1,181 @@ +<?php +namespace de\raumzeitlabor\PartKeepr\Part; +use de\RaumZeitLabor\PartKeepr\Service\RestfulService; + +declare(encoding = 'UTF-8'); + +use de\RaumZeitLabor\PartKeepr\Service\Service; +use de\RaumZeitLabor\PartKeepr\Part\PartManager, + de\RaumZeitLabor\PartKeepr\Stock\StockEntry, + de\RaumZeitLabor\PartKeepr\PartKeepr, + de\RaumZeitLabor\PartKeepr\Session\SessionManager; + +class PartService extends Service implements RestfulService { + public function get () { + if ($this->hasParameter("id")) { + return PartManager::getInstance()->getPart($this->getParameter("id"))->serialize(); + } else { + if ($this->hasParameter("sort")) { + $tmp = json_decode($this->getParameter("sort"), true); + + $aSortParams = $tmp[0]; + } else { + $aSortParams = array( + "property" => "name", + "direction" => "ASC"); + } + return PartManager::getInstance()->getParts( + $this->getParameter("start", $this->getParameter("start", 0)), + $this->getParameter("limit", $this->getParameter("limit", 25)), + $this->getParameter("sortby", $aSortParams["property"]), + $this->getParameter("dir", $aSortParams["direction"]), + $this->getParameter("query", ""), + $this->getParameter("category", 0), + $this->getParameter("categoryScope", "all"), + $this->getParameter("stockMode", "all"), + $this->getParameter("withoutPrice", false), + $this->getParameter("storageLocation", "")); + } + } + + public function create () { + throw new \Exception("Not yet implemented"); + } + + public function update () { + throw new \Exception("Not yet implemented"); + } + + public function destroy () { + throw new \Exception("Not yet implemented"); + } + + public function getPartParameterNames () { + $dql = "SELECT pp.name FROM de\RaumZeitLabor\PartKeepr\PartParameter\PartParameter pp GROUP BY pp.name"; + $query = PartKeepr::getEM()->createQuery($dql); + + return array("data" => $query->getArrayResult()); + } + + // Old stuff below + public function getParts () { + $aParameters = array( + "start" => $this->getParameter("start", 0), + "limit" => $this->getParameter("limit", 15), + "sort" => $this->getParameter("sort", "name"), + "dir" => $this->getParameter("dir", "asc"), + "filter" => $this->getParameter("filter", ""), + "category" => $this->getParameter("category", 0), + "stockmode" => $this->getParameter("stockmode", "all") + ); + return PartManager::getInstance()->getParts($aParameters); + } + + public function addStock () { + $part = PartManager::getInstance()->getPart($this->getParameter("part")); + + $user = SessionManager::getCurrentSession()->getUser(); + + $stock = new StockEntry($part, intval($this->getParameter("stock")), $user); + + $price = floatval($this->getParameter("price")); + + if ($price != 0) { + $stock->setPrice($price); + } + + PartKeepr::getEM()->persist($stock); + PartKeepr::getEM()->flush(); + + $part->updateStockLevel(); + + PartKeepr::getEM()->flush(); + + return true; + } + + public function addOrUpdatePart () { + $aParameters = array(); + + $aParameters["part"] = $this->getParameter("part", null); + + if ($this->hasParameter("name")) { + $aParameters["name"] = $this->getParameter("name"); + } + + if ($this->hasParameter("minStockLevel")) { + $aParameters["minstock"] = $this->getParameter("minStockLevel"); + } + + if ($this->hasParameter("storageLocation_id")) { + $aParameters["storagelocation"] = $this->getParameter("storageLocation_id"); + } + + if ($this->hasParameter("category_id")) { + $aParameters["category"] = $this->getParameter("category_id"); + } + + if ($this->hasParameter("footprint_id")) { + $aParameters["footprint"] = $this->getParameter("footprint_id"); + } + + if ($this->hasParameter("comment")) { + $aParameters["comment"] = $this->getParameter("comment"); + } + + if ($this->hasParameter("quantity")) { + $aParameters["quantity"] = $this->getParameter("quantity"); + } + + if ($this->hasParameter("distributorChanges")) { + $aParameters["distributorChanges"] = $this->getParameter("distributorChanges"); + } + + if ($this->hasParameter("manufacturerChanges")) { + $aParameters["manufacturerChanges"] = $this->getParameter("manufacturerChanges"); + } + + if ($this->hasParameter("parameterChanges")) { + $aParameters["parameterChanges"] = $this->getParameter("parameterChanges"); + } + + if ($this->hasParameter("partUnit_id")) { + $aParameters["partUnit"] = $this->getParameter("partUnit_id"); + } + + PartManager::getInstance()->addOrUpdatePart($aParameters); + + return true; + } + + public function deleteStock () { + $part = PartManager::getInstance()->getPart($this->getParameter("part")); + + $user = SessionManager::getCurrentSession()->getUser(); + + $stock = new StockEntry($part, 0-intval($this->getParameter("stock")), $user); + + PartKeepr::getEM()->persist($stock); + PartKeepr::getEM()->flush(); + + $part->updateStockLevel(); + + PartKeepr::getEM()->flush(); + + return true; + } + + public function getPart () { + $part = PartManager::getInstance()->getPart($this->getParameter("part")); + + return $this->serializePart($part); + } + + public function deletePart () { + PartManager::getInstance()->deletePart($this->getParameter("part")); + } + + private function serializePart ($part) { + return $part->serialize(); + } +}+ \ No newline at end of file diff --git a/src/de/RaumZeitLabor/PartKeepr/Part/PartUnit.php b/src/de/RaumZeitLabor/PartKeepr/Part/PartUnit.php @@ -0,0 +1,134 @@ +<?php +namespace de\RaumZeitLabor\PartKeepr\Part; +declare(encoding = 'UTF-8'); + +use de\RaumZeitLabor\PartKeepr\PartKeepr, + de\RaumZeitLabor\PartKeepr\Util\Exceptions\OutOfRangeException; + + +/** @Entity **/ +class PartUnit { + /** + * @Id @Column(type="integer") + * @GeneratedValue(strategy="AUTO") + * @var int + */ + private $id; + + /** + * Defines the name of the unit + * @Column + * @var string + */ + private $name; + + /** + * Defines the short name of the unit + * @Column + * @var string + */ + private $shortName; + + /** + * Defines if the unit is default or not. + * + * @Column(type="boolean") + * @var boolean + */ + private $is_default; + + /** + * @OneToMany(targetEntity="de\RaumZeitLabor\PartKeepr\Part\Part",mappedBy="partUnit") + */ + private $parts; + + + /** + * Creates a new part unit. + * + * Sets the default to false. + */ + public function __construct () { + $this->setDefault(false); + } + + /** + * Sets the name for this unit + * @param string $name The name for this unit + * @return nothing + */ + public function setName ($name) { + $this->name = $name; + } + + /** + * Returns the name for this unit + * @param none + * @return string The name for this unit + */ + public function getName () { + return $this->name; + } + + /** + * Sets the short name for this unit. + * + * Short names are used for list views (e.g. if your unit name is "metres", your short name could be "m") + * @param string $shortName The short name + * @return nothing + */ + public function setShortName ($shortName) { + $this->shortName = $shortName; + } + + /** + * Returns the short name for this unit + * @param none + * @return string The short name for this unit + */ + public function getShortName () { + return $this->shortName; + } + + /** + * Returns the ID for this object. + * @param none + * @return int The ID for this object + */ + public function getId () { + return $this->id; + } + + /** + * Defines if the unit is default or not. + * @param boolean $default True if the unit is default, false otherwise + */ + public function setDefault ($default) { + $this->is_default = (bool)$default; + } + + /** + * Returns if the unit is default or not + * @param none + * @return boolean True if the unit is default, false for not + */ + public function getDefault () { + return $this->is_default; + } + + /** + * Serializes the object and returns it as array, suitable + * to process via json_encode. + * @param none + * @return array An array containing the object information + */ + public function serialize () { + return array( + "id" => $this->getId(), + "name" => $this->getName(), + "shortName" => $this->getShortName(), + "default" => $this->getDefault() + ); + } +} + + \ No newline at end of file diff --git a/src/de/RaumZeitLabor/PartKeepr/PartDistributor/PartDistributorManager.php b/src/de/RaumZeitLabor/PartKeepr/PartDistributor/PartDistributorManager.php @@ -0,0 +1,75 @@ +<?php +namespace de\RaumZeitLabor\PartKeepr\PartDistributor; +declare(encoding = 'UTF-8'); + +use de\RaumZeitLabor\PartKeepr\Util\Singleton, + de\RaumZeitLabor\PartKeepr\Manufacturer\Manufacturer, + de\RaumZeitLabor\PartKeepr\PartKeepr, + de\RaumZeitLabor\PartKeepr\Manufacturer\Exceptions\ManufacturerNotFoundException; + +class PartDistributorManager extends Singleton { + public function getPartDistributors ($start = 0, $limit = 10, $sort = "name", $dir = "asc", $filter = "") { + + $qb = PartKeepr::getEM()->createQueryBuilder(); + $qb->select("pd.orderNumber, part.id AS part_id, dist.id AS distributor_id")->from("de\RaumZeitLabor\PartKeepr\Part\PartDistributor","pd") + ->leftJoin('pd.distributor', "dist") + ->leftJoin("pd.part", "part"); + + /*if ($filter != "") { + $manufacturer = Manufacturer::loadById($filter); + $qb = $qb->where("st.manufacturer = :manufacturer"); + $qb->setParameter("manufacturer", $manufacturer); + }*/ + + if ($limit > -1) { + $qb->setMaxResults($limit); + $qb->setFirstResult($start); + } + + $qb->orderBy("pd.".$sort, $dir); + + $query = $qb->getQuery(); + + $result = $query->getResult(); + + $totalQueryBuilder = PartKeepr::getEM()->createQueryBuilder(); + $totalQueryBuilder->select("COUNT(pd.id)")->from("de\RaumZeitLabor\PartKeepr\Part\PartDistributor","pd"); + + + /* + if ($filter != "") { + $totalQueryBuilder = $totalQueryBuilder->where("st.manufacturer = :manufacturer"); + $totalQueryBuilder->setParameter("manufacturer", $manufacturer); + }*/ + + $totalQuery = $totalQueryBuilder->getQuery(); + + return array("data" => $result, "totalCount" => $totalQuery->getSingleScalarResult()); + } + + public function getPartDistributor ($id) { + $partDistributor = PartKeepr::getEM()->find("de\RaumZeitLabor\PartKeepr\Part\PartDistributor", $id); + + if ($partDistributor) { + return $partDistributor; + } else { + throw new PartDistributorNotFoundException(); + } + } + + public function addPartDistributor ($orderNumber) { + $partDistributor = new PartDistributor(); + $partDistributor->setName($orderNumber); + + PartKeepr::getEM()->persist($partDistributor); + PartKeepr::getEM()->flush(); + + return $partDistributor; + } + public function deletePartDistributor ($id) { + $manufacturer = $this->getManufacturer($id); + + PartKeepr::getEM()->remove($manufacturer); + PartKeepr::getEM()->flush(); + } +}+ \ No newline at end of file diff --git a/src/de/RaumZeitLabor/PartKeepr/PartDistributor/PartDistributorService.php b/src/de/RaumZeitLabor/PartKeepr/PartDistributor/PartDistributorService.php @@ -0,0 +1,88 @@ +<?php +namespace de\RaumZeitLabor\PartKeepr\ManufacturerICLogo; +use de\RaumZeitLabor\PartKeepr\Manufacturer\ManufacturerICLogo; + +use de\RaumZeitLabor\PartKeepr\Image\TempImage; + +use de\RaumZeitLabor\PartKeepr\Service\RestfulService; + +declare(encoding = 'UTF-8'); + +use de\RaumZeitLabor\PartKeepr\Service\Service; +use de\RaumZeitLabor\PartKeepr\PartKeepr, + de\RaumZeitLabor\PartKeepr\Manufacturer\Manufacturer, + de\RaumZeitLabor\PartKeepr\Session\SessionManager; + +class PartDistributorService extends Service implements RestfulService { + public function get () { + if ($this->hasParameter("id")) { + return PartDistributorManager::getInstance()->getManufacturerICLogo($this->getParameter("id"))->serialize(); + } else { + if ($this->hasParameter("sort")) { + $tmp = json_decode($this->getParameter("sort"), true); + + $aSortParams = $tmp[0]; + } else { + $aSortParams = array( + "property" => "id", + "direction" => "ASC"); + } + + $filter = ""; + + if ($this->hasParameter("filter")) { + $tmp = json_decode($this->getParameter("filter"), true); + + foreach ($tmp as $item) { + if (array_key_exists("property", $item)) { + if ($item["property"] == "manufacturer_id") { + if (array_key_exists("value", $item)) { + $filter = $item["value"]; + } + } + } + } + } + return ManufacturerICLogoManager::getInstance()->getManufacturerICLogos( + $this->getParameter("start", $this->getParameter("start", 0)), + $this->getParameter("limit", $this->getParameter("limit", 25)), + $this->getParameter("sortby", $aSortParams["property"]), + $this->getParameter("dir", $aSortParams["direction"]), + $filter); + } + } + + public function create () { + $this->requireParameter("tmp_id"); + $this->requireParameter("manufacturer_id"); + + $tmpImage = TempImage::loadById($this->getParameter("tmp_id")); + + $image = new ManufacturerICLogo(); + + $manufacturer = Manufacturer::loadById($this->getParameter("manufacturer_id")); + + $image->setManufacturer($manufacturer); + $image->replace($tmpImage->getImageFilename()); + PartKeepr::getEM()->persist($image); + PartKeepr::getEM()->flush(); + + return $image->serialize(); + } + + public function update () { + + } + + public function destroy () { + $this->requireParameter("id"); + + $logo = ManufacturerICLogo::loadById($this->getParameter("id")); + + PartKeepr::getEM()->remove($logo); + PartKeepr::getEM()->flush(); + + return array("data" => null); + } + +}+ \ No newline at end of file diff --git a/src/de/RaumZeitLabor/PartKeepr/PartKeepr.php b/src/de/RaumZeitLabor/PartKeepr/PartKeepr.php @@ -0,0 +1,223 @@ +<?php +namespace de\RaumZeitLabor\PartKeepr; + +use Doctrine\Common\ClassLoader, + Doctrine\ORM\Configuration, + Doctrine\ORM\EntityManager, + de\RaumZeitLabor\PartKeepr\Util\Configuration as PartKeeprConfiguration; + + + +class PartKeepr { + /** + * + * Contains the doctrine entity manager. + * @var Doctrine\ORM\EntityManager + */ + private static $entityManager = null; + + /** + * Initializes the PartKeepr system + * + * You *need* to call this method before doing anything else. + * + * An environment is used to load a different configuration file. + * Usually, you don't need to pass anything here. + * + * @param $environment string The environment to use, null otherwise. + * @return nothing + */ + public static function initialize ($environment = null) { + self::initializeClassLoaders(); + self::initializeConfig($environment); + self::initializeDoctrine(); + } + + /** + * Initializes the doctrine class loader and sets up the + * directories. + * + * @param none + * @return nothing + */ + public static function initializeClassLoaders() { + require_once 'Doctrine/Common/ClassLoader.php'; + + + $classLoader = new ClassLoader('de\RaumZeitLabor\PartKeepr', dirname(dirname(dirname(__DIR__)))); + $classLoader->register(); // register on SPL autoload stack + + $classLoader = new ClassLoader('Doctrine\ORM'); + $classLoader->register(); // register on SPL autoload stack + + $classLoader = new ClassLoader('Doctrine\DBAL'); + $classLoader->register(); // register on SPL autoload stack + + $classLoader = new ClassLoader('Doctrine\Common'); + $classLoader->register(); // register on SPL autoload stack + + $classLoader = new ClassLoader('Symfony', 'Doctrine'); + $classLoader->register(); // register on SPL autoload stack + + $classLoader = new ClassLoader("DoctrineExtensions\NestedSet", dirname(dirname(dirname(dirname(__DIR__)))) ."/3rdparty/doctrine2-nestedset/lib"); + $classLoader->register(); + } + + + /** + * Initializes the configuration for a given environment. + * + * An environment is used to load a different configuration file. + * + * Usually, you don't need to pass anything here. + * + * + * @param $environment string The environment to use, null otherwise. + * @return nothing + */ + public static function initializeConfig ($environment = null) { + if ($environment != null) { + include(dirname(dirname(dirname(dirname(__DIR__))))."/config-$environment.php"); + } else { + include(dirname(dirname(dirname(dirname(__DIR__))))."/config.php"); + } + + } + /** + * Initializes the doctrine framework and + * sets all required configuration options. + * + * @param none + * @return nothing + */ + public static function initializeDoctrine () { + + + $config = new Configuration; + + $driverImpl = $config->newDefaultAnnotationDriver( + array(__DIR__) + //array(__DIR__."/Session") + + ); + $config->setMetadataDriverImpl($driverImpl); + + $connectionOptions = array( + 'driver' => PartKeeprConfiguration::getOption("partkeepr.database.driver","pdo_mysql"), + 'dbname' => PartKeeprConfiguration::getOption("partkeepr.database.dbname", "partkeepr"), + 'user' => PartKeeprConfiguration::getOption("partkeepr.database.username", "partkeepr"), + 'password' => PartKeeprConfiguration::getOption("partkeepr.database.password", "partkeepr"), + 'host' => PartKeeprConfiguration::getOption("partkeepr.database.hostname", "localhost") + ); + + $cache = new \Doctrine\Common\Cache\ApcCache(); + $config->setMetadataCacheImpl($cache); + + $config->setQueryCacheImpl($cache); + + //$logger = new \Doctrine\DBAL\Logging\EchoSQLLogger(); + //$config->setSQLLogger($logger); + + /* @todo what's up with this proxy stuff? */ + // Proxy configuration + $config->setProxyDir(dirname(dirname(dirname(__DIR__))) . '/Proxies'); + $config->setProxyNamespace('Proxies'); + $config->setEntityNamespaces(self::getEntityClasses()); + $config->setAutoGenerateProxyClasses(false); + + $logger = new \Doctrine\DBAL\Logging\EchoSQLLogger(); + //$config->setSQLLogger($logger); + + self::$entityManager = EntityManager::create($connectionOptions, $config); + } + + /** + * Returns the EntityManager. Shortcut for getEntityManager(). + * @param none + * @return Doctrine\ORM\EntityManager The EntityManager + */ + public static function getEM () { + return self::getEntityManager(); + } + + /** + * Returns the EntityManager. + * @param none + * @return Doctrine\ORM\EntityManager The EntityManager + */ + public static function getEntityManager () { + if (!self::$entityManager instanceof EntityManager) { + throw new Exception("No EntityManager found. Make sure you called initializeDoctrine() or initialize()."); + } + return self::$entityManager; + } + + public static function getClassMetaData () { + $classes = self::getEntityClasses(); + + $aClasses = array(); + + foreach ($classes as $class) { + $aClasses[] = PartKeepr::getEM()->getClassMetadata($class); + } + + return $aClasses; + } + + public static function getEntityClasses () { + return array( + 'de\RaumZeitLabor\PartKeepr\Auth\User', + 'de\RaumZeitLabor\PartKeepr\Session\Session', + 'de\RaumZeitLabor\PartKeepr\Footprint\Footprint', + 'de\RaumZeitLabor\PartKeepr\Category\Category', + 'de\RaumZeitLabor\PartKeepr\Part\Part', + 'de\RaumZeitLabor\PartKeepr\Part\PartUnit', + 'de\RaumZeitLabor\PartKeepr\Part\PartManufacturer', + 'de\RaumZeitLabor\PartKeepr\Part\PartDistributor', + 'de\RaumZeitLabor\PartKeepr\StorageLocation\StorageLocation', + 'de\RaumZeitLabor\PartKeepr\Stock\StockEntry', + 'de\RaumZeitLabor\PartKeepr\Manufacturer\Manufacturer', + 'de\RaumZeitLabor\PartKeepr\Distributor\Distributor', + 'de\RaumZeitLabor\PartKeepr\Image\Image', + 'de\RaumZeitLabor\PartKeepr\Image\CachedImage', + 'de\RaumZeitLabor\PartKeepr\Image\TempImage', + 'de\RaumZeitLabor\PartKeepr\Manufacturer\ManufacturerICLogo', + 'de\RaumZeitLabor\PartKeepr\Statistic\StatisticSnapshot', + 'de\RaumZeitLabor\PartKeepr\Statistic\StatisticSnapshotUnit', + 'de\RaumZeitLabor\PartKeepr\SiPrefix\SiPrefix', + 'de\RaumZeitLabor\PartKeepr\Unit\Unit', + 'de\RaumZeitLabor\PartKeepr\PartParameter\PartParameter' + ); + } + + /** + *@todo stub + */ + public static function i18n ($string) { + return $string; + } + + public static function createGUIDv4() { + return sprintf('%04x%04x-%04x-%04x-%04x-%04x%04x%04x', + + // 32 bits for "time_low" + mt_rand(0, 0xffff), mt_rand(0, 0xffff), + + // 16 bits for "time_mid" + mt_rand(0, 0xffff), + + // 16 bits for "time_hi_and_version", + // four most significant bits holds version number 4 + mt_rand(0, 0x0fff) | 0x4000, + + // 16 bits, 8 bits for "clk_seq_hi_res", + // 8 bits for "clk_seq_low", + // two most significant bits holds zero and one for variant DCE1.1 + mt_rand(0, 0x3fff) | 0x8000, + + // 48 bits for "node" + mt_rand(0, 0xffff), mt_rand(0, 0xffff), mt_rand(0, 0xffff) + ); + } +} +?>+ \ No newline at end of file diff --git a/src/de/RaumZeitLabor/PartKeepr/PartParameter/PartParameter.php b/src/de/RaumZeitLabor/PartKeepr/PartParameter/PartParameter.php @@ -0,0 +1,221 @@ +<?php +namespace de\RaumZeitLabor\PartKeepr\PartParameter; +declare(encoding = 'UTF-8'); + +use de\RaumZeitLabor\PartKeepr\PartKeepr, + de\RaumZeitLabor\PartKeepr\Util\Exceptions\OutOfRangeException, + de\RaumZeitLabor\PartKeepr\Unit\Unit, + de\RaumZeitLabor\PartKeepr\Part\Part, + de\RaumZeitLabor\PartKeepr\SiPrefix\SiPrefix; + + +/** + * This object represents a parameter. Each parameter can have an unit (defined by the class "Unit") associated with + * a numeric value. + * + * @Entity @HasLifecycleCallbacks + **/ +class PartParameter { + /** + * @Id @Column(type="integer") + * @GeneratedValue(strategy="AUTO") + * @var integer + */ + private $id; + + /** + * @ManyToOne(targetEntity="de\RaumZeitLabor\PartKeepr\Part\Part") + * The part this parameter is bound to + * @var Part + */ + private $part; + + /** + * The name of the parameter (e.g. Resistance, Voltage) + * @Column(type="string") + * @var string + */ + private $name; + + /** + * A description for this parameter + * @Column(type="string") + * @var string + */ + private $description; + + /** + * The unit for this type. May be null. + * + * @ManyToOne(targetEntity="de\RaumZeitLabor\PartKeepr\Unit\Unit") + * @var Unit + */ + private $unit; + + /** + * The value of the unit. Together with the prefix, it becomes the actual value. + * + * Example: If you have 10µ, the value field will contain "10", the prefix object is linked to the SiPrefix + * representing "µ" and the rawValue field will contain 0.000001 + * @Column(type="float") + * @var float + */ + private $value; + + /** + * The SiPrefix of the unit + * @ManyToOne(targetEntity="de\RaumZeitLabor\PartKeepr\SiPrefix\SiPrefix") + * @var object + */ + private $siPrefix; + + /** + * The raw value of the unit. + * @Column(type="float") + * @var float + */ + private $rawValue; + + /** + * Sets the name for this parameter + * @param string $name The name + */ + public function setName ($name) { + $this->name = $name; + } + + /** + * Returns the name for this parameter + * @return string The name for this parameter + */ + public function getName () { + return $this->name; + } + + /** + * Sets the description for this parameter + * @param string $description The description + */ + public function setDescription ($description) { + $this->description = $description; + } + + /** + * Returns the description + * @return string The description + */ + public function getDescription () { + return $this->description; + } + + /** + * Sets the unit + * @param Unit $unit The unit to set + */ + public function setUnit (Unit $unit = null) { + $this->unit = $unit; + } + + /** + * Returns the unit + * @return Unit the unit + */ + public function getUnit () { + return $this->unit; + } + + /** + * Sets the part + * @param Part $part The part to set + */ + public function setPart (Part $part) { + $this->part = $part; + } + + /** + * Returns the part + * @return Part the part + */ + public function getPart () { + return $this->part; + } + + /** + * Sets the value + * @param float $value The value to set + */ + public function setValue ($value) { + $this->value = $value; + + $this->recalculateRawValue(); + } + + /** + * Returns the value + * @return float The value + */ + public function getValue () { + return $this->value; + } + + /** + * Sets the si prefix for this parameter + * @param SiPrefix $prefix The prefix to set, or null + */ + public function setSiPrefix (SiPrefix $prefix = null) { + $this->siPrefix = $prefix; + + $this->recalculateRawValue(); + } + + /** + * Returns the si prefix for this parameter + * @return SiPrefix the si prefix or null + */ + public function getSiPrefix () { + return $this->siPrefix; + } + + /** + * Returns the ID for this object. + * @param none + * @return int The ID for this object + */ + public function getId () { + return $this->id; + } + + private function recalculateRawValue () { + if (is_object($this->getSiPrefix())) { + $power = $this->getSiPrefix()->getPower(); + } else { + $power = 0; + } + + $this->rawValue = $this->getValue() * pow(10, $power); + } + + /** + * Returns the data of this object in a serialized form. + * @return array The result array + */ + public function serialize () { + return array( + "id" => $this->getId(), + "name" => $this->getName(), + "description" => $this->getDescription(), + "value" => $this->getValue(), + "part_id" => $this->getPart()->getId(), + "siprefix_id" => is_object($this->getSiPrefix()) ? $this->getSiPrefix()->getId() : null, + "prefixedValue" => array( + /* We duplicate most data because of strange ExtJS stuff... */ + "value" => $this->getValue(), + "power" => is_object($this->getSiPrefix()) ? $this->getSiPrefix()->getPower() : 0, + "symbol" => is_object($this->getSiPrefix()) ? $this->getSiPrefix()->getSymbol() : "", + "siprefix_id" => is_object($this->getSiPrefix()) ? $this->getSiPrefix()->getId() : null + ), + "unit_id" => is_object($this->getUnit()) ? $this->getUnit()->getId() : null + ); + } +} + + \ No newline at end of file diff --git a/src/de/RaumZeitLabor/PartKeepr/PartUnit/PartUnitManager.php b/src/de/RaumZeitLabor/PartKeepr/PartUnit/PartUnitManager.php @@ -0,0 +1,96 @@ +<?php +namespace de\RaumZeitLabor\PartKeepr\PartUnit; +declare(encoding = 'UTF-8'); + +use de\RaumZeitLabor\PartKeepr\Util\Singleton, + de\RaumZeitLabor\PartKeepr\Part\PartUnit, + de\RaumZeitLabor\PartKeepr\PartKeepr, + de\RaumZeitLabor\PartKeepr\Category\CategoryManager, + de\RaumZeitLabor\PartKeepr\PartUnit\Exceptions\PartUnitNotFoundException; + +class PartUnitManager extends Singleton { + public function getPartUnits ($start = 0, $limit = 10, $sort = "name", $dir = "asc", $filter = "") { + + $qb = PartKeepr::getEM()->createQueryBuilder(); + $qb->select("st.id, st.name, st.shortName, st.is_default AS default")->from("de\RaumZeitLabor\PartKeepr\Part\PartUnit","st"); + + if ($filter != "") { + $qb = $qb->where("st.name LIKE :filter"); + $qb->setParameter("filter", "%".$filter."%"); + } + + if ($limit > -1) { + $qb->setMaxResults($limit); + $qb->setFirstResult($start); + } + + $qb->orderBy("st.".$sort, $dir); + + $query = $qb->getQuery(); + + $result = $query->getResult(); + + foreach ($result as $key => $row) { + foreach ($row as $rowkey => $column) { + if ($rowkey == "default") { + if ($column == 0) { + $result[$key][$rowkey] = false; + } else { + $result[$key][$rowkey] = true; + } + } + } + } + + $totalQueryBuilder = PartKeepr::getEM()->createQueryBuilder(); + $totalQueryBuilder->select("COUNT(st.id)")->from("de\RaumZeitLabor\PartKeepr\Part\PartUnit","st"); + + + + if ($filter != "") { + $totalQueryBuilder = $totalQueryBuilder->where("st.name LIKE :filter"); + $totalQueryBuilder->setParameter("filter", "%".$filter."%"); + } + + $totalQuery = $totalQueryBuilder->getQuery(); + + return array("data" => $result, "totalCount" => $totalQuery->getSingleScalarResult()); + } + + public function getPartUnit ($id) { + $partUnit = PartKeepr::getEM()->find("de\RaumZeitLabor\PartKeepr\Part\PartUnit", $id); + + if ($partUnit) { + return $partUnit; + } else { + throw new PartUnitNotFoundException(); + } + } + + public function deletePartUnit ($id) { + $partUnit = $this->getPartUnit($id); + + PartKeepr::getEM()->remove($partUnit); + PartKeepr::getEM()->flush(); + } + + public function setDefaultPartUnit ($id) { + PartKeepr::getEM()->beginTransaction(); + + $dql = 'UPDATE de\RaumZeitLabor\PartKeepr\Part\PartUnit pu SET pu.is_default = 1 WHERE pu.id = :id'; + PartKeepr::getEM()->createQuery($dql)->setParameter("id", $id)->execute(); + + $dql = 'UPDATE de\RaumZeitLabor\PartKeepr\Part\PartUnit pu SET pu.is_default = 0 WHERE pu.id != :id'; + PartKeepr::getEM()->createQuery($dql)->setParameter("id", $id)->execute(); + + PartKeepr::getEM()->commit(); + } + + public function getUnitCounts () { + $dql = 'SELECT SUM(p.stockLevel) AS stockLevel, pu FROM de\RaumZeitLabor\PartKeepr\Part\PartUnit pu LEFT JOIN pu.parts p GROUP BY pu.id'; + + $result = PartKeepr::getEM()->createQuery($dql)->getResult(); + + return $result; + } +}+ \ No newline at end of file diff --git a/src/de/RaumZeitLabor/PartKeepr/PartUnit/PartUnitService.php b/src/de/RaumZeitLabor/PartKeepr/PartUnit/PartUnitService.php @@ -0,0 +1,81 @@ +<?php +namespace de\RaumZeitLabor\PartKeepr\PartUnit; +use de\RaumZeitLabor\PartKeepr\Service\RestfulService; + +declare(encoding = 'UTF-8'); + +use de\RaumZeitLabor\PartKeepr\Service\Service; +use de\RaumZeitLabor\PartKeepr\PartKeepr, + de\RaumZeitLabor\PartKeepr\Part\PartUnit, + de\RaumZeitLabor\PartKeepr\Session\SessionManager; + +class PartUnitService extends Service implements RestfulService { + public function get () { + if ($this->hasParameter("id")) { + return PartUnitManager::getInstance()->getPartUnit($this->getParameter("id"))->serialize(); + } else { + if ($this->hasParameter("sort")) { + $tmp = json_decode($this->getParameter("sort"), true); + + $aSortParams = $tmp[0]; + } else { + $aSortParams = array( + "property" => "name", + "direction" => "ASC"); + } + return PartUnitManager::getInstance()->getPartUnits( + $this->getParameter("start", $this->getParameter("start", 0)), + $this->getParameter("limit", $this->getParameter("limit", 25)), + $this->getParameter("sortby", $aSortParams["property"]), + $this->getParameter("dir", $aSortParams["direction"]), + $this->getParameter("query", "")); + } + } + + public function create () { + $this->requireParameter("name"); + + $partUnit = new PartUnit; + + $this->setPartUnitData($partUnit); + + PartKeepr::getEM()->persist($partUnit); + PartKeepr::getEM()->flush(); + + return array("data" => $partUnit->serialize()); + } + + private function setPartUnitData (PartUnit $partUnit) { + $partUnit->setName($this->getParameter("name")); + $partUnit->setShortName($this->getParameter("shortName","")); + } + + public function update () { + $this->requireParameter("id"); + $this->requireParameter("name"); + + $partUnit = PartUnitManager::getInstance()->getPartUnit($this->getParameter("id")); + + $this->setPartUnitData($partUnit); + PartKeepr::getEM()->flush(); + + return array("data" => $partUnit->serialize()); + + } + + public function destroy () { + $this->requireParameter("id"); + + PartUnitManager::getInstance()->deletePartUnit($this->getParameter("id")); + + return array("data" => null); + } + + public function setDefault () { + $this->requireParameter("id"); + + $partUnit = PartUnitManager::getInstance()->setDefaultPartUnit($this->getParameter("id")); + + return array("data" => null); + } +}+ \ No newline at end of file diff --git a/src/de/RaumZeitLabor/PartKeepr/REST/ApplicationController.php b/src/de/RaumZeitLabor/PartKeepr/REST/ApplicationController.php @@ -0,0 +1,42 @@ +<?php +namespace de\RaumZeitLabor\PartKeepr\REST; + +// Class taken over from the Sencha example +class ApplicationController { + public $request, $id, $params; + + /** + * dispatch + * Dispatch request to appropriate controller-action by convention according to the HTTP method. + */ + public function dispatch($request) { + $this->request = $request; + $this->id = $request->id; + $this->params = $request->params; + + if ($request->isRestful()) { + return $this->dispatchRestful(); + } + if ($request->action) { + return $this->{$request->action}(); + } + } + + protected function dispatchRestful() { + switch ($this->request->method) { + case 'GET': + return $this->view(); + break; + case 'POST': + return $this->create(); + break; + case 'PUT': + return $this->update(); + break; + case 'DELETE': + return $this->destroy(); + break; + } + } +} + diff --git a/src/de/RaumZeitLabor/PartKeepr/REST/Model.php b/src/de/RaumZeitLabor/PartKeepr/REST/Model.php @@ -0,0 +1,71 @@ +<?php +namespace de\RaumZeitLabor\PartKeepr\REST; + +// Class taken over from the Sencha example +class Model { + public $id, $attributes; + static function create($params) { + $obj = new self(get_object_vars($params)); + $obj->save(); + return $obj; + } + static function find($id) { + global $dbh; + $found = null; + foreach ($dbh->rs() as $rec) { + if ($rec['id'] == $id) { + $found = new self($rec); + break; + } + } + return $found; + } + static function update($id, $params) { + global $dbh; + $rec = self::find($id); + + if ($rec == null) { + return $rec; + } + $rs = $dbh->rs(); + + foreach ($rs as $idx => $row) { + if ($row['id'] == $id) { + $rec->attributes = array_merge($rec->attributes, get_object_vars($params)); + $dbh->update($idx, $rec->attributes); + break; + } + } + return $rec; + } + static function destroy($id) { + global $dbh; + $rec = null; + $rs = $dbh->rs(); + foreach ($rs as $idx => $row) { + if ($row['id'] == $id) { + $rec = new self($dbh->destroy($idx)); + break; + } + } + return $rec; + } + static function all() { + global $dbh; + return $dbh->rs(); + } + + public function __construct($params) { + $this->id = isset($params['id']) ? $params['id'] : null; + $this->attributes = $params; + } + public function save() { + global $dbh; + $this->attributes['id'] = $dbh->pk(); + $dbh->insert($this->attributes); + } + public function to_hash() { + return $this->attributes; + } +} + diff --git a/src/de/RaumZeitLabor/PartKeepr/REST/Request.php b/src/de/RaumZeitLabor/PartKeepr/REST/Request.php @@ -0,0 +1,115 @@ +<?php +namespace de\RaumZeitLabor\PartKeepr\REST; + +// Class taken over from the Sencha example +class Request { + public $restful, $method, $controller, $action, $id, $params; + + public function __construct($params) { + $this->restful = (isset($params["restful"])) ? $params["restful"] : false; + $this->method = $_SERVER["REQUEST_METHOD"]; + $this->parseRequest(); + } + public function isRestful() { + return $this->restful; + } + + public function getMethod () { + return $this->method; + } + + public function getParams () { + if ($this->params === null) { + $this->params = array(); + } + + if ($this->id !== null) { + $this->params["id"] = $this->id; + } + + $this->params = array_merge($_REQUEST, $this->params); + return $this->params; + } + + public function getService () { + if ($this->controller == "") { + $this->controller = $_REQUEST["service"]; + } + + $serviceName = $this->controller."Service"; + $namespace = 'de\RaumZeitLabor\PartKeepr\\'; + $cat = $this->controller . "\\"; + $fullName= $namespace . $cat . $serviceName; + + $class = new $fullName($this->getParams()); + + return $class; + } + + public function getAction () { + return $this->action; + } + + protected function parseRequest() { + if ($this->method == 'PUT') { // <-- Have to jump through hoops to get PUT data + $raw = ''; + $httpContent = fopen('php://input', 'r'); + while ($kb = fread($httpContent, 1024)) { + $raw .= $kb; + } + fclose($httpContent); + $params = array(); + parse_str($raw, $params); + + if (isset($params['data'])) { + $this->params = json_decode($params['data'], true); + } else { + $params = json_decode($raw, true); + $this->params = $params; + } + } else { + // grab JSON data if there... + $this->params = (isset($_REQUEST['data'])) ? json_decode($_REQUEST['data'], true) : null; + + if (isset($_REQUEST['data'])) { + $this->params = json_decode($_REQUEST['data'], true); + } else { + $raw = ''; + $httpContent = fopen('php://input', 'r'); + while ($kb = fread($httpContent, 1024)) { + $raw .= $kb; + } + $params = json_decode($raw, true); + if ($params) { + $this->params = $params; + } + } + + } + // Quickndirty PATH_INFO parser + if (isset($_SERVER["PATH_INFO"])){ + $cai = '/^\/([A-Za-z]+\w)\/([A-Za-z]+\w)\/([0-9]+)$/'; // /controller/action/id + $ca = '/^\/([A-Za-z]+\w)\/([A-Za-z]+)$/'; // /controller/action + $ci = '/^\/([A-Za-z]+\w)\/([0-9]+)$/'; // /controller/id + $c = '/^\/([A-Za-z]+\w)$/'; // /controller + $i = '/^\/([0-9]+)$/'; // /id + $matches = array(); + if (preg_match($cai, $_SERVER["PATH_INFO"], $matches)) { + $this->controller = $matches[1]; + $this->action = $matches[2]; + $this->id = $matches[3]; + } else if (preg_match($ca, $_SERVER["PATH_INFO"], $matches)) { + $this->controller = $matches[1]; + $this->action = $matches[2]; + } else if (preg_match($ci, $_SERVER["PATH_INFO"], $matches)) { + $this->controller = $matches[1]; + $this->id = $matches[2]; + } else if (preg_match($c, $_SERVER["PATH_INFO"], $matches)) { + $this->controller = $matches[1]; + } else if (preg_match($i, $_SERVER["PATH_INFO"], $matches)) { + $this->id = $matches[1]; + } + } + } +} + diff --git a/src/de/RaumZeitLabor/PartKeepr/REST/Response.php b/src/de/RaumZeitLabor/PartKeepr/REST/Response.php @@ -0,0 +1,21 @@ +<?php +namespace de\RaumZeitLabor\PartKeepr\REST; + +// Class taken over from the Sencha example +class Response { + public $success, $data, $message, $errors, $tid, $trace; + + public function __construct($params = array()) { + $this->success = isset($params["success"]) ? $params["success"] : false; + $this->message = isset($params["message"]) ? $params["message"] : ''; + $this->data = isset($params["data"]) ? $params["data"] : array(); + } + + public function to_json() { + return json_encode(array( + 'success' => $this->success, + 'message' => $this->message, + 'data' => $this->data + )); + } +} diff --git a/src/de/RaumZeitLabor/PartKeepr/Service/AdminService.php b/src/de/RaumZeitLabor/PartKeepr/Service/AdminService.php @@ -0,0 +1,17 @@ +<?php +namespace de\RaumZeitLabor\PartKeepr\Service; +use de\RaumZeitLabor\PartKeepr\Session\SessionManager; + +declare(encoding = 'UTF-8'); + +class AdminService extends Service { + public function mayCall ($call) { + if (SessionManager::getCurrentSession()->getUser()->isAdmin()) { + return true; + } else { + return false; + } + } +} + +?>+ \ No newline at end of file diff --git a/src/de/RaumZeitLabor/PartKeepr/Service/AnonService.php b/src/de/RaumZeitLabor/PartKeepr/Service/AnonService.php @@ -0,0 +1,9 @@ +<?php +namespace de\RaumZeitLabor\PartKeepr\Service; +declare(encoding = 'UTF-8'); + +class AnonService extends Service { + +} + +?>+ \ No newline at end of file diff --git a/src/de/RaumZeitLabor/PartKeepr/Service/Exceptions/ServiceException.php b/src/de/RaumZeitLabor/PartKeepr/Service/Exceptions/ServiceException.php @@ -0,0 +1,9 @@ +<?php +namespace de\RaumZeitLabor\PartKeepr\Service\Exceptions; +declare(encoding = 'UTF-8'); + +use de\RaumZeitLabor\PartKeepr\Util\SerializableException; + +class ServiceException extends SerializableException {} + +?>+ \ No newline at end of file diff --git a/src/de/RaumZeitLabor/PartKeepr/Service/RestfulService.php b/src/de/RaumZeitLabor/PartKeepr/Service/RestfulService.php @@ -0,0 +1,10 @@ +<?php +namespace de\RaumZeitLabor\PartKeepr\Service; +declare(encoding = 'UTF-8'); + +interface RestfulService { + public function get (); + public function create (); + public function update (); + public function destroy (); +}+ \ No newline at end of file diff --git a/src/de/RaumZeitLabor/PartKeepr/Service/Service.php b/src/de/RaumZeitLabor/PartKeepr/Service/Service.php @@ -0,0 +1,68 @@ +<?php +namespace de\RaumZeitLabor\PartKeepr\Service; +use de\RaumZeitLabor\PartKeepr\Session\Session; + +declare(encoding = 'UTF-8'); + +use de\RaumZeitLabor\PartKeepr\Session\SessionManager, + de\RaumZeitLabor\PartKeepr\Service\Exceptions\ServiceException; + +class Service { + private $params; + + public function __construct (Array $params) { + $this->params = $params; + } + + public function mayCall ($call) { + if (SessionManager::getCurrentSession()->getUser() === null) { + return false; + } else { + /* @todo: Implement permission checking */ + return true; + } + + + } + + protected function requireParameter ($name) { + if (!$this->hasParameter($name)) { + throw new ServiceException(sprintf("Parameter %s is required.", $name)); + } + } + + public function getParameter ($name, $default = null) { + if (!$this->hasParameter($name)) { + return $default; + } else { + return $this->params[$name]; + } + } + + public function hasParameter ($name) { + if (array_key_exists($name, $this->params)) { + return true; + } else { + return false; + } + } + + public function hasHeader ($name) { + $targetName = "HTTP_".strtoupper($name); + + return array_key_exists($targetName, $_SERVER); + } + + public function getHeader ($name) { + $targetName = "HTTP_".strtoupper($name); + + if (array_key_exists($targetName, $_SERVER)) { + return $_SERVER[$targetName]; + } else { + throw new \Exception("Header ".$targetName." not found"); + } + } +} + + +?>+ \ No newline at end of file diff --git a/src/de/RaumZeitLabor/PartKeepr/Service/ServiceManager.php b/src/de/RaumZeitLabor/PartKeepr/Service/ServiceManager.php @@ -0,0 +1,85 @@ +<?php +namespace de\RaumZeitLabor\PartKeepr\Service; +use de\RaumZeitLabor\PartKeepr\Session\SessionManager; + +declare(encoding = 'UTF-8'); + +use de\RaumZeitLabor\PartKeepr\Service\Exceptions\ServiceException, + de\RaumZeitLabor\PartKeepr\PartKeepr, + de\RaumZeitLabor\PartKeepr\REST\Request; + +class ServiceManager { + + public static function call () { + + $request = new Request(array('restful' => true)); + $service = $request->getService(); + + //print_r($request->action); + + if ($service->hasHeader("call")) { + $call = $service->getHeader("call"); + } elseif (array_key_exists("call", $_REQUEST) && $_REQUEST["call"] != "") { + $call = $_REQUEST["call"]; + } elseif ($request->action != "") { + $call = $request->action; + } else { + switch (strtoupper($request->getMethod())) { + case "POST": + $call = "create"; + break; + case "GET": + $call = "get"; + break; + case "PUT": + $call = "update"; + break; + case "DELETE": + $call = "destroy"; + break; + default: + $call = $request->getMethod(); + break; + } + } + + $allowCall = true; + + if (!is_subclass_of($service, "de\\RaumZeitLabor\\PartKeepr\\Service\\AnonService")) { + + $session = null; + if ($service->hasHeader("session")) { + $sessionid = $service->getHeader("session"); + } + + if (array_key_exists("session", $_REQUEST) && $session === null) { + $sessionid = $_REQUEST["session"]; + } + if ($sessionid === null) + { + $session = SessionManager::getInstance()->startSession(); + throw new ServiceException("You called a non-anonymous service, but did not pass the 'session' parameter."); + } else { + $session = SessionManager::getInstance()->resumeSession($sessionid); + } + + if (!$service->mayCall($call)) { + $allowCall = false; + } + } + + if (!$allowCall) { + throw new ServiceException("Permission denied"); + } + + $result = $service->$call(); + + PartKeepr::getEM()->flush(); + + return $result; + + } + +} + +?>+ \ No newline at end of file diff --git a/src/de/RaumZeitLabor/PartKeepr/Session/Exceptions/SessionNotFoundException.php b/src/de/RaumZeitLabor/PartKeepr/Session/Exceptions/SessionNotFoundException.php @@ -0,0 +1,11 @@ +<?php +namespace de\RaumZeitLabor\PartKeepr\Session\Exceptions; +declare(encoding = 'UTF-8'); + +use de\RaumZeitLabor\PartKeepr\Util\SerializableException; + +class SessionNotFoundException extends SerializableException { + public function __construct ($id) { + parent::__construct("The session with the id $id could not be found"); + } +}+ \ No newline at end of file diff --git a/src/de/RaumZeitLabor/PartKeepr/Session/Session.php b/src/de/RaumZeitLabor/PartKeepr/Session/Session.php @@ -0,0 +1,51 @@ +<?php +namespace de\RaumZeitLabor\PartKeepr\Session; +declare(encoding = 'UTF-8'); + +use de\RaumZeitLabor\PartKeepr\Auth\User; + +/** @Entity */ +class Session { + + /** @Id @Column(type="integer") + * @GeneratedValue(strategy="AUTO") + */ + private $id; + + /** @Column(length=50) */ + private $sessionid; + + /** + * @ManyToOne(targetEntity="de\RaumZeitLabor\PartKeepr\Auth\User") + */ + private $user; + + public function __construct () { + + } + + public function start () { + session_start(); + + $this->sessionid = session_id(); + } + + public function getSessionID () { + return $this->sessionid; + } + + public function resume () { + session_id($this->sessionid); + session_start(); + } + + public function getUser () { + return $this->user; + } + + public function setUser (User $user) { + $this->user = $user; + } + +} +?>+ \ No newline at end of file diff --git a/src/de/RaumZeitLabor/PartKeepr/Session/SessionManager.php b/src/de/RaumZeitLabor/PartKeepr/Session/SessionManager.php @@ -0,0 +1,59 @@ +<?php +namespace de\RaumZeitLabor\PartKeepr\Session; +declare(encoding = 'UTF-8'); + +use de\RaumZeitLabor\PartKeepr\Util\Singleton, + de\RaumZeitLabor\PartKeepr\Auth\User, + de\RaumZeitLabor\PartKeepr\Session\Exceptions\SessionNotFoundException, + de\RaumZeitLabor\PartKeepr\PartKeepr; + +class SessionManager extends Singleton { + public static $currentSession = null; + + public static function getCurrentSession () { + return self::$currentSession; + } + + public function startSession (User $user = null) { + if (is_object($user)) { + try { + $query = PartKeepr::getEM()->createQuery("SELECT s FROM de\\RaumZeitLabor\\PartKeepr\\Session\\Session s WHERE s.user = :user"); + $query->setParameter("user", $user); + $query->execute(); + + $session = $query->getSingleResult(); + $session->resume(); + } catch (\Exception $e) { + $session = new Session; + $session->setUser($user); + $session->start(); + PartKeepr::getEM()->persist($session); + } + } else { + $session = new Session; + $session->setUser($user); + $session->start(); + PartKeepr::getEM()->persist($session); + } + + self::$currentSession = $session; + + return $session; + } + + public function resumeSession ($session) { + $query = PartKeepr::getEM()->createQuery("SELECT s FROM de\\RaumZeitLabor\\PartKeepr\\Session\\Session s WHERE s.sessionid = :session"); + $query->setParameter("session", $session); + $query->execute(); + try { + self::$currentSession = $query->getSingleResult(); + return self::$currentSession; + } catch (\Doctrine\ORM\NonUniqueResultException $e) { + throw new \Exception("Fatal error: Multiple sessions with id $session found."); + } catch (\Doctrine\ORM\NoResultException $e) { + throw new SessionNotFoundException($session); + } + + } +} +?>+ \ No newline at end of file diff --git a/src/de/RaumZeitLabor/PartKeepr/SiPrefix/SiPrefix.php b/src/de/RaumZeitLabor/PartKeepr/SiPrefix/SiPrefix.php @@ -0,0 +1,115 @@ +<?php +namespace de\RaumZeitLabor\PartKeepr\SiPrefix; +declare(encoding = 'UTF-8'); + +use de\RaumZeitLabor\PartKeepr\PartKeepr, + de\RaumZeitLabor\PartKeepr\Util\Exceptions\OutOfRangeException; + + +/** @Entity **/ +class SiPrefix { + /** + * @Id @Column(type="integer") + * @GeneratedValue(strategy="AUTO") + * @var integer + */ + private $id; + + /** + * The prefix of the Si-Prefix (e.g. yotta, deca, deci, centi) + * @Column(type="string") + * @var string + */ + private $prefix; + + /** + * The symbol of the Si-Prefix (e.g. m, M, G) + * @Column(type="string",length=2) + * @var string + */ + private $symbol; + + /** + * The power of the Si-Prefix (e.g. milli = 10^-3) + * @Column(type="integer") + * @var int + */ + private $power; + + /** + * Sets the prefix name. + * @param string $prefix + */ + public function setPrefix ($prefix) { + $this->prefix = $prefix; + } + + /** + * Returns the prefix name + * @return string The prefix name + */ + public function getPrefix () { + return $this->prefix; + } + + /** + * Sets the symbol for the prefix + * @param string $symbol The symbol + */ + public function setSymbol ($symbol) { + $this->symbol = $symbol; + } + + /** + * Returns the symbol for the prefix + * @return string The symbol + */ + public function getSymbol () { + return $this->symbol; + } + + /** + * Sets the power in a 10^n power (n=power) + * @param int $power The 10^power + */ + public function setPower ($power) { + $this->power = $power; + } + + /** + * Returns the power (10^n) + * @return int The power + */ + public function getPower () { + return $this->power; + } + + /** + * Returns the ID for this object. + * @param none + * @return int The ID for this object + */ + public function getId () { + return $this->id; + } + + /** + * Serializes the object into an array format. + * @return array the object in serialized format. + */ + public function serialize () { + return array( + "id" => $this->getId(), + "symbol" => $this->getSymbol(), + "prefix" => $this->getPrefix(), + "power" => $this->getPower()); + } + + /** + * Loads a prefix by ID + * @param int $id The ID to load + */ + public static function loadById ($id) { + return PartKeepr::getEM()->find(get_called_class(), $id); + } +}+ \ No newline at end of file diff --git a/src/de/RaumZeitLabor/PartKeepr/SiPrefix/SiPrefixService.php b/src/de/RaumZeitLabor/PartKeepr/SiPrefix/SiPrefixService.php @@ -0,0 +1,29 @@ +<?php +namespace de\RaumZeitLabor\PartKeepr\SiPrefix; +use de\RaumZeitLabor\PartKeepr\Service\RestfulService; + +declare(encoding = 'UTF-8'); + +use de\RaumZeitLabor\PartKeepr\Service\Service; +use de\RaumZeitLabor\PartKeepr\PartKeepr, + de\RaumZeitLabor\PartKeepr\Session\SessionManager; + +class SiPrefixService extends Service implements RestfulService { + public function get () { + $query = PartKeepr::getEM()->createQuery("SELECT si.id, si.prefix, si.symbol, si.power FROM de\RaumZeitLabor\PartKeepr\SiPrefix\SiPrefix si"); + + return array("data" => $query->getArrayResult()); + } + + public function create () { + throw new \Exception("Not yet implemented"); + } + + public function update () { + throw new \Exception("Not yet implemented"); + } + + public function destroy () { + throw new \Exception("Not yet implemented"); + } +} diff --git a/src/de/RaumZeitLabor/PartKeepr/Statistic/StatisticService.php b/src/de/RaumZeitLabor/PartKeepr/Statistic/StatisticService.php @@ -0,0 +1,37 @@ +<?php +namespace de\RaumZeitLabor\PartKeepr\Statistic; +declare(encoding = 'UTF-8'); + +use de\RaumZeitLabor\PartKeepr\Service\Service; +use de\RaumZeitLabor\PartKeepr\PartKeepr, + de\RaumZeitLabor\PartKeepr\Part\PartManager, + de\RaumZeitLabor\PartKeepr\Category\CategoryManager, + de\RaumZeitLabor\PartKeepr\PartUnit\PartUnitManager; + +class StatisticService extends Service { + public function getCurrentStats () { + + $aData = array(); + $aData["partCount"] = PartManager::getInstance()->getPartCount(); + $aData["categoryCount"] = CategoryManager::getInstance()->getCategoryCount(); + $aData["totalPrice"] = PartManager::getInstance()->getTotalPrice(); + $aData["averagePrice"] = PartManager::getInstance()->getAveragePrice(); + $aData["partsWithPrice"] = PartManager::getInstance()->getPartCount(true); + $aData["partsWithoutPrice"] = $aData["partCount"] - $aData["partsWithPrice"]; + + $result = PartUnitManager::getInstance()->getUnitCounts(); + + $aUnits = array(); + + foreach ($result as $row) { + $aUnits[] = array( + "name" => $row[0]->getName(), + "stockLevel" => $row["stockLevel"]); + } + + $aData["units"] = $aUnits; + + return $aData; + } + +}+ \ No newline at end of file diff --git a/src/de/RaumZeitLabor/PartKeepr/Statistic/StatisticSnapshot.php b/src/de/RaumZeitLabor/PartKeepr/Statistic/StatisticSnapshot.php @@ -0,0 +1,111 @@ +<?php +namespace de\RaumZeitLabor\PartKeepr\Statistic; +declare(encoding = 'UTF-8'); + +use de\RaumZeitLabor\PartKeepr\PartKeepr; + + +/** @Entity **/ +class StatisticSnapshot { + /** + * @Id @Column(type="integer") + * @GeneratedValue(strategy="AUTO") + * @var integer + */ + private $id; + + /** + * Defines the date when this snapshot has been taken + * @Column(type="datetime") + * @var DateTime + */ + private $dateTime; + + /** + * Defines the amount of different parts in the database + * @Column(type="integer") + * @var int + */ + private $parts; + + /** + * Defines the amount of categories + * @Column(type="integer") + * @var int + */ + private $categories; + + /** + * Holds all defined units in the database + * @OneToMany(targetEntity="de\RaumZeitLabor\PartKeepr\Statistic\StatisticSnapshotUnit",mappedBy="statisticSnapshot",cascade={"persist", "remove"}) + */ + private $units; + + /** + * Creates a new statistic snapshot + */ + public function __construct () { + $this->units = new \Doctrine\Common\Collections\ArrayCollection(); + $this->setDateTime(new \DateTime()); + } + + /** + * Sets the date+time for the snapshot + * @param \DateTime $dateTime The date+time for the snapshot + */ + public function setDateTime (\DateTime $dateTime) { + $this->dateTime = $dateTime; + } + + /** + * Returns the date+time for the snapshot + * @return DateTime The date+time for the snapshot + */ + public function getDateTime () { + return $this->dateTime; + } + + /** + * Sets the amount of overall parts for the snapshot + * @param int $parts The amount of parts + */ + public function setParts ($parts) { + $this->parts = $parts; + } + + /** + * Returns the amount of overall parts for the snapshot + * @return int The amount of parts + */ + public function getParts () { + return $this->parts; + } + + /** + * Sets the amount of categories for the snapshot + * @param int $categories The amount of categories + */ + public function setCategories ($categories) { + $this->categories = $categories; + } + + /** + * Returns the amount of categories + * @return int The amount of categories + */ + public function getCategories () { + return $this->categories; + } + + /** + * Returns the ID of this snapshot + * @return int The ID of this snapshot + */ + public function getId () { + return $this->id; + } + + public function getUnits () { + return $this->units; + } +}+ \ No newline at end of file diff --git a/src/de/RaumZeitLabor/PartKeepr/Statistic/StatisticSnapshotManager.php b/src/de/RaumZeitLabor/PartKeepr/Statistic/StatisticSnapshotManager.php @@ -0,0 +1,33 @@ +<?php +namespace de\RaumZeitLabor\PartKeepr\Statistic; +declare(encoding = 'UTF-8'); + +use de\RaumZeitLabor\PartKeepr\Util\Singleton, + de\RaumZeitLabor\PartKeepr\Part\PartUnit, + de\RaumZeitLabor\PartKeepr\Part\PartManager, + de\RaumZeitLabor\PartKeepr\PartUnit\PartUnitManager, + de\RaumZeitLabor\PartKeepr\PartKeepr, + de\RaumZeitLabor\PartKeepr\Category\CategoryManager, + de\RaumZeitLabor\PartKeepr\PartUnit\Exceptions\PartUnitNotFoundException; + +class StatisticSnapshotManager extends Singleton { + public function createSnapshot () { + + $snapshot = new StatisticSnapshot(); + $snapshot->setParts(PartManager::getInstance()->getPartCount()); + $snapshot->setCategories(CategoryManager::getInstance()->getCategoryCount()); + + $result = PartUnitManager::getInstance()->getUnitCounts(); + + foreach ($result as $row) { + $snapshotUnit = new StatisticSnapshotUnit(); + $snapshotUnit->setPartUnit($row[0]); + $snapshotUnit->setStatisticSnapshot($snapshot); + $snapshotUnit->setStockLevel($row["stockLevel"]); + $snapshot->getUnits()->add($snapshotUnit); + } + + PartKeepr::getEM()->persist($snapshot); + PartKeepr::getEM()->flush(); + } +}+ \ No newline at end of file diff --git a/src/de/RaumZeitLabor/PartKeepr/Statistic/StatisticSnapshotUnit.php b/src/de/RaumZeitLabor/PartKeepr/Statistic/StatisticSnapshotUnit.php @@ -0,0 +1,98 @@ +<?php +namespace de\RaumZeitLabor\PartKeepr\Statistic; + +use de\RaumZeitLabor\PartKeepr\Statistic\StatisticSnapshot; +use de\RaumZeitLabor\PartKeepr\Part\PartUnit; + +declare(encoding = 'UTF-8'); + +use de\RaumZeitLabor\PartKeepr\PartKeepr; + + +/** @Entity **/ +class StatisticSnapshotUnit { + /** + * @Id @Column(type="integer") + * @GeneratedValue(strategy="AUTO") + * @var integer + */ + private $id; + + /** + * @ManyToOne(targetEntity="de\RaumZeitLabor\PartKeepr\Statistic\StatisticSnapshot") + * The statistic snapshot this entity belongs to + * @var StatisticSnapshot + */ + private $statisticSnapshot; + + /** + * @ManyToOne(targetEntity="de\RaumZeitLabor\PartKeepr\Part\PartUnit") + * The statistic snapshot this entity belongs to + * @var StatisticSnapshot + */ + private $partUnit; + + /** + * The stockLevel for the unit + * @Column(type="integer") + * @var int + */ + private $stockLevel; + + /** + * Sets the statistic snapshot this entity belongs to + * @param StatisticSnapshot $snapshot The snapshot + */ + public function setStatisticSnapshot (StatisticSnapshot $snapshot) { + $this->statisticSnapshot = $snapshot; + } + + /** + * Returns the snapshot this entity belongs to + * @return StatisticSnapshot The snapshot + */ + public function getStatisticSnapshot () { + return $this->statisticSnapshot; + } + + /** + * + * Sets the part unit for this entity + * @param PartUnit $unit The part unit + */ + public function setPartUnit (PartUnit $unit) { + $this->partUnit = $unit; + } + + /** + * Returns the part unit for this entity + * @return PartUnit The part unit + */ + public function getPartUnit () { + return $this->partUnit; + } + + /** + * Returns the ID of this statistic snapshot unit + * @return int The ID + */ + public function getId () { + return $this->id; + } + + /** + * Sets the stock level for this unit snapshot + * @param int $stockLevel + */ + public function setStockLevel ($stockLevel) { + $this->stockLevel = $stockLevel; + } + + /** + * Returns the stock level for this unit snapshot + * @return int The stock level + */ + public function getStockLevel () { + return $this->stockLevel; + } +}+ \ No newline at end of file diff --git a/src/de/RaumZeitLabor/PartKeepr/Stock/StockEntry.php b/src/de/RaumZeitLabor/PartKeepr/Stock/StockEntry.php @@ -0,0 +1,192 @@ +<?php +namespace de\RaumZeitLabor\PartKeepr\Stock; +declare(encoding = 'UTF-8'); + +use de\RaumZeitLabor\PartKeepr\Part\Part; +use de\RaumZeitLabor\PartKeepr\Auth\User; +use de\RaumZeitLabor\PartKeepr\PartKeepr; + +/** @Entity @HasLifecycleCallbacks **/ +class StockEntry { + + /** + * @Id @Column(type="integer") + * @GeneratedValue(strategy="AUTO") + * @var unknown_type + */ + private $id; + + /** + * @Column(type="integer") + */ + private $stockLevel; + + /** + * @ManyToOne(targetEntity="de\RaumZeitLabor\PartKeepr\Part\Part") + */ + private $part; + + /** + * @ManyToOne(targetEntity="de\RaumZeitLabor\PartKeepr\Auth\User") + */ + private $user; + + /** + * @Column(type="decimal",precision=5, scale=2,nullable=true) + * @var float + */ + private $price; + + /** + * @Column(type="datetime") + * @var DateTime + */ + private $dateTime; + + /** + * Creates a new stock entry. A stock entry tracks how many parts + * were the stockLevel is the amount of items added/removed, + * by which user and how much the user paid for it (for adding parts only!) + * + * @param Part $part The part which was added/removed + * @param int $stockLevel The stock level. Positive value means added parts, negative values means removed parts. + * @param User $user The user who removed/added parts + */ + public function __construct (Part $part, $stockLevel, User $user = null) { + $this->setPart($part); + $this->setStockLevel($stockLevel); + $this->setUser($user); + $this->setDateTime(new \DateTime()); + } + + + /** + * Sets the date+time + * @param \DateTime $dateTime The date+time + */ + private function setDateTime (\DateTime $dateTime) { + $this->dateTime = $dateTime; + } + + /** + * Returns the date+time when the record was created. + * @return \DateTime The date+time when the record was created + */ + public function getDateTime () { + return $this->dateTime; + } + + /** + * Sets the price for the item stored. + * + * Please note that the price is for a single item only, and can be null. + * @param float $price The price to set + */ + public function setPrice ($price) { + $this->price = $price; + } + + /** + * Returns the price for this entry. The price is for a single item only. + * + * @return float The price for this entry. + */ + public function getPrice () { + return $this->price; + } + + /** + * Sets the stock level for this entry. + * + * Negative values means part removal, positive values means part adding. + * @param int $stockLevel The stock level + */ + public function setStockLevel($stockLevel) { + $this->stockLevel = $stockLevel; + } + + /** + * Returns the stock level for this entry. + * @return int The stock level + */ + public function getStockLevel () { + return $this->stockLevel; + } + + /** + * Sets the part assigned to this entry. + * @param Part $part The part to set + */ + public function setPart (Part $part) { + $this->part = $part; + } + + /** + * Sets the user assigned to this entry. + * @param User $user The user The user to set + */ + public function setUser (User $user = null) { + $this->user = $user; + } + + /** + * Returns the user for this entry + * @return User the user + */ + public function getUser () { + return $this->user; + } + + /** + * Returns the ID for this entity. + * @return int The ID + */ + public function getId () { + return $this->id; + } + + /** + * If the stock level is negative, we can't have a price. + * @PrePersist + */ + public function checkPrice () { + if ($this->getStockLevel() < 0 && $this->getPrice() !== null) { + $this->setPrice(null); + } + } + + /** + * Updates the stock leve for a part + * @PostPersist + */ + public function postPersist () { + $this->updateStockLevel(); + $this->updatePrice(); + } + + + public function updateStockLevel () { + $query = PartKeepr::getEM()->createQuery("SELECT SUM(se.stockLevel) FROM de\RaumZeitLabor\PartKeepr\Stock\StockEntry se WHERE se.part = :part"); + $query->setParameter("part", $this->part); + $val = $query->getSingleScalarResult(); + + $query = PartKeepr::getEM()->createQuery('UPDATE de\RaumZeitLabor\PartKeepr\Part\Part p SET p.stockLevel = :val WHERE p = :part'); + $query->setParameter("val", $val); + $query->setParameter("part", $this->part); + $query->execute(); + } + + /** + * Updates the average price for a part + */ + public function updatePrice () { + $query = PartKeepr::getEM()->createQuery("SELECT SUM(se.price*se.stockLevel) / SUM(se.stockLevel) FROM de\RaumZeitLabor\PartKeepr\Stock\StockEntry se WHERE se.part = :part AND se.stockLevel > 0"); + $query->setParameter("part", $this->part); + $val = $query->getSingleScalarResult(); + + $query = PartKeepr::getEM()->createQuery('UPDATE de\RaumZeitLabor\PartKeepr\Part\Part p SET p.averagePrice = :val WHERE p = :part'); + $query->setParameter("val", $val); + $query->setParameter("part", $this->part); + $query->execute(); + } +}+ \ No newline at end of file diff --git a/src/de/RaumZeitLabor/PartKeepr/Stock/StockService.php b/src/de/RaumZeitLabor/PartKeepr/Stock/StockService.php @@ -0,0 +1,51 @@ +<?php +namespace de\raumzeitlabor\PartKeepr\Stock; + +declare(encoding = 'UTF-8'); + +use de\RaumZeitLabor\PartKeepr\Stock\StockEntry, + de\RaumZeitLabor\PartKeepr\PartKeepr, + de\RaumZeitLabor\PartKeepr\Service\RestfulService, + de\RaumZeitLabor\PartKeepr\Service\Service;; + + +class StockService extends Service implements RestfulService { + public function get () { + $qb = PartKeepr::getEM()->createQueryBuilder(); + + $qb->select("se")->from("de\RaumZeitLabor\PartKeepr\Stock\StockEntry","se") + ->where("se.part = :part") + ->orderBy("se.dateTime", "DESC") + ->setParameter("part", $this->getParameter("item")); + + $results = $qb->getQuery()->getResult(); + + $aData = array(); + + foreach ($results as $result) { + $aData[] = array( + "username" => is_object($result->getUser()) ? $result->getUser()->getUsername() : PartKeepr::i18n("Unknown User"), + "amount" => abs($result->getStockLevel()), + "datetime" => $result->getDateTime()->format("Y-m-d H:i:s"), + "id" => $result->getId(), + "direction" => ($result->getStockLevel() < 0) ? "out" : "in", + "price" => $result->getPrice() + ); + } + + + return array("data" => $aData); + } + + public function create () { + throw new \Exception("Not yet implemented"); + } + + public function update () { + throw new \Exception("Not yet implemented"); + } + + public function destroy () { + throw new \Exception("Not yet implemented"); + } +}+ \ No newline at end of file diff --git a/src/de/RaumZeitLabor/PartKeepr/StorageLocation/Exceptions/StorageLocationNotFoundException.php b/src/de/RaumZeitLabor/PartKeepr/StorageLocation/Exceptions/StorageLocationNotFoundException.php @@ -0,0 +1,12 @@ +<?php +namespace de\RaumZeitLabor\PartKeepr\StorageLocation\Exceptions; + +use de\RaumZeitLabor\PartKeepr\Util\SerializableException, + de\RaumZeitLabor\PartKeepr\PartKeepr; + +class StorageLocationNotFoundException extends SerializableException { + public function __construct () { + parent::__construct(PartKeepr::i18n("Storage Location not found.")); + } +} +?>+ \ No newline at end of file diff --git a/src/de/RaumZeitLabor/PartKeepr/StorageLocation/StorageLocation.php b/src/de/RaumZeitLabor/PartKeepr/StorageLocation/StorageLocation.php @@ -0,0 +1,34 @@ +<?php +namespace de\RaumZeitLabor\PartKeepr\StorageLocation; +declare(encoding = 'UTF-8'); + +/** @Entity **/ +class StorageLocation { + + /** + * @Id @Column(type="integer") + * @GeneratedValue(strategy="AUTO") + * @var unknown_type + */ + private $id; + + /** + * @Column(type="string",unique=true) + */ + private $name; + + public function setName ($name) { + $this->name = $name; + } + + public function getName () { + return $this->name; + } + public function getId () { + return $this->id; + } + + public function serialize () { + return array("id" => $this->id, "name" => $this->name); + } +}+ \ No newline at end of file diff --git a/src/de/RaumZeitLabor/PartKeepr/StorageLocation/StorageLocationManager.php b/src/de/RaumZeitLabor/PartKeepr/StorageLocation/StorageLocationManager.php @@ -0,0 +1,88 @@ +<?php +namespace de\RaumZeitLabor\PartKeepr\StorageLocation; +declare(encoding = 'UTF-8'); + +use de\RaumZeitLabor\PartKeepr\Util\Singleton, + de\RaumZeitLabor\PartKeepr\StorageLocation\StorageLocation, + de\RaumZeitLabor\PartKeepr\PartKeepr, + de\RaumZeitLabor\PartKeepr\Category\CategoryManager, + de\RaumZeitLabor\PartKeepr\StorageLocation\Exceptions\StorageLocationNotFoundException; + +class StorageLocationManager extends Singleton { + public function getStorageLocations ($start = 0, $limit = 10, $sort = "footprint", $dir = "asc", $filter = "") { + + $qb = PartKeepr::getEM()->createQueryBuilder(); + $qb->select("st.id, st.name")->from("de\RaumZeitLabor\PartKeepr\StorageLocation\StorageLocation","st"); + + if ($filter != "") { + $qb = $qb->where("st.name LIKE :filter"); + $qb->setParameter("filter", "%".$filter."%"); + } + + if ($limit > -1) { + $qb->setMaxResults($limit); + $qb->setFirstResult($start); + } + + $qb->orderBy("st.".$sort, $dir); + + $query = $qb->getQuery(); + + $result = $query->getResult(); + + $totalQueryBuilder = PartKeepr::getEM()->createQueryBuilder(); + $totalQueryBuilder->select("COUNT(st.id)")->from("de\RaumZeitLabor\PartKeepr\StorageLocation\StorageLocation","st"); + + + + if ($filter != "") { + $totalQueryBuilder = $totalQueryBuilder->where("st.name LIKE :filter"); + $totalQueryBuilder->setParameter("filter", "%".$filter."%"); + } + + $totalQuery = $totalQueryBuilder->getQuery(); + + return array("data" => $result, "start" => $start, "totalCount" => $totalQuery->getSingleScalarResult()); + } + + public function getStorageLocation ($id) { + $storageLocation = PartKeepr::getEM()->find("de\RaumZeitLabor\PartKeepr\StorageLocation\StorageLocation", $id); + + if ($storageLocation) { + return $storageLocation; + } else { + throw new StorageLocationNotFoundException(); + } + } + + public function addStorageLocation ($name) { + $storageLocation = new StorageLocation(); + $storageLocation->setName($name); + + PartKeepr::getEM()->persist($storageLocation); + PartKeepr::getEM()->flush(); + + return $storageLocation; + } + public function deleteStorageLocation ($id) { + $storageLocation = $this->getStorageLocation($id); + + PartKeepr::getEM()->remove($storageLocation); + PartKeepr::getEM()->flush(); + } + + public function getOrCreateStorageLocation ($storageLocation) { + if (is_int($storageLocation)) { + try { + return $this->getStorageLocation($storageLocation); + } catch (StorageLocationNotFoundException $e) {} + } + + $sl = new StorageLocation(); + $sl->setName($storageLocation); + + PartKeepr::getEM()->persist($sl); + + return $sl; + } +}+ \ No newline at end of file diff --git a/src/de/RaumZeitLabor/PartKeepr/StorageLocation/StorageLocationService.php b/src/de/RaumZeitLabor/PartKeepr/StorageLocation/StorageLocationService.php @@ -0,0 +1,105 @@ +<?php +namespace de\RaumZeitLabor\PartKeepr\StorageLocation; +use de\RaumZeitLabor\PartKeepr\Service\RestfulService; + +declare(encoding = 'UTF-8'); + +use de\RaumZeitLabor\PartKeepr\Service\Service; +use de\RaumZeitLabor\PartKeepr\Part\PartManager, + de\RaumZeitLabor\PartKeepr\Stock\StockEntry, + de\RaumZeitLabor\PartKeepr\PartKeepr, + de\RaumZeitLabor\PartKeepr\Session\SessionManager; + +class StorageLocationService extends Service implements RestfulService { + + public function get () { + if ($this->hasParameter("id")) { + return StorageLocationManager::getInstance()->getStorageLocation($this->getParameter("id"))->serialize(); + } else { + if ($this->hasParameter("sort")) { + $tmp = json_decode($this->getParameter("sort"), true); + + $aSortParams = $tmp[0]; + } else { + $aSortParams = array( + "property" => "name", + "direction" => "ASC"); + } + return StorageLocationManager::getInstance()->getStorageLocations( + $this->getParameter("start", $this->getParameter("start", 0)), + $this->getParameter("limit", $this->getParameter("limit", 25)), + $this->getParameter("sortby", $aSortParams["property"]), + $this->getParameter("dir", $aSortParams["direction"]), + $this->getParameter("query", "")); + } + } + + public function create () { + $this->requireParameter("name"); + + $sl = StorageLocationManager::getInstance()->addStorageLocation($this->getParameter("name")); + + return array("data" => $sl->serialize()); + } + + public function update () { + $this->requireParameter("id"); + $this->requireParameter("name"); + $storageLocation = StorageLocationManager::getInstance()->getStorageLocation($this->getParameter("id")); + $storageLocation->setName($this->getParameter("name")); + + PartKeepr::getEM()->flush(); + + return array("data" => $storageLocation->serialize()); + + } + + public function destroy () { + $this->requireParameter("id"); + + StorageLocationManager::getInstance()->deleteStorageLocation($this->getParameter("id")); + + return array("data" => null); + } + + // Old Stuff below + public function getStorageLocations() { + return StorageLocationManager::getInstance()->getStorageLocations( + $this->getParameter("start", 0), + $this->getParameter("limit", 10), + $this->getParameter("sortby", "name"), + $this->getParameter("dir", "asc"), + $this->getParameter("filter", "")); + } + + public function addStorageLocation () { + $this->requireParameter("name"); + + StorageLocationManager::getInstance()->addStorageLocation($this->getParameter("name")); + } + + public function deleteStorageLocation () { + $this->requireParameter("id"); + + StorageLocationManager::getInstance()->deleteStorageLocation($this->getParameter("id")); + } + + public function getStorageLocation () { + $this->requireParameter("id"); + + return StorageLocationManager::getInstance()->getStorageLocation($this->getParameter("id"))->serialize(); + } + + public function saveStorageLocation () { + $this->requireParameter("id"); + $this->requireParameter("name"); + + $storageLocation = StorageLocationManager::getInstance()->getStorageLocation($this->getParameter("id")); + + $storageLocation->setName($this->getParameter("name")); + + PartKeepr::getEM()->flush(); + + return $storageLocation->serialize(); + } +}+ \ No newline at end of file diff --git a/src/de/RaumZeitLabor/PartKeepr/TempImage/TempImageService.php b/src/de/RaumZeitLabor/PartKeepr/TempImage/TempImageService.php @@ -0,0 +1,22 @@ +<?php +namespace de\RaumZeitLabor\PartKeepr\TempImage; + +use de\RaumZeitLabor\PartKeepr\Service\Service; +use de\RaumZeitLabor\PartKeepr\Image\TempImage; +use de\RaumZeitLabor\PartKeepr\PartKeepr; + +class TempImageService extends Service { + + public function upload () { + $image = new TempImage(); + + $file = $_FILES['userfile']['tmp_name']; + + $image->replace($file); + PartKeepr::getEM()->persist($image); + PartKeepr::getEM()->flush(); + + return array("id" => $image->getId()); + } +} + + \ No newline at end of file diff --git a/src/de/RaumZeitLabor/PartKeepr/Unit/Unit.php b/src/de/RaumZeitLabor/PartKeepr/Unit/Unit.php @@ -0,0 +1,111 @@ +<?php +namespace de\RaumZeitLabor\PartKeepr\Unit; +declare(encoding = 'UTF-8'); + +use de\RaumZeitLabor\PartKeepr\PartKeepr, + de\RaumZeitLabor\PartKeepr\Util\Exceptions\OutOfRangeException, + de\RaumZeitLabor\PartKeepr\SiPrefix\SiPrefix; + + +/** + * This object represents an unit. Units can be: Volt, Hertz etc. + * + * @Entity + **/ +class Unit { + /** + * @Id @Column(type="integer") + * @GeneratedValue(strategy="AUTO") + * @var integer + */ + private $id; + + /** + * The name of the unit (e.g. Volts, Ampere, Farad, Metres) + * @Column(type="string") + * @var string + */ + private $name; + + /** + * The symbol of the unit (e.g. V, A, F, m) + * @Column(type="string") + * @var string + */ + private $symbol; + + /** + * Defines the allowed SiPrefixes for this parameter unit + * @ManyToMany(targetEntity="de\RaumZeitLabor\PartKeepr\SiPrefix\SiPrefix") + * @JoinTable(name="UnitSiPrefixes", + * joinColumns={@JoinColumn(name="unit_id", referencedColumnName="id")}, + * inverseJoinColumns={@JoinColumn(name="siprefix_id", referencedColumnName="id")} + * ) + * @var ArrayCollection + */ + private $prefixes; + + /** + * Creates a new Unit. + */ + public function __construct () { + $this->prefixes = new \Doctrine\Common\Collections\ArrayCollection(); + } + + /** + * Sets the name for this unit + * @param string $name the name for this unit + */ + public function setName ($name) { + $this->name = $name; + } + + /** + * Returns the name for this unit + * @return string The unit name + */ + public function getName () { + return $this->name; + } + + /** + * Sets the symbol for this unit + * @param string $symbol The symbol + */ + public function setSymbol ($symbol) { + $this->symbol = $symbol; + } + + /** + * Returns the symbol for this unit + * @return string The symbol + */ + public function getSymbol () { + return $this->symbol; + } + + /** + * Returns the si-prefix list for this unit + * @return array An array of SiPrefix objects + */ + public function getPrefixes () { + return $this->prefixes; + } + + /** + * Returns the ID for this object. + * @param none + * @return int The ID for this object + */ + public function getId () { + return $this->id; + } + + /** + * Loads a unit by ID + * @param int $id The ID to load + */ + public static function loadById ($id) { + return PartKeepr::getEM()->find(get_called_class(), $id); + } +}+ \ No newline at end of file diff --git a/src/de/RaumZeitLabor/PartKeepr/Unit/UnitManager.php b/src/de/RaumZeitLabor/PartKeepr/Unit/UnitManager.php @@ -0,0 +1,80 @@ +<?php +namespace de\RaumZeitLabor\PartKeepr\Unit; +declare(encoding = 'UTF-8'); + +use de\RaumZeitLabor\PartKeepr\Util\Singleton, + de\RaumZeitLabor\PartKeepr\PartKeepr, + de\RaumZeitLabor\PartKeepr\Unit\Exceptions\UnitNotFoundException; + +class UnitManager extends Singleton { + public function getUnits ($start = 0, $limit = 10, $sort = "name", $dir = "asc", $filter = "") { + + $qb = PartKeepr::getEM()->createQueryBuilder(); + $qb->select("u.id, u.name, u.symbol")->from("de\RaumZeitLabor\PartKeepr\Unit\Unit","u"); + + if ($filter != "") { + $qb = $qb->where("u.name LIKE :filter"); + $qb->setParameter("filter", "%".$filter."%"); + } + + if ($limit > -1) { + $qb->setMaxResults($limit); + $qb->setFirstResult($start); + } + + $qb->orderBy("u.".$sort, $dir); + + $query = $qb->getQuery(); + + $result = $query->getResult(); + + $totalQueryBuilder = PartKeepr::getEM()->createQueryBuilder(); + $totalQueryBuilder->select("COUNT(u.id)")->from("de\RaumZeitLabor\PartKeepr\Unit\Unit","u"); + + + + if ($filter != "") { + $totalQueryBuilder = $totalQueryBuilder->where("u.name LIKE :filter"); + $totalQueryBuilder->setParameter("filter", "%".$filter."%"); + } + + $totalQuery = $totalQueryBuilder->getQuery(); + + foreach ($result as $key => $value) { + $result[$key]["prefixes"] = $this->getSiPrefixes($value["id"]); + } + + return array("data" => $result, "totalCount" => $totalQuery->getSingleScalarResult()); + } + + public function getSiPrefixes ($id) { + $unit = UnitManager::getInstance()->getUnit($id); + + $aData = array(); + + foreach ($unit->getPrefixes() as $prefix) { + $aData[] = $prefix->serialize(); + } + + return array("response" => array("totalCount" => count($aData), "data" => $aData)); + } + + public function getUnit ($id) { + $unit = PartKeepr::getEM()->find("de\RaumZeitLabor\PartKeepr\Unit\Unit", $id); + + if ($unit) { + return $unit; + } else { + throw new UnitNotFoundException(); + } + } + + public function deleteUnit ($id) { + $unit = $this->getUnit($id); + + PartKeepr::getEM()->remove($unit); + PartKeepr::getEM()->flush(); + } + + +}+ \ No newline at end of file diff --git a/src/de/RaumZeitLabor/PartKeepr/Unit/UnitService.php b/src/de/RaumZeitLabor/PartKeepr/Unit/UnitService.php @@ -0,0 +1,91 @@ +<?php +namespace de\RaumZeitLabor\PartKeepr\Unit; +use de\RaumZeitLabor\PartKeepr\Service\RestfulService; + +declare(encoding = 'UTF-8'); + +use de\RaumZeitLabor\PartKeepr\Service\Service; +use de\RaumZeitLabor\PartKeepr\PartKeepr, + de\RaumZeitLabor\PartKeepr\Part\PartUnit, + de\RaumZeitLabor\PartKeepr\SiPrefix\SiPrefix, + de\RaumZeitLabor\PartKeepr\Session\SessionManager; + +class UnitService extends Service implements RestfulService { + public function get () { + if ($this->hasParameter("id")) { + return UnitManager::getInstance()->getUnit($this->getParameter("id"))->serialize(); + } else { + if ($this->hasParameter("sort")) { + $tmp = json_decode($this->getParameter("sort"), true); + + $aSortParams = $tmp[0]; + } else { + $aSortParams = array( + "property" => "name", + "direction" => "ASC"); + } + return UnitManager::getInstance()->getUnits( + $this->getParameter("start", $this->getParameter("start", 0)), + $this->getParameter("limit", $this->getParameter("limit", 25)), + $this->getParameter("sortby", $aSortParams["property"]), + $this->getParameter("dir", $aSortParams["direction"]), + $this->getParameter("query", "")); + } + } + + public function setUnitPrefixes () { + $this->requireParameter("id"); + + $unit = UnitManager::getInstance()->getUnit($this->getParameter("id")); + + $prefixes = $unit->getPrefixes(); + + $prefixes->clear(); + + foreach ($this->getParameter("prefixes") as $prefix) { + $prefix = SiPrefix::loadById($prefix); + $prefixes->add($prefix); + } + + } + + public function create () { + $this->requireParameter("name"); + + $unit = new Unit; + + $this->setUnitData($unit); + + PartKeepr::getEM()->persist($unit); + PartKeepr::getEM()->flush(); + + return array("data" => $unit->serialize()); + } + + private function setUnitData (Unit $unit) { + $unit->setName($this->getParameter("name")); + $unit->setSymbol($this->getParameter("symbol")); + } + + public function update () { + $this->requireParameter("id"); + $this->requireParameter("name"); + + $unit = UnitManager::getInstance()->getUnit($this->getParameter("id")); + + $this->setUnitData($unit); + PartKeepr::getEM()->flush(); + + return array("data" => $unit->serialize()); + + } + + public function destroy () { + $this->requireParameter("id"); + + UnitManager::getInstance()->deleteUnit($this->getParameter("id")); + + return array("data" => null); + } + +}+ \ No newline at end of file diff --git a/src/de/RaumZeitLabor/PartKeepr/User/UserManager.php b/src/de/RaumZeitLabor/PartKeepr/User/UserManager.php @@ -0,0 +1,64 @@ +<?php +namespace de\RaumZeitLabor\PartKeepr\User; +declare(encoding = 'UTF-8'); + +use de\RaumZeitLabor\PartKeepr\Util\Singleton, + de\RaumZeitLabor\PartKeepr\Auth\User, + de\RaumZeitLabor\PartKeepr\PartKeepr, + de\RaumZeitLabor\PartKeepr\Category\CategoryManager, + de\RaumZeitLabor\PartKeepr\User\Exceptions\UserNotFoundException; + +class UserManager extends Singleton { + public function getUsers ($start = 0, $limit = 10, $sort = "name", $dir = "asc", $filter = "") { + + $qb = PartKeepr::getEM()->createQueryBuilder(); + $qb->select("st.id, st.username")->from("de\RaumZeitLabor\PartKeepr\Auth\User","st"); + + if ($filter != "") { + $qb = $qb->where("st.username LIKE :filter"); + $qb->setParameter("filter", "%".$filter."%"); + } + + if ($limit > -1) { + $qb->setMaxResults($limit); + $qb->setFirstResult($start); + } + + $qb->orderBy("st.".$sort, $dir); + + $query = $qb->getQuery(); + + $result = $query->getResult(); + + $totalQueryBuilder = PartKeepr::getEM()->createQueryBuilder(); + $totalQueryBuilder->select("COUNT(st.id)")->from("de\RaumZeitLabor\PartKeepr\Auth\User","st"); + + + + if ($filter != "") { + $totalQueryBuilder = $totalQueryBuilder->where("st.name LIKE :filter"); + $totalQueryBuilder->setParameter("filter", "%".$filter."%"); + } + + $totalQuery = $totalQueryBuilder->getQuery(); + + return array("data" => $result, "totalCount" => $totalQuery->getSingleScalarResult()); + } + + public function getUser ($id) { + $user = PartKeepr::getEM()->find("de\RaumZeitLabor\PartKeepr\Auth\User", $id); + + if ($user) { + return $user; + } else { + throw new UserNotFoundException(); + } + } + + public function deleteUser ($id) { + $user = $this->getUser($id); + + PartKeepr::getEM()->remove($user); + PartKeepr::getEM()->flush(); + } +}+ \ No newline at end of file diff --git a/src/de/RaumZeitLabor/PartKeepr/User/UserService.php b/src/de/RaumZeitLabor/PartKeepr/User/UserService.php @@ -0,0 +1,77 @@ +<?php +namespace de\RaumZeitLabor\PartKeepr\User; +use de\RaumZeitLabor\PartKeepr\Service\RestfulService; + +declare(encoding = 'UTF-8'); + +use de\RaumZeitLabor\PartKeepr\Service\AdminService; +use de\RaumZeitLabor\PartKeepr\PartKeepr, + de\RaumZeitLabor\PartKeepr\Auth\User, + de\RaumZeitLabor\PartKeepr\Session\SessionManager; + +class UserService extends AdminService implements RestfulService { + public function get () { + if ($this->hasParameter("id")) { + return UserManager::getInstance()->getUser($this->getParameter("id"))->serialize(); + } else { + if ($this->hasParameter("sort")) { + $tmp = json_decode($this->getParameter("sort"), true); + + $aSortParams = $tmp[0]; + } else { + $aSortParams = array( + "property" => "username", + "direction" => "ASC"); + } + return UserManager::getInstance()->getUsers( + $this->getParameter("start", $this->getParameter("start", 0)), + $this->getParameter("limit", $this->getParameter("limit", 25)), + $this->getParameter("sortby", $aSortParams["property"]), + $this->getParameter("dir", $aSortParams["direction"]), + $this->getParameter("query", "")); + } + } + + public function create () { + $this->requireParameter("username"); + + $user = new User; + + $this->setUserData($user); + + PartKeepr::getEM()->persist($user); + PartKeepr::getEM()->flush(); + + return array("data" => $user->serialize()); + } + + private function setUserData (User $user) { + $user->setUsername($this->getParameter("username")); + + if ($this->hasParameter("password") && $this->getParameter("password") !== "") { + $user->setHashedPassword($this->getParameter("password")); + } else { + $user->setHashedPassword(""); + } + } + + public function update () { + $this->requireParameter("id"); + $this->requireParameter("username"); + $user = UserManager::getInstance()->getUser($this->getParameter("id")); + + $this->setUserData($user); + PartKeepr::getEM()->flush(); + + return array("data" => $user->serialize()); + + } + + public function destroy () { + $this->requireParameter("id"); + + UserManager::getInstance()->deleteUser($this->getParameter("id")); + + return array("data" => null); + } +}+ \ No newline at end of file diff --git a/src/de/RaumZeitLabor/PartKeepr/Util/Configuration.php b/src/de/RaumZeitLabor/PartKeepr/Util/Configuration.php @@ -0,0 +1,43 @@ +<?php +namespace de\RaumZeitLabor\PartKeepr\Util; + +/** + * This class manages simple key -> value configurations within the system. + * + * This allows the user to configure certain aspects of the system in a central place. + * + * The convention is to use a dotted format, for example: + * + * flipbeat.cms.layoutrenderer + * + * @author felicitus + */ +class Configuration { + private static $options = array(); + + /** + * Sets the option to value. + * + * @param string $option The option to set + * @param string $value The value to set + */ + public static function setOption ($option, $value) { + Configuration::$options[$option] = $value; + } + + /** + * Returns the value of an option. The developer + * may additionally specify a default value, which + * is returned when no option was found. + * + * @param string $option The option to return + * @param string $default The default value if the option was not found + */ + public static function getOption ($option, $default = false) { + if (!array_key_exists($option, Configuration::$options)) { + return $default; + } + return Configuration::$options[$option]; + } +} +?>+ \ No newline at end of file diff --git a/src/de/RaumZeitLabor/PartKeepr/Util/Exceptions/OutOfRangeException.php b/src/de/RaumZeitLabor/PartKeepr/Util/Exceptions/OutOfRangeException.php @@ -0,0 +1,7 @@ +<?php +namespace de\RaumZeitLabor\PartKeepr\Util\Exceptions; +declare(encoding = 'UTF-8'); + +use de\RaumZeitLabor\PartKeepr\Util\SerializableException; + +class OutOfRangeException extends SerializableException {} diff --git a/src/de/RaumZeitLabor/PartKeepr/Util/SerializableException.php b/src/de/RaumZeitLabor/PartKeepr/Util/SerializableException.php @@ -0,0 +1,58 @@ +<?php +namespace de\RaumZeitLabor\PartKeepr\Util; + +class SerializableException extends \Exception { + protected $detailMessage = "No detail message has been entered."; + + /* @todo: stub */ + public function getDetail () { + return $this->detailMessage; + } + + public function setDetail ($message) { + $this->detailMessage = $message; + } + + public function serialize () { + return array( + "message" => $this->getMessage(), + "detail" => $this->getDetail(), + "exception" => get_class($this) + //"backtrace" => $this->getFormattedTrace() + ); + } + + public function getFormattedTrace () { + $items = $this->getTrace(); + + $message = ""; + + $args = array(); + + foreach ($items as $id => $item) { + foreach ($item["args"] as $item) { + switch (gettype($item)) { + case "object": + if (method_exists($item, "__toString")) { + $args[] = get_class($item) . "(".$item->__toString().")"; + } else { + $args[] = get_class($item); + } + case "array": + $args[] = "array"; + break; + default: + $args[] = $item; + break; + } + } + + $message .= $item["file"].":".$item["line"]."\n"; + $message .= $item["function"] ."(".implode(",", $args).")"."\n\n"; + } + + return $message; + } + +} +?>+ \ No newline at end of file diff --git a/src/de/RaumZeitLabor/PartKeepr/Util/Singleton.php b/src/de/RaumZeitLabor/PartKeepr/Util/Singleton.php @@ -0,0 +1,20 @@ +<?php +namespace de\RaumZeitLabor\PartKeepr\Util; + +abstract class Singleton { + static $instance = null; + + private function __construct () { + + } + + public static function getInstance () { + if (!static::$instance instanceof static) { + static::$instance = new static; + } + + return static::$instance; + } +} + +?>+ \ No newline at end of file diff --git a/src/de/RaumZeitLabor/PartKeepr/Util/UtilService.php b/src/de/RaumZeitLabor/PartKeepr/Util/UtilService.php @@ -0,0 +1,14 @@ +<?php +namespace de\raumzeitlabor\PartKeepr\Util; +declare(encoding = 'UTF-8'); + +use de\RaumZeitLabor\PartKeepr\Service\AnonService; + +class UtilService extends AnonService { + public function clearCache () { + apc_clear_cache(); + apc_clear_cache("user"); + + return array("status" => "ok"); + } +}+ \ No newline at end of file diff --git a/testing/PartTest.php b/testing/PartTest.php @@ -1,18 +1,18 @@ <?php -namespace de\RaumZeitLabor\PartDB2\Tests; +namespace de\RaumZeitLabor\PartKeepr\Tests; declare(encoding = 'UTF-8'); -include("../src/de/RaumZeitLabor/PartDB2/PartDB2.php"); +include("../src/de/RaumZeitLabor/PartKeepr/PartKeepr.php"); -use de\RaumZeitLabor\PartDB2\Auth\User; -use de\RaumZeitLabor\PartDB2\Footprint\Footprint; -use de\RaumZeitLabor\PartDB2\Footprint\FootprintManager; -use de\RaumZeitLabor\PartDB2\Category\Category; -use de\RaumZeitLabor\PartDB2\Category\CategoryManager; -use de\RaumZeitLabor\PartDB2\PartDB2; -use de\RaumZeitLabor\PartDB2\Part\Part; +use de\RaumZeitLabor\PartKeepr\Auth\User; +use de\RaumZeitLabor\PartKeepr\Footprint\Footprint; +use de\RaumZeitLabor\PartKeepr\Footprint\FootprintManager; +use de\RaumZeitLabor\PartKeepr\Category\Category; +use de\RaumZeitLabor\PartKeepr\Category\CategoryManager; +use de\RaumZeitLabor\PartKeepr\PartKeepr; +use de\RaumZeitLabor\PartKeepr\Part\Part; -PartDB2::initialize(); +PartKeepr::initialize(); $category = CategoryManager::getInstance()->getCategory(2); $footprint = FootprintManager::getInstance()->getFootprint(2); @@ -23,5 +23,5 @@ $part->setCategory($category->getNode()); $part->setName("Tolles Bauteil"); $part->setComment("0815 zeugs"); -PartDB2::getEM()->persist($part); -PartDB2::getEM()->flush();- \ No newline at end of file +PartKeepr::getEM()->persist($part); +PartKeepr::getEM()->flush();+ \ No newline at end of file diff --git a/testing/Service.php b/testing/Service.php @@ -1,17 +1,17 @@ <?php -namespace de\RaumZeitLabor\PartDB2\Tests; +namespace de\RaumZeitLabor\PartKeepr\Tests; declare(encoding = 'UTF-8'); -include("../src/de/RaumZeitLabor/PartDB2/PartDB2.php"); +include("../src/de/RaumZeitLabor/PartKeepr/PartKeepr.php"); -use de\RaumZeitLabor\PartDB2\Auth\User; -use de\RaumZeitLabor\PartDB2\PartDB2; -use de\RaumZeitLabor\PartDB2\Util\SerializableException; -use de\RaumZeitLabor\PartDB2\Auth\UserManager; -use de\RaumZeitLabor\PartDB2\Session\SessionManager; -use de\RaumZeitLabor\PartDB2\Service\ServiceManager; +use de\RaumZeitLabor\PartKeepr\Auth\User; +use de\RaumZeitLabor\PartKeepr\PartKeepr; +use de\RaumZeitLabor\PartKeepr\Util\SerializableException; +use de\RaumZeitLabor\PartKeepr\Auth\UserManager; +use de\RaumZeitLabor\PartKeepr\Session\SessionManager; +use de\RaumZeitLabor\PartKeepr\Service\ServiceManager; -PartDB2::initialize(); +PartKeepr::initialize(); /*class User { public $username; @@ -40,7 +40,7 @@ $server->handle();*/ $callStruct = array( - "service" => "de.RaumZeitLabor.PartDB2.Auth.AuthManagerService", + "service" => "de.RaumZeitLabor.PartKeepr.Auth.AuthManagerService", "call" => "login", "parameters" => array( "username" => "2test", @@ -54,5 +54,5 @@ ServiceManager::call($callStruct); -PartDB2::getEM()->flush(); +PartKeepr::getEM()->flush(); ?> \ No newline at end of file diff --git a/testing/SetupDatabase.php b/testing/SetupDatabase.php @@ -1,37 +1,37 @@ <?php -namespace de\RaumZeitLabor\PartDB2\Tests; -use de\RaumZeitLabor\PartDB2\PartParameter\PartParameter; +namespace de\RaumZeitLabor\PartKeepr\Tests; +use de\RaumZeitLabor\PartKeepr\PartParameter\PartParameter; declare(encoding = 'UTF-8'); -use de\RaumZeitLabor\PartDB2\Unit\Unit; +use de\RaumZeitLabor\PartKeepr\Unit\Unit; -use de\RaumZeitLabor\PartDB2\SiPrefix\SiPrefix; +use de\RaumZeitLabor\PartKeepr\SiPrefix\SiPrefix; declare(encoding = 'UTF-8'); -include("../src/de/RaumZeitLabor/PartDB2/PartDB2.php"); +include("../src/de/RaumZeitLabor/PartKeepr/PartKeepr.php"); -use de\RaumZeitLabor\PartDB2\Auth\User; -use de\RaumZeitLabor\PartDB2\Footprint\Footprint; -use de\RaumZeitLabor\PartDB2\Footprint\FootprintManager; -use de\RaumZeitLabor\PartDB2\PartDB2; -use de\RaumZeitLabor\PartDB2\Part\PartUnit; -use de\RaumZeitLabor\PartDB2\Category\Category; -use de\RaumZeitLabor\PartDB2\Part\Part; -use de\RaumZeitLabor\PartDB2\StorageLocation\StorageLocation; -use de\RaumZeitLabor\PartDB2\Stock\StockEntry; -use de\RaumZeitLabor\PartDB2\Category\CategoryManager; -use de\RaumZeitLabor\PartDB2\Category\CategoryManagerService; +use de\RaumZeitLabor\PartKeepr\Auth\User; +use de\RaumZeitLabor\PartKeepr\Footprint\Footprint; +use de\RaumZeitLabor\PartKeepr\Footprint\FootprintManager; +use de\RaumZeitLabor\PartKeepr\PartKeepr; +use de\RaumZeitLabor\PartKeepr\Part\PartUnit; +use de\RaumZeitLabor\PartKeepr\Category\Category; +use de\RaumZeitLabor\PartKeepr\Part\Part; +use de\RaumZeitLabor\PartKeepr\StorageLocation\StorageLocation; +use de\RaumZeitLabor\PartKeepr\Stock\StockEntry; +use de\RaumZeitLabor\PartKeepr\Category\CategoryManager; +use de\RaumZeitLabor\PartKeepr\Category\CategoryManagerService; -use de\RaumZeitLabor\PartDB2\Manufacturer\ManufacturerICLogo; -use de\RaumZeitLabor\PartDB2\Manufacturer\Manufacturer; -use de\RaumZeitLabor\PartDB2\Distributor\Distributor; +use de\RaumZeitLabor\PartKeepr\Manufacturer\ManufacturerICLogo; +use de\RaumZeitLabor\PartKeepr\Manufacturer\Manufacturer; +use de\RaumZeitLabor\PartKeepr\Distributor\Distributor; -use de\RaumZeitLabor\PartDB2\Part\PartDistributor; -use de\RaumZeitLabor\PartDB2\Part\PartManufacturer; +use de\RaumZeitLabor\PartKeepr\Part\PartDistributor; +use de\RaumZeitLabor\PartKeepr\Part\PartManufacturer; -PartDB2::initialize(); +PartKeepr::initialize(); echo "=)))==========================================\n"; @@ -64,9 +64,9 @@ echo "Performing actions...\n"; chmod("../src/Proxies", 0777); chmod("../data/images", 0777); -$tool = new \Doctrine\ORM\Tools\SchemaTool(PartDB2::getEM()); +$tool = new \Doctrine\ORM\Tools\SchemaTool(PartKeepr::getEM()); -$classes = PartDB2::getClassMetaData(); +$classes = PartKeepr::getClassMetaData(); $tool->dropDatabase($classes); $tool->createSchema($classes); @@ -76,7 +76,7 @@ $user = new User(); $user->setUsername("test"); $user->setPassword("test"); -PartDB2::getEM()->persist($user); +PartKeepr::getEM()->persist($user); /* Create footprints */ @@ -87,12 +87,12 @@ mysql_connect("localhost", "partdb", "partdb"); mysql_select_db("partdb"); $partUnit = new PartUnit(); -$partUnit->setName(PartDB2::i18n("Pieces")); -$partUnit->setShortName(PartDB2::i18n("pcs")); +$partUnit->setName(PartKeepr::i18n("Pieces")); +$partUnit->setShortName(PartKeepr::i18n("pcs")); $partUnit->setDefault(true); -PartDB2::getEM()->persist($partUnit); -PartDB2::getEM()->flush(); +PartKeepr::getEM()->persist($partUnit); +PartKeepr::getEM()->flush(); echo "Creating footprints from SetupData/footprints.php\n"; @@ -103,7 +103,7 @@ while ($sFootprint = mysql_fetch_assoc($r)) { $footprint->setFootprint(convertText($sFootprint["name"])); echo " Adding footprint ".$sFootprint["name"]."\r"; - PartDB2::getEM()->persist($footprint); + PartKeepr::getEM()->persist($footprint); $newFootprints[$sFootprint["id"]] = $footprint; } @@ -152,7 +152,7 @@ $r = mysql_query("SELECT * FROM storeloc"); while ($store = mysql_fetch_assoc($r)) { $oStorageLocation = new StorageLocation(); $oStorageLocation->setName(convertText($store["name"])); - PartDB2::getEM()->persist($oStorageLocation); + PartKeepr::getEM()->persist($oStorageLocation); echo "Migrating storage location ".sprintf("%-40s", $store["name"])."\r"; $newStorageLocations[$store["id"]] = $oStorageLocation; } @@ -171,11 +171,11 @@ foreach ($data as $prefixName => $data) { $prefix->setSymbol($data["symbol"]); $aSiPrefixes[] = $prefix; - PartDB2::getEM()->persist($prefix); + PartKeepr::getEM()->persist($prefix); } -PartDB2::getEM()->flush(); +PartKeepr::getEM()->flush(); /* Add units */ $data = \Symfony\Component\Yaml\Yaml::load("../setup/data/units.yaml"); @@ -200,12 +200,12 @@ foreach ($data as $unitName => $data) { } } - PartDB2::getEM()->persist($unit); + PartKeepr::getEM()->persist($unit); $aUnits[] = $unit; } -PartDB2::getEM()->flush(); +PartKeepr::getEM()->flush(); /* Add manufacturers and IC logos */ @@ -218,7 +218,7 @@ foreach ($data as $mfgname => $logos) { $manufacturer = new Manufacturer(); $manufacturer->setName($mfgname); - PartDB2::getEM()->persist($manufacturer); + PartKeepr::getEM()->persist($manufacturer); $aManufacturers[] = $manufacturer; foreach ($logos as $logo) { @@ -226,18 +226,18 @@ foreach ($data as $mfgname => $logos) { $mfglogo->setManufacturer($manufacturer); $mfglogo->replace("../setup/data/manufacturers/images/".$logo); - PartDB2::getEM()->persist($mfglogo); + PartKeepr::getEM()->persist($mfglogo); } } -PartDB2::getEM()->flush(); +PartKeepr::getEM()->flush(); $r = mysql_query("SELECT * FROM suppliers"); while ($supplier = mysql_fetch_assoc($r)) { $distributor = new Distributor(); $distributor->setName($supplier["name"]); - PartDB2::getEM()->persist($distributor); + PartKeepr::getEM()->persist($distributor); $aDistributors[$supplier["id"]] = $distributor; } @@ -264,7 +264,7 @@ while ($part = mysql_fetch_assoc($r)) { $oPart->getDistributors()->add(new PartDistributor($oPart, $aDistributors[$part["id_supplier"]])); //echo "Migrating part ".sprintf("%-40s", $part["name"])."\r"; - PartDB2::getEM()->persist($oPart); + PartKeepr::getEM()->persist($oPart); $oStock = new StockEntry($oPart, $part["instock"]); @@ -279,7 +279,7 @@ while ($part = mysql_fetch_assoc($r)) { } } - PartDB2::getEM()->persist($oStock); + PartKeepr::getEM()->persist($oStock); /* Add some random parameters */ @@ -295,20 +295,20 @@ while ($part = mysql_fetch_assoc($r)) { $oPartParameter->setUnit($aUnits[array_rand($aUnits)]); $oPartParameter->setValue($val); $oPartParameter->setSiPrefix($prefix); - PartDB2::getEM()->persist($oPartParameter); + PartKeepr::getEM()->persist($oPartParameter); } $fc++; if ($fc>100) { - PartDB2::getEM()->flush(); + PartKeepr::getEM()->flush(); $fc=0; } } -PartDB2::getEM()->flush(); +PartKeepr::getEM()->flush(); diff --git a/testing/genman.php b/testing/genman.php @@ -1,12 +1,12 @@ <?php -include("../src/de/RaumZeitLabor/PartDB2/PartDB2.php"); +include("../src/de/RaumZeitLabor/PartKeepr/PartKeepr.php"); -use de\RaumZeitLabor\PartDB2\PartDB2; +use de\RaumZeitLabor\PartKeepr\PartKeepr; //include("/usr/share/php/Doctrine/Symfony/Component/Yaml/Yaml.php"); //include("/usr/share/php/Doctrine/Symfony/Component/Yaml/Dumper.php"); //include("/usr/share/php/Doctrine/Symfony/Component/Yaml/Inline.php"); -PartDB2::initialize(); +PartKeepr::initialize(); $dom = new DOMDocument(); $dom->loadHTMLFile("manufacturers.html"); diff --git a/tests/Auth/AuthManagerTest.php b/tests/Auth/AuthManagerTest.php @@ -1,14 +1,14 @@ <?php -namespace de\RaumZeitLabor\PartDB2\Tests\Auth; +namespace de\RaumZeitLabor\PartKeepr\Tests\Auth; -use de\RaumZeitLabor\PartDB2\Auth\AuthManager; +use de\RaumZeitLabor\PartKeepr\Auth\AuthManager; class AuthManagerTest extends \PHPUnit_Framework_TestCase { public function testBasics () { $authManager = AuthManager::getInstance(); if (!$authManager instanceof AuthManager) { - $this->fail('$authManager is not an instance of de\RaumZeitLabor\PartDB2\Auth\AuthManager'); + $this->fail('$authManager is not an instance of de\RaumZeitLabor\PartKeepr\Auth\AuthManager'); } } } diff --git a/tests/Auth/UserManagerTest.php b/tests/Auth/UserManagerTest.php @@ -1,10 +1,10 @@ <?php -namespace de\RaumZeitLabor\PartDB2\Tests\Auth; +namespace de\RaumZeitLabor\PartKeepr\Tests\Auth; -use de\RaumZeitLabor\PartDB2\Auth\UserManager, - de\RaumZeitLabor\PartDB2\Auth\User, - de\RaumZeitLabor\PartDB2\Auth\Exceptions\UserAlreadyExistsException, - de\RaumZeitLabor\PartDB2\PartDB2; +use de\RaumZeitLabor\PartKeepr\Auth\UserManager, + de\RaumZeitLabor\PartKeepr\Auth\User, + de\RaumZeitLabor\PartKeepr\Auth\Exceptions\UserAlreadyExistsException, + de\RaumZeitLabor\PartKeepr\PartKeepr; class UserManagerTest extends \PHPUnit_Framework_TestCase { @@ -25,7 +25,7 @@ class UserManagerTest extends \PHPUnit_Framework_TestCase { $this->userManager->createUser($user); - $this->setExpectedException("de\RaumZeitLabor\PartDB2\Auth\Exceptions\UserAlreadyExistsException"); + $this->setExpectedException("de\RaumZeitLabor\PartKeepr\Auth\Exceptions\UserAlreadyExistsException"); $this->userManager->createUser($user); } @@ -35,7 +35,7 @@ class UserManagerTest extends \PHPUnit_Framework_TestCase { $user = new User; $user->setUsername("foobar"); - $this->setExpectedException("de\RaumZeitLabor\PartDB2\Auth\Exceptions\UserDoesNotExistException"); + $this->setExpectedException("de\RaumZeitLabor\PartKeepr\Auth\Exceptions\UserDoesNotExistException"); $this->userManager->deleteUser($user); $user = new User; @@ -49,14 +49,14 @@ class UserManagerTest extends \PHPUnit_Framework_TestCase { $user->setPassword("test"); $this->userManager->createUser($user); - PartDB2::getEM()->flush(); + PartKeepr::getEM()->flush(); $user2 = new User; $user2->setRawUsername("2test"); $user2->setPassword("test"); /* User shouldn't be able to login, even if we cut numbers and special chars from usernames */ - $this->setExpectedException("de\RaumZeitLabor\PartDB2\Auth\Exceptions\InvalidLoginDataException"); + $this->setExpectedException("de\RaumZeitLabor\PartKeepr\Auth\Exceptions\InvalidLoginDataException"); $this->userManager->authenticate($user2); } diff --git a/tests/Auth/UserTest.php b/tests/Auth/UserTest.php @@ -1,8 +1,8 @@ <?php -namespace de\RaumZeitLabor\PartDB2\Tests\Auth; +namespace de\RaumZeitLabor\PartKeepr\Tests\Auth; declare(encoding = 'UTF-8'); -use de\RaumZeitLabor\PartDB2\Auth\User; +use de\RaumZeitLabor\PartKeepr\Auth\User; class UserTest extends \PHPUnit_Framework_TestCase { public function testBasics () { diff --git a/tests/Util/ConfigurationTest.php b/tests/Util/ConfigurationTest.php @@ -1,7 +1,7 @@ <?php -namespace de\RaumZeitLabor\PartDB2\Tests\Util; +namespace de\RaumZeitLabor\PartKeepr\Tests\Util; -use de\RaumZeitLabor\PartDB2\Util\Configuration; +use de\RaumZeitLabor\PartKeepr\Util\Configuration; class ConfigurationTest extends \PHPUnit_Framework_TestCase { public function testConfiguration () { diff --git a/tests/bootstrap.php b/tests/bootstrap.php @@ -1,15 +1,15 @@ <?php -namespace de\RaumZeitLabor\PartDB2\Tests; +namespace de\RaumZeitLabor\PartKeepr\Tests; declare(encoding = 'UTF-8'); -use de\raumzeitlabor\PartDB2\PartDB2; +use de\raumzeitlabor\PartKeepr\PartKeepr; -include(dirname(__DIR__). "/src/de/RaumZeitLabor/PartDB2/PartDB2.php"); +include(dirname(__DIR__). "/src/de/RaumZeitLabor/PartKeepr/PartKeepr.php"); -PartDB2::initialize("test"); +PartKeepr::initialize("test"); -$tool = new \Doctrine\ORM\Tools\SchemaTool(PartDB2::getEM()); -$classes = PartDB2::getClassMetaData(); +$tool = new \Doctrine\ORM\Tools\SchemaTool(PartKeepr::getEM()); +$classes = PartKeepr::getClassMetaData(); $tool->dropSchema($classes); $tool->createSchema($classes); diff --git a/tests/reports/phpunit/allclasses-frame.html b/tests/reports/phpunit/allclasses-frame.html @@ -1,16 +0,0 @@ -<html> -<head> -<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> -<title>All Unit Test Classes</title> -<link rel="stylesheet" type="text/css" title="Style" href="stylesheet.css"> -</head> -<body> -<h2>Classes</h2> -<table width="100%"> -<tr><td nowrap><a target="classFrame" href="default/de%5CRaumZeitLabor%5CPartDB2%5CTests%5CAuth%5CAuthManagerTest.html">de\RaumZeitLabor\PartDB2\Tests\Auth\AuthManagerTest</a></td></tr> -<tr><td nowrap><a target="classFrame" href="default/de%5CRaumZeitLabor%5CPartDB2%5CTests%5CAuth%5CUserManagerTest.html">de\RaumZeitLabor\PartDB2\Tests\Auth\UserManagerTest</a></td></tr> -<tr><td nowrap><a target="classFrame" href="default/de%5CRaumZeitLabor%5CPartDB2%5CTests%5CAuth%5CUserTest.html">de\RaumZeitLabor\PartDB2\Tests\Auth\UserTest</a></td></tr> -<tr><td nowrap><a target="classFrame" href="default/de%5CRaumZeitLabor%5CPartDB2%5CTests%5CUtil%5CConfigurationTest.html">de\RaumZeitLabor\PartDB2\Tests\Util\ConfigurationTest</a></td></tr> -</table> -</body> -</html> diff --git a/tests/reports/phpunit/default/AuthManagerTest.html b/tests/reports/phpunit/default/AuthManagerTest.html @@ -1,51 +0,0 @@ -<html> -<head> -<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> -<title>Unit Test Results: default.AuthManagerTest</title> -<link rel="stylesheet" type="text/css" title="Style" href="../stylesheet.css"> -</head> -<body> -<h1>Unit Test Results</h1> -<table width="100%"><tr> -<td align="left"></td> -<td align="right">Designed for use with <a href="http://www.phpunit.de">PHPUnit</a> and <a href="http://www.phing.info/">Phing</a>.</td> -</tr></table> -<hr size="1"> -<h3>Class default.AuthManagerTest</h3> -<table class="details" border="0" cellpadding="5" cellspacing="2" width="95%"> -<tr valign="top"> -<th width="80%">Name</th> -<th>Tests</th> -<th>Errors</th> -<th>Failures</th> -<th nowrap>Time(s)</th> -</tr> -<tr valign="top" class="Pass"> -<td><a href="AuthManagerTest.html">AuthManagerTest</a></td> -<td>1</td> -<td>0</td> -<td>0</td> -<td>0.002</td> -</tr> -</table> -<h2>Tests</h2> -<table class="details" border="0" cellpadding="5" cellspacing="2" width="95%"> -<tr valign="top"> -<th>Name</th> -<th>Status</th> -<th width="80%">Type</th> -<th nowrap>Time(s)</th> -</tr> -<tr valign="top" class="TableRowColor"> -<td>testBasics</td> -<td>Success</td> -<td></td> -<td>0.002</td> -</tr> -</table> -<table width="100%"> -<tr><td><hr noshade size="1"></td></tr> -<tr><td class="small">Report generated at 2010-09-07T06:40:17+02:00</td></tr> -</table> -</body> -</html> diff --git a/tests/reports/phpunit/default/de\RaumZeitLabor\PartDB2\AuthManagerTest.html b/tests/reports/phpunit/default/de\RaumZeitLabor\PartDB2\AuthManagerTest.html @@ -1,51 +0,0 @@ -<html> -<head> -<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> -<title>Unit Test Results: default.de\RaumZeitLabor\PartDB2\AuthManagerTest</title> -<link rel="stylesheet" type="text/css" title="Style" href="../stylesheet.css"> -</head> -<body> -<h1>Unit Test Results</h1> -<table width="100%"><tr> -<td align="left"></td> -<td align="right">Designed for use with <a href="http://www.phpunit.de">PHPUnit</a> and <a href="http://www.phing.info/">Phing</a>.</td> -</tr></table> -<hr size="1"> -<h3>Class default.de\RaumZeitLabor\PartDB2\AuthManagerTest</h3> -<table class="details" border="0" cellpadding="5" cellspacing="2" width="95%"> -<tr valign="top"> -<th width="80%">Name</th> -<th>Tests</th> -<th>Errors</th> -<th>Failures</th> -<th nowrap>Time(s)</th> -</tr> -<tr valign="top" class="Pass"> -<td><a href="de%5CRaumZeitLabor%5CPartDB2%5CAuthManagerTest.html">de\RaumZeitLabor\PartDB2\AuthManagerTest</a></td> -<td>1</td> -<td>0</td> -<td>0</td> -<td>0.001</td> -</tr> -</table> -<h2>Tests</h2> -<table class="details" border="0" cellpadding="5" cellspacing="2" width="95%"> -<tr valign="top"> -<th>Name</th> -<th>Status</th> -<th width="80%">Type</th> -<th nowrap>Time(s)</th> -</tr> -<tr valign="top" class="TableRowColor"> -<td>testBasics</td> -<td>Success</td> -<td></td> -<td>0.001</td> -</tr> -</table> -<table width="100%"> -<tr><td><hr noshade size="1"></td></tr> -<tr><td class="small">Report generated at 2010-09-07T06:57:59+02:00</td></tr> -</table> -</body> -</html> diff --git a/tests/reports/phpunit/default/de\RaumZeitLabor\PartDB2\Tests\Auth\AuthManagerTest.html b/tests/reports/phpunit/default/de\RaumZeitLabor\PartDB2\Tests\Auth\AuthManagerTest.html @@ -1,51 +0,0 @@ -<html> -<head> -<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> -<title>Unit Test Results: default.de\RaumZeitLabor\PartDB2\Tests\Auth\AuthManagerTest</title> -<link rel="stylesheet" type="text/css" title="Style" href="../stylesheet.css"> -</head> -<body> -<h1>Unit Test Results</h1> -<table width="100%"><tr> -<td align="left"></td> -<td align="right">Designed for use with <a href="http://www.phpunit.de">PHPUnit</a> and <a href="http://www.phing.info/">Phing</a>.</td> -</tr></table> -<hr size="1"> -<h3>Class default.de\RaumZeitLabor\PartDB2\Tests\Auth\AuthManagerTest</h3> -<table class="details" border="0" cellpadding="5" cellspacing="2" width="95%"> -<tr valign="top"> -<th width="80%">Name</th> -<th>Tests</th> -<th>Errors</th> -<th>Failures</th> -<th nowrap>Time(s)</th> -</tr> -<tr valign="top" class="Pass"> -<td><a href="de%5CRaumZeitLabor%5CPartDB2%5CTests%5CAuth%5CAuthManagerTest.html">de\RaumZeitLabor\PartDB2\Tests\Auth\AuthManagerTest</a></td> -<td>1</td> -<td>0</td> -<td>0</td> -<td>0.019</td> -</tr> -</table> -<h2>Tests</h2> -<table class="details" border="0" cellpadding="5" cellspacing="2" width="95%"> -<tr valign="top"> -<th>Name</th> -<th>Status</th> -<th width="80%">Type</th> -<th nowrap>Time(s)</th> -</tr> -<tr valign="top" class="TableRowColor"> -<td>testBasics</td> -<td>Success</td> -<td></td> -<td>0.019</td> -</tr> -</table> -<table width="100%"> -<tr><td><hr noshade size="1"></td></tr> -<tr><td class="small">Report generated at 2010-09-10T00:58:29+02:00</td></tr> -</table> -</body> -</html> diff --git a/tests/reports/phpunit/default/de\RaumZeitLabor\PartDB2\Tests\Auth\UserManagerTest.html b/tests/reports/phpunit/default/de\RaumZeitLabor\PartDB2\Tests\Auth\UserManagerTest.html @@ -1,69 +0,0 @@ -<html> -<head> -<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> -<title>Unit Test Results: default.de\RaumZeitLabor\PartDB2\Tests\Auth\UserManagerTest</title> -<link rel="stylesheet" type="text/css" title="Style" href="../stylesheet.css"> -</head> -<body> -<h1>Unit Test Results</h1> -<table width="100%"><tr> -<td align="left"></td> -<td align="right">Designed for use with <a href="http://www.phpunit.de">PHPUnit</a> and <a href="http://www.phing.info/">Phing</a>.</td> -</tr></table> -<hr size="1"> -<h3>Class default.de\RaumZeitLabor\PartDB2\Tests\Auth\UserManagerTest</h3> -<table class="details" border="0" cellpadding="5" cellspacing="2" width="95%"> -<tr valign="top"> -<th width="80%">Name</th> -<th>Tests</th> -<th>Errors</th> -<th>Failures</th> -<th nowrap>Time(s)</th> -</tr> -<tr valign="top" class="Pass"> -<td><a href="de%5CRaumZeitLabor%5CPartDB2%5CTests%5CAuth%5CUserManagerTest.html">de\RaumZeitLabor\PartDB2\Tests\Auth\UserManagerTest</a></td> -<td>4</td> -<td>0</td> -<td>0</td> -<td>0.165</td> -</tr> -</table> -<h2>Tests</h2> -<table class="details" border="0" cellpadding="5" cellspacing="2" width="95%"> -<tr valign="top"> -<th>Name</th> -<th>Status</th> -<th width="80%">Type</th> -<th nowrap>Time(s)</th> -</tr> -<tr valign="top" class="TableRowColor"> -<td>testUserExists</td> -<td>Success</td> -<td></td> -<td>0.043</td> -</tr> -<tr valign="top" class="TableRowColor"> -<td>testCreateUser</td> -<td>Success</td> -<td></td> -<td>0.021</td> -</tr> -<tr valign="top" class="TableRowColor"> -<td>testDeleteUser</td> -<td>Success</td> -<td></td> -<td>0.005</td> -</tr> -<tr valign="top" class="TableRowColor"> -<td>testDoctrineUsernameBug</td> -<td>Success</td> -<td></td> -<td>0.097</td> -</tr> -</table> -<table width="100%"> -<tr><td><hr noshade size="1"></td></tr> -<tr><td class="small">Report generated at 2010-09-10T00:58:29+02:00</td></tr> -</table> -</body> -</html> diff --git a/tests/reports/phpunit/default/de\RaumZeitLabor\PartDB2\Tests\Auth\UserTest.html b/tests/reports/phpunit/default/de\RaumZeitLabor\PartDB2\Tests\Auth\UserTest.html @@ -1,51 +0,0 @@ -<html> -<head> -<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> -<title>Unit Test Results: default.de\RaumZeitLabor\PartDB2\Tests\Auth\UserTest</title> -<link rel="stylesheet" type="text/css" title="Style" href="../stylesheet.css"> -</head> -<body> -<h1>Unit Test Results</h1> -<table width="100%"><tr> -<td align="left"></td> -<td align="right">Designed for use with <a href="http://www.phpunit.de">PHPUnit</a> and <a href="http://www.phing.info/">Phing</a>.</td> -</tr></table> -<hr size="1"> -<h3>Class default.de\RaumZeitLabor\PartDB2\Tests\Auth\UserTest</h3> -<table class="details" border="0" cellpadding="5" cellspacing="2" width="95%"> -<tr valign="top"> -<th width="80%">Name</th> -<th>Tests</th> -<th>Errors</th> -<th>Failures</th> -<th nowrap>Time(s)</th> -</tr> -<tr valign="top" class="Pass"> -<td><a href="de%5CRaumZeitLabor%5CPartDB2%5CTests%5CAuth%5CUserTest.html">de\RaumZeitLabor\PartDB2\Tests\Auth\UserTest</a></td> -<td>1</td> -<td>0</td> -<td>0</td> -<td>0.016</td> -</tr> -</table> -<h2>Tests</h2> -<table class="details" border="0" cellpadding="5" cellspacing="2" width="95%"> -<tr valign="top"> -<th>Name</th> -<th>Status</th> -<th width="80%">Type</th> -<th nowrap>Time(s)</th> -</tr> -<tr valign="top" class="TableRowColor"> -<td>testBasics</td> -<td>Success</td> -<td></td> -<td>0.016</td> -</tr> -</table> -<table width="100%"> -<tr><td><hr noshade size="1"></td></tr> -<tr><td class="small">Report generated at 2010-09-10T00:58:29+02:00</td></tr> -</table> -</body> -</html> diff --git a/tests/reports/phpunit/default/de\RaumZeitLabor\PartDB2\Tests\Util\ConfigurationTest.html b/tests/reports/phpunit/default/de\RaumZeitLabor\PartDB2\Tests\Util\ConfigurationTest.html @@ -1,51 +0,0 @@ -<html> -<head> -<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> -<title>Unit Test Results: default.de\RaumZeitLabor\PartDB2\Tests\Util\ConfigurationTest</title> -<link rel="stylesheet" type="text/css" title="Style" href="../stylesheet.css"> -</head> -<body> -<h1>Unit Test Results</h1> -<table width="100%"><tr> -<td align="left"></td> -<td align="right">Designed for use with <a href="http://www.phpunit.de">PHPUnit</a> and <a href="http://www.phing.info/">Phing</a>.</td> -</tr></table> -<hr size="1"> -<h3>Class default.de\RaumZeitLabor\PartDB2\Tests\Util\ConfigurationTest</h3> -<table class="details" border="0" cellpadding="5" cellspacing="2" width="95%"> -<tr valign="top"> -<th width="80%">Name</th> -<th>Tests</th> -<th>Errors</th> -<th>Failures</th> -<th nowrap>Time(s)</th> -</tr> -<tr valign="top" class="Pass"> -<td><a href="de%5CRaumZeitLabor%5CPartDB2%5CTests%5CUtil%5CConfigurationTest.html">de\RaumZeitLabor\PartDB2\Tests\Util\ConfigurationTest</a></td> -<td>1</td> -<td>0</td> -<td>0</td> -<td>0.009</td> -</tr> -</table> -<h2>Tests</h2> -<table class="details" border="0" cellpadding="5" cellspacing="2" width="95%"> -<tr valign="top"> -<th>Name</th> -<th>Status</th> -<th width="80%">Type</th> -<th nowrap>Time(s)</th> -</tr> -<tr valign="top" class="TableRowColor"> -<td>testConfiguration</td> -<td>Success</td> -<td></td> -<td>0.009</td> -</tr> -</table> -<table width="100%"> -<tr><td><hr noshade size="1"></td></tr> -<tr><td class="small">Report generated at 2010-09-10T00:58:29+02:00</td></tr> -</table> -</body> -</html> diff --git a/tests/reports/phpunit/default/package-frame.html b/tests/reports/phpunit/default/package-frame.html @@ -1,17 +0,0 @@ -<html> -<head> -<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> -<title>Unit Test Classes: default</title> -<link rel="stylesheet" type="text/css" title="Style" href="../stylesheet.css"> -</head> -<body> -<table width="100%"><tr><td nowrap><h2><a href="package-summary.html" target="classFrame">default</a></h2></td></tr></table> -<h2>Classes</h2> -<table width="100%"> -<tr><td nowrap><a href="de%5CRaumZeitLabor%5CPartDB2%5CTests%5CAuth%5CAuthManagerTest.html" target="classFrame">de\RaumZeitLabor\PartDB2\Tests\Auth\AuthManagerTest</a></td></tr> -<tr><td nowrap><a href="de%5CRaumZeitLabor%5CPartDB2%5CTests%5CAuth%5CUserManagerTest.html" target="classFrame">de\RaumZeitLabor\PartDB2\Tests\Auth\UserManagerTest</a></td></tr> -<tr><td nowrap><a href="de%5CRaumZeitLabor%5CPartDB2%5CTests%5CAuth%5CUserTest.html" target="classFrame">de\RaumZeitLabor\PartDB2\Tests\Auth\UserTest</a></td></tr> -<tr><td nowrap><a href="de%5CRaumZeitLabor%5CPartDB2%5CTests%5CUtil%5CConfigurationTest.html" target="classFrame">de\RaumZeitLabor\PartDB2\Tests\Util\ConfigurationTest</a></td></tr> -</table> -</body> -</html> diff --git a/tests/reports/phpunit/default/package-summary.html b/tests/reports/phpunit/default/package-summary.html @@ -1,57 +0,0 @@ -<html> -<head> -<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> -<link rel="stylesheet" type="text/css" title="Style" href="../stylesheet.css"> -</head> -<body onload="open('package-frame.html','classListFrame')"> -<h1>Unit Test Results</h1> -<table width="100%"><tr> -<td align="left"></td> -<td align="right">Designed for use with <a href="http://www.phpunit.de">PHPUnit</a> and <a href="http://www.phing.info/">Phing</a>.</td> -</tr></table> -<hr size="1"> -<h3>Package default</h3> -<h2>Classes</h2> -<p><table class="details" border="0" cellpadding="5" cellspacing="2" width="95%"> -<tr valign="top"> -<th width="80%">Name</th> -<th>Tests</th> -<th>Errors</th> -<th>Failures</th> -<th nowrap>Time(s)</th> -</tr> -<tr valign="top" class="Pass"> -<td><a href="de%5CRaumZeitLabor%5CPartDB2%5CTests%5CAuth%5CAuthManagerTest.html">de\RaumZeitLabor\PartDB2\Tests\Auth\AuthManagerTest</a></td> -<td>1</td> -<td>0</td> -<td>0</td> -<td>0.019</td> -</tr> -<tr valign="top" class="Pass"> -<td><a href="de%5CRaumZeitLabor%5CPartDB2%5CTests%5CAuth%5CUserManagerTest.html">de\RaumZeitLabor\PartDB2\Tests\Auth\UserManagerTest</a></td> -<td>4</td> -<td>0</td> -<td>0</td> -<td>0.165</td> -</tr> -<tr valign="top" class="Pass"> -<td><a href="de%5CRaumZeitLabor%5CPartDB2%5CTests%5CAuth%5CUserTest.html">de\RaumZeitLabor\PartDB2\Tests\Auth\UserTest</a></td> -<td>1</td> -<td>0</td> -<td>0</td> -<td>0.016</td> -</tr> -<tr valign="top" class="Pass"> -<td><a href="de%5CRaumZeitLabor%5CPartDB2%5CTests%5CUtil%5CConfigurationTest.html">de\RaumZeitLabor\PartDB2\Tests\Util\ConfigurationTest</a></td> -<td>1</td> -<td>0</td> -<td>0</td> -<td>0.009</td> -</tr> -</table></p> -<table width="100%"> -<tr><td><hr noshade size="1"></td></tr> -<tr><td class="small">Report generated at 2010-09-10T00:58:29+02:00</td></tr> -</table> -</body> -</html> diff --git a/tests/reports/phpunit/index.html b/tests/reports/phpunit/index.html @@ -1,19 +0,0 @@ -<html> -<head> -<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> -<title>Unit Test Results.</title> -</head> -<frameset cols="20%,80%"> -<frameset rows="30%,70%"> -<frame src="overview-frame.html" name="packageListFrame"> -<frame src="allclasses-frame.html" name="classListFrame"> -</frameset> -<frame src="overview-summary.html" name="classFrame"> -<noframes> -<h2>Frame Alert</h2> -<p> - This document is designed to be viewed using the frames feature. If you see this message, you are using a non-frame-capable web client. - </p> -</noframes> -</frameset> -</html> diff --git a/tests/reports/phpunit/overview-frame.html b/tests/reports/phpunit/overview-frame.html @@ -1,12 +0,0 @@ -<html> -<head> -<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> -<title>All Unit Test Packages</title> -<link rel="stylesheet" type="text/css" title="Style" href="stylesheet.css"> -</head> -<body> -<h2><a href="overview-summary.html" target="classFrame">Home</a></h2> -<h2>Packages</h2> -<table width="100%"><tr><td nowrap><a href="./default/package-summary.html" target="classFrame">default</a></td></tr></table> -</body> -</html> diff --git a/tests/reports/phpunit/overview-summary.html b/tests/reports/phpunit/overview-summary.html @@ -1,56 +0,0 @@ -<html> -<head> -<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> -<title>Unit Test Results: Summary</title> -<link rel="stylesheet" type="text/css" title="Style" href="stylesheet.css"> -</head> -<body onload="open('allclasses-frame.html','classListFrame')"> -<h1>Unit Test Results</h1> -<table width="100%"><tr> -<td align="left"></td> -<td align="right">Designed for use with <a href="http://www.phpunit.de">PHPUnit</a> and <a href="http://www.phing.info/">Phing</a>.</td> -</tr></table> -<hr size="1"> -<h2>Summary</h2> -<table class="details" border="0" cellpadding="5" cellspacing="2" width="95%"> -<tr valign="top"> -<th>Tests</th> -<th>Failures</th> -<th>Errors</th> -<th>Success rate</th> -<th>Time</th> -</tr> -<tr valign="top" class="Pass"> -<td>7</td> -<td>0</td> -<td>0</td> -<td>100.00%</td> -<td>0.209</td> -</tr> -</table> -<table border="0" width="95%"><tr><td style="text-align: justify;"> - Note: <em>failures</em> are anticipated and checked for with assertions while <em>errors</em> are unanticipated. - </td></tr></table> -<h2>Packages</h2> -<table class="details" border="0" cellpadding="5" cellspacing="2" width="95%"> -<tr valign="top"> -<th width="80%">Name</th> -<th>Tests</th> -<th>Errors</th> -<th>Failures</th> -<th nowrap>Time(s)</th> -</tr> -<tr valign="top" class="Pass"> -<td><a href="./default/package-summary.html">default</a></td> -<td>7</td> -<td>0</td> -<td>0</td> -<td>0.209</td> -</tr> -</table> -<table width="100%"> -<tr><td><hr noshade size="1"></td></tr> -<tr><td class="small">Report generated at 2010-09-10T00:58:29+02:00</td></tr> -</table> -</body> -</html> diff --git a/tests/reports/phpunit/stylesheet.css b/tests/reports/phpunit/stylesheet.css @@ -1,66 +0,0 @@ -<?xml version="1.0"?> - -body { - font-family: verdana,arial,helvetica; - color:#000000; - font-size: 12px; -} -table tr td, table tr th { - font-family: verdana,arial,helvetica; - font-size: 12px; -} -table.details tr th{ - font-family: verdana,arial,helvetica; - font-weight: bold; - text-align:left; - background:#a6caf0; -} -table.details tr td{ - background:#eeeee0; -} - -p { - line-height:1.5em; - margin-top:0.5em; margin-bottom:1.0em; - font-size: 12px; -} -h1 { - margin: 0px 0px 5px; - font-family: verdana,arial,helvetica; -} -h2 { - margin-top: 1em; margin-bottom: 0.5em; - font-family: verdana,arial,helvetica; -} -h3 { - margin-bottom: 0.5em; - font-family: verdana,arial,helvetica; -} -h4 { - margin-bottom: 0.5em; - font-family: verdana,arial,helvetica; -} -h5 { - margin-bottom: 0.5em; - font-family: verdana,arial,helvetica; -} -h6 { - margin-bottom: 0.5em; - font-family: verdana,arial,helvetica; -} -.Error { - font-weight:bold; color:red; -} -.Failure { - font-weight:bold; color:purple; -} -.small { - font-size: 9px; -} -a { - color: #003399; -} -a:hover { - color: #888888; -} - diff --git a/tests/reports/phpunit/testsuites.xml b/tests/reports/phpunit/testsuites.xml @@ -1,28 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<testsuites> - <testsuite name="Phing Batchtest" tests="7" assertions="12" failures="0" errors="1" time="0.286509"> - <testsuite name="de\RaumZeitLabor\PartDB2\Tests\Auth\AuthManagerTest" file="/home/felicitus/public_html/partdb2/tests/Auth/AuthManagerTest.php" namespace="de\RaumZeitLabor\PartDB2\Tests\Auth" fullPackage="de.RaumZeitLabor.PartDB2.Tests.Auth" tests="1" assertions="0" failures="0" errors="0" time="0.003725"> - <testcase name="testBasics" class="de\RaumZeitLabor\PartDB2\Tests\Auth\AuthManagerTest" file="/home/felicitus/public_html/partdb2/tests/Auth/AuthManagerTest.php" line="7" assertions="0" time="0.003725"/> - </testsuite> - <testsuite name="de\RaumZeitLabor\PartDB2\Tests\Auth\UserManagerTest" file="/home/felicitus/public_html/partdb2/tests/Auth/UserManagerTest.php" namespace="de\RaumZeitLabor\PartDB2\Tests\Auth" fullPackage="de.RaumZeitLabor.PartDB2.Tests.Auth" tests="4" assertions="3" failures="0" errors="1" time="0.235301"> - <testcase name="testUserExists" class="de\RaumZeitLabor\PartDB2\Tests\Auth\UserManagerTest" file="/home/felicitus/public_html/partdb2/tests/Auth/UserManagerTest.php" line="17" assertions="1" time="0.073451"/> - <testcase name="testCreateUser" class="de\RaumZeitLabor\PartDB2\Tests\Auth\UserManagerTest" file="/home/felicitus/public_html/partdb2/tests/Auth/UserManagerTest.php" line="21" assertions="1" time="0.031516"/> - <testcase name="testDeleteUser" class="de\RaumZeitLabor\PartDB2\Tests\Auth\UserManagerTest" file="/home/felicitus/public_html/partdb2/tests/Auth/UserManagerTest.php" line="33" assertions="1" time="0.015458"/> - <testcase name="testDoctrineUsernameBug" class="de\RaumZeitLabor\PartDB2\Tests\Auth\UserManagerTest" file="/home/felicitus/public_html/partdb2/tests/Auth/UserManagerTest.php" line="46" assertions="0" time="0.114876"> - <error type="Exception">de\RaumZeitLabor\PartDB2\Tests\Auth\UserManagerTest::testDoctrineUsernameBug -Exception: - -/home/felicitus/public_html/partdb2/src/de/RaumZeitLabor/PartDB2/Auth/UserManager.php:47 -/home/felicitus/public_html/partdb2/tests/Auth/UserManagerTest.php:59 -/usr/share/php/phing.php:37 -</error> - </testcase> - </testsuite> - <testsuite name="de\RaumZeitLabor\PartDB2\Tests\Auth\UserTest" file="/home/felicitus/public_html/partdb2/tests/Auth/UserTest.php" namespace="de\RaumZeitLabor\PartDB2\Tests\Auth" fullPackage="de.RaumZeitLabor.PartDB2.Tests.Auth" tests="1" assertions="6" failures="0" errors="0" time="0.019053"> - <testcase name="testBasics" class="de\RaumZeitLabor\PartDB2\Tests\Auth\UserTest" file="/home/felicitus/public_html/partdb2/tests/Auth/UserTest.php" line="8" assertions="6" time="0.019053"/> - </testsuite> - <testsuite name="de\RaumZeitLabor\PartDB2\Tests\Util\ConfigurationTest" file="/home/felicitus/public_html/partdb2/tests/Util/ConfigurationTest.php" namespace="de\RaumZeitLabor\PartDB2\Tests\Util" fullPackage="de.RaumZeitLabor.PartDB2.Tests.Util" tests="1" assertions="3" failures="0" errors="0" time="0.028430"> - <testcase name="testConfiguration" class="de\RaumZeitLabor\PartDB2\Tests\Util\ConfigurationTest" file="/home/felicitus/public_html/partdb2/tests/Util/ConfigurationTest.php" line="7" assertions="3" time="0.028430"/> - </testsuite> - </testsuite> -</testsuites>