I have a function I have to fill out, and the only way I can see doing it is a mess. The function I have is:
public function($keys = array(), $pages = array()){}
Essentially the goal is:
- If keys are an array and each key is not set, do something.
- If Keys are not an array and are not set, do something.
The same concept goes for pages.
so that's four if statements, then we do:
If key is array but pages is not, if pages is array but key is not. if both are arrays....
What I have so far is:
public function sidebar($keys = array(), $pages = array()){
$builder = AisisCore_Factory_Pattern::create('AisisCore_Template_Builder');
if(is_array($keys)){
foreach($keys as $key){
if(!$builder->get_specific_option($key)){
get_sidebar();
}
}
}else{
if(!$builder->get_specific_option($keys)){
get_sidebar();
}
}
if(is_array($pages)){
foreach($pages as $page){
if(!$page){
get_sidebar();
}
}
}else{
if(!$pages){
get_sidebar();
}
}
}
You can see its quickly becoming a mess. get_specific_option
will check if that key exists. arrays are done like: array('key', 'secondKey')
and so on. pages are done as such: array(is_page(), is_category())
- each of those returns true or false, hence the boolean check. get_sidebar()
will get the sidebar if, say for example, a key is not set, or a page does not equal true.
I am not sure how to create this function with out it being a disaster. Can some one help?