Jump to content

permanent archive of relational data? permalinks?


bernhard
 Share

Recommended Posts

i'll be building a site for a sportsclub very soon. there will be some players and some teams

team a

- player a

- player b

- player c

team b

- player a

- player b

- player xyz

i wanted the players to be selectable via page-field so that changes to player a reflect to both teams a + b.

so far so good - but the client asked for a way to archive data.... eg team a (2012, 2013, 2014...)

so when i use pageclone to copy data to the archive there will always be the current picture + name + weight + height of all the players and that is not what the archive is meant to show. there should be a kind of history with "permalinks"

any ideas how to approach this? maybe use pagecache and permanently save this file? but how to get the image+file data if there is an <img src="...assets...xy.jpg">?

thanks in advance :)

Link to comment
Share on other sites

I think the best way would be to archive the whole tree or at least the branches of data that need to be archived, e. g. player and team pages. Then you can update the normal part of the page and save the cloned archive pages and maybe lock them to be uneditable. You'd just need to write a "archive process" so the pagefields are not only cloned but also updated to reflect the now archived playerdata.

Link to comment
Share on other sites

You'd just need to write a "archive process" so the pagefields are not only cloned but also updated to reflect the now archived playerdata.

thank you for your reply. could you please go a little bit more in detail on this? "archive process - not only cloned but also updated"

Link to comment
Share on other sites

If you're cloning the team and player pages to be archived, these maybe get cloned to a subtree /2014/… . The problem is, the team pages' pagefields do still point to the original player pages, as the field just saves the id. So you'd need to have some way to also change the pagefields to point to their newly cloned playerpages. Something like this. 

// $page = teampage
foreach($page->players as $player){
  $page->players->remove($player);

  // Get the same player but the archived one.
  $archived_player = $pages->get("name=$player->name, has_parent=$page->parent");
  $page->players->add($archived_player);
}

$page->of(false);
$page->save("players");

If you're comfortable with building small modules I would even suggest just packing all the logic in a Process module, where you just choose the year to be archived and press a button and everything is getting moved and changed automatically. It would at least be more fail save, than doing it by hand somehow.

  • Like 1
Link to comment
Share on other sites

Shouldn't be to hard to do. The example module and maybe this thread https://processwire.com/talk/topic/2089-create-simple-forms-using-api/ , if  you need forms, should get you there. The rest is just the standart api. Also keep in mind the option of locking the archived pages. This way after your done, no one can accidentally change the archive.

Link to comment
Share on other sites

thanks arjen - i like the idea of showing a team history to every player and (as almost always) this would be very simple with PW and the approach above :)

i'm only thinking of how to identify the players exactly because when cloning the pages i don't like identifying them by ->find('name=xy') as there could be players with the same name. maybe i'll create an additional field name+birthday or just use any unique hash...

Link to comment
Share on other sites

  • 3 months later...

@BernhardB Did you have any success experimenting with a simple archive module? 

I am a teacher, and I am looking for a way to archive a course from last semester, so there is a copy for reference, while being able to change the pages slightly for next semester. 

I want to be able to make a copy of the tree below (and including) 'All Things Media: Design', and move it to 'Past Courses', but still keep the original where it is, so I can change it for the upcoming semester.

post-2947-0-20835300-1434042184_thumb.pn

I am ashamed to say I only know basic php :\

@LostKobrakai To use the code you mentioned, would I need to create a new template? 

UPDATE: Resolved

I found the Page Clone module in Modules > Core > Process and just needed to install it. It comes packaged with PW.

post-2947-0-83421300-1434043065_thumb.pn

It is pictured above.

This was so easy! I hope this post helps another noob :)

Link to comment
Share on other sites

hi kathep,

glad you found the page clone module ;) it's not sufficient for me because it does not permanently archive referenced pages from pagefields. so if you have any pagefields be aware of that!

you know what i'm talking about?

ps: unfortunately i didn't find the time to do more work on this yet. i have to do other things first, but i'll definitely implement this feature then.

Link to comment
Share on other sites

@BernhardB

What do you mean on "archiving"?

Only a static state (no publicly available), or a page that can be viewed on the site?

If its only static, then generating a PDF or static HTML files (with all assets) isn't an option?

  • Like 1
Link to comment
Share on other sites

I know, but a static html fragment could serve as an archive imo.

If future styling is an issue, some kind of JSON data could be generated (+required assets saved, like images).

Link to comment
Share on other sites

hi tpr,

thanks for thinking about my problem :)

any ideas how to approach this? maybe use pagecache and permanently save this file? but how to get the image+file data if there is an <img src="...assets...xy.jpg">?

at first i also thought about saving only the html but now i think i will go lostkobrakais approach of cloning all players and then re-referencing all the page fields. that way all style updates will also affect historical data and that's good for my project :) it's a site for a sports club and it wants to "archive" teams and players from previous seasons being accessible via the normal website menu.

unfortunately i can't start on this because there are huge other parts to develop first...

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...