function listEntities($level) { if (!in_array($level, $this->getSchema()->getLevels())) { throw new VF_Level_Exception_InvalidLevel('Invalid level [' . $level . ']'); } $parent_id = 0; $parentLevel = $this->getSchema()->getPrevLevel($level); if ($parentLevel) { $parent_id = $this->getSelected($parentLevel); } $levelObject = new VF_Level($level); if ($this->isNotRootAndHasNoParent($level, $parent_id)) { return array(); } if (!$parentLevel || !$parent_id) { if ($this->shouldListAll()) { return $levelObject->listAll(); } else { return $levelObject->listInUse(array()); } } if ($this->shouldListAll()) { return $levelObject->listAll($parent_id); } else { return $levelObject->listInUse($this->getFlexibleSearch()->getLevelAndValueForSelectedPreviousLevels($level)); } }
function _toHtml() { $return = '<ul>'; $make = new VF_Level('make'); foreach ($make->listAll() as $eachMake) { $return .= '<li><a href="?make=' . $eachMake->getId() . '"><img src="/logos/' . strtoupper($eachMake->getTitle()) . '.jpg" /></a></li>'; } $return .= '</ul>'; return $return; }
function testListAllObeysParentIdForModel() { $y2000 = $this->newYear('2000'); $y2000->save(); $y2001 = $this->newYear('2001'); $y2001->save(); $honda = $this->newMake('Honda'); $honda->save($y2000); $honda = $this->newMake('Honda'); $honda->save($y2001); $civic = $this->newModel('Civic'); $civic->save($honda->getId()); $model = new VF_Level('model'); $models = $model->listAll(array('year'=>$y2000->getId(), 'make'=>$honda->getId())); $this->assertEquals( 0, count($models), 'list all should not find items from different parent id even in global mode' ); }
function testListAllWithParentId() { $vehicle1 = $this->createMMY( 'A', 'A', '1' ); $vehicle2 = $this->createMMY( 'A', 'B', '1' ); $vehicle3 = $this->createMMY( 'B', 'Z', 'Z' ); $this->insertMappingMMY( $vehicle1 ); $this->insertMappingMMY( $vehicle2 ); $this->insertMappingMMY( $vehicle3 ); $model = new VF_Level('model'); $actual = $model->listAll($vehicle1->getLevel('make')->getId()); $this->assertEquals( 'A', $actual[0]->getTitle(), 'should sort items' ); $this->assertEquals( 'B', $actual[1]->getTitle(), 'should sort items' ); }
function testShouldListChildrenLevelsInSecondSchema() { $schema = VF_Schema::create('foo,bar'); $vehicle = $this->createVehicle(array('foo' => '123', 'bar' => '456'), $schema); $bar = new VF_Level('bar', null, $schema); $actual = $bar->listAll($vehicle->getValue('foo')); $this->assertEquals('456', $actual[0]->getTitle(), 'should list children levels in 2nd schema'); }