php class structure
Ey, I'm working on a large project but I don't have any idea of how to make my classes properly. I have to make Microsoft Office Word file from php and it works but the classes aren't any good designed so I'm working on V2 now.
Here a screen of a piece of the UML to give you an idea.
Explanation of the UML. It is possible to add text, paragraphs and/or images to the word document itself. But it must also be possible to add a header and/or footer and add text, paragraphs and/or images to the header/footer.
I thougth of makeing a get/set class for text, paragraphs etc.. and then read it all in the WordDocument class en generate the right xml.
But don't know how I can work this out in php, anyone who can help me out the basics?
I see this more as 1 "word" class and each of these items as a function of that class. I think you are trying to make everything a class which is not what is needed.
Maybe so, but only my paragraph class has around 15 vars for all the properties, so if I use 1 class I end up with a class that has 60 vars and 120 getters and setters or so (The numbers can be a bit high though :p)
Isn't there a better way?
To me, I would design it like that:
- A class WordDocument
|_ collection of 'Page'
- A class Page
|_ collection of 'Paragraph'
|_ header (instance of 'Paragraph')
|_ footer (instance of 'Paragraph')
- A class Paragraph
|_ adaptation (left, right, centered, justified)
- A class Image
Headers and footers are nothing but a paragraphs so no need to create those classes. Find just a way to store in your WordDocument the information about "are the headers and the footers the same for all pages or are they differents for the first one ?". In the 'Page' constructor, if a header and/or a footer have already been created, just think to add to the 'header' and/or the 'footer' attributes a reference to those created.
The WordDocument class has a collection of class Page so typically, an array of instances of class 'Page'.
The Paragraph class could contain text and images but no need to create the class Text. What methods could exist in a such class ?
mmmm I don't see anything more.
Someone correct me if I'm wrong :-)
Gibou thanks for your explanation. But I have a few questions on your post. How do I add the objects Page etc.. to the class WordDocument. Now I have a method addParagraph and then I pass the object paragraph to that method or should I extend Page class with WordDocument class?
And it is possible to put images and text in header/footer as well and it is also possible to add pagenumbers to those so it's a little more then only paragraphs. In the class Text I know have all the properties like fontsize, fontfamily, fontcolor, bold, italic, underline. And with the Text class I can give every line other properties. That's why I have a Text class.
I love more comments from anybody to help me solve this problem :)
You add pages like this:
In your "WordDocument" class, you have a addPage() method:
But i don't advise you to do that. Indeed, when you add some text before a paragraph, you push the following ones to bottom and a paragraph could go to the following page. It could be hard to check.
I advise more to insert an attribute 'position' to the 'Paragraph' class which is incremented at each inserted paragraph.
Have a nice day
|All times are GMT. The time now is 01:29 AM.|
Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0