Get markup for in progress async backups,
to use in backup table UI.

@param \core_backup_renderer $renderer The backup renderer object.
@param integer $instanceid The context id to get backup data for.
@return array $tabledata the rows of table data.
169048
public static function get_async_backups($renderer, $instanceid) {
        global $DB;

        $tabledata = array();

        // Get relevant backup ids based on context instance id.
        $select = 'itemid = ? AND execution = ? AND status < ? AND status > ?';
        $params = array($instanceid, backup::EXECUTION_DELAYED, backup::STATUS_FINISHED_ERR, backup::STATUS_NEED_PRECHECK);
        $backups = $DB->get_records_select('backup_controllers', $select, $params, 'timecreated DESC', 'id, backupid, timecreated');

        foreach ($backups as $backup) {
            $bc = \backup_controller::load_controller($backup->backupid);  // Get the backup controller.
            $filename = $bc->get_plan()->get_setting('filename')->get_value();
            $timecreated = $backup->timecreated;
            $status = $renderer->get_status_display($bc->get_status(), $bc->get_backupid());

            $tablerow = array($filename, userdate($timecreated), '-', '-', '-', $status);
            $tabledata[] = $tablerow;
        }

        return $tabledata;
    }
21717
public function render(ResultsRenderer $renderer)
    {
        $output = '';
        if ($this->result->headersDifferent()) {
            $output .= sprintf(
                "%s      %s\n%s  %s",
                $renderer->style('YOUR HEADERS:', ['bold', 'yellow']),
                $this->headers($this->result->getActualHeaders(), $renderer),
                $renderer->style('EXPECTED HEADERS:', ['bold', 'yellow']),
                $this->headers($this->result->getExpectedHeaders(), $renderer, false)
            );
        }

        if ($this->result->bodyDifferent()) {
            if ($this->result->headersAndBodyDifferent()) {
                $output .= "\n" . $renderer->style('- - - - - - - - -', ['default', 'bold']) . "\n\n";
            }

            $output .= sprintf(
                "%s       %s\n\n%s   %s\n",
                $renderer->style('YOUR OUTPUT:', ['bold', 'yellow']),
                $renderer->style(sprintf('"%s"', $this->result->getActualOutput()), 'red'),
                $renderer->style('EXPECTED OUTPUT:', ['bold', 'yellow']),
                $renderer->style(sprintf('"%s"', $this->result->getExpectedOutput()), 'green')
            );
        }

        return $output;
    }
149458
protected function can_backup(field_controller $field, int $instanceid) : bool {
        return $this->can_view($field, $instanceid) || $this->can_edit($field, $instanceid);
    }
470703
public function display(core_backup_renderer $renderer) {

        $prevstageurl = new moodle_url('/backup/restorefile.php', array('contextid' => $this->contextid));
        $nextstageurl = new moodle_url('/backup/restore.php', array(
            'contextid' => $this->contextid,
            'filepath'  => $this->filepath,
            'stage'     => restore_ui::STAGE_DESTINATION));

        $format = backup_general_helper::detect_backup_format($this->filepath);

        if ($format === backup::FORMAT_UNKNOWN) {
            // Unknown format - we can't do anything here.
            return $renderer->backup_details_unknown($prevstageurl);

        } else if ($format !== backup::FORMAT_MOODLE) {
            // Non-standard format to be converted.
            $details = array('format' => $format, 'type' => backup::TYPE_1COURSE); // todo type to be returned by a converter
            return $renderer->backup_details_nonstandard($nextstageurl, $details);

        } else {
            // Standard MBZ backup, let us get information from it and display.
            $this->details = backup_general_helper::get_backup_information($this->filepath);
            return $renderer->backup_details($this->details, $nextstageurl);
        }
    }
1097600
public function render(RendererInterface $renderer = null)
    {
        if ($renderer) {
            return $renderer->render($this);
        }

        return '<td' . $this->attributes->render() . '>' . $this->content . '</td>';
    }
315277
protected function rendererFactory($renderer): RendererInterface
	{
		return $renderer instanceof Closure ? $this->container->call($renderer) : $this->container->get($renderer);
	}
572811
public static final Renderer<BigDecimal> instance() { // NOPMD it's thread save!
    if (BigDecimalRenderer.instanceRenderer == null) {
      synchronized (BigDecimalRenderer.class) {
        if (BigDecimalRenderer.instanceRenderer == null) {
          BigDecimalRenderer.instanceRenderer = new BigDecimalRenderer();
        }
      }
    }
    return BigDecimalRenderer.instanceRenderer;
  }
911858
public function render(Render $renderer)
	{
		$content = '';

		foreach ( $this->getContents() as $option )
		{
			$content .= "\n" . $renderer->render($option);
		}

		return Html::tag('select', $this->getAttributes(), $content);
	}
941758
public function copyAssets($renderer)
    {
        // If the assets folder doesn' exist in the output path for this renderer, copy it
        $source = realpath(dirname(__FILE__));
        $assets_source = realpath($source.'/../../assets/'.$renderer);
        if (false === $assets_source) {
            //There is no assets to copy for this renderer
            return;
        }

        //first create the assets dir
        $destination = $this->outputPath.DIRECTORY_SEPARATOR.'assets';
        @mkdir($destination);

        $this->recurse_copy($assets_source, $destination.DIRECTORY_SEPARATOR.$renderer);
    }
1090517
public function loadData($writerId, array $tables, $incrementalLoad = null, $queue = 'primary')
    {
        $job = $this->loadDataAsync($writerId, $tables, $incrementalLoad, $queue);
        if (!isset($job['url'])) {
            throw new ServerException('Load data job returned unexpected result: ' . json_encode($job, JSON_PRETTY_PRINT));
        }

        return $this->waitForJob($job['url']);
    }
90442
public static function get_async_backup_progress($backupids, $contextid) {
        global $CFG;
        require_once($CFG->dirroot . '/backup/util/includes/backup_includes.php');
        require_once($CFG->dirroot . '/backup/util/includes/restore_includes.php');

        // Parameter validation.
        self::validate_parameters(
                self::get_async_backup_progress_parameters(),
                array(
                    'backupids' => $backupids,
                    'contextid' => $contextid
                )
        );

        // Context validation.
        list($context, $course, $cm) = get_context_info_array($contextid);
        self::validate_context($context);

        if ($cm) {
            require_capability('moodle/backup:backupactivity', $context);
        } else {
            require_capability('moodle/backup:backupcourse', $context);
            $instanceid = $course->id;
        }

        $results = array();
        foreach ($backupids as $backupid) {
            $results[] = backup_controller_dbops::get_progress($backupid);
        }

        return $results;
    }
1195088
public function html(PhpRenderer $renderer = null) {
        $view = new View();
        $view->setResponse(new Response());
        $resolver = new TemplateMapResolver();

        if($renderer === null) {
            $renderer = new PhpRenderer();
            $resolver->add($this->getTemplate(), $this->getDefaultTemplatePath($this->getTemplate()));
            $renderer->setResolver($resolver);
        } else {
            $renderer->resolver()->attach($resolver);
        }

        $view->getEventManager()->attach(new PhpRendererStrategy($renderer));

        $view->render($this);

        return $view->getResponse()->getContent();
    }
429615
public function addRowRenderer(RowRendererInterface $renderer): void
    {
        // Test if all required columns are present in column model
        $required_columns = $renderer->getRequiredColumns();

        foreach ($required_columns as $column) {
            if (!$this->exists($column)) {
                $cls = get_class($renderer);
                $msg = "Renderer '$cls' requires column '$column' to be present in column model.";
                throw new Exception\MissingColumnException(__METHOD__ . ': ' . $msg);
            }
        }

        $this->row_renderers->append($renderer);
    }
490475
public static final Renderer<Double> instance() { // NOPMD it's thread save!
    if (PercentDoubleRenderer.instanceRenderer == null) {
      synchronized (PercentDoubleRenderer.class) {
        if (PercentDoubleRenderer.instanceRenderer == null) {
          PercentDoubleRenderer.instanceRenderer = new PercentDoubleRenderer();
        }
      }
    }
    return PercentDoubleRenderer.instanceRenderer;
  }
953229
protected function get_visible_fields(int $instanceid) : array {
        $handler = $this;
        return array_filter($this->get_fields(),
            function($field) use($handler, $instanceid) {
                return $handler->can_view($field, $instanceid);
            }
        );
    }
1319757
public function renderer($row)
    {
        if (!isset($this->_data['renderer'])) {
            return null;
        }

        if (is_string($this->_data['renderer'])) {
            $renderer = $this->_data['renderer'];
            $namespace = ResourceTable::collection()->rendererNamespace();
            if ($namespace) {
                $renderer = $namespace.'\\'.$renderer;
            }
            $renderer = new $renderer();
            return $renderer->render($row);
        }

        return $this->_data['renderer']($row);
    }
1348837
public static final Renderer<Boolean> instance() { // NOPMD it's thread save!
    if (BooleanRenderer.instanceRenderer == null) {
      synchronized (BooleanRenderer.class) {
        if (BooleanRenderer.instanceRenderer == null) {
          BooleanRenderer.instanceRenderer = new BooleanRenderer();
        }
      }
    }
    return BooleanRenderer.instanceRenderer;
  }