Ejemplo n.º 1
0
 /**
  * Unset config instance from the singleton, so next time the config will be get, it will be recreated from
  * current (and possibly adjusted to our needs) environment variables.
  */
 public static function unsetConfigInstance()
 {
     $configProviderSingleton = ConfigProvider::getInstance();
     $reflection = new \ReflectionClass($configProviderSingleton);
     $instance = $reflection->getProperty('config');
     $instance->setAccessible(true);
     $instance->setValue($configProviderSingleton, null);
     $instance->setAccessible(false);
 }
Ejemplo n.º 2
0
 /**
  * Method to determine if the logged-in user has already voted for this article.
  *
  * @return bool True if they have voted already, false otherwise
  *
  * @since 1.0
  *
  * @throws Alpha\Exception\AlphaException
  */
 public function checkUserVoted()
 {
     $config = ConfigProvider::getInstance();
     $sessionProvider = $config->get('session.provider.name');
     $session = SessionProviderFactory::getInstance($sessionProvider);
     // just going to return true if nobody is logged in
     if ($session->get('currentUser') == null) {
         return true;
     }
     $userID = $session->get('currentUser')->getID();
     $vote = new ArticleVote();
     $sqlQuery = 'SELECT COUNT(*) AS usersVote FROM ' . $vote->getTableName() . " WHERE articleOID='" . $this->OID . "' AND personOID='" . $userID . "';";
     $result = $this->query($sqlQuery);
     if (!isset($result[0])) {
         throw new AlphaException('Failed to check if the current user voted for the article [' . $this->OID . '], query [' . $sqlQuery . ']');
         return false;
     }
     $row = $result[0];
     if ($row['usersVote'] == '0') {
         return false;
     } else {
         return true;
     }
 }