private function loadBlocks($itemId) { $sql = "SELECT * FROM block\n LEFT JOIN `block_item` ON `block_item`.`block_id` = block.`block_id`\n LEFT JOIN `block_group` ON `block_group`.`block_id` = block.`block_id`\n WHERE\n ((`block`.`item_exclusive` = 0 AND `block_item`.`item_id` = :itemId)\n OR\n (`block`.`item_exclusive` = 1 AND `block_item`.`item_id` IS NULL))\n AND\n ((`block`.`group_exclusive` = 0 AND `block_group`.`group_id` IN (:aGroupId))\n OR\n (`block`.`group_exclusive` = 1 AND (`block_group`.`group_id` IS NULL OR `block_group`.`group_id` NOT IN (:aGroupId))))\n GROUP BY `block`.`block_id`;"; $sth = DKY_DB::query($sql); $sth->bind("itemId", $itemId); $sth->bind("aGroupId", $_SESSION["aGroupId"]); $sth->execute(); while ($aBlock = $sth->fetch()) { $block = $this->getBlock($aBlock["block_name"], $aBlock["component_name"]); if (!empty($block)) { $block->init($aBlock, $this->_request); $this->aBlocks[$block->position][] = $block; } } }
/** * Get paginated data from a DB statement using the specified * * @param DKY_DB_Statement $sth * @param unknown $aQueryParams * @return array Paged data array. */ public static function getPagedData($sth, $page, $limit, $delta) { $aPagedData = array(); $aPagedData["pageNum"] = $page; $aPagedData["pageLimit"] = $limit; $aPagedData["pageDelta"] = $delta; $aStatementParams = $sth->getStatementParams(); $query = $sth->getSelectQuery(); // Get the total number of rows for the query. $queryNoLimit = "SELECT COUNT(*) AS `total_rows` FROM (" . $query . ") AS `data`;"; $sthNoLimit = DKY_DB::query($queryNoLimit); $sthNoLimit->bindParams($aStatementParams); $sthNoLimit->execute(); $row = $sthNoLimit->fetch(); $aPagedData["totalRows"] = $row["total_rows"]; // Get paged rows. $sthPage = DKY_DB::query("SELECT * FROM ({$query}) AS `data` LIMIT :pager_offset, :pager_limit;"); $sthPage->bindParams($aStatementParams); $pagerOffset = $aPagedData["pageLimit"] * ($aPagedData["pageNum"] - 1); $pagerLimit = $aPagedData["pageLimit"]; $sthPage->bind("pager_offset", $pagerOffset); $sthPage->bind("pager_limit", $pagerLimit); $sthPage->execute(); $aPagedData["rowCount"] = $sthPage->getRowCount(); $aPagedData["aData"] = $sthPage->fetchAll(); if (!empty($aPagedData["rowCount"])) { $aPagedData["totalPages"] = ceil($aPagedData["totalRows"] / $aPagedData["pageLimit"]); } else { $aPagedData["totalPages"] = 0; } $aPagedData["rowsAfter"] = $aPagedData["totalRows"] - $aPagedData["pageNum"] * $aPagedData["pageLimit"]; $aPagedData["rowsBefore"] = ($aPagedData["pageNum"] - 1) * $aPagedData["pageLimit"]; $aPagedData["pagesAfter"] = ceil($aPagedData["rowsAfter"] / $aPagedData["pageLimit"]); $aPagedData["pagesBefore"] = ceil($aPagedData["rowsBefore"] / $aPagedData["pageLimit"]); return $aPagedData; }
public function deleteBranch($nodeId) { DKY_DB::beginTransaction(); $aNode = $this->getNodeById($nodeId); $do_set = DKY_DB::query("DELETE FROM `" . $this->_table . "` WHERE `left_id` >= :leftId AND `right_id` <= :rightId"); $do_set->bind("leftId", $aNode["left_id"]); $do_set->bind("rightId", $aNode["right_id"]); $do_set = $sth->execute(); $this->_shiftNodesLeft($aNode["right_id"] - $aNode["left_id"] + 1, $aNode["left_id"]); return DKY_DB::commit(); }
public static function getColumns($table) { $sth = DKY_DB::query("DESCRIBE `" . $table . "`;"); $sth->execute(); return $sth->fetchAll(); }