source: pro-bachkim-filespace/sourcecode/api.violet.vn/www/lib/common/userBase.class.php @ 136

Last change on this file since 136 was 19, checked in by dungnv, 11 years ago
File size: 4.3 KB
Line 
1<?php
2
3class userBase {
4
5  const MAX_PLUS_POINT = 30;
6
7  protected $user;
8
9  public function userBase($user) {
10    $this->user = $user;
11  }
12
13  public function getTitle() {
14    return '';
15  }
16
17  public function getAvatar($type = 'avatar', $options = array()) {
18    $avatar = $this->user->getUsAvatar();
19    if (strpos($avatar, ':') !== false) {
20      $avatars = unserialize($avatar);
21      $avatar = $avatars[($type=='avatar'? 0: 1)][0];
22    }
23    if ($avatar == null) {
24      $mf = ($this->user->getUsSex()==2? 'f': '');
25      $avatar = "no_$type$mf.jpg";
26    }
27    return image_tag(sfConfig::get('app_thumbnail_root').$this->getAvatarPath($type, false).$avatar, $options);
28  }
29
30  public function getHtmlName($avatar = false, $homepage = false) {
31    if ($this->user->getUsId() == null) return "KhÃŽng rõ";
32    $html = '';
33    $link = '/user/show?id='.$this->user->getUsId();
34    if ($avatar) {
35      $avalink = link_to($this->getAvatar('avatar', array('style'=>'float:left', 'width'=>'30px', 'height'=>30)), $link);
36      $html .= content_tag('div', $avalink, array('class'=>'ava'));
37    }
38    $html .= link_to($this->user->getUsFullname(), $link);
39    if ($homepage) {
40        $url = $this->user->getUsHomepage();
41        if ($url) $html .= ' ('.link_to('trang riêng', $url).')';
42    }
43    return $html;
44  }
45
46  public function getAvatarPath($type = 'avatar', $absolute = true) {
47    return sfConfig::get($absolute? 'sf_upload_dir': 'sf_upload_dir_name')."/thumbnails/$type/";
48  }
49
50  public function SaveAvatar($action) {
51    $us_id = $this->user->getUsId();
52    $avatar = $us_id.'.jpg';
53    $this->user->setUsAvatar($avatar);
54    $fileName1 = $this->getAvatarPath('avatar').$avatar;
55    $fileName2 = $this->getAvatarPath('photo').$avatar;
56
57    $tempFile = $action->getRequest()->CopyTempFile($action->uploaded, "user_{$us_id}_picture.jpg");
58    list($width, $height) = @getimagesize($tempFile);
59    if ($width/$height < 163/187) myUtility::SizeImage(150, 200, $tempFile, $fileName2);
60    else if ($width/$height > 187/163) myUtility::SizeImage(200, 150, $tempFile, $fileName2);
61    else myUtility::SizeImage(175, 175, $tempFile, $fileName2);
62    myUtility::SizeImage(60, 60, $tempFile, $fileName1);
63    myUtility::track_upload($fileName1, 'thumbnails');
64    myUtility::track_upload($fileName2, 'thumbnails');
65    unlink($tempFile);
66  }
67
68  public function checkUserLock() {
69    /*
70    if (sfContext::getInstance()->getRequest()->getCookie('vol_lock')==1) {
71      throw new Exception('Máy tính này đã bị khóa truy cập');
72    }
73    */
74
75    // Check whether user can signIn or not
76    switch ($this->user->getUsStatus()) {
77      case 4:
78      case 5:
79      case 6:
80      case 7:
81        if (strtotime($this->user->getUsLastvisited()) > time()) {
82          throw new Exception('Tài khoản này bị khóa đến '.$this->user->getUsLastvisited('H:i d-m-Y'));
83        }
84        else $this->user->setUsStatus($this->user->getUsStatus() - 4);
85        break;
86      case 8:
87        sfContext::getInstance()->getResponse()->setCookie('vol_lock', 1, time() + 86400*5);
88        throw new Exception('Tài khoản này đã bị khóa vÄ©nh viễn');
89        break;
90    }
91
92    sfDatabaseSessionStorage::kickUserByName($this->user->getUsUsername());
93  }
94
95  public function onLogin() {
96    // cộng điểm trong lần đăng nhập đầu tiên cá»§a tuần
97    $lastvisited = $this->user->getUsLastvisited();
98    if ($lastvisited != null && date("W", strtotime($lastvisited)) != date("W")) {
99      $maxPlus = self::MAX_PLUS_POINT;
100      $download = explode(',', $this->user->getUsDownload());
101      $plus = min(intval($download[0]), $maxPlus);
102      $plus = max($plus, $maxPlus - $this->user->getUsScore());
103      $this->user->setUsPointPlus($this->user->getUsPointPlus() + $plus);
104      $this->user->setUsScore($this->user->getUsScore() + $plus);
105      $download[0] = 0;
106      $this->user->setUsDownload(implode(',', $download));
107    }
108
109    $this->user->setUsLastvisited(date('Y-m-d H:i:s'));
110    $this->user->save();
111    myUtility::log('['.$this->user->getUsId().']: '.myUtility::getRealIpAddr(), 'login.log');
112  }
113
114  public static function getUserObject($user) {
115    $tblcheckinfo = $user->getTblblogcheckinfo();
116    if (!$tblcheckinfo) return new userBase($user);
117
118    $position = $tblcheckinfo->getCiPosition();
119    if ($position < 40) return new userTeacher($user);
120    else return new userBase($user);
121  }
122}
Note: See TracBrowser for help on using the repository browser.