Unverified Commit c75cc3ff authored by Stefan Auditor's avatar Stefan Auditor Committed by Stefan Auditor
Browse files

Issue #3282696 by sanduhrs: Port of l10n_community: Update explore projects page

parent b79cc633
Loading
Loading
Loading
Loading
+39 −45
Original line number Diff line number Diff line
@@ -3,7 +3,6 @@ declare(strict_types=1);

namespace Drupal\l10n_community\Controller;

use Drupal\Core\Cache\Cache;
use Drupal\Core\Config\ConfigManagerInterface;
use Drupal\Core\Controller\ControllerBase;
use Drupal\Core\Database\Connection;
@@ -22,7 +21,7 @@ class L10nCommunityProjectsController extends ControllerBase {
   *
   * @var \Drupal\Core\Database\Connection
   */
  protected $connection;
  protected Connection $connection;

  /**
   * The config manager.
@@ -64,16 +63,11 @@ class L10nCommunityProjectsController extends ControllerBase {
   *
   * @return \Drupal\Core\StringTranslation\TranslatableMarkup|void
   *   Translatable markup object.
   *
   * @throws \Drupal\Component\Plugin\Exception\InvalidPluginDefinitionException
   * @throws \Drupal\Component\Plugin\Exception\PluginNotFoundException
   */
  public function title() {
    /** @var \Drupal\l10n_server\Entity\L10nServerProject $project */
    $project = \Drupal::routeMatch()->getParameter('project');

    /** @var \Drupal\l10n_server\Entity\L10nServerProjectInterface $project */
    if ($project) {
    $project = \Drupal::routeMatch()->getParameter('project');
    if ($project instanceof L10nServerProjectInterface) {
      return $this->t('@project_name releases', [
        '@project_name' => $project->label(),
      ]);
@@ -114,67 +108,55 @@ class L10nCommunityProjectsController extends ControllerBase {

    // If we have more projects compared to what we show at the moment, display
    // an autocomplete jumpbox to jump to a project.
    //    if (count($string_counts) > $pager_setting) {
    //      $form = drupal_get_form('l10n_community_explore_projects_jump_form');
    //      $output .= drupal_render($form);
    //    }

    //    $pager = theme('pager', array('tags' => NULL, 'element' => 0));

    //    $output .= _l10n_community_alphabetic_pager();
    //    $output .= $pager;
    if (count($string_counts) > $pager_setting) {
      $build['form_jump'] = \Drupal::formBuilder()
        ->getForm('Drupal\l10n_community\Form\JumpForm');
    }

    $rows = [];
    $table = [];
    foreach ($projects as $project) {
      $rows[] = [
      $table[] = [
        [
          'data' => t('<a href="@url">@project</a>', [
            '@project' => $project->title,
            '@url' => Url::fromUri('internal:/translate/projects/' . $project->pid)->toString(),
          ]),
          'class' => ['rowhead'],
        ],
        [
          'data' => [
            '#theme' => 'l10n_community_progress_columns',
            '#sum' => 100,
            '#translated' => rand(0, 100),
            '#has_suggestion' => 9,
            '#sum' => (@$string_counts[$project->pid]['count'] * $language_count),
            '#translated' => @$string_counts[$project->pid]['translations'],
            '#has_suggestion' => @$string_counts[$project->pid]['suggestions'],
          ],
        ],
      ];
      //      $rows[] = array_merge(
      //        [
      //            'data' => t('<a href="@url">@project</a>', [
      //              '@project' => $project->title,
      //              '@url' => Url::fromUri('internal:/translate/projects/' . $project->pid)->toString(),
      //            ]),
      //            'class' => ['rowhead'],
      //        ],
      //        // Multiply summary count by languages handled, so we get an
      //        // accurate picture of completeness.
      //        ['data' => $progress],
      //      );
    }
    //    $output .= theme('table', array('header' => theme('l10n_community_progress_headers', array('mainhead' => t('Project'))), 'rows' => $table, 'attributes' => array('class' => array('l10n-community-overview'))));
    //    $output .= $pager;
    //    return $output . '<div class="clear-block"></div>';
    }

    $build['pre_pager'] = [
      '#type' => 'pager',
    ];
    $build['content'] = [
      '#type' => 'table',
      '#header' => [
        t('Project'),
        t('Progress'),
      ],
      '#rows' => $rows,
      '#rows' => $table,
      '#attributes' => [
        'class' => [
          'l10n-community-overview',
        ],
      ],
      '#cache' => [
        'max-age' => Cache::PERMANENT,
        // @todo Fix cache handling.
        // 'max-age' => Cache::PERMANENT,
      ],
    ];
    $build['post_pager'] = [
      '#type' => 'pager',
    ];

    return $build;
  }
@@ -183,8 +165,10 @@ class L10nCommunityProjectsController extends ControllerBase {
   * Builds the response.
   *
   * @param \Drupal\l10n_server\Entity\L10nServerProjectInterface $project
   *   The project entity.
   *
   * @return array
   *   A render array.
   */
  public function overview(L10nServerProjectInterface $project) {
    $build['content'] = [
@@ -198,8 +182,10 @@ class L10nCommunityProjectsController extends ControllerBase {
   * Builds the response.
   *
   * @param \Drupal\l10n_server\Entity\L10nServerProjectInterface $project
   *   The project entity.
   *
   * @return array
   *   A render array.
   */
  public function export(L10nServerProjectInterface $project) {
    $build['content'] = [
@@ -213,8 +199,10 @@ class L10nCommunityProjectsController extends ControllerBase {
   * Builds the response.
   *
   * @param \Drupal\l10n_server\Entity\L10nServerProjectInterface $project
   *   The project entity.
   *
   * @return array
   *   A render array.
   */
  public function releases(L10nServerProjectInterface $project) {
    $build['content'] = [
@@ -228,9 +216,12 @@ class L10nCommunityProjectsController extends ControllerBase {
   * Builds the response.
   *
   * @param \Drupal\l10n_server\Entity\L10nServerProjectInterface $project
   *   The project entity.
   * @param \Drupal\l10n_server\Entity\L10nServerReleaseInterface $release
   *   The release entity.
   *
   * @return array
   *   A render array.
   */
  public function release(L10nServerProjectInterface $project, L10nServerReleaseInterface $release) {
    $build['content'] = [
@@ -243,7 +234,7 @@ class L10nCommunityProjectsController extends ControllerBase {
  /**
   * Provides a list of projects from the database, ordered by uri.
   *
   * @param $options
   * @param array $options
   *   Associative array of options
   *    - 'uri': Project URI, if requesting information about one project only.
   *      If not specified, information about all projects is returned.
@@ -251,7 +242,8 @@ class L10nCommunityProjectsController extends ControllerBase {
   *      NULL, no pager is used.
   *    - 'all': If not specified, unpublished projects are excluded (default).
   *      If TRUE, even unpublished projects are returned (for admin pages).
   * @return
   *
   * @return array
   *   An associative array keyed with project uris.
   */
  private function getProjects(array $options = []) {
@@ -271,7 +263,9 @@ class L10nCommunityProjectsController extends ControllerBase {
        $initials = $this->getProjectInitials();
        if (isset($initials[$options['initial']])) {
          $args = $initials[$options['initial']]['values'];
          for ($i=0; $i < count($args); $i++) { $arguments[':p_' . $i] = $args[$i]; }
          for ($i = 0; $i < count($args); $i++) {
            $arguments[':p_' . $i] = $args[$i];
          }
          $placeholders = implode(',', array_keys($arguments));
          $select->where("SUBSTRING(title, 1, 1) IN ($placeholders)", $arguments);
        }
@@ -323,7 +317,7 @@ class L10nCommunityProjectsController extends ControllerBase {
   * Build a list of initials of active projects for listings.
   */
  private function getProjectInitials() {
    // Grab the unique initials of all active projects
    // Grab the unique initials of all active projects.
    $result = \Drupal::database()
      ->query('SELECT DISTINCT(SUBSTR(title, 1, 1)) AS initial FROM {l10n_server_project} WHERE status = :status ORDER BY initial ASC', [
        ':status' => 1,