Jump to content

cvarick

New Members
  • Posts

    1
  • Joined

  • Last visited

    Never

Profile Information

  • Gender
    Not Telling

cvarick's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. 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; }
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.