Format the current row's actions column.

@param   tour    $tour       The tour for this row.
@return  string
506696
protected function col_actions(tour $tour) {
        $actions = [];

        if ($tour->is_first_tour()) {
            $actions[] = helper::get_filler_icon();
        } else {
            $actions[] = helper::format_icon_link($tour->get_moveup_link(), 't/up',
                    get_string('movetourup', 'tool_usertours'));
        }

        if ($tour->is_last_tour($this->tourcount)) {
            $actions[] = helper::get_filler_icon();
        } else {
            $actions[] = helper::format_icon_link($tour->get_movedown_link(), 't/down',
                    get_string('movetourdown', 'tool_usertours'));
        }

        $actions[] = helper::format_icon_link($tour->get_view_link(), 't/viewdetails', get_string('view'));
        $actions[] = helper::format_icon_link($tour->get_edit_link(), 't/edit', get_string('edit'));
        $actions[] = helper::format_icon_link($tour->get_export_link(), 't/export',
                get_string('exporttour', 'tool_usertours'), 'tool_usertours');
        $actions[] = helper::format_icon_link($tour->get_delete_link(), 't/delete', get_string('delete'), null, [
                'data-action'   => 'delete',
                'data-id'       => $tour->get_id(),
            ]);

        return implode('&nbsp;', $actions);
    }
620412
public function addTranslationAction($template = 'expendable::admin.form.components.datatable.translations', $route = '')
    {
        $this->add('translation', function($model) use ($template, $route) {

            $languages    = Language::withoutCurrentLanguage()->get();
            $translations = Translation::byElement($model)->pluck('id_element', 'iso')->toArray();
            return view($template, array(
                'languages'    => $languages,
                'translations' => $translations,
                'data'         => $model->toArray(),
                'route'        => !empty($route) ? $route.'@' : $this->getControllerNameForAction().'@'
            ))->render();
        });

    }
1341708
def evaluate_tour_Q(self, tour):
        
        from .chic import score_evaluate_Q
        return score_evaluate_Q(tour, self.active_sizes, self.Q)
903591
public function col_note($row) {
        if ($this->is_downloading()) {
            return $row->note;
        } else {
            return format_text($row->note, FORMAT_MOODLE);
        }
    }
658510
private function formatRule($rules)
    {
        if (is_array($rules)) {
            foreach ($rules as $rule) {
                $formatted[] = $this->formatRule($rule);
            }

            return $formatted ?? [];
        }

        if (is_object($rules) || is_callable($rules)) {
            return $rules;
        }

        if (Str::contains($rules, 'required_if') && preg_match('/(.*):(.*),(.*)/', $rules, $matches)) {
            $column = Str::startsWith($matches[2], '*.') ? $matches[2] : '*.' . $matches[2];

            return $matches[1] . ':' . $column . ',' . $matches[3];
        }

        return $rules;
    }
1342409
public static function transRoute($route) {
        $app = app();
        $locale = \Sirgrimorum\CrudGenerator\CrudGenerator::setLocale();
        //$locale = $app->getLocale();
        $routes = explode(".", $route);
        $base = "";
        if (count($routes) > 1) {
            $base = \Sirgrimorum\CrudGenerator\CrudGenerator::transRouteModel($routes[0]);
            if ($base != "") {
                $base .= ".";
            }
            $route = $routes[1];
        }
        $transroute = $app->translator->trans('routes.actions.' . $route, [], $locale);
        if (stripos($transroute, ".") !== false) {
            $transroute = $app->translator->trans('crudgenerator::admin.routes.' . $route, [], $locale);
            if (stripos($transroute, ".") !== false) {
                $transroute = $route;
            }
        }
        //$route = $app->translator->trans('crudgenerator::admin.routes.' . $route);
        return $base . $transroute;
    }
682792
def separate_tour_and_o(row):
    
    tour = []
    tour_o = []
    for contig in row.split():
        if contig[-1] in ('+', '-', '?'):
            tour.append(contig[:-1])
            tour_o.append(contig[-1])
        else:  # Unoriented
            tour.append(contig)
            tour_o.append('?')
    return tour, tour_o
165871
public function format($row)
    {
        $data = $this->getArray($row);
        $data = $this->process($data);

        return json_encode($data, $this->encodeOptions);
    }
31491
public function format($root, $path, $route = null)
    {
        $path = '/'.trim($path, '/');

        if ($this->formatHostUsing) {
            $root = call_user_func($this->formatHostUsing, $root, $route);
        }

        if ($this->formatPathUsing) {
            $path = call_user_func($this->formatPathUsing, $path, $route);
        }

        return trim($root.$path, '/');
    }
1072291
public function FormatFromSettings($member = null)
    {
        if (!$member) {
            $member = Security::getCurrentUser();
        }

        // Fall back to nice
        if (!$member) {
            return $this->Nice();
        }

        // Get user format
        $format = $member->getTimeFormat();
        return $this->Format($format);
    }
468613
public function render($template)
    {
        $actions = $this->getActions();
        $this->flushActions();

        return $this->table->getRender()->getTwig()->render($template, ['actions' => $actions]);
    }
926909
public function execute($action) {
        admin_externalpage_setup('tool_usertours/tours');
        // Add the main content.
        switch($action) {
            case self::ACTION_NEWTOUR:
            case self::ACTION_EDITTOUR:
                $this->edit_tour(optional_param('id', null, PARAM_INT));
                break;

            case self::ACTION_MOVETOUR:
                $this->move_tour(required_param('id', PARAM_INT));
                break;

            case self::ACTION_EXPORTTOUR:
                $this->export_tour(required_param('id', PARAM_INT));
                break;

            case self::ACTION_IMPORTTOUR:
                $this->import_tour();
                break;

            case self::ACTION_VIEWTOUR:
                $this->view_tour(required_param('id', PARAM_INT));
                break;

            case self::ACTION_HIDETOUR:
                $this->hide_tour(required_param('id', PARAM_INT));
                break;

            case self::ACTION_SHOWTOUR:
                $this->show_tour(required_param('id', PARAM_INT));
                break;

            case self::ACTION_DELETETOUR:
                $this->delete_tour(required_param('id', PARAM_INT));
                break;

            case self::ACTION_RESETFORALL:
                $this->reset_tour_for_all(required_param('id', PARAM_INT));
                break;

            case self::ACTION_NEWSTEP:
            case self::ACTION_EDITSTEP:
                $this->edit_step(optional_param('id', null, PARAM_INT));
                break;

            case self::ACTION_MOVESTEP:
                $this->move_step(required_param('id', PARAM_INT));
                break;

            case self::ACTION_DELETESTEP:
                $this->delete_step(required_param('id', PARAM_INT));
                break;

            case self::ACTION_LISTTOURS:
            default:
                $this->print_tour_list();
                break;
        }
    }
25451
public function format_button($field)
    {
        $class = $this->columns[$field]['button_class'];

        $icon = $this->columns[$field]['icon'];
        if ($icon) {
            if ($icon[0] != '<') {
                $icon = '<span class="icon-'.$icon.'"></span>';
            }
            $icon .= '&nbsp;';
        }

        $this->current_row_html[$field] =
            '<button class="atk-button-small do-'.$field.'  '.$class.'" data-id="'.$this->model->id.'">'.
                $icon.$this->columns[$field]['descr'].
            '</button>';
    }
845675
def iter_last_tour(tourfile, clm):
    
    row = open(tourfile).readlines()[-1]
    _tour, _tour_o = separate_tour_and_o(row)
    tour = []
    tour_o = []
    for tc, to in zip(_tour, _tour_o):
        if tc not in clm.contigs:
            logging.debug("Contig `{}` in file `{}` not found in `{}`"
                          .format(tc, tourfile, clm.idsfile))
            continue
        tour.append(tc)
        tour_o.append(to)
    return tour, tour_o
1062144
public function formatRow()
    {
        // execute CompleteLister row formating
        parent::formatRow();

        if (empty($this->columns)) {
            throw $this->exception('No columns defined for grid');
        }

        foreach ($this->columns as $field => $column) {
            if ((is_array($this->current_row) || $this->current_row instanceof ArrayAccess)
                && array_key_exists($field, $this->current_row)
            ) {
                $this->current_row[$field.'_original'] = $this->current_row[$field];
            }

            // if model field has listData structure, then get value instead of key
            if ($this->model && $f = $this->model->hasElement($field)) {
                $v = $this->current_row[$field];

                if ($this->model instanceof \atk4\data\Model) {
                    /** @type \atk4\data\Field $f */
                    if (isset($f->enum) && $values = $f->enum) {
                        $this->current_row[$field] = isset($f->ui['valueList'][$v])
                            ? $f->ui['valueList'][$v]
                            : $values[$v];
                    }
                } else {
                    /** @type Field $f */
                    if ($f->type() !== 'boolean' && $values = $f->listData()) {
                        $this->current_row[$field] = $values[$v];
                    }
                }
            }

            // process formatters
            $this->executeFormatters($field, $column, 'format_');

            // setting cell parameters (tdparam)
            $this->applyTDParams($field);
        }
    }
231855
public static function filter_matches(tour $tour, context $context) {
        global $USER;

        $values = $tour->get_filter_values(self::get_filter_name());

        if (empty($values)) {
            // There are no values configured.
            // No values means all.
            return true;
        }

        // Presence within the array is sufficient. Ignore any value.
        $values = array_flip($values);

        if (isset($values[self::ROLE_SITEADMIN]) && is_siteadmin()) {
            // This tour has been restricted to a role including site admin, and this user is a site admin.
            return true;
        }

        // Use a request cache to save on DB queries.
        // We may be checking multiple tours and they'll all be for the same userid, and contextid
        $cache = \cache::make_from_params(\cache_store::MODE_REQUEST, 'tool_usertours', 'filter_role');

        // Get all of the roles used in this context, including special roles such as user, and frontpageuser.
        $cachekey = "{$USER->id}_{$context->id}";
        $userroles = $cache->get($cachekey);
        if ($userroles === false) {
            $userroles = get_user_roles_with_special($context);
            $cache->set($cachekey, $userroles);
        }

        // Some special roles do not include the shortname.
        // Therefore we must fetch all roles too. Thankfully these don't actually change based on context.
        // They do require a DB call, so let's cache it.
        $cachekey = "allroles";
        $allroles = $cache->get($cachekey);
        if ($allroles === false) {
            $allroles = get_all_roles();
            $cache->set($cachekey, $allroles);
        }

        // Now we can check whether any of the user roles are in the list of allowed roles for this filter.
        foreach ($userroles as $role) {
            $shortname = $allroles[$role->roleid]->shortname;
            if (isset($values[$shortname])) {
                return true;
            }
        }

        return false;
    }
1235795
protected function print_tour_list() {
        global $PAGE, $OUTPUT;

        $this->header();
        echo \html_writer::span(get_string('tourlist_explanation', 'tool_usertours'));
        $table = new table\tour_list();
        $tours = helper::get_tours();
        foreach ($tours as $tour) {
            $table->add_data_keyed($table->format_row($tour));
        }

        $table->finish_output();
        $actions = [
            (object) [
                'link'  => helper::get_edit_tour_link(),
                'linkproperties' => [],
                'img'   => 'b/tour-new',
                'title' => get_string('newtour', 'tool_usertours'),
            ],
            (object) [
                'link'  => helper::get_import_tour_link(),
                'linkproperties' => [],
                'img'   => 'b/tour-import',
                'title' => get_string('importtour', 'tool_usertours'),
            ],
            (object) [
                'link'  => new \moodle_url('https://moodle.net/tours'),
                'linkproperties' => [
                        'target' => '_blank',
                    ],
                'img'   => 'b/tour-shared',
                'title' => get_string('sharedtourslink', 'tool_usertours'),
            ],
        ];

        echo \html_writer::start_tag('div', [
                'class' => 'tour-actions',
            ]);

        echo \html_writer::start_tag('ul');
        foreach ($actions as $config) {
            $action = \html_writer::start_tag('li');
            $linkproperties = $config->linkproperties;
            $linkproperties['href'] = $config->link;
            $action .= \html_writer::start_tag('a', $linkproperties);
            $action .= $OUTPUT->pix_icon($config->img, $config->title, 'tool_usertours');
            $action .= \html_writer::div($config->title);
            $action .= \html_writer::end_tag('a');
            $action .= \html_writer::end_tag('li');
            echo $action;
        }
        echo \html_writer::end_tag('ul');
        echo \html_writer::end_tag('div');

        // JS for Tour management.
        $PAGE->requires->js_call_amd('tool_usertours/managetours', 'setup');
        $this->footer();
    }