public function vote($answer) { XDB::startTransaction(); XDB::execute('INSERT INTO qdj_votes SET qdj = {?}, uid = {?}, rank = 0, rule = "null"', $this->id(), S::user()->id()); $vote = XDB::insertID(); // Get the rank $rank = XDB::query('SELECT COUNT(*)+1 FROM qdj_votes WHERE qdj = {?} AND rank != 0', $this->id())->fetchOneCell(); if ($rank == 1) { if ($this->writer === null) { $this->select(QDJSelect::all()); } XDB::execute('INSERT INTO qdj_votes SET qdj = {?}, uid = {?}, rank = 0, rule = 10', $this->id(), $this->writer->id()); } $rule = null; switch ($rank) { case 1: $rule = '1'; break; case 2: $rule = '2'; break; case 3: $rule = '3'; break; case 13: $rule = '4'; break; case 42: $rule = '5'; break; case 69: $rule = '6'; break; case 314: $rule = '7'; break; case substr(strrchr(IPAddress::get(), '.'), 1): $rule = '8'; break; case date('d') + date('m'): $rule = '9'; break; } XDB::execute('UPDATE qdj_votes SET rank = {?}, rule = {?} WHERE vote_id = {?}', $rank, $rule, $vote); XDB::commit(); if ($answer == 1) { XDB::execute('UPDATE qdj SET count1 = count1+1 WHERE id={?}', $this->id()); } else { XDB::execute('UPDATE qdj SET count2 = count2+1 WHERE id={?}', $this->id()); } }
/** * Is the current user a room master ? * @return boolean */ public function isRoomMaster() { $user = S::user(); if (!$user) { return false; } return $user->isWeb() || $user->hasRights($this, Rights::admin()) || $this->rooms()->ips()->has(IPAddress::get()); }