TalkPHP
 
 
Account Login
Latest Articles
» The basic usage of PHPTAL, a XML/XHTML template library for PHP
» Vulnerable methods and the areas they are commonly trusted in.
» Simple way to protect a form from bot
» The Basics On: How Session Stealing Works
» How to keep your forms from double posting data
IRC Channel
IRC Speech Bubble Join the friendly bunch on IRC...
(#TalkPHP on Freenode)

...Also available via a web interface.

See this thread for information on the TalkPHP Free Hugs Initiative™. Subject to availability.
Associates
Associates
CSS Tutorials
Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old 02-18-2009, 03:01 PM   #1 (permalink)
The Wanderer
 
Join Date: Jan 2008
Posts: 13
Thanks: 0
Ultimatum is on a distinguished road
Default 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.
http://img145.imageshack.us/my.php?image=umldy6.jpg

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?
Ultimatum is offline  
Reply With Quote
Old 02-18-2009, 08:57 PM   #2 (permalink)
The Addict
 
CoryMathews's Avatar
 
Join Date: Nov 2007
Location: USA
Posts: 256
Thanks: 7
CoryMathews is on a distinguished road
Default

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.
CoryMathews is offline  
Reply With Quote
Old 02-19-2009, 11:01 PM   #3 (permalink)
The Wanderer
 
Join Date: Jan 2008
Posts: 13
Thanks: 0
Ultimatum is on a distinguished road
Default

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?
Ultimatum is offline  
Reply With Quote
Old 02-20-2009, 10:52 AM   #4 (permalink)
The Contributor
 
Gibou's Avatar
 
Join Date: Nov 2007
Location: France, near Paris
Posts: 53
Thanks: 6
Gibou is on a distinguished road
Default

To me, I would design it like that:

- A class WordDocument
|_ title
|_ collection of 'Page'
|_ ...

- A class Page
|_ id
|_ collection of 'Paragraph'
|_ header (instance of 'Paragraph')
|_ footer (instance of 'Paragraph')
|_ ...

- A class Paragraph
|_ text
|_ adaptation (left, right, centered, justified)
|_ ...

- A class Image
|_ url
|_ width
|_ height
|_ ...

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
__________________
Wedus project's Website
Send a message via MSN to Gibou
Gibou is offline  
Reply With Quote
Old 02-23-2009, 08:32 AM   #5 (permalink)
The Wanderer
 
Join Date: Jan 2008
Posts: 13
Thanks: 0
Ultimatum is on a distinguished road
Default

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 :)
Ultimatum is offline  
Reply With Quote
Old 02-23-2009, 10:38 AM   #6 (permalink)
The Contributor
 
Gibou's Avatar
 
Join Date: Nov 2007
Location: France, near Paris
Posts: 53
Thanks: 6
Gibou is on a distinguished road
Default

Quote:
Originally Posted by Ultimatum View 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?
Don't extend, no. The class Page is not a container of WordDocument.
You add pages like this:
In your "WordDocument" class, you have a addPage() method:

PHP Code:
<?php
private Array pages;

public function 
addPage(Page &page)
{
  
this->pages[] = page;
}
?>
You create the instance outsite and you add it, passing it by reference. The method had it into the class collection (pages).


Quote:
Originally Posted by Ultimatum View Post
And it is possible to put images and text in header/footer as well
Header and Footer are 'Paragraph' instances. Paragraph can contains images, no problem.

Quote:
Originally Posted by Ultimatum View Post
and it is also possible to add pagenumbers to those so it's a little more then only paragraphs.
No problem, when you add a paragraph, it's a method "addParagraph" in the 'Page class' when you add, you take the Page instance id and put it into a 'Paragraph' 'pageId' attribute.
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.


Quote:
Originally Posted by Ultimatum View Post
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 don't need a class for that. Why don't you keep dob codes inside the text ? You just have to transform dob codes into html tags (or others depending on the api you use to create your Word documents) with regular expressions.

Have a nice day
__________________
Wedus project's Website
Send a message via MSN to Gibou
Gibou is offline  
Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
A Generic Singleton Base Class Theo Advanced PHP Programming 7 08-18-2008 02:25 AM
[Tutorial] Basic tutorial about class basics Tanax Absolute Beginners 14 07-24-2008 01:37 PM
Pure PHP template class. abiko Advanced PHP Programming 1 04-02-2008 05:45 PM
PHP5 Classes A to Z Part 1 quantumkangaroo Advanced PHP Programming 11 04-01-2008 04:21 AM
Tutorial: PHP and OOP, a beginners guide Village Idiot Tips & Tricks 0 09-06-2007 04:23 PM


All times are GMT. The time now is 11:56 AM.

 
     

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0
Inactive Reminders By Icora Web Design