root/trunk/apps/snippets/lib/myUser.class.php

Revision 2, 1.4 kB (checked in by fabien, 4 years ago)

initial import

  • Property svn:mime-type set to text/x-php
  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
Line 
1 <?php
2
3 class myUser extends sfBasicSecurityUser
4 {
5   public function signIn($user)
6   {
7     $this->setAttribute('user_id', $user->getId(), 'user');
8     $this->setAttribute('login', $user->getlogin(), 'user');
9     $this->setAttribute('name', $user->__toString(), 'user');
10
11     $this->setAuthenticated(true);
12
13     $this->addCredential('user');
14
15     if ($user->getIsAdmin())
16     {
17       $this->addCredential('admin');
18     }
19   }
20
21   public function signOut()
22   {
23     $this->getAttributeHolder()->removeNamespace('user');
24
25     $this->setAuthenticated(false);
26     $this->clearCredentials();
27   }
28
29   public function getUserLogin()
30   {
31     return $this->getAttribute('login', false, 'user');
32   }
33
34   public function getUserName()
35   {
36     return $this->getAttribute('name', false, 'user');
37   }
38
39   public function getUserId()
40   {
41     return $this->getAttribute('user_id', false, 'user');
42   }
43
44   public function canVoteFor($snippet)
45   {
46     // only authenticated users can vote
47     if(!$this->isAuthenticated())
48     {
49       return false;
50     }
51
52     $user_id = $this->getUserId();
53
54     // you can't vote for your own questions
55     if ($snippet->getSnippetUser()->getId() == $user_id)
56     {
57       return false;
58     }
59
60     // you can vote only once
61     $c = new Criteria();
62     $c->add(SnippetVotePeer::USER_ID, $user_id) ;
63     $c->add(SnippetVotePeer::SNIPPET_ID, $snippet->getId());
64     $vote = SnippetVotePeer::doSelectOne($c);
65
66     return ($vote) ? false : true;
67   }
68 }
69
70 ?>
Note: See TracBrowser for help on using the browser.