/** * Track an action * * Params is an array of * * array( * 'user' => 'username/uniqueid', * 'url' => 'urlbeingviewed', * 'actionname' => 'the name of the action' * 'actionid' => 'uniqueid for the actor in the action' * 'remoteip' => 'the remote ip' * ) * * @param array $params */ public function trackAction($params) { $entry = new TrackerEntry(); $entry->bind($params); $validator = new ModelValidator(); if (!$validator->isValid($entry)) { throw new InvalidModelException($validator->getMessages()); } // Save the entry $this->dbService->createObject($entry); }
/** * Creates a new timesheet record * * @param Task $task */ public function addTimesheetRecord(Task $task, User $user, $start, $end) { if ($start > $end) { throw new InvalidTimesheetRecordException('Start is after end'); } $task->start(); $timeRecord = new TimesheetRecord(); $timeRecord->starttime = $start; $timeRecord->endtime = $end; $timeRecord->taskid = $task->id; $timeRecord->userid = $user->getUsername(); if ($this->dbService->createObject($timeRecord)) { $this->updateTaskTime($task); return $timeRecord; } return null; }
/** * Creates a new user * * @param Array $params * @return The created user * @throws InvalidModelException * @throws ExistingUserException */ public function createUser($params, $setAsAuthenticated = true, $role = User::ROLE_USER, $userType = null) { if ($userType == null) { $userType = $this->userClass; } // Check if there's a user with this email first. $select = $this->dbService->select(); $select->from(strtolower($userType), '*')->where('username=?', $params['username'])->orWhere('email=?', $params['email']); $existing = $this->dbService->getObject($select, $userType); if ($existing) { throw new ExistingUserException($params['username'] . ' already exists'); } $newPass = null; if (isset($params['password'])) { $newPass = $params['password']; } $params['role'] = $role; // Create a user with initial information $user = $userType; $user = new $user(); $user->generateSaltedPassword($params['password']); unset($params['password']); $user->bind($params); $validator = new ModelValidator(); if (!$validator->isValid($user)) { throw new InvalidModelException($validator->getMessages()); } // so now we save the user, then reset their password which emails, // then we set them as the authenticated user. if ($this->dbService->createObject($user)) { $this->trackerService->track('create-user', $user->id); if ($setAsAuthenticated) { $this->authService->setAuthenticatedUser($user); } return $user; } return null; }