示例#1
0
 public function execute()
 {
     if ($this->photo->isValid()) {
         $name = sha1($this->user->getId() . $this->user->getLogin() . $this->user->getRegisteredAt() . time() . uniqid('ffdf'));
         $photoUploader = new PhotoFormatter($this->photo->getRealPath(), self::MINIMUM_SIZE, self::MAXIMUM_SIZE, $this->output);
         $old = $this->user->getAvatar();
         $photoUploader->setNewName($name);
         $photoUploader->loadAndScale(self::START_SIZE);
         $this->user->setAvatar($name);
         $this->repository->update($this->user);
         if (!empty($old)) {
             $photoUploader->removeOld($old, self::START_SIZE);
         }
     }
 }
示例#2
0
 public function getCredentialChangeRequest($id, User $currentUser)
 {
     $data = $this->conn->fetchAssoc('SELECT * FROM `' . CoreTables::CREDENTIAL_CHANGE_TBL . '` WHERE `id` = :id', [':id' => $id]);
     if (empty($data) || $data['userId'] != $currentUser->getId()) {
         throw new ModelException('The specified credential change request does not exist.');
     }
     return CredentialChangeRequest::fromArray($currentUser, $data);
 }
示例#3
0
 private function buildRepresentations(User $user)
 {
     $projects = $this->conn->fetchAll('SELECT a.`id`, a.`name`, a.`slug`, c.`role`, c.`note` FROM `' . CoreTables::AREA_TBL . '` a ' . 'INNER JOIN `' . CoreTables::AREA_MEMBER_TBL . '` c ON c.`areaId` = a.`id` ' . 'WHERE c.`userId` = :userId ORDER BY a.`name`', [':userId' => $user->getId()]);
     $items = array();
     foreach ($projects as $proj) {
         $items[] = new ProjectRepresentation($proj['slug'], $proj['name'], 'area_dashboard', 'AreaNominative: 0', 'purple', $this->resolver->getRole('Area', $proj['role']), $proj['note']);
     }
     return $items;
 }
示例#4
0
 private function buildRepresentations(User $user)
 {
     $projects = $this->conn->fetchAll('SELECT g.`id`, g.`name`, g.`slug`, c.`role`, c.`note` FROM `' . CoreTables::GROUP_TBL . '` g ' . 'INNER JOIN `' . CoreTables::GROUP_MEMBER_TBL . '` c ON c.`groupId` = g.`id` ' . 'WHERE c.`userId` = :userId ORDER BY g.`name`', [':userId' => $user->getId()]);
     $items = array();
     foreach ($projects as $proj) {
         $items[] = new ProjectRepresentation($proj['slug'], $proj['name'], 'group_dashboard', 'GroupNominative: 0', 'default', $this->resolver->getRole('Group', $proj['role']), $proj['note']);
     }
     return $items;
 }
示例#5
0
 public function findAvailableCourses(User $user)
 {
     $items = $this->conn->fetchAll('SELECT c.`id`, c.`name`, c.`deadline`, r.`result` AS `user_result`, r.`passedQuestions` AS `user_passedQuestions`, ' . 'r.`totalQuestions` AS `user_totalQuestions`, r.`completedAt` AS `user_completedAt`, arr.`result` AS `area_result`, arr.`passedQuestions` AS `area_passedQuestions`, ' . 'arr.`totalQuestions` AS `area_totalQuestions`, arr.`completedAt` AS `area_completedAt` ' . 'FROM `' . CourseTables::COURSE_TBL . '` c ' . 'LEFT JOIN `' . CourseTables::COURSE_AREA_RESULT_TBL . '` ar ON (ar.`courseId` = c.`id` AND ar.`areaId` = :areaId) ' . 'LEFT JOIN `' . CourseTables::COURSE_RESULT_TBL . '` arr ON (arr.`courseId` = ar.`courseId` AND arr.`userId` = ar.`userId`) ' . 'LEFT JOIN `' . CourseTables::COURSE_RESULT_TBL . '` r ON (r.`courseId` = c.`id` AND r.`userId` = :userId) ' . 'WHERE c.`isPublished` = 1 AND c.`projectId` = :projectId ORDER BY c.`displayOrder`', [':areaId' => $this->area->getId(), ':userId' => $user->getId(), ':projectId' => $this->area->getProject()->getId()]);
     foreach ($items as &$item) {
         TestResult::processResults($item, 'user_');
         TestResult::processResults($item, 'area_');
     }
     return $items;
 }
示例#6
0
 public static function fetchByRequestor(Connection $conn, $id, User $requestor)
 {
     $data = $conn->fetchAssoc('SELECT r.*, v.id AS `verifier_id`, v.`name` AS `verifier_name`, ' . 't.`id` AS `territory_id`, t.`name` AS `territory_name`, t.`areaNum` AS `territory_areaNum`, t.`requestNum` as `territory_requestNum` ' . 'FROM `' . CoreTables::AREA_REQUEST_TBL . '` r ' . 'INNER JOIN `' . CoreTables::TERRITORY_TBL . '` t ON t.`id` = r.`territoryId` ' . 'LEFT JOIN `' . CoreTables::USER_TBL . '` v ON v.`id` = r.`verifierId` ' . 'WHERE r.`id` = :id AND r.`requestorId` = :requestorId', [':id' => $id, ':requestorId' => $requestor->getId()]);
     if (null === $data) {
         return false;
     }
     $project = Project::fetch($conn, $data['projectId']);
     $item = self::fromArray($data);
     $item->setProject($project);
     $item->setRequestor($requestor);
     if (!empty($data['verifier_id'])) {
         $item->verifier = new Verifier($data['verifier_id'], $data['verifier_name']);
     }
     $item->setTerritory($item->oldTerritory = Territory::fromArray($data, 'territory'));
     return $item;
 }
示例#7
0
 protected function tryRecordingAreaResult(Connection $conn, Area $area, TestTrial $trial)
 {
     $areaResult = AreaCourseResult::fetchResult($conn, $area, $this->course);
     if ($areaResult->result == Question::RESULT_UNKNOWN) {
         $conn->insert(CourseTables::COURSE_AREA_RESULT_TBL, ['areaId' => $area->getId(), 'userId' => $this->user->getId(), 'courseId' => $this->course->getId()]);
         $progress = CourseProgress::fetchByArea($conn, $area);
         $progress->updateResults($conn, $areaResult, $trial);
         return $progress;
     } elseif ($areaResult->result == Question::RESULT_INVALID) {
         $conn->update(CourseTables::COURSE_AREA_RESULT_TBL, ['areaId' => $area->getId(), 'userId' => $this->user->getId(), 'courseId' => $this->course->getId()], ['areaId' => $area->getId(), 'courseId' => $this->course->getId()]);
         $progress = CourseProgress::fetchByArea($conn, $area);
         $progress->updateResults($conn, $areaResult, $trial);
         return $progress;
     }
     return true;
 }
示例#8
0
 private function createResultForUserAndArea(User $user, Area $area, $result, $questionNum, $passedQuestions)
 {
     self::$conn->insert(CourseTables::COURSE_RESULT_TBL, ['userId' => $user->getId(), 'courseId' => $this->course->getId(), 'trialNumber' => '1', 'result' => $result, 'startedAt' => time() - 100, 'completedAt' => time() - 50, 'totalQuestions' => $questionNum, 'passedQuestions' => $passedQuestions]);
     self::$conn->insert(CourseTables::COURSE_AREA_RESULT_TBL, ['areaId' => $area->getId(), 'userId' => $user->getId(), 'courseId' => $this->course->getId()]);
 }
 private function buildRepresentations(User $user)
 {
     $projects = $this->conn->fetchAll('SELECT p.`id`, p.`name`, p.`slug`, c.`role`, c.`note` FROM `' . CoreTables::PROJECT_TBL . '` p ' . 'INNER JOIN `' . CoreTables::PROJECT_MEMBER_TBL . '` c ON c.`projectId` = p.`id` ' . 'WHERE p.`archived` = 0 AND c.`userId` = :userId ORDER BY p.`name`', [':userId' => $user->getId()]);
     $items = array();
     foreach ($projects as $proj) {
         $items[] = new ProjectRepresentation($proj['slug'], $proj['name'], 'project_dashboard', 'ProjectNominative: 0', 'primary', $this->resolver->getRole('Project', $proj['role']), $proj['note']);
     }
     return $items;
 }
示例#10
0
文件: Course.php 项目: zyxist/cantiga
 /**
  * Certain courses do not have a test. In this situation the user may click a button where he
  * simply confirms in good-faith that he/she has completed the given course.
  * 
  * @param Connection $conn Database connection
  * @param Area $area The area which finishes the course.
  * @param User $user The user who completes the course.
  * @return CourseProgress|boolean
  */
 public function confirmGoodFaithCompletion(Connection $conn, Area $area, User $user)
 {
     if ($this->hasTest()) {
         throw new ModelException('Cannot confirm good-faith completion for a course that has a test assigned.');
     }
     try {
         $stmt = $conn->prepare('INSERT INTO `' . CourseTables::COURSE_RESULT_TBL . '` ' . '(`userId`, `courseId`, `trialNumber`, `startedAt`, `completedAt`, `result`, `totalQuestions`, `passedQuestions`) ' . 'VALUES(:userId, :courseId, 1, :startedAt, :completedAt, :result, :totalQuestions, :passedQuestions)');
         $stmt->bindValue(':userId', $user->getId());
         $stmt->bindValue(':courseId', $this->getId());
         $stmt->bindValue(':result', Question::RESULT_CORRECT);
         $stmt->bindValue(':startedAt', time());
         $stmt->bindValue(':completedAt', time());
         $stmt->bindValue(':totalQuestions', 1);
         $stmt->bindValue(':passedQuestions', 1);
         $stmt->execute();
         $areaResult = AreaCourseResult::fetchResult($conn, $area, $this);
         if ($areaResult->getResult() == Question::RESULT_UNKNOWN) {
             $conn->insert(CourseTables::COURSE_AREA_RESULT_TBL, ['userId' => $user->getId(), 'areaId' => $area->getId(), 'courseId' => $this->id]);
             $progress = CourseProgress::fetchByArea($conn, $area);
             $progress->updateGoodFaithCompletion($conn);
             return $progress;
         }
         return true;
     } catch (UniqueConstraintViolationException $exception) {
         throw new ModelException('Cannot complete a completed test!');
     }
 }
 public function clearMembership(User $user)
 {
     $this->conn->executeUpdate('UPDATE `' . CoreTables::GROUP_TBL . '` g INNER JOIN `' . CoreTables::GROUP_MEMBER_TBL . '` m ON m.`groupId` = g.`id` ' . 'SET g.`memberNum` = (g.`memberNum` - 1) WHERE m.`userId` = :userId', [':userId' => $user->getId()]);
     $this->conn->executeQuery('DELETE FROM `' . CoreTables::GROUP_MEMBER_TBL . '` WHERE `userId` = :userId', [':userId' => $user->getId()]);
     return 'groupNum';
 }
示例#12
0
 private function insertResult(Course $course, Area $area, User $user, $result)
 {
     self::$conn->insert(CourseTables::COURSE_RESULT_TBL, array('userId' => $user->getId(), 'courseId' => $course->getId(), 'trialNumber' => 1, 'startedAt' => time(), 'completedAt' => time(), 'result' => $result, 'totalQuestions' => 0, 'passedQuestions' => 0));
     self::$conn->insert(CourseTables::COURSE_AREA_RESULT_TBL, ['areaId' => $area->getId(), 'userId' => $user->getId(), 'courseId' => $course->getId()]);
 }
示例#13
0
 /**
  * Shows all invitations for the given user.
  * 
  * @param \Cantiga\CoreBundle\Repository\User $user
  */
 public function findInvitations(User $user)
 {
     return $this->conn->fetchAll('SELECT i.`id`, i.`createdAt`, i.`note`, u.`name` AS `inviterName`, i.`resourceType`, i.`resourceName` ' . 'FROM `' . CoreTables::INVITATION_TBL . '` i ' . 'INNER JOIN `' . CoreTables::USER_TBL . '` u ON u.`id` = i.`inviterId` ' . 'WHERE i.`userId` = :userId ' . 'ORDER BY i.`id` DESC', [':userId' => $user->getId()]);
 }
 public function clearMembership(User $user)
 {
     $this->conn->executeUpdate('UPDATE `' . CoreTables::PROJECT_TBL . '` p INNER JOIN `' . CoreTables::PROJECT_MEMBER_TBL . '` m ON m.`projectId` = p.`id` ' . 'SET p.`memberNum` = (p.`memberNum` - 1) WHERE m.`userId` = :userId', [':userId' => $user->getId()]);
     $this->conn->executeQuery('DELETE FROM `' . CoreTables::PROJECT_MEMBER_TBL . '` WHERE `userId` = :userId', [':userId' => $user->getId()]);
     return 'projectNum';
 }
示例#15
0
文件: Area.php 项目: zyxist/cantiga
 public function removeMember(Connection $conn, User $user)
 {
     if (1 == $conn->delete(CoreTables::AREA_MEMBER_TBL, ['areaId' => $this->getId(), 'userId' => $user->getId()])) {
         $conn->executeQuery('UPDATE `' . CoreTables::USER_TBL . '` SET `areaNum` = (`areaNum` - 1) WHERE `id` = :id', [':id' => $user->getId()]);
         $conn->executeQuery('UPDATE `' . CoreTables::AREA_TBL . '` SET `memberNum` = (SELECT COUNT(`userId`) FROM `' . CoreTables::AREA_MEMBER_TBL . '` WHERE `areaId` = :id) WHERE `id` = :id2', [':id' => $this->getId(), ':id2' => $this->getId()]);
         return true;
     }
     return false;
 }
示例#16
0
文件: Group.php 项目: zyxist/cantiga
 public function removeMember(Connection $conn, User $user)
 {
     if (1 == $conn->delete(CoreTables::GROUP_MEMBER_TBL, ['groupId' => $this->getId(), 'userId' => $user->getId()])) {
         $conn->executeQuery('UPDATE `' . CoreTables::GROUP_TBL . '` SET `memberNum` = (`memberNum` - 1) WHERE `id` = :id', [':id' => $this->id]);
         $conn->executeQuery('UPDATE `' . CoreTables::USER_TBL . '` SET `groupNum` = (`groupNum` - 1) WHERE `id` = :id', [':id' => $user->getId()]);
         return true;
     }
     return false;
 }
示例#17
0
 public function performTransition(User $currentUser, $additionalPermissionsGranted, $newStatus)
 {
     if ($this->status == self::STATUS_NEW) {
         if ($newStatus == self::STATUS_ANSWERING) {
             $this->responder = $currentUser;
             $this->answeredAt = time();
             $this->completedAt = null;
             $this->status = $newStatus;
             return;
         } elseif ($newStatus == self::STATUS_CLOSED && $additionalPermissionsGranted) {
             $this->responder = $currentUser;
             $this->completedAt = time();
             $this->status = $newStatus;
             return;
         }
     } elseif ($this->status == self::STATUS_ANSWERING) {
         if ($newStatus == self::STATUS_COMPLETED && $currentUser->getId() == $this->responder->getId()) {
             $this->completedAt = time();
             $this->status = $newStatus;
             return;
         } elseif ($newStatus == self::STATUS_NEW && $additionalPermissionsGranted) {
             $this->responder = null;
             $this->answeredAt = null;
             $this->completedAt = null;
             $this->status = $newStatus;
             return;
         }
     } elseif ($this->status == self::STATUS_COMPLETED) {
         if ($newStatus == self::STATUS_ANSWERING && ($currentUser->getId() == $this->responder->getId() || $additionalPermissionsGranted)) {
             $this->completedAt = null;
             $this->status = $newStatus;
             return;
         } elseif ($newStatus == self::STATUS_NEW && $additionalPermissionsGranted) {
             $this->responder = null;
             $this->answeredAt = null;
             $this->completedAt = null;
             $this->status = $newStatus;
             return;
         }
     } elseif ($this->status == self::STATUS_CLOSED) {
         if ($newStatus == self::STATUS_NEW && $additionalPermissionsGranted) {
             $this->responder = null;
             $this->answeredAt = null;
             $this->completedAt = null;
             $this->status = $newStatus;
             return;
         }
     }
     throw new ModelException('This status transition is not allowed.');
 }
示例#18
0
 public function clearMembership(User $user)
 {
     $this->conn->executeUpdate('UPDATE `' . CoreTables::AREA_TBL . '` a INNER JOIN `' . CoreTables::AREA_MEMBER_TBL . '` m ON m.`areaId` = a.`id` ' . 'SET a.`memberNum` = (a.`memberNum` - 1) WHERE m.`userId` = :userId', [':userId' => $user->getId()]);
     $this->conn->executeQuery('DELETE FROM `' . CoreTables::AREA_MEMBER_TBL . '` WHERE `userId` = :userId', [':userId' => $user->getId()]);
     return 'areaNum';
 }
示例#19
0
 public function insert(Connection $conn)
 {
     $conn->insert(CoreTables::CREDENTIAL_CHANGE_TBL, ['userId' => $this->user->getId(), 'requestIp' => $this->requestIp, 'requestTime' => $this->requestTime, 'provisionKey' => $this->provisionKey, 'email' => $this->email, 'password' => $this->password, 'salt' => $this->salt]);
     return $this->id = $conn->lastInsertId();
 }
示例#20
0
 public function join(Connection $conn, User $user)
 {
     $this->user = $user;
     $conn->update(CoreTables::INVITATION_TBL, ['userId' => $user->getId()], ['id' => $this->id]);
 }