예제 #1
0
 /**
  * Set up tests.
  *
  * @since 2.0
  */
 protected function setUp()
 {
     $config = ConfigProvider::getInstance();
     $config->set('session.provider.name', 'Alpha\\Util\\Http\\Session\\SessionProviderArray');
     $tag = new Tag();
     $tag->rebuildTable();
     $denum = new DEnum();
     $denum->rebuildTable();
     $item = new DEnumItem();
     $item->rebuildTable();
     // create a default article DEnum category
     $denum = new DEnum('Alpha\\Model\\Article::section');
     $item->set('value', 'Main');
     $item->set('DEnumID', $denum->getID());
     $item->save();
     $article = new Article();
     $article->rebuildTable();
     $articleVote = new ArticleVote();
     $articleVote->rebuildTable();
     $articleComment = new ArticleComment();
     $articleComment->rebuildTable();
     $person = new Person();
     $person->rebuildTable();
     $rights = new Rights();
     $rights->rebuildTable();
     $rights->set('name', 'Standard');
     $rights->save();
     $rights = new Rights();
     $rights->set('name', 'Admin');
     $rights->save();
 }
예제 #2
0
 /**
  * Set up tests.
  *
  * @since 2.0
  */
 protected function setUp()
 {
     $config = ConfigProvider::getInstance();
     $config->set('session.provider.name', 'Alpha\\Util\\Http\\Session\\SessionProviderArray');
     $tag = new Tag();
     $tag->rebuildTable();
     $denum = new DEnum();
     $denum->rebuildTable();
     $item = new DEnumItem();
     $item->rebuildTable();
     $article = new Article();
     $article->rebuildTable();
     $articleVote = new ArticleVote();
     $articleVote->rebuildTable();
     $articleComment = new ArticleComment();
     $articleComment->rebuildTable();
     $person = new Person();
     $person->rebuildTable();
     $rights = new Rights();
     $rights->rebuildTable();
     $rights->set('name', 'Standard');
     $rights->save();
     $rights = new Rights();
     $rights->set('name', 'Admin');
     $rights->save();
 }
예제 #3
0
파일: Article.php 프로젝트: alphadevx/alpha
 /**
  * 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;
     }
 }