| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657 |
- <?php
- class FeatureAttrSelected {
- static function select($typeName, array $listPrimaryKeys) {
- $idUser = User::getID();
- self::prepareUserTable($typeName, $idUser);
- $tableName = self::getAttributeTableName($typeName, $idUser);
- foreach ($listPrimaryKeys as $pk) {
- DB::getPDO()->execSql(" insert ignore `{$tableName}` (`primaryKey`) values ( :pk ) ", [ ':pk' => $pk ]);
- }
- }
- static function unselect($typeName, array $listPrimaryKeys) {
- $idUser = User::getID();
- self::prepareUserTable($typeName, $idUser);
- $tableName = self::getAttributeTableName($typeName, $idUser);
- foreach ($listPrimaryKeys as $pk) {
- DB::getPDO()->execSql(" delete from `{$tableName}` where `primaryKey` = :pk ", [ ':pk' => $pk ]);
- }
- }
- static function prepareUserTable($typeName, $idUser) {
- static $_created = [];
- $key = "{$typeName}-{$idUser}";
- if (!array_key_exists($key, $_created)) {
- self::_prepareUserTable($typeName, $idUser);
- $_created[$key] = true;
- }
- }
- static function _prepareUserTable($typeName, $idUser) {
- $tableName = self::getAttributeTableName($typeName, $idUser);
- // DB::getPDO()->execSql(" DROP TABLE IF EXISTS `{$tableName}` ");
- // TODO: primaryKey type from $acl
- DB::getPDO()->execSql("
- CREATE TABLE IF NOT EXISTS `{$tableName}` (
- `primaryKey` int(11) NOT NULL,
- UNIQUE KEY `primaryKey` (`primaryKey`)
- ) ENGINE=MyISAM DEFAULT CHARSET=latin2;
- ");
- }
- static function getAttributeTableName($typeName, $idUser) {
- static $_created = [];
- $key = "{$typeName}-{$idUser}";
- if (!array_key_exists($key, $_created)) {
- $_created[$key] = self::_getAttributeTableName($typeName, $idUser);
- }
- return $_created[$key];
- }
- static function _getAttributeTableName($typeName, $idUser) {
- $acl = ACL::getAclByTypeName($typeName);
- $rootTableName = $acl->getRootTableName();
- return "{$rootTableName}__@selected_{$idUser}";
- }
- }
|