Example #1
0
 public static function getPage_Dashboard($contents, $containers)
 {
     // ask developers (who are the target audience) for feedback
     if (Authentication::isUserDeveloper()) {
         $contents[] = new UI_Alert('<p>How do you like ' . CONFIG_SITE_NAME . '? Does it help you?</p><p>If you have any questions or feedback, please get in touch with us at <a href="mailto:' . CONFIG_SITE_EMAIL . '">' . CONFIG_SITE_EMAIL . '</a></p>');
     }
     $createProjectButton = new UI_Link('Create new project', URL::toPage('create_project'), UI_Link::TYPE_SUCCESS);
     $projectList = Database::select("SELECT a.repositoryID, a.role, b.name, b.visibility, b.defaultLanguage FROM roles AS a JOIN repositories AS b ON a.repositoryID = b.id WHERE a.userID = " . intval(Authentication::getUserID()) . " ORDER BY b.name ASC");
     self::setTitle('Dashboard');
     $contents[] = new UI_Heading('Dashboard', true);
     if (Authentication::isUserDeveloper()) {
         if (count($projectList) > 0) {
             $projectTable = new UI_Table(array('Project', 'Review', 'Default language', 'Visibility'));
             $projectTable->setColumnPriorities(4, 3, 3, 2);
             foreach ($projectList as $projectData) {
                 $linkedName = new UI_Link(htmlspecialchars($projectData['name']), URL::toProject($projectData['repositoryID']), UI_Link::TYPE_UNIMPORTANT);
                 $languageName = Language::getLanguageNameFull($projectData['defaultLanguage']);
                 $pendingEditsURL = URL::toReview($projectData['repositoryID']);
                 $pendingEdits = Database::getPendingEditsByRepositoryCount($projectData['repositoryID']);
                 $pendingEditsButton = $pendingEdits > 0 ? new UI_Link($pendingEdits, $pendingEditsURL, UI_Link::TYPE_INFO) : new UI_Link($pendingEdits, $pendingEditsURL, UI_Link::TYPE_UNIMPORTANT, '', '', 'return false;');
                 $pendingInvitationsURL = URL::toInvitations($projectData['repositoryID']);
                 $pendingInvitations = Database::getInvitationsByRepositoryCount($projectData['repositoryID']);
                 $pendingInvitationsButton = $pendingInvitations > 0 ? new UI_Link($pendingInvitations, $pendingInvitationsURL, UI_Link::TYPE_INFO) : new UI_Link($pendingInvitations, $pendingInvitationsURL, UI_Link::TYPE_UNIMPORTANT, '', '', 'return false;');
                 $projectTable->addRow(array($linkedName->getHTML(), $pendingEditsButton->getHTML() . ' ' . $pendingInvitationsButton->getHTML(), $languageName, Repository::getRepositoryVisibilityTag($projectData['visibility'])));
             }
             $contents[] = new UI_Paragraph($createProjectButton);
             $contents[] = $projectTable;
             $contents[] = new UI_Paragraph($createProjectButton);
         } else {
             $contents[] = new UI_Paragraph($createProjectButton);
             $contents[] = new UI_Paragraph('You have no projects yet. You may either host your own projects or contribute to other projects that have been shared with you.');
         }
         $cell = new UI_Cell($contents);
         $row = new UI_Row(array($cell));
         $containers[] = new UI_Container(array($row));
         return new UI_Group($containers);
     } else {
         $contents[] = new UI_Paragraph('Visit any project that you want to contribute to. Having signed in, you may now contribute to all public projects. For private projects, you must first apply for an invitation.');
         $contents[] = new UI_Paragraph('You should have received a project\'s link from its owners already. Just visit this link to start translating.');
         $cellIntroduction = new UI_Cell($contents);
         $rowIntroduction = new UI_Row(array($cellIntroduction));
         $containerIntroduction = new UI_Container(array($rowIntroduction));
         $contents = array();
         $contents[] = new UI_Heading('Recently visited', true, 3);
         $recentRepositories = Authentication::getCachedRepositories();
         if (empty($recentRepositories)) {
             $contents[] = new UI_Paragraph('You have not visited any projects recently.');
         } else {
             $listRecentlyVisited = new UI_List();
             foreach ($recentRepositories as $recentRepositoryID => $recentRepositoryName) {
                 $listRecentlyVisited->addItem(new UI_Link(htmlspecialchars($recentRepositoryName), URL::toProject($recentRepositoryID)));
             }
             $contents[] = $listRecentlyVisited;
         }
         $cellVisited = new UI_Cell($contents);
         $rowVisited = new UI_Row(array($cellVisited));
         $containerVisited = new UI_Container(array($rowVisited));
         $contents = array();
         $contents[] = new UI_Heading('Contributed to', true, 3);
         $contributedRepositories = Database::getRepositoriesByContribution(Authentication::getUserID());
         if (empty($contributedRepositories)) {
             $contents[] = new UI_Paragraph('You have not contributed to any projects lately.');
         } else {
             $listRecentlyVisited = new UI_List();
             foreach ($contributedRepositories as $contributedRepository) {
                 $listRecentlyVisited->addItem(new UI_Link(htmlspecialchars($contributedRepository['name']), URL::toProject($contributedRepository['repositoryID'])));
             }
             $contents[] = $listRecentlyVisited;
         }
         $cellContributed = new UI_Cell($contents);
         $rowContributed = new UI_Row(array($cellContributed));
         $containerContributed = new UI_Container(array($rowContributed));
         $contents = array();
         $contents[] = new UI_Heading('Latest invitation requests', true, 3);
         $invitationRequests = Database::getInvitationsByUser(Authentication::getUserID());
         if (empty($invitationRequests)) {
             $contents[] = new UI_Paragraph('You have not requested any invitations yet.');
         } else {
             $listInvitationRequests = new UI_List();
             foreach ($invitationRequests as $invitationRequest) {
                 $projectLink = new UI_Link(htmlspecialchars($invitationRequest['name']), URL::toProject($invitationRequest['repositoryID']));
                 $listInvitationRequests->addItem($projectLink->getHTML() . ' (' . date('d.m.Y H:i', $invitationRequest['request_time']) . ') &raquo; <strong>' . Repository::getInvitationStatus($invitationRequest['accepted']) . '</strong>');
             }
             $contents[] = $listInvitationRequests;
         }
         $cellInvitations = new UI_Cell($contents);
         $rowInvitations = new UI_Row(array($cellInvitations));
         $containerInvitations = new UI_Container(array($rowInvitations));
         $containers[] = $containerIntroduction;
         $containers[] = $containerVisited;
         $containers[] = $containerContributed;
         $containers[] = $containerInvitations;
         return new UI_Group($containers);
     }
 }