Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

PHP class - need help with dates formats

Posted on 2008-06-14
4
Medium Priority
?
209 Views
Last Modified: 2010-04-21
Hi,
I am trying to write my first PHP class and I am not sure I know exactly what I doing.
Basically I want to be create new orders or update and existing order and return dates in both MySQL format and in a format for viewing, most orders will be new but some might be updates that already have a current expiry date.
Any assistance or comments would be appreciated.

<?php 
 
 
//new placeOrder($current_expdate, $days, $special, $credit, $amount, $payment_option, $payment_type);
 
class placeOrder{
   
   function placeOrder($expiry_date, $days='90', $special='1', $credit='1',$amount='99.00', $payment_option='None', $payment_type='Credit'){ 
				
 
 
				if (isset($expiry_date)) {
				
				//Get current expiry date and add days to current date
				$this->mysql_expiry_date = $expiry_date; 
				$expiry_date = explode("-", $expiry_date);
				$expiry_date = mktime (0,0,0,date($expiry_date[1]) ,date($expiry_date[2]) ,date($expiry_date[0]));
				$new_expiry_date = ($expiry_date + ((24 * 60 * 60 * $days) * $special));
				$this->display_new_expiry_date = date("D jS M, Y", $new_expiry_date);
				$new_expiry_date = date("Y-m-d", $new_expiry_date);
				
				}else { 
		        $new_expiry_date = date("Y-m-d", time());
				}
				
				$this->new_expiry_date = $new_expiry_date;
				
				
				
				$this->display_expiry_date = date("D jS M, Y", $new_expiry_date);
				$this->mysql_current_date = date("Y-m-d",$current_expiry_date);  
				$this->display_current_date = date("F jS, Y",$current_expiry_date);;
			
				$this->display_order_date = date("D jS M, Y",time() + ((24 * 60 * 60 )));
 
				$this->mysql_order_date = date("Y-m-d",time() + ((24 * 60 * 60 )));
				$this->adlength = ($days * $special * $credit);
				$this->amount = $amount;
				$this->payment_option = $payment_option; 
	 			$this->payment_type = $payment_type; 
			 } 
 
	
	
				function new_order_report(){
					echo "<br>New Order Details<br>"; 
					echo "Payment Type: $this->payment_type <br>"; 
					echo "Advertisment Amount Paying : $this->amount <br>";
					echo "Payment Option: $this->payment_option<br>";
					
					echo "<br>Ad Length: $this->adlength Days"; 
					echo "<br>List Date: $this->display_order_date"; 
					echo "<br>Expiry Date: $this->display_expiry_date";
					
					
					echo "<br>Order Date: $this->display_order_date";
					echo "<br>List Date: $this->mysql_order_date";
					echo "<br>Expiry Date: $this->mysql_expiry_date<br>";
			
				}	
			
			function updated_order_report(){
					echo "<br>Updated Order Details<br>"; 
					echo "Payment Type: $this->payment_type <br>"; 
					echo "Advertisment Amount Paying : $ $this->amount <br>";
					echo "Payment Option: $this->payment_option<br>";
					
					echo "<br>Ad Length: $this->adlength Days"; 
					echo "<br>List Date: $this->display_order_date"; 
					
					echo "<br>Order Date: $this->display_order_date";
					echo "<br>New Expiry Date - MySQL format: $this->new_expiry_date";
					echo "<br>New Expiry Date - Screen format: $this->display_new_expiry_date";
					echo "<br>Old Expiry Date - MySQL Format: $this->mysql_expiry_date<br>";
			
				}	
 
}
 
//new placeOrder($current_expdate, $days, $special, $credit, $amount, $payment_option, $payment_type);
$update_order = new placeOrder('2009-01-01',35,1,1,'30.00','Credit Card','Paid');
$update_order->updated_order_report();
 
new placeOrder($current_expdate, $days, $special, $credit, $amount, $payment_option, $payment_type);
$private_order = new placeOrder('',90,1,1,'30.00','Cheque','Paid');
$private_order ->new_order_report();
 
?>

Open in new window

0
Comment
Question by:sabecs
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
4 Comments
 
LVL 19

Accepted Solution

by:
bevhost earned 2000 total points
ID: 21787344
instead of explode & mktime consider using strtotime

                                $expiry_date=strtotime($expiry_date);
                                $new_expiry_date=strtotime($days." days",$expiry_date);

0
 

Author Comment

by:sabecs
ID: 21788139
Thanks bevhost for your help, just wondering if there is a better way to code the whole thing or is the way a class should be created?
0
 
LVL 19

Expert Comment

by:bevhost
ID: 21799126
Clases are great if you have several different kind's of orders.
This way you can create a base class that has all the most common functions,
but when you need a custom order you can extend the class and redeclare or add any functions that need to be different.
0
 

Author Closing Comment

by:sabecs
ID: 31467290
Thanks for your help.
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Foreword (July, 2015) Since I first wrote this article, years ago, a great many more people have begun using the internet.  They are coming online from every part of the globe, learning, reading, shopping and spending money at an ever-increasing ra…
Build an array called $myWeek which will hold the array elements Today, Yesterday and then builds up the rest of the week by the name of the day going back 1 week.   (CODE) (CODE) Then you just need to pass your date to the function. If i…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

705 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question