/** * @var ItemTreeBounds $itemTreeBounds * @param string $addCondition * @param array $addParameters * @return Item[] */ public function getContainedItems(ItemTreeBounds $itemTreeBounds, $addCondition = "", $addParameters = array()) { $uploadTreeTableName = $itemTreeBounds->getUploadTreeTableName(); $statementName = __METHOD__ . ".{$uploadTreeTableName}"; $view = new UploadTreeViewProxy($itemTreeBounds, array(UploadTreeViewProxy::CONDITION_PLAIN_FILES)); $this->dbManager->prepare($statementName, $view->asCTE() . " SELECT * FROM " . $view->getDbViewName() . " ut " . ($addCondition ? " WHERE " . $addCondition : '')); $res = $this->dbManager->execute($statementName, $addParameters); $items = array(); while ($row = $this->dbManager->fetchArray($res)) { $items[] = $this->createItem($row, $uploadTreeTableName); } $this->dbManager->freeResult($res); return $items; }
public function testWithMultipleConditions() { $this->itemTreeBounds->shouldReceive("getUploadTreeTableName")->once()->withNoArgs()->andReturn("foo"); $this->itemTreeBounds->shouldReceive("getUploadId")->once()->withNoArgs()->andReturn(5); $this->itemTreeBounds->shouldReceive("getLeft")->once()->withNoArgs()->andReturn(22); $this->itemTreeBounds->shouldReceive("getRight")->once()->withNoArgs()->andReturn(43); $uploadTreeView = new UploadTreeViewProxy($this->itemTreeBounds, array(UploadTreeViewProxy::CONDITION_UPLOAD, UploadTreeViewProxy::CONDITION_PLAIN_FILES, UploadTreeViewProxy::CONDITION_RANGE)); assertThat($uploadTreeView->getDbViewQuery(), is("SELECT * FROM foo WHERE upload_fk = 5 AND ((ufile_mode & (3<<28))=0) AND pfile_fk != 0 AND lft BETWEEN 22 AND 43")); }