/** * Returns "TRUE" when $this can sudo under $obSudo * * @param RM_User_Object $obUser * @return bool */ public function canSudoUnderUser(RM_User_Object $obSudo) { if (!$this->isSomeAdmin()) { return FALSE; } if ($this->_mapper->getLevelFromRootGroupByUser($this) > $this->_mapper->getLevelFromRootGroupByUser($obSudo)) { return FALSE; } return TRUE; }
/** * Sweep user day table * * @return void **/ public function userDaySweeper() { $begin = microtime(true); $sql = "drop table if exists %USER_DAY_TMP%;\r\ncreate table %USER_DAY_TMP%\r\n(\r\n user_id int,\r\n dt date,\r\n result_id int,\r\n PRIMARY KEY (user_id, dt)\r\n);\r\n\r\ninsert into %USER_DAY_TMP% (user_id, dt, result_id) select user_id, date_entered, count(*) from %USER_PURCHASE% where status_id = 3 and is_deleted = 0 and date_entered >= '%DAY%' group by user_id, date_entered;\r\n\r\nupdate %USER_DAY% p left JOIN %USER_DAY_TMP% d on p.user_id = d.user_id and p.event_date = d.dt set p.result_id = ifnull(d.result_id, 0) where p.result_id > -1 and d.user_id is not null;\r\n\r\nupdate %USER_DAY% p, %USER_DAY_TMP% d set p.result_id = d.result_id where p.result_id < 0 and p.user_id = d.user_id and p.event_date = d.dt and d.result_id > 0;\r\n\r\ndrop table if exists %USER_DAY_TMP%;\r\n\r\ndelete from %USER_DAY% where event_date < '2006-04-01';"; $sql = str_replace('%USER_DAY%', $this->_mapper->table('day'), $sql); $sql = str_replace('%USER_DAY_TMP%', $this->_mapper->table('day') . '_fix_tmp', $sql); $sql = str_replace('%USER_PURCHASE%', M('Purchase')->table('purchase'), $sql); $day = M('Date')->dbDate(M('Date')->add(M('Date')->dbDate(), '-' . C('diary.min-date-shift'))); $sql = str_replace('%DAY%', $day, $sql); M('Db')->execBatch($sql); $end = microtime(true); M('Trace')->trace('user_day_sweeper', "User day sweeper execution time: " . round($end - $begin, 2) . " sec"); // так как sweeper запускается ночью, то отправим емейл с уведомлением (в логах трудно отследить, запускался sweeper ночью или нет). M("MailSend")->sendAdminMail(array("subject" => "User day sweeper", "body" => 'table: ' . $this->_mapper->table('day') . "\n" . 'execution time: ' . round($end - $begin, 2) . ' sec')) or die("Cannot send mail!"); }
/** * Returns icon for a person * * @return void **/ public function statusIcon() { if ($this->id() == -2) { return 'present'; } if ($this->id() == -1) { return 'all_family'; } if ($this->is_panelist == 1) { return $this->user()->statusIcon(); } if ($this->is_animal) { return $this->_animalIcon(); } if ($this->age() < C('user.adult-age')) { return 'baby'; } if ($this->_mapper->anketaAnswered($this->id())) { return 'family'; } return 'family_noank'; }
public function runAs($userId, $call, array $args = array()) { $origUser = $this->_loggedUser; $exception = NULL; if ($this->_runAs) { throw new RM_Base_Exception_BadUsage("Nested runAs() is prohibited!"); } $this->_runAs = 1; $this->_loggedUser = $userId == 0 ? $this->_mapper->getAnonymousUser() : $this->_mapper->loadUserById($userId); // change user context try { $result = call_user_func_array($call, $args); } catch (Exception $e) { $exception = $e; } $this->_loggedUser = $origUser; // restore user context $this->_runAs = 0; if ($exception) { throw $exception; } return $result; }
/** * Saves leave. * * @return bool */ public function save() { $this->_mapper->setDaysByLeave($this); $data['mdate'] = M('Tools')->date()->dbDateTime(); return parent::save(); }