[ '@namespace' => 'default_objects/SystemFunction', '@primaryKey' => 'name', 'name' => [ '@type' => 'xsd:string' ], 'description' => [ '@type' => 'xsd:string', '@label' => "Opis" ], 'param' => [ '@type' => 'xsd:string', '@label' => "Parametry", '@macOccurs' => 'unbounded' ], // 'autor' => [ '@type' => 'xsd:string' ], // 'utworzono' => [ '@type' => 'xsd:date' ], // 'zaktualizowaƂ' => [ '@type' => 'xsd:string' ], // 'zaktualizowano' => [ '@type' => 'xsd:date' ] ] ]; public $_rootTableName = 'CRM_LISTA_ZASOBOW'; public function getTotal($params = []) { return count($this->_getAllItems()); } public function getItems($params = []) { $items = $this->_getAllItems(); $currSortCol = V::get('order_by', 'ID', $params); $currSortFlip = strtolower(V::get('order_dir', 'desc', $params)); // TODO: validate $currSortCol is in field list // TODO: validate $currSortFlip ('asc' or 'desc') $aliasMap = array(); foreach ($this->_simpleSchema['root'] as $key => $field) { if ('@' === substr($key, 0, 1)) continue; $aliasMap[ $key ] = $key;// (!empty($field['@alias'])) ? $field['@alias'] : $key; } // TODO: if (!array_key_exists($currSortCol, $aliasMap)) throw new Exception("field name not allowed to sort"); $currSortCol = (array_key_exists($currSortCol, $aliasMap)) ? $aliasMap[$currSortCol] : null; if (!empty($currSortCol) && ('asc' == $currSortFlip || 'desc' == $currSortFlip)) { usort($items, function ($itemA, $itemB) use ($currSortCol, $currSortFlip) { $a = strtolower(V::get($currSortCol, '', $itemA)); $b = strtolower(V::get($currSortCol, '', $itemB)); if ($a == $b) return 0; else if ('asc' == $currSortFlip) return ($a < $b) ? -1 : 1; else if ('desc' == $currSortFlip) return ($a > $b) ? -1 : 1; throw new Exception("BUG - Wrong sort param - order dir"); }); } $limit = V::get('limit', 0, $params); $limit = ($limit < 0) ? 0 : $limit; $offset = V::get('limitstart', 0, $params); $offset = ($offset < 0) ? 0 : $offset; return array_slice($items, $offset, ($limit > 0) ? $limit : null, $preserve_keys = true); } public function _getAllItems($params = []) { static $_cacheAllItems = null; if (null !== $_cacheAllItems) return $_cacheAllItems; $_cacheAllItems = []; $_cacheAllItems[] = [ 'name' => "Calendar", 'description' => "Calendar" ]; $_cacheAllItems[] = [ 'name' => "ProcesEditor", 'description' => "ProcesEditor" ]; $_cacheAllItems[] = [ 'name' => "ProcesView", 'description' => "ProcesView" ]; $_cacheAllItems[] = [ 'name' => "ProjektyKosztorys", 'description' => "ProjektyKosztorys" ]; $_cacheAllItems[] = [ 'name' => "ProjektyKosztyWstepnychRobot", 'description' => "ProjektyKosztyWstepnychRobot" ]; $_cacheAllItems[] = [ 'name' => "ProjektyOdbiorKosztorys", 'description' => "ProjektyOdbiorKosztorys" ]; $_cacheAllItems[] = [ 'name' => "ProjektyOfertaAdminKosztorys", 'description' => "ProjektyOfertaAdminKosztorys" ]; $_cacheAllItems[] = [ 'name' => "ProjektyOfertaKosztorys", 'description' => "ProjektyOfertaKosztorys" ]; $_cacheAllItems[] = [ 'name' => "ProjektyProNetMediaApproveZam", 'description' => "ProjektyProNetMediaApproveZam" ]; $_cacheAllItems[] = [ 'name' => "ProjektyProNetMediaBudget", 'description' => "ProjektyProNetMediaBudget" ]; $_cacheAllItems[] = [ 'name' => "ProjektyProNetMediaFinalApproveZam", 'description' => "ProjektyProNetMediaFinalApproveZam" ]; $_cacheAllItems[] = [ 'name' => "ProjektyProNetMediaRequestApproveZam", 'description' => "ProjektyProNetMediaRequestApproveZam" ]; $_cacheAllItems[] = [ 'name' => "ProjektyProNetMediaZamZlec", 'description' => "ProjektyProNetMediaZamZlec" ]; $_cacheAllItems[] = [ 'name' => "ProjektyPrzedmiarKosztorys", 'description' => "ProjektyPrzedmiarKosztorys" ]; $_cacheAllItems[] = [ 'name' => "ProjektyZamowieniaKosztorys", 'description' => "ProjektyZamowieniaKosztorys" ]; $_cacheAllItems[] = [ 'name' => "ProjektyZestawienieSwMikRurKosztorys", 'description' => "ProjektyZestawienieSwMikRurKosztorys" ]; $_cacheAllItems[] = [ 'name' => "RaportyKasowe", 'description' => "RaportyKasowe" ]; $_cacheAllItems[] = [ 'name' => "UserProNetMediaZaliczka", 'description' => "UserProNetMediaZaliczka" ]; $_cacheAllItems[] = [ 'name' => "WmsGenerate", 'description' => "WmsGenerate" ]; return $_cacheAllItems; } }