コード例 #1
0
 public function createInwicastUserIfNotExists(User $user, $token, Mediacenter $mediacenter)
 {
     $connection = $this->connectionFactory->createConnection($mediacenter->getDatabaseParameters());
     $qb = $connection->createQueryBuilder();
     $qb->select('usr.username, usr.token')->from('mdcr_inwicast_user_tokens', 'usr')->where('usr.username = :username')->andWhere('usr.tokenapp = :platform')->setParameter("username", $user->getUsername())->setParameter("platform", $this->platformName);
     $result = $qb->execute()->fetch();
     if (!$result) {
         //$qb_insert = $connection->createQueryBuilder();
         $sql = "INSERT INTO mdcr_inwicast_user_tokens" . " (`username`, `firstname`, `lastname`, `email`, `userrole`, `token`, `tokendate`, `tokenapp`)" . " VALUES (?, ?, ?, ?, ?, ?, ?, ?)";
         $query = $connection->prepare($sql);
         $query->bindValue(1, $user->getUsername());
         $query->bindValue(2, $user->getFirstName());
         $query->bindValue(3, $user->getLastName());
         $query->bindValue(4, $user->getMail());
         $query->bindValue(5, $user->getPlatformRole()->getName());
         $query->bindValue(6, $token);
         $query->bindValue(7, date('Y-m-d H:i:s'));
         $query->bindValue(8, $this->platformName);
         $query->execute();
     } else {
         $qb_update = $connection->createQueryBuilder();
         $qb_update->update('mdcr_inwicast_user_tokens')->set('token', '?')->set('tokendate', '?')->set('tokenapp', '?')->where('username = ?')->setParameter(0, $token)->setParameter(1, date('Y-m-d H:i:s'))->setParameter(2, $this->platformName)->setParameter(3, $user->getUsername());
         $qb_update->execute();
     }
     return true;
 }