Sign in to follow this  
nickngqs

Export CSV for a page

Recommended Posts

Does anyone know how to do an export of a page entries to CSV using the Processwire way?

I'm trying to setup a list where the client can see a list of user's form values.

Example ->

A front end form -> Upon submit -> Adds to database -> Shows on the admin of Processwire.

From there, I can see the entries and sort stuff. And lastly I can export them in CSV.

I'm looking at the Processwire cheatsheet and see the $files, is this the one I should be looking at? 

Share this post


Link to post
Share on other sites

I didn't understood everything but you can take a look at this thread :

 

 

and this module if it help :

 

 

  • Like 2

Share this post


Link to post
Share on other sites

I use something called SimpleExcel to export / import CSV.

http://faisalman.github.io/simple-excel-php/

 

Here's an example code snippet for Export :

$AllPages is just the data source, so you can replace it with your own.
I would also ignore all the col_subcat fields and any associated functions like GetSubCategoryNames.

You can replace 'SSS-Exported' at the bottom to the filename of your choosing.

    public function ProcessXML() {

        $AllPages =  Data::PagesAllContentsNoInteraktives();

        if ($AllPages->count()==0)
            exit;

        $_colTitle  = 0; //A
        $_colCategory=1; //B
        $_colSubcat1 =2; //C
        $_colSubcat2 =3; //D
        $_colSubcat3 =4; //E
        $_colSubcat4 =5; //F
        $_colSubcat5 =6; //G
        $_colContent = 7; //H
        $_colIntro   = 8; //I
        $_colAuthor  = 9;//J
        $_colImage   = 10;//K
        $_colAlt     = 11;//L
        $_colTitleNav= 12;//M
        $_colSEOTitle= 13;//N
        $_colKeywords= 14;//O
        $_colSEOImage= 16;//Q
        $_colMeta    = 15;//P
        $_colURL     = 17;//R
        $_colURLnew  = 18;//S
        $_colCanonical=19;//T
        $_colParent  = 20;//U
        $_colAudio   = 21;//V
        $_colVideo   = 22;//W
        $worksheet = array();

        array_push($worksheet,
        array(
            'Title',
            'Category',
            'Sub-Category I',
            'Sub-Category II',
            'Sub-Category III',
            'Sub-Category IV',
            'Sub-Category V',
            'Content',
            'Intro',
            'Author',
            'Image',
            'Alt',
            'Title for Navigation',
            'SEO Title',
            'Keywords',
            'Meta Description',
            'SEO Image',
            'URL',
            'URL New',
            'Canonical',
            'Parent',
            'Audio',
            'Video URL',
            'ID'
            )
        );

        foreach ($AllPages as $page) {
            try {

                $subcats = GetSubCategoryNames($page);

                $subcat1='';
                $subcat2='';
                $subcat3='';
                $subcat4='';
                $subcat5='';

                try {
                    $subcat1 = $subcats[0];
                    $subcat2 = $subcats[1];
                    $subcat3 = $subcats[2];
                    $subcat4 = $subcats[3];
                    $subcat5 = $subcats[4];
                }
                catch (\Exception $e)
                {}

                array_push($worksheet, array(
                    $page->title,
                    GetCategoryName($page),
                    $subcat1,
                    $subcat2,
                    $subcat3,
                    $subcat4,
                    $subcat5,
                    $page->content,
                    $page->content_intro,
                    $page->author,
                    $page->image,
                    $page->image_alt,
                    $page->title_nav,
                    $page->seo_title,
                    $page->seo_keywords,
                    $page->seo_description,
                    $page->seo_image,
                    $page->url,
                    $page->url,
                    '',
                    $page->seo_canonical,
                    $page->audio,
                    $page->video_url,
                    $page->id
                ));
            }
            catch (\Exception $e) {
                WriteLog($e->getMessage() . " " . "{$page->title}" . " has errors");
            }
        }

        try {
            $excel = new SimpleExcel('xml');

            $excel->writer->setData($worksheet);
            $excel->writer->saveFile('SSS-Exported');
        } catch (\Exception $e) {
            WriteLog($e->getMessage());
        }


    }


 

P/S In case you need to switch from CSV to XML, this post could be of interest.

 

.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.

  • Similar Content

    • By JurgenP
      First of all I'm as new to ProcessWire (PW) as they come, so bear with me if I ask stupid questions with obvious answers.
      I started looking into PW because I'm looking for something that would take out some of the grunt work of building an applications, yet be flexible enough to be able to implement custom functionality.
      I'm trying to work out if PW is suitable for my needs, ...
      A the moment I'm trying to create an architecture for a web platform on which multiple websites/webshops (750-1000) for pharmacists will be run.
      The websites will have different types of information, obviously there will be the 'own' pages the pharmacists create themselves.
      But as pharmacists tend 'not to be computer people' there is also content provided by the platform to make the site look alive, as well as public health information provided by the goverment.
      I was wondering if there is a way to structure/set up PW so that they have full access to their own content, and limited access (basically chose to publish it or not) to the externally provided content.
      Also is there a way to have the templates/page for the own content located in their own folder, and the 'external ones' in a shared folder so that they don't have to be repeated 1000 times on the server (and if modifications need to be done, it only has to be done once as well).
      Sincerely,
      Jurgen
    • By cosmicsafari
      Hi all,
      Im a bit confused by an issue I have come across today.
      I have a module which connects to a third party (once an hour using LazyCron), parses a publicly available XML file, turns it into useable information which I then use the API to save as PW Pages.
      On the whole this has been working great however today I noticed that it kept failing on one of the imports.
      After doing some investigation I realised its appears to be dying at the save page stage.
      From the documentation $page-save() should return either True/False, so I thought I would update the code to reflect this while debugging.
      $this->log(1); $bool = $p->save(); if($bool){ $this->log('Saved successfully'); } else { $this->log('Fail to save'); } $this->log(2); However the script only gets to the save() part and then appears to terminate. Then when checking the error log the latest entry is always just '1'
      Any ideas as i'm a tad confused why I at least don't get a response of some kind?
       
       
       
    • By Mirza
      Hi All,
      Arabic content changes not available in page getChanges method
      While editing the page from admin panel in the multi-language field, added a hook to save the changes made to the page.
       
      $this->pages->addHookAfter('saveReady', $this, 'hookUpdateLog');  
      public function hookUpdateLog(HookEvent $event) { $page = $event->arguments[0]; if(in_array($page->template->name, $this->templateList)) { $this->logFieldChanges($page); } } public function logFieldChanges($page) { $changes = $page->getChanges(); //This changes does not contain the field of arabic changes. }
      Please let me know, If I am approaching in a right way.

    • By ov3rtak3r
      Hello everyone!
      I am new to Processwire and really like it, but now I have a problem that I can't solve by myself.
      I have created following templates:
      data_people (no template-file)
      person_listing (person_listing.php)
      person_detail (person_detail.php)

      I have added the following Pages:
      Actor, Director, Stuff using template person_listing.php [visible in frontend]
      "People" using template data_people [not visible, only for data]
      -> "Georg Klonee" using template person_detail [is visible, but should not be shown using path /en/person/georg-klonee]

      Example Person: Georg Klonee
      The Problem:
      He is a Actor and a Director, so I want him to be shown in the Listing of /en/actors and /en/directors. No problem until here - it works. But now, when I click him, the URL for the Detail-Page is unfortunately /en/person/georg-klonee. But I want it to be /en/actors/georg-klonee, if i open the details from Actors-Page (and of course /en/directors/georg-klonee when on Directors-Page).
      How can I get this to work? I am also using TemplateEngine-Module with TemplateTwigEngine-Module, hopefully this won't be a problem? I tried it with URL-Segments for person_listing.php. But how can I abort the rendering of people_listing and start rendering person_detail.php?
       
      Thanks for your help in advance.
    • By mcwhitey
      Hi,
      How can I display, on every page of my site, what roles can view that pages template, based on what is checked in settings>templates>template-name>ACCESS TAB?
      I've only gotten as far as displaying the name of the current template: echo $page->template->get('name'); But I'm stuck here. Tried things like $page->template->get('permissions'); but I guess it's a bit more complicated than that.
      Hope someone van point me in the right direction.
      Cheers.