public function get_childs($pid = 0, $level = 1) { try { if ($pid) { $q = 'SELECT sp1.* FROM'; $q .= ' `' . $this->di->get_name() . '` AS sp1'; $q .= ' LEFT JOIN `' . $this->di->get_name() . '` AS sp2 ON sp2.left < sp1.left AND sp2.right > sp1.right'; $q .= ' WHERE'; $q .= ' sp2.id = ' . $pid; if ($level) { $q .= ' AND (sp1.level - sp2.level) <= ' . $level; } if ($this->di->where) { $q .= ' AND (' . str_replace('[table]', 'sp1.', $this->di->where) . ')'; } if (!$this->di->order) { $q .= ' ORDER BY sp1.left'; } else { $q .= ' ORDER BY sp1.' . str_replace('`', '', join(', sp1.', $this->di->order)); } } else { $q = 'SELECT * FROM `' . $this->di->get_name() . '`'; $sql_where = ''; if ($level) { $sql_where[] = '`level` <= ' . $level; } if ($this->di->where) { $sql_where[] = '(' . str_replace('[table]', $this->di->get_name() . '.', $this->di->where) . ')'; } if ($sql_where) { $q .= ' WHERE ' . join(' AND ', $sql_where); } if (!$this->di->order) { $q .= ' ORDER BY `left`'; } else { $q .= ' ORDER BY ' . JOIN(', ', $this->di->order) . ''; } } $this->di->connector->fetchMethod = PDO::FETCH_ASSOC; $this->di->_get($q); return $this->di->get_results(); } catch (Exception $e) { throw new Exception('Error while getting childs: ' . $e->getMessage()); } }
public function CreateRecord() { global $dbase; $attributes = $this->SanitizedAttributes(); //get all out attributes, then we can use arey keys to get they keys of those attributes and JOIN them $sql = "INSERT INTO " . self::$TableName . " ("; $sql .= JOIN(", ", array_keys($attributes)); $sql .= ") VALUES ('"; $sql .= JOIN("', '", array_values($attributes)); $sql .= "')"; if ($dbase->Query($sql)) { $this->id = $dbase->insert_id(); return true; } else { return false; } }