Take the 2-minute tour ×
Code Review Stack Exchange is a question and answer site for peer programmer code reviews. It's 100% free, no registration required.

I'm new Zendframework. Can you help to optimize this Model function, witch get from Db list of Manufactures with some conditions

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
add comment

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.