[289] | 1 | <?php |
---|
| 2 | |
---|
| 3 | /** |
---|
| 4 | * Subclass for representing a row from the 'tbluser' table. |
---|
| 5 | * |
---|
| 6 | * |
---|
| 7 | * |
---|
| 8 | * @package lib.model |
---|
| 9 | */ |
---|
| 10 | class Tbluser extends BaseTbluser { |
---|
| 11 | |
---|
| 12 | private $oldUsername = null; |
---|
| 13 | protected $userObj = null; |
---|
| 14 | |
---|
| 15 | public function getObject() { |
---|
| 16 | if ($this->userObj == null) $this->userObj = userBase::getUserObject($this); |
---|
| 17 | return $this->userObj; |
---|
| 18 | } |
---|
| 19 | |
---|
| 20 | public function setUsUsername($v) { |
---|
| 21 | if ($this->oldUsername==null) $this->oldUsername = $this->getUsUsername(); |
---|
| 22 | parent::setUsUsername($v); |
---|
| 23 | } |
---|
| 24 | |
---|
| 25 | public function save(PropelPDO $con = null) { |
---|
| 26 | $create = $this->getUsId()==null; |
---|
| 27 | |
---|
| 28 | // update infor in tblbloguser |
---|
| 29 | if ($this->isColumnModified(TbluserPeer::US_USERNAME)) { |
---|
| 30 | $c = new Criteria(); |
---|
| 31 | $c->add(TblbloguserPeer::US_USER, $this->getUsId()); |
---|
| 32 | $tblblogusers = TblbloguserPeer::doSelect($c); |
---|
| 33 | foreach ($tblblogusers as $tblbloguser) { |
---|
| 34 | $tblbloguser->setUsNickname($this->getUsUsername()); |
---|
| 35 | $tblbloguser->save(); |
---|
| 36 | } |
---|
| 37 | $c = new Criteria(); |
---|
| 38 | $c->add(TblblogPeer::BL_USER, $this->getUsId()); |
---|
| 39 | $c->add(TblblogPeer::BL_SHORTNAME, $this->oldUsername); |
---|
| 40 | $c->add(TblblogPeer::BL_TYPE, 1); |
---|
| 41 | $tblblog = TblblogPeer::doSelectOne($c); |
---|
| 42 | if ($tblblog) { |
---|
| 43 | $tblblog->setBlShortname($this->getUsUsername()); |
---|
| 44 | $tblblog->save(); |
---|
| 45 | } |
---|
| 46 | } |
---|
| 47 | if ($this->isColumnModified(TbluserPeer::US_LASTNAME) || $this->isColumnModified(TbluserPeer::US_FIRSTNAME)) { |
---|
| 48 | $val = new Criteria(); |
---|
| 49 | $val->add(TblbloguserPeer::US_FULLNAME, $this->getUsFullName()); |
---|
| 50 | $c = new Criteria(); |
---|
| 51 | $c->add(TblbloguserPeer::US_USER, $this->getUsId()); |
---|
| 52 | BasePeer::doUpdate($c, $val, Propel::getConnection(TblbloguserPeer::DATABASE_NAME)); |
---|
| 53 | } |
---|
| 54 | if ($this->isColumnModified(TbluserPeer::US_SCORE)) { |
---|
| 55 | $val = new Criteria(); |
---|
| 56 | $val->add(TblblogcheckinfoPeer::CI_SCORE, $this->getUsScore()); |
---|
| 57 | $c = new Criteria(); |
---|
| 58 | $c->add(TblblogcheckinfoPeer::CI_USERID, $this->getUsId()); |
---|
| 59 | BasePeer::doUpdate($c, $val, Propel::getConnection(TblblogcheckinfoPeer::DATABASE_NAME)); |
---|
| 60 | } |
---|
| 61 | |
---|
| 62 | parent::save($con); |
---|
| 63 | if ($create) { |
---|
| 64 | $this->setUsIdmd5(md5($this->getUsId())); |
---|
| 65 | parent::save($con); |
---|
| 66 | } |
---|
| 67 | } |
---|
| 68 | |
---|
| 69 | /** |
---|
| 70 | * |
---|
| 71 | * @return full name of user |
---|
| 72 | */ |
---|
| 73 | public function getUsFullname() { |
---|
| 74 | if ($this->getUsStatus()<10) { |
---|
| 75 | if (null==$this->getUsLastname() && null==$this->getUsFirstname()) |
---|
| 76 | return $this->getUsUsername(); |
---|
| 77 | else |
---|
| 78 | return $this->getUsLastname().' '.$this->getUsFirstname(); |
---|
| 79 | } else { |
---|
| 80 | return 'Äang bá» khóa'; |
---|
| 81 | } |
---|
| 82 | } |
---|
| 83 | |
---|
| 84 | public function setUsFullname($fullname) { |
---|
| 85 | $names = split(' ', $fullname); |
---|
| 86 | $firstname = array_pop($names); |
---|
| 87 | $lastname = join($names, ' '); |
---|
| 88 | $this->setUsFirstname($firstname); |
---|
| 89 | $this->setUsLastname($lastname); |
---|
| 90 | } |
---|
| 91 | |
---|
| 92 | public function getUsHomePage() { |
---|
| 93 | $homePage = parent::getUsHomepage(); |
---|
| 94 | if ($homePage === null) { |
---|
| 95 | $c = new Criteria(); |
---|
| 96 | $c->add(TblblogPeer::BL_USER, $this->getUsId()); |
---|
| 97 | $c->add(TblblogPeer::BL_TYPE, 1); |
---|
| 98 | $tblblog = TblblogPeer::doSelectOne($c); |
---|
| 99 | if (!$tblblog) $homePage = ''; |
---|
| 100 | else { |
---|
| 101 | $homePage = $tblblog->getRootUrl(); |
---|
| 102 | if (preg_match('@^http://(.+)/@', $homePage, $match)) $homePage = $match[1]; |
---|
| 103 | } |
---|
| 104 | $this->setUsHomepage($homePage); |
---|
| 105 | $this->save(); |
---|
| 106 | } |
---|
| 107 | if ($homePage != '') $homePage = 'http://'.$homePage; |
---|
| 108 | return $homePage; |
---|
| 109 | } |
---|
| 110 | |
---|
| 111 | public function getUsKey() { |
---|
| 112 | $key = parent::getUsKey(); |
---|
| 113 | if ($key == null) { |
---|
| 114 | $key = rand(1, time()); |
---|
| 115 | $this->setUsKey($key); |
---|
| 116 | $this->save(); |
---|
| 117 | } |
---|
| 118 | return $key; |
---|
| 119 | } |
---|
| 120 | |
---|
| 121 | /** |
---|
| 122 | * |
---|
| 123 | * @return number of presentation which is downloaded by user |
---|
| 124 | */ |
---|
| 125 | public function getDownloadPresentationCount() { |
---|
| 126 | $c = new Criteria(); |
---|
| 127 | $c->add(TbluserpresentationPeer::USPRE_USER, $this->getUsId()); |
---|
| 128 | return TbluserpresentationPeer::doCount($c); |
---|
| 129 | } |
---|
| 130 | |
---|
| 131 | /** |
---|
| 132 | * |
---|
| 133 | * @return number of document which is downloaded by user |
---|
| 134 | */ |
---|
| 135 | public function getDownloadDocumentCount() { |
---|
| 136 | $c = new Criteria(); |
---|
| 137 | $c->add(TbluserdocumentPeer::USDOC_USER, $this->getUsId()); |
---|
| 138 | return TbluserdocumentPeer::doCount($c); |
---|
| 139 | } |
---|
| 140 | |
---|
| 141 | /** |
---|
| 142 | * |
---|
| 143 | * @return number of presentation which is uploaded by user |
---|
| 144 | */ |
---|
| 145 | public function getUploadPresentationCount() { |
---|
| 146 | $c = new Criteria(); |
---|
| 147 | $c->add(TblpresentationPeer::PR_USER, $this->getUsId()); |
---|
| 148 | $c->add(TblpresentationPeer::PR_STATUS, array(0,1,100,101), Criteria::IN); |
---|
| 149 | return TblpresentationPeer::doCount($c); |
---|
| 150 | } |
---|
| 151 | |
---|
| 152 | /** |
---|
| 153 | * |
---|
| 154 | * @return number of document which is uploaded by user |
---|
| 155 | */ |
---|
| 156 | public function getUploadDocumentCount() { |
---|
| 157 | $c = new Criteria(); |
---|
| 158 | $c->add(TbldocumentPeer::DOC_USER, $this->getUsId()); |
---|
| 159 | $c->add(TbldocumentPeer::DOC_STATUS, array(0,1,100,101), Criteria::IN); |
---|
| 160 | return TbldocumentPeer::doCount($c); |
---|
| 161 | } |
---|
| 162 | |
---|
| 163 | //diem upload bai giang |
---|
| 164 | public function getUploadPresentationsPoint() { |
---|
| 165 | $c = new Criteria(); |
---|
| 166 | $c->add(TblpresentationPeer::PR_USER, $this->getUsId()); |
---|
| 167 | $c->add(TblpresentationPeer::PR_STATUS, array(0,1,100,101), Criteria::IN); |
---|
| 168 | $c->addSelectColumn('sum(pr_hit)'); |
---|
| 169 | $rs = TblpresentationPeer::doSelectStmt($c); |
---|
| 170 | $row = $rs->fetch(PDO::FETCH_NUM); |
---|
| 171 | $rs->closeCursor(); |
---|
| 172 | return (int)$row[0]; |
---|
| 173 | } |
---|
| 174 | |
---|
| 175 | //diem upload tu lieu |
---|
| 176 | public function getUploadDocumentsPoint() { |
---|
| 177 | $c = new Criteria(); |
---|
| 178 | $c->add(TbldocumentPeer::DOC_USER, $this->getUsId()); |
---|
| 179 | $c->add(TbldocumentPeer::DOC_STATUS, array(0,1,100,101), Criteria::IN); |
---|
| 180 | $c->addSelectColumn('sum(doc_hit)'); |
---|
| 181 | $rs = TbldocumentPeer::doSelectStmt($c); |
---|
| 182 | $row = $rs->fetch(PDO::FETCH_NUM); |
---|
| 183 | $rs->closeCursor(); |
---|
| 184 | return (int)$row[0]; |
---|
| 185 | } |
---|
| 186 | |
---|
| 187 | //diem download (bai giang, ko tinh tu lieu) |
---|
| 188 | public function getDownloadPresentationsPoint() { |
---|
| 189 | $c = new Criteria(); |
---|
| 190 | $c->add(TbluserpresentationPeer::USPRE_USER, $this->getUsId()); |
---|
| 191 | $down_pre = TbluserpresentationPeer::doCount($c); |
---|
| 192 | return $down_pre; |
---|
| 193 | } |
---|
| 194 | |
---|
| 195 | //tong diem cua thanh vien |
---|
| 196 | public function getUserPoint() { |
---|
| 197 | $up_pre = $this->getUploadPresentationsPoint(); |
---|
| 198 | $up_doc = $this->getUploadDocumentsPoint(); |
---|
| 199 | $down_pre = $this->getDownloadPresentationsPoint(); |
---|
| 200 | |
---|
| 201 | $score = 80 + $this->getUsPointplus() + $up_pre*3 + $up_doc*1 - $down_pre*1; |
---|
| 202 | if ($score != $this->getUsScore()) { |
---|
| 203 | $this->setUsScore($score); |
---|
| 204 | $this->save(); |
---|
| 205 | } |
---|
| 206 | return $score; |
---|
| 207 | } |
---|
| 208 | |
---|
| 209 | public function incDownload($save = true, $incWeekScore = 0) { |
---|
| 210 | $download = explode(',', $this->getUsDownload()); |
---|
| 211 | if (isset($download[1])) $download[1] = intval($download[1]) + 1; |
---|
| 212 | if ($incWeekScore != 0) $download[0] = intval($download[0]) + $incWeekScore; |
---|
| 213 | $this->setUsDownload(implode(',', $download)); |
---|
| 214 | if ($save) $this->save(); |
---|
| 215 | } |
---|
| 216 | |
---|
| 217 | public function incUpload($save = true) { |
---|
| 218 | $download = explode(',', $this->getUsDownload()); |
---|
| 219 | if (!isset($download[2])) return; |
---|
| 220 | $download[2] = intval($download[2]) + 1; |
---|
| 221 | $this->setUsDownload(implode(',', $download)); |
---|
| 222 | if ($save) $this->save(); |
---|
| 223 | } |
---|
| 224 | |
---|
| 225 | public function getUsUpDown() { |
---|
| 226 | $download = explode(',', $this->getUsDownload()); |
---|
| 227 | if (!isset($download[1]) || !isset($download[2])) { |
---|
| 228 | $download[1] = $this->getDownloadPresentationCount() + $this->getDownloadDocumentCount(); |
---|
| 229 | $download[2] = $this->getUploadPresentationCount() + $this->getUploadDocumentCount(); |
---|
| 230 | $this->setUsDownload(implode(',', $download)); |
---|
| 231 | $this->save(); |
---|
| 232 | } |
---|
| 233 | return $download; |
---|
| 234 | } |
---|
| 235 | } |
---|