/** * @return ISqlCommand */ public function Build() { $sql = self::REPORT_TEMPLATE; $sql = str_replace('[SELECT_TOKEN]', $this->GetSelectList(), $sql); $sql = str_replace('[JOIN_TOKEN]', $this->GetJoin(), $sql); $sql = str_replace('[AND_TOKEN]', $this->GetWhereAnd(), $sql); $sql = str_replace('[GROUP_BY_TOKEN]', $this->GetGroupBy(), $sql); $sql = str_replace('[ORDER_TOKEN]', $this->GetOrderBy(), $sql); $sql = str_replace('[LIMIT_TOKEN]', $this->GetLimit(), $sql); $query = new AdHocCommand($sql); foreach ($this->parameters as $parameter) { $query->AddParameter($parameter); } return $query; }
/** * @param $username * @return mixed */ private function GetDrupalAccount($username) { define(DRUPAL_ROOT, $this->drupalDir); include_once DRUPAL_ROOT . '/includes/bootstrap.inc'; drupal_bootstrap(DRUPAL_BOOTSTRAP_CONFIGURATION); global $databases; $db = $databases['default']['default']; $dbname = $db['database']; if (!empty($db['prefix'])) { $dbname = "{$db['prefix']}{$dbname}"; } $host = $db['host']; if (!empty($db['port'])) { $host .= ":{$db['port']}"; } $drupalDb = new Database(new MySqlConnection($db['username'], $db['password'], $host, $dbname)); $command = new AdHocCommand('select * from users where name=@user or mail=@user'); $command->AddParameter(new Parameter('@user', $username)); $reader = $drupalDb->Query($command); if ($row = $reader->GetRow()) { $account = new stdClass(); foreach ($row as $k => $v) { $account->{$k} = $v; } return $account; } return false; }