|
|
@@ -1,168 +1,40 @@
|
|
|
<?php
|
|
|
|
|
|
-Lib::loadClass('Core_AclBase');
|
|
|
+Lib::loadClass('Core_AclSimpleSchemaBase');// extends Core_AclBase
|
|
|
Lib::loadClass('Core_AclHelper');
|
|
|
Lib::loadClass('FileStorage');
|
|
|
|
|
|
-class Schema_ZaliczkaStorageAcl extends Core_AclBase {
|
|
|
+class Schema_ZaliczkaStorageAcl extends Core_AclSimpleSchemaBase {
|
|
|
|
|
|
- public function __construct() {
|
|
|
- $this->parentAcl = User::getAcl()->getObjectAcl('default_db', 'USER_ZALICZKA');
|
|
|
- // DBG::_(true, true, "parentAcl", $this->parentAcl, __CLASS__, __FUNCTION__, __LINE__);
|
|
|
- }
|
|
|
- public function getNamespace() { return 'default_objects/' . $this->getName(); }
|
|
|
- public function getSourceName() { return 'default_objects'; }
|
|
|
- public function init($force = false) {}
|
|
|
- public function isInitialized() { return true; }
|
|
|
- public function getName() { return 'Zaliczka'; }
|
|
|
- public function getRootTableName() { return 'USER_ZALICZKA'; }
|
|
|
- public function getFieldListByIdZasob() { return $this->getRealFieldListByIdZasob(); }
|
|
|
- public function getVisibleFieldListByIdZasob() { return $this->getRealFieldListByIdZasob(); }
|
|
|
- public function getVirtualFieldListByIdZasob() { return array(); }
|
|
|
- public function getRealFieldListByIdZasob($force = false) {
|
|
|
- $cols = $this->parentAcl->getRealFieldListByIdZasob();
|
|
|
- $cols[100001] = 'Pracownik';
|
|
|
- $cols[100002] = 'Pozycja';
|
|
|
- return $cols;
|
|
|
- }
|
|
|
- public function getFields() {// @returns array - $this->_fields
|
|
|
- $fields = $this->parentAcl->getFields();
|
|
|
- $fields[100001] = ['name'=>'Pracownik', 'perms'=>'RWXC', 'opis'=>'Pracownik pobierający zaliczkę', 'sort_prio'=>1000, 'label'=>'Pracownik'];
|
|
|
- $fields[100002] = ['name'=>'Pozycja', 'perms'=>'RWXC', 'opis'=>'Pozycje zaliczki', 'sort_prio'=>1001, 'label'=>'Pozycje'];
|
|
|
- return $fields;
|
|
|
- }
|
|
|
- public function getFieldType($fieldName) {
|
|
|
- foreach ($this->getFields() as $field) {
|
|
|
- if ($fieldName == $field['name']) return $field;
|
|
|
- }
|
|
|
- return null;
|
|
|
- }
|
|
|
-
|
|
|
- // TODO: replace legacy functions: isAllowed, hasFieldPerm, getFieldIdByName
|
|
|
- public function canCreateField($fieldName) {
|
|
|
- if ('Pracownik' == $fieldName) return true;
|
|
|
- if ('Pozycja' == $fieldName) return true;
|
|
|
- return $this->parentAcl->canCreateField($fieldName);
|
|
|
- }
|
|
|
- public function canReadField($fieldName) {
|
|
|
- if ('File' == $fieldName) return true;
|
|
|
- if ('AccessGroupRead' == $fieldName) return true;
|
|
|
- if ('AccessGroupWrite' == $fieldName) return true;
|
|
|
- if ('AccessOwner' == $fieldName) return true;
|
|
|
- return $this->parentAcl->canReadField($fieldName);
|
|
|
- }
|
|
|
- public function canReadObjectField($fieldName, $record) {
|
|
|
- if ('File' == $fieldName) return true;
|
|
|
- if ('AccessGroupRead' == $fieldName) return true;
|
|
|
- if ('AccessGroupWrite' == $fieldName) return true;
|
|
|
- if ('AccessOwner' == $fieldName) return true;
|
|
|
- return $this->parentAcl->canReadObjectField($fieldName, $record);
|
|
|
- }
|
|
|
- public function canWriteField($fieldName) {
|
|
|
- if ('File' == $fieldName) return true;
|
|
|
- if ('AccessGroupRead' == $fieldName) return true;
|
|
|
- if ('AccessGroupWrite' == $fieldName) return true;
|
|
|
- if ('AccessOwner' == $fieldName) return true;
|
|
|
- return $this->parentAcl->canWriteField($fieldName);
|
|
|
- }
|
|
|
- public function canWriteObjectField($fieldName, $record) {
|
|
|
- if ('File' == $fieldName) return true;
|
|
|
- if ('AccessGroupRead' == $fieldName) return true;
|
|
|
- if ('AccessGroupWrite' == $fieldName) return true;
|
|
|
- if ('AccessOwner' == $fieldName) return true;
|
|
|
- return $this->parentAcl->canWriteObjectField($fieldName, $record);
|
|
|
- }
|
|
|
+ public $_simpleSchema = [
|
|
|
+ '@typeName' => 'default_objects:Zaliczka',
|
|
|
+ '@baseTypeName' => 'default_db:ZALICZKA',
|
|
|
+ 'id' => 'xsd:integer',
|
|
|
+ 'created' => 'xsd:date',
|
|
|
+ 'worker' => [
|
|
|
+ '@ref' => 'default_objects:AccessOwner',// local_ref:default_objects:AccessOwner
|
|
|
+ ],
|
|
|
+ 'kwota' => 'xsd:decimal',
|
|
|
+ 'pozycja' => [
|
|
|
+ '@ref' => 'default_objects:ZaliczkaPozycja',
|
|
|
+ '@maxOccurs' => 'unbounded',
|
|
|
+ // 'id' => 'xsd:integer',
|
|
|
+ // 'kwota' => 'xsd:decimal',
|
|
|
+ // 'korespondencja' => [// 'ref:korespondencja'
|
|
|
+ // '@baseTypeName' => 'default_db:IN7_DZIENNIK_KORESP',
|
|
|
+ // 'id' => 'xsd:integer',
|
|
|
+ // 'title' => 'xsd:string',
|
|
|
+ // 'kategoriaKosztu' => 'xsd:string'
|
|
|
+ // ],
|
|
|
+ // 'projekt' => [// 'ref:projekt'
|
|
|
+ // '@baseTypeName' => 'default_db:IN7_MK_BAZA_DYSTRYBUCJI',
|
|
|
+ // 'id' => 'xsd:integer',
|
|
|
+ // 'nrBudowy' => 'xsd:string'
|
|
|
+ // ]
|
|
|
+ ]
|
|
|
+ ];
|
|
|
|
|
|
- public function getTotal($params = array()) {// TODO: use ParseOgcQuery
|
|
|
- $DBG = V::get('DBG_DS', 0, $_GET, 'int');
|
|
|
- if($DBG>2){echo 'C.'.get_class($this).' L.' . __LINE__ . " getTotal \$params:";print_r($params);echo "\n";}
|
|
|
- return $this->parentAcl->getTotal($params);
|
|
|
- }
|
|
|
- public function getItem($primaryKey) {
|
|
|
- $items = $this->getItems(['primaryKey'=>$primaryKey]);
|
|
|
- return (!empty($items[$primaryKey])) ? $items[$primaryKey] : null;
|
|
|
- }
|
|
|
- public function getItems($params = array()) {// TODO: use ParseOgcQuery
|
|
|
- $DBG = V::get('DBG_DS', 0, $_GET, 'int');
|
|
|
- if($DBG>2){echo 'C.'.get_class($this).' L.' . __LINE__ . " getItems \$params:";print_r($params);echo "\n";}
|
|
|
- $items = array();
|
|
|
- $rawItems = $this->parentAcl->getItems($params);
|
|
|
- foreach ($rawItems as $pk => $item) $items[$pk] = (array)$item;
|
|
|
- if($DBG>2){echo 'C.'.get_class($this).' L.' . __LINE__ . " getItems \$items:";print_r($items);echo "\n";}
|
|
|
- if (empty($items)) return $items;
|
|
|
- $this->fetchItemRef($items);// TODO: only fields from request
|
|
|
- if($DBG>2){echo 'C.'.get_class($this).' L.' . __LINE__ . " getItems after fetchItemRef \$items:";print_r($items);echo "\n";}
|
|
|
- return $items;
|
|
|
- }
|
|
|
- public function fetchItemRef(&$items) {
|
|
|
- $DBG = V::get('DBG_DS', 0, $_GET, 'int');
|
|
|
- $refs = array();// fieldName => xsdType
|
|
|
- foreach ($this->getRealFieldListByIdZasob() as $id => $fieldName) {
|
|
|
- $fieldType = $this->getXsdFieldType($fieldName);
|
|
|
- if ('ref:' == substr($fieldType, 0, 4)) $refs[$fieldName] = substr($fieldType, 4);
|
|
|
- else if ('alias_ref:' == substr($fieldType, 0, 10)) {
|
|
|
- $refs[$fieldName] = substr($fieldType, 10);
|
|
|
- }
|
|
|
- }
|
|
|
- if (empty($refs)) return $items;
|
|
|
- $pkList = array_keys($items);
|
|
|
- $sqlPk = array(); foreach ($pkList as $pk) { $sqlPk[] = DB::getPDO()->quote($pk, PDO::PARAM_STR); } $sqlPk = implode(", ", $sqlPk);
|
|
|
- $refRows = array();// $fieldName => [ pk, ... ]
|
|
|
- foreach ($refs as $fieldName => $type) {
|
|
|
- $acl = Core_AclHelper::getAclByTypeName($type);
|
|
|
- // TODO: Core_AclBase->fetchRefs($fieldName, $pkList = array());// $refPk[$fieldName] = $this->fetchRefs($fieldName, $pkList);
|
|
|
- $refTableName = $this->createRefTable($fieldName);
|
|
|
- if($DBG>2){echo 'C.'.get_class($this).' L.' . __LINE__ . " getItems loop(\$fieldName:{$fieldName}) \$refTableName:({$refTableName})";echo"\n";}
|
|
|
- $refRows[$fieldName] = DB::getPDO()->fetchAllByKey("
|
|
|
- select r.*
|
|
|
- from `{$refTableName}` r
|
|
|
- where r.PRIMARY_KEY in({$sqlPk})
|
|
|
- and r.A_STATUS != 'DELETED'
|
|
|
- ", $key = 'PRIMARY_KEY');
|
|
|
- if($DBG>2){echo 'C.'.get_class($this).' L.' . __LINE__ . " getItems loop(\$fieldName:{$fieldName}) \$refTableName:({$refTableName}), \$refRows[$fieldName]";print_r($refRows[$fieldName]);echo"\n";}
|
|
|
- }
|
|
|
- foreach ($refRows as $fieldName => $refList) {
|
|
|
- foreach ($refList as $pk => $ref) {
|
|
|
- $items[ $pk ][ $fieldName ][] = array('xlink' => "{$refs[$fieldName]}.{$ref['REMOTE_PRIMARY_KEY']}");
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- public function addItem($itemTodo) {
|
|
|
- return $this->parentAcl->addItem($itemTodo);
|
|
|
- }
|
|
|
- public function updateItem($itemPatch) {
|
|
|
- return $this->parentAcl->updateItem($itemPatch);
|
|
|
- }
|
|
|
-
|
|
|
- public function getGeomFieldType($fieldName) { return null; }
|
|
|
- public function getPrimaryKeyField() { return 'ID'; }
|
|
|
- public function getID() { return 0; }
|
|
|
- public function getAttributesFromZasoby() { return array(); }
|
|
|
- public function isEnumerationField($fieldName) {
|
|
|
- if ('A_STATUS' == $fieldName) return true;
|
|
|
- return false;
|
|
|
- }
|
|
|
- public function getEnumerations($fieldName) {
|
|
|
- if ('A_STATUS' == $fieldName) return $this->parentAcl->getEnumerations($fieldName);
|
|
|
- return null;
|
|
|
- }
|
|
|
- public function getXsdFieldType($fieldName) {
|
|
|
- if ('File' == $fieldName) return 'ref:p5_objects:File';
|
|
|
- // if ('File1' == $fieldName) return 'alias_ref:p5_objects:File';
|
|
|
- // if ('File2' == $fieldName) return 'alias_ref:p5_objects:File';
|
|
|
- // if ('NestedObjectTest' == $fieldName) return 'local_ref:p5_objects:NestedObjectTest';
|
|
|
- if ('AccessGroupRead' == $fieldName) return 'ref:default_objects:AccessGroupRead';
|
|
|
- if ('AccessGroupWrite' == $fieldName) return 'ref:default_objects:AccessGroupWrite';
|
|
|
- if ('AccessOwner' == $fieldName) return 'ref:default_objects:AccessOwner';
|
|
|
- return $this->parentAcl->getXsdFieldType($fieldName);
|
|
|
- }
|
|
|
- public function isGeomField($fldName) {
|
|
|
- if ('File' == $fieldName) return false;
|
|
|
- if ('AccessGroupRead' == $fieldName) return false;
|
|
|
- if ('AccessGroupWrite' == $fieldName) return false;
|
|
|
- if ('AccessOwner' == $fieldName) return false;
|
|
|
- // if ('NestedObjectTest' == $fieldName) return false;
|
|
|
- return $this->parentAcl->isGeomField($fldName);
|
|
|
- }
|
|
|
+ public function getName() { return 'Zaliczka'; }
|
|
|
+ public function getRootTableName() { return 'ZALICZKA'; }
|
|
|
|
|
|
}
|