Take the 2-minute tour ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free, no registration required.

I've never written a php class before from scratch. But I guess you have to start somewhere right? I've got an idea, but need help with logic. Please tell me what you think. Below is shorthand obviously. In the planning stages.

Class - 
 -> type (recurring, single, day)
 -> Recurring days (4,2,3,4,1,2....etc. for odd schedules- need even pairs)
 -> Shift Type (onshift, vacation, medical, etc...)
 -> Emp Id
 -> Start
 -> End
 -> Location Id
 -> Hours per day
 -> Day start time

 get schedule ( by account/location/company/unit/crew/individual )
      select single entries
      separate array into days (1 day) increments
      if single entries have linking day entries, replace array with day entry information
      return mysql array of days for the time period;

 set schedule ( dates, emp id)
      if recurring
          if already exisits || conflicts with existing
              error
          create recurring template in db table
          create single db entries using recurring days for 1 year
      if single
          if date is between dates already in db || more than 1 year out
              error
          else
              insert into db
      if day
          if no existing single range
             error
          else
             insert into db under day table, with id linking to id of existing single.

 remove recurringOnly(emp id)
      delete all entries with recurring id

 remove all entries( from this date forward, emp id )
      delete entries with start date > date

 cronUpdate( cron start / end dates)
      if cron start / end dates
           delete anything with dates bigger than nextUpdate (to make sure no errors)
           select recurring db entries with nextUpdate between cron start/ end
           insert into db the next set of "recurring days" for the employee
           update nextUpdate date for employee
      else - error
share|improve this question
    
+1 for pseudocode. However, can you be more specific about what logic you're looking for help with? –  Jordan Oct 14 '11 at 21:18
    
Logan, kudos to you for wanting to do this the correct way and actually brainstorming your process. I love users like you. But what exactly do you need help with? –  Levi Morrison Oct 14 '11 at 21:36
    
I'm nervous about the the get schedule, where I split into day increments. I'm thinking that it could be pretty cpu intensive, especially when getting schedules for a whole department of folks. Also, it'd be a lot of data xfer'd back to the page. But I can't see any other way to be able to update adjusted individual day information. –  Logan Klenner Oct 14 '11 at 21:43
    
@Logan: Can you build an UML class diagram for your class? That would be better help. –  Victor Oct 21 '11 at 12:17
add comment

migrated from stackoverflow.com Oct 15 '11 at 13:27

This question came from our site for professional and enthusiast programmers.

1 Answer

The first data that you listed could be the attributes. Remember to set the attributes to private and the getters and setters method public. Then you can create the methods based on these algorithms you already got. it is a nice idea to code your class in a single file with the same name as your class to help organize your project.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.