Link to home
Start Free TrialLog in
Avatar of rgb192
rgb192Flag for United States of America

asked on

design pattern for a series of tasks

what is a design pattern


$user1= new Instructions($user_name);

$user1->select_rows_of_table_in_mysql($subject, $body, $email_addresses);
$user1->log_in_to_phpmailer($user_name);
$user1->send_emails_using_phpmailer($user_name);
$user1->insert_phpmailer_errors;

and then repeat for $user2, $user3

And then if I wanted to see the data from the table
$user1->see_phpmailer_errors($user_name) for each user


I think that I am copy pasting too many instances for each task
Avatar of Julian Hansen
Julian Hansen
Flag of South Africa image

It depends on what your tasks are doing.

For instance you could have a loop going through a list of users (array or resultset from a database) - for each user found perform the tasks.

If the emails are the same for each user you could simply add all users to the distribution list - and send the mail once but this is only an option if you are sending the same email to everyone and there are no user specific per user settings.

Also depending on what the Instructions object does - you could structure your code either to reuse an existing instance or create a new one for each user.

My feeling though is that a foreach loop on a list of users is the way to go.
SOLUTION
Avatar of Ray Paseur
Ray Paseur
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of rgb192

ASKER

>>My feeling though is that a foreach loop on a list of users is the way to go.

>>Repeated tasks in PHP are performed with iterators.  Iterators are "control structures," so named because they control the flow of logic in the PHP script.  They include foreach() and while()


should this be a factory where everything gets done for each username

because I think that the code will get disorganized with
if for foreach
statements
outside the class
should this be a factory where everything gets done for each username
Possibly -- that would seem to make sense, but I can't really know for sure without seeing the data.  You would be a better judge of that than I can be.
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of rgb192

ASKER

Thank you for teaching me ways to organize the code.

I will provide more examples soon