Jump to content

Import relational table into pages


manlio
 Share

Recommended Posts

Hi to everyone. After spending some time reading and trying to have a better understanding of Processwire, now I have some more questions.

I need to import in PW two relational table (that have in common an ID_instructor field) and convert them to pages.

The name of the two tables are instructors and courses, I have imported instructors as users with CSV importer and the hierarchy now looks like

instructors

> member name1

> member name2

> member name3

> member name4

Now I would like to import the courses related to every instructor to having a result hierarchy like this

instructors

> member name1

>>course1

>>course2

>>course3

> member name2

>>course1

> member name3

>>course1

>>course2

>>course3

>>course4

> member name4

>>course1

>>course2

>>course3

 

I think that bootstrapping processwire is the way to go http://processwire.com/api/include/.

Can someone give an example of the code should I use to get started?

Thank you!

Link to comment
Share on other sites

Are there scenarios thinkable where a course could have multiple instructors? In that case you would probably want to reference the instructors via a page field belonging to the course template. Or even, when a course can only have 1 instructor this might be best/flexible way.

So you would have:

instructors

>member name1

>member name2

courses

>course1

>course2

and then the course pages would have a field of type 'FieldtypePage', where you can choose one or more instructor pages, depending on your needs.

  • Like 4
Link to comment
Share on other sites

Yep, exactly what Sinnut says. And the best part: You also can import the courses with the CSV importer. Just define a page field in the course template which relates to the instructor(s). You can easily customize the CSV importer module for that case. For example a reference to instructors with ids 1012,1024,1034 should be placed in a column in the CSV export which then is tied to the page field. Of course the ids don't match "the old" ones, so you have to apply some additional logic in the importer. For example it could be possible to import the old id with the instructors in an extra field and while importing the courses you look for the matching instructor and build the relation via the page field. Search the forums a bit, especially the CSV import thread, there are a lot of good solutions hidden :)

  • Like 4
Link to comment
Share on other sites

Interesting approach! At this time I only need a single instructor reference. Just a question. There is any drawback in using this approach instead of using hierarchy? For example when query the pages by instructor or something like this?

I don't have experience because I'm still trying to structure the site.

Thank you!

Link to comment
Share on other sites

Ok, thank you MadeMyDay and SiNNut, I will try to read more on the CSV importer and trying to follow this steps

You can easily customize the CSV importer module for that case. For example a reference to instructors with ids 1012,1024,1034 should be placed in a column in the CSV export which then is tied to the page field. Of course the ids don't match "the old" ones, so you have to apply some additional logic in the importer. For example it could be possible to import the old id with the instructors in an extra field and while importing the courses you look for the matching instructor and build the relation via the page field

although I'm not very confident in my php skills  :) . Eventually I will ask again for your help.

Thank you very much.

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...