Example #1
0
 public function test_grouped_convert_path_with_recipes()
 {
     // prepare some grouped data
     $data = array('ID' => 77, 'NAME' => 'Pale lagers', 'BEERS' => array(array('BEER' => array('ID' => 67, 'NAME' => 'Pilsner Urquell')), array('BEER' => array('ID' => 34, 'NAME' => 'Heineken'))));
     // implict recipes work for grouped data if the path is declared as grouped
     $path = new convert_path('beer_style', '/ROOT/BEER_STYLES/BEER_STYLE', array(), true);
     $data = $path->apply_recipes($data);
     $this->assertEquals('Heineken', $data['beers'][1]['beer']['name']);
     // an attempt to provide explicit recipes on grouped elements throws exception
     $this->setExpectedException('convert_path_exception');
     $path = new convert_path('beer_style', '/ROOT/BEER_STYLES/BEER_STYLE', array('renamefields' => array('name' => 'beername')), true);
 }
Example #2
0
    /**
     * Helper method used by {@link self::register_handler()}
     *
     * @param convert_path $pelement path element
     * @param array of convert_path instances
     * @return bool true if grouped parent was found, false otherwise
     */
    protected function grouped_parent_exists($pelement, $elements) {

        foreach ($elements as $element) {
            if ($pelement->get_path() == $element->get_path()) {
                // don't compare against itself
                continue;
            }
            // if the element is grouped and it is a parent of pelement, return true
            if ($element->is_grouped() and strpos($pelement->get_path() .  '/', $element->get_path()) === 0) {
                return true;
            }
        }

        // no grouped parent found
        return false;
    }