src/Charcoal/Admin/Service/Exporter.php
private function prepareOptions()
    {
        $metadata = $this->metadata();

        // Can be override from the outside.
        if (!$this->exportIdent()) {
            $exportIdent = $this->exportIdent() ? : $this->metadata()->get('admin.default_export');
            if (!$exportIdent) {
                throw new Exception(sprintf(
                    'No export ident defined for "%s" in %s',
                    $this->objType(),
                    get_class($this)
                ));
            }

            $this->setExportIdent($exportIdent);
        }

        $export = $metadata->get('admin.export.'.$this->exportIdent());
        if (!$export) {
            throw new Exception(sprintf(
                'No export data defined for "%s" at "%s" in %s',
                $this->objType(),
                $this->exportIdent(),
                get_class($this)
            ));
        }

        if (is_string($export)) {
            $export = $metadata->get('admin.lists.'.$export);
            if (!$export) {
                throw new Exception(sprintf(
                    'No export data defined for "%s" in %s',
                    $this->objType(),
                    get_class($this)
                ));
            }
        }

        if (!isset($export['properties'])) {
            throw new Exception(sprintf(
                'No properties defined to export "%s" in %s',
                $this->objType(),
                get_class($this)
            ));
        }

        if (isset($export['exporter_options'])) {
            $opts = $export['exporter_options'];
            if (isset($opts['convert_br_to_newlines'])) {
                $this->setConvertBrToNewlines($opts['convert_br_to_newlines']);
            }
            if (isset($opts['strip_tags'])) {
                $this->setStripTags($opts['strip_tags']);
            }
            if (isset($opts['filename'])) {
                $this->setFilename($opts['filename']);
            }
        }

        // Default filename.
        // Filename is not a requirement
        if (!$this->filename()) {
            $ts = new DateTime('now');
            $filename = str_replace('/', '.', strtolower($this->objType())).'-export-'.$ts->format('Ymd.His').'.csv';
            $this->setFilename($filename);
        }

        // Properties to be exported
        // They will defined the file header and the rows.
        $this->setProperties($export['properties']);

        // Unnecessary for collection config.
        unset($export['properties']);
        unset($export['exporter_options']);

        // The rest is just collection config
        $this->setCollectionConfig($export);

        return $this;
    }
private function prepareOptions()
    {
        $metadata = $this->metadata();

        // Can be override from the outside.
        if (!$this->exportIdent()) {
            $exportIdent = $this->exportIdent() ? : $this->metadata()->get('admin.default_export');
            if (!$exportIdent) {
                throw new Exception(sprintf(
                    'No export ident defined for "%s" in %s',
                    $this->objType(),
                    get_class($this)
                ));
            }

            $this->setExportIdent($exportIdent);
        }

        $export = $metadata->get('admin.export.'.$this->exportIdent());
        if (!$export) {
            throw new Exception(sprintf(
                'No export data defined for "%s" at "%s" in %s',
                $this->objType(),
                $this->exportIdent(),
                get_class($this)
            ));
        }

        if (is_string($export)) {
            $export = $metadata->get('admin.lists.'.$export);
            if (!$export) {
                throw new Exception(sprintf(
                    'No export data defined for "%s" in %s',
                    $this->objType(),
                    get_class($this)
                ));
            }
        }

        if (!isset($export['properties'])) {
            throw new Exception(sprintf(
                'No properties defined to export "%s" in %s',
                $this->objType(),
                get_class($this)
            ));
        }

        if (isset($export['exporter_options'])) {
            $opts = $export['exporter_options'];
            if (isset($opts['convert_br_to_newlines'])) {
                $this->setConvertBrToNewlines($opts['convert_br_to_newlines']);
            }
            if (isset($opts['strip_tags'])) {
                $this->setStripTags($opts['strip_tags']);
            }
            if (isset($opts['filename'])) {
                $this->setFilename($opts['filename']);
            }
        }

        // Default filename.
        // Filename is not a requirement
        if (!$this->filename()) {
            $ts = new DateTime('now');
            $filename = str_replace('/', '.', strtolower($this->objType())).'-export-'.$ts->format('Ymd.His').'.csv';
            $this->setFilename($filename);
        }

        // Properties to be exported
        // They will defined the file header and the rows.
        $this->setProperties($export['properties']);

        // Unnecessary for collection config.
        unset($export['properties']);
        unset($export['exporter_options']);

        // The rest is just collection config
        $this->setCollectionConfig($export);

        return $this;
    }
private function prepareOptions ( ) { $ metadata = $ this -> metadata ( ) ; // Can be override from the outside. if ( ! $ this -> exportIdent ( ) ) { $ exportIdent = $ this -> exportIdent ( ) ? : $ this -> metadata ( ) -> get ( 'admin.default_export' ) ; if ( ! $ exportIdent ) { throw new Exception ( sprintf ( 'No export ident defined for "%s" in %s' , $ this -> objType ( ) , get_class ( $ this ) ) ) ; } $ this -> setExportIdent ( $ exportIdent ) ; } $ export = $ metadata -> get ( 'admin.export.' . $ this -> exportIdent ( ) ) ; if ( ! $ export ) { throw new Exception ( sprintf ( 'No export data defined for "%s" at "%s" in %s' , $ this -> objType ( ) , $ this -> exportIdent ( ) , get_class ( $ this ) ) ) ; } if ( is_string ( $ export ) ) { $ export = $ metadata -> get ( 'admin.lists.' . $ export ) ; if ( ! $ export ) { throw new Exception ( sprintf ( 'No export data defined for "%s" in %s' , $ this -> objType ( ) , get_class ( $ this ) ) ) ; } } if ( ! isset ( $ export [ 'properties' ] ) ) { throw new Exception ( sprintf ( 'No properties defined to export "%s" in %s' , $ this -> objType ( ) , get_class ( $ this ) ) ) ; } if ( isset ( $ export [ 'exporter_options' ] ) ) { $ opts = $ export [ 'exporter_options' ] ; if ( isset ( $ opts [ 'convert_br_to_newlines' ] ) ) { $ this -> setConvertBrToNewlines ( $ opts [ 'convert_br_to_newlines' ] ) ; } if ( isset ( $ opts [ 'strip_tags' ] ) ) { $ this -> setStripTags ( $ opts [ 'strip_tags' ] ) ; } if ( isset ( $ opts [ 'filename' ] ) ) { $ this -> setFilename ( $ opts [ 'filename' ] ) ; } } // Default filename. // Filename is not a requirement if ( ! $ this -> filename ( ) ) { $ ts = new DateTime ( 'now' ) ; $ filename = str_replace ( '/' , '.' , strtolower ( $ this -> objType ( ) ) ) . '-export-' . $ ts -> format ( 'Ymd.His' ) . '.csv' ; $ this -> setFilename ( $ filename ) ; } // Properties to be exported // They will defined the file header and the rows. $ this -> setProperties ( $ export [ 'properties' ] ) ; // Unnecessary for collection config. unset ( $ export [ 'properties' ] ) ; unset ( $ export [ 'exporter_options' ] ) ; // The rest is just collection config $ this -> setCollectionConfig ( $ export ) ; return $ this ; }
Set all data from the metadata.
@throws Exception If no export ident is specified or found.
@throws Exception If no export data is found.
@throws Exception If no properties are defined.
@return Exporter Chainable.
Set all data from the metadata .