cvarick Posted February 2, 2012 Share Posted February 2, 2012 To anyone that has a few minutes to waste... I recently started working on a platform which was created by another programmer. I am unable to figure out what he was really doing here. Would be awesome if someone could help me out and give me their opinion on the matter. Maybe do some commenting for me. further detail: the function is being called and "performed" on a sql query using cakpPhp framework. Thanks in advance! See below: public function myGenerateList($conditions = null, $order = null, $limit = null, $keyPath = null, $valuePath = null, $separator = '') { if ($keyPath == null && $valuePath == null && $this->hasField($this->displayField)) { $fields = array($this->primaryKey, $this->displayField); } else { $fields = null; } $recursive = $this->recursive; $result = $this->findAll($conditions, $fields, $order, $limit); $this->recursive = $recursive; if(!$result) { return false; } if ($keyPath == null) { $keyPath = '{n}.' . $this->name . '.' . $this->primaryKey; } if ($valuePath == null) { $valuePath = '{n}.' . $this->name . '.' . $this->displayField; } // extract the keys as normal $keys = Set::extract($result, $keyPath); $finalVals = array(); // explode the value path by our delimiter $tmpVals = explode('#', $valuePath); $i = 0; foreach($tmpVals as $tmpVal) { // extract the data for each path sibling $vals = Set::extract($result, $tmpVal); // and insert it at the appropriate position in our final value array // use the separator when we need to append the values foreach($vals as $key => $value) { if(!array_key_exists($key, $finalVals)) { $finalVals[$key] = $value; } else { $finalVals[$key] .= $separator.$value; } } $i++; } if (!empty($keys) && !empty($finalVals)) { $out = array(); $return = array_combine($keys, $finalVals); return $return; } return null; } Quote Link to comment https://forums.phpfreaks.com/topic/256285-what-is-this-function-doing/ Share on other sites More sharing options...
teng84 Posted February 3, 2012 Share Posted February 3, 2012 it fetches records I think but not sure since it is calling another functions Quote Link to comment https://forums.phpfreaks.com/topic/256285-what-is-this-function-doing/#findComment-1313938 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.