/** * Creates and stores the parsed AQL array */ public function makeAqlArray() { $m = $this->_model_name; if ($m == 'Model' || !$m) { $this->_aql_array = aql2array($this->_aql); } else { self::$_metadata[$m]['aql_array'] =& aql2array::get($m, $this->getStoredAql()); } }
/** * shorthand for the aql2array class * @param string $aql * @return array */ function aql2array($param1, $param2 = null) { if (aql::is_aql($param1)) { $r = new aql2array($param1); return $r->aql_array; } else { return aql2array::get($param1, $param2); } }
/** * Checks for 'ide' fields in the where clause and changes them into id fields * decrypts the values * @param array $where * @param string $table scope of this where clause * @return array */ public function prepare_where($where, $table) { if (!is_array($where)) { return $where; } // looking for ides to map to ids with decrypt $pattern = '/\\b(?<field>[\\w.]*ide)\\s*=\\s*(?<ide>[\\w\']+)?/i'; $find_matches = function ($str) use($pattern) { preg_match_all($pattern, trim($str), $matches); return $matches; }; return array_map(function ($where) use($table, $find_matches) { $matches = $find_matches($where); $field = $matches['field'][0]; if (empty($field)) { return $where; } $ide = str_replace("'", '', $matches['ide'][0]); $table_field = explode('.', $field); $field_name = $table_field[1] ?: $table_field[0]; $tmp = aql2array::table_name_from_id_field($field_name); $table_name = $table_field[1] ? $tmp ?: $table_field[0] : ($tmp ?: $table); $id = decrypt($ide, $table_name); return preg_replace('/ide$/', 'id', $field) . ' = ' . $id; }, $where); }
/** * @param string $aql * @return string */ public function get_primary_table($aql) { $aql = self::is_aql($aql) ? $aql : self::get_aql($aql); $t = new aql2array($aql, false); return $t->get_primary_table(); }