コード例 #1
0
ファイル: Tree.php プロジェクト: kstep/pnut
 public function __construct(Storage_Db $db, $path = null)
 {
     if ($path && is_string($path) && !is_numeric($path)) {
         parent::__construct($db);
         $condition = $tables = array();
         $apath = explode("/", trim($path, "/"));
         $pathlen = count($apath) - 1;
         // t0.parent_id = 0 and t1.parent_id = t2.id and ... and tN.parent_id = 0 and t0.name = $apath[0] and ... and tN.name = $apath[N]
         foreach ($apath as $index => $name) {
             $tables[] = "{$this->_view} as t{$index}";
             $condition[] = ($index > 0 ? "t{$index}.{$this->_parent_field} = t" . ($index - 1) . ".id" : "t0.{$this->_parent_field} = 0") . " AND t{$index}.name = '" . addslashes($name) . "'";
         }
         $data = $db->select($tables, "t{$pathlen}.*", implode(" AND ", $condition), 1)->fetchFirst();
         if ($data) {
             $this->parseData($data);
         }
     } else {
         parent::__construct($db, $path);
     }
 }