Code Review Stack Exchange is a question and answer site for peer programmer code reviews. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm new to Zend Framework. Can you help me optimize this function, which gets a list of Manufactures with some conditions from a database?

private function Manufactures(
    $Condition = array(),
    $Order = array('name' => 'ASC'),
    $Strict = TRUE,
    $Limit = NULL)
{
    $Request = $this->_DbTable->select();
    $Clause  = $Strict ? '=' : 'LIKE';
    foreach ($Condition as $index => $value) {
        if (!is_array($value)) {
            $Request->where($this->_DbTable->info('name') . '.' . $index . ' '. $Clause .' ?', $value);
        } else {
            foreach ($value as $key => $val) {
                if (is_array($val)) {
                    foreach ($val as $valIndex) {
                        if (isset($valIndex['modifier']) && isset($valIndex['value'])) {
                            $Request->where($this->_DbTable->info('name') . '.' . $key . ' ' . $valIndex['modifier']. ' ?', $valIndex['value']);
                        }
                    }
                }
            }
        }
    }
    foreach ($Order as $index => $value) {
        $Request->order($index . ' ' . $value);
    }
    if($Limit) $Request->limit($Limit);
    $Data = $this->_DbTable->fetchAll($Request)
                           ->toArray();
    return isset($Data) ? $Data : NULL;
}
share|improve this question

Your Answer

 
discard

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

Browse other questions tagged or ask your own question.