Esempio n. 1
0
 public function afterSave()
 {
     // parent for path and full url
     if ($this->isRoot()) {
         # path
         $path = $this->title;
         # full url
         $url = $this->url_part ? '/' . $this->url_part : $this->url_part;
     } else {
         $parents = $this->ancestors()->findAll();
         // path
         $tmp = CHtml::listData($parents, 'id', 'title');
         $tmp[] = $this->title;
         $path = implode(' → ', $tmp);
         // full url
         if (!empty($this->url_part)) {
             $tmp = CHtml::listData($parents, 'id', 'url_part');
             $tmp[] = $this->url_part;
             $tmp = EArray::trimEmpty($tmp);
             $url = '/' . implode('/', $tmp);
         } else {
             $url = null;
         }
     }
     $this->updateByPk($this->id, array('path' => $path, 'url' => $url));
     return parent::afterSave();
 }
Esempio n. 2
0
 /**
  * Process filter
  * @param  callable                     $closure
  * @return \Kohkimakimoto\EArray\EArray
  */
 public function filter($closure)
 {
     if (!$closure instanceof \Closure) {
         throw new \RuntimeException("The argument must be a closure");
     }
     $new = new EArray();
     foreach ($this as $key => $value) {
         if (call_user_func($closure, $key, $value)) {
             $rawValue = $this->getRawValue($key);
             $new->set($key, $rawValue);
         }
     }
     return $new;
 }