Show information data panel
@param  mixed  $data
@param  string $title
@param  array  $opts
@return int
546092
public static function show($data, string $title = 'Information Panel', array $opts = []): int
    {
        if (!$data) {
            Console::write('<info>No data to display!</info>');
            return -2;
        }

        $opts = \array_merge([
            'borderChar' => '*',
            'ucFirst'    => true,
        ], $opts);

        $data  = \is_array($data) ? \array_filter($data) : [\trim($data)];
        $title = \trim($title);

        $panelData  = []; // [ 'label' => 'value' ]
        $borderChar = $opts['borderChar'];

        $labelMaxWidth = 0; // if label exists, label max width
        $valueMaxWidth = 0; // value max width

        foreach ($data as $label => $value) {
            // label exists
            if (!\is_numeric($label)) {
                $width         = \mb_strlen($label, 'UTF-8');
                $labelMaxWidth = $width > $labelMaxWidth ? $width : $labelMaxWidth;
            }

            // translate array to string
            if (\is_array($value)) {
                $temp = '';

                /** @var array $value */
                foreach ($value as $key => $val) {
                    if (\is_bool($val)) {
                        $val = $val ? 'True' : 'False';
                    } else {
                        $val = (string)$val;
                    }

                    $temp .= (!\is_numeric($key) ? "$key: " : '') . "<info>$val</info>, ";
                }

                $value = \rtrim($temp, ' ,');
            } elseif (\is_bool($value)) {
                $value = $value ? 'True' : 'False';
            } else {
                $value = \trim((string)$value);
            }

            // get value width
            /** @var string $value */
            $value = \trim($value);
            $width = \mb_strlen(\strip_tags($value), 'UTF-8'); // must clear style tag

            $valueMaxWidth     = $width > $valueMaxWidth ? $width : $valueMaxWidth;
            $panelData[$label] = $value;
        }

        $border     = null;
        $panelWidth = $labelMaxWidth + $valueMaxWidth;
        Console::startBuffer();

        // output title
        if ($title) {
            $title       = \ucwords($title);
            $titleLength = \mb_strlen($title, 'UTF-8');
            $panelWidth  = $panelWidth > $titleLength ? $panelWidth : $titleLength;
            $indentSpace = \str_pad(' ', \ceil($panelWidth / 2) - \ceil($titleLength / 2) + 2 * 2, ' ');
            Console::write("  {$indentSpace}<bold>{$title}</bold>");
        }

        // output panel top border
        if ($borderChar) {
            $border = \str_pad($borderChar, $panelWidth + (3 * 3), $borderChar);
            Console::write('  ' . $border);
        }

        // output panel body
        $panelStr = FormatUtil::spliceKeyValue($panelData, [
            'leftChar'    => "  $borderChar ",
            'sepChar'     => ' | ',
            'keyMaxWidth' => $labelMaxWidth,
            'ucFirst'     => $opts['ucFirst'],
        ]);

        // already exists "\n"
        Console::write($panelStr, false);

        // output panel bottom border
        if ($border) {
            Console::write("  $border\n");
        }

        Console::flushBuffer();
        unset($panelData);
        return 0;
    }
1334529
public function deserialize(array $data, PanelFacet $panel, array $options = [])
    {
        $this->sipe('id', 'setUuid', $data, $panel);
        $this->sipe('title', 'setName', $data, $panel);
        $this->sipe('position', 'setPosition', $data, $panel);

        if (isset($data['roles'])) {
            $this->deserializeRoles($data['roles'], $panel);
        }

        if (isset($data['fields']) && in_array(Options::DEEP_DESERIALIZE, $options)) {
            $panel->resetFieldFacets();
            $i = 0;

            foreach ($data['fields'] as $field) {
                if (!isset($field['restrictions']['order'])) {
                    $field['restrictions']['order'] = $i;
                }
                ++$i;
                $fieldFacet = $this->_om->getObject($field, FieldFacet::class) ?? new FieldFacet();
                $fieldFacet = $this->ffSerializer->deserialize($field, $fieldFacet, $options);
                $fieldFacet->setPanelFacet($panel);
            }
        }
    }
6579
public function read(array $opts) {
        $statement = array_merge_recursive(parent::read($opts), [
            'verb' => [
                'id' => 'http://adlnet.gov/expapi/verbs/attended',
                'display' => $this->readVerbDisplay($opts),
            ],
            'object' => [
                'id' => $opts['session_url'],
                'definition' => [
                    'type' => $opts['session_type'],
                    'name' => [
                        $opts['context_lang'] => $opts['session_name'],
                    ],
                    'description' => [
                        $opts['context_lang'] => $opts['session_description'],
                    ]
                ],
            ],
            'result' => [
                'duration' => $opts['attempt_duration'],
                'completion' => $opts['attempt_completion']
            ],
            'context' => [
                'instructor' => $this->readUser($opts, 'user'),
                'contextActivities' => [
                    'grouping' => [
                        $this->readCourse($opts),
                    ],
                    'parent' => [
                        $this->readModule($opts),
                    ],
                    'category' => [
                        [
                            'id' => 'http://xapi.trainingevidencesystems.com/recipes/attendance/0_0_1#simple',
                            'definition' => [
                                'type' => 'http://id.tincanapi.com/activitytype/recipe'
                            ]
                        ]
                    ],
                ],
            ],
        ]);

        // Overwrite actor, don't merge it. 
        $statement['actor'] = $this->readUser($opts, 'attendee');

        return $statement;
    }
765469
public function keyword($title, $content, $options = [])
    {
        $data = array_merge([
            'title'   => $title, 
            'content' => $content
        ], $options);

        return $this->send('keyword', $data);
    }
366771
public function parseFeedback($opts){
        $parsedQuestions = [];
        $scoreMax = 0;
        $scoreRaw = 0;

        foreach ($opts['questions'] as $item => $question) {
            // Find the response to the current question
            $currentResponse = null;
            foreach ($opts['attempt']->responses as $responseId => $response) {
                if (!empty($response->item) && $response->item == $item) {
                    $currentResponse = $response;
                }
            }

            if (is_null($currentResponse)) {
                // Perhaps a label or the learner did not answer this question - don't add to the array.
                break;
            }

            // Parse the current question
            $parsedQuestion = (object)[
                'question' => $question,
                'options' => $this->parseQuestionPresentation($question->presentation, $question->typ),
                'score' => (object) [
                    'max' => 0,
                    'raw' => 0
                ],
                'response' => null
            ];

            $parsedQuestion->response = $currentResponse->id;

            // Add scores and response
            foreach ($parsedQuestion->options as $optionIndex => $option) {
                if (isset($option->value) && $option->value > $parsedQuestion->score->max) {
                    $parsedQuestion->score->max = $option->value;
                }

                // Find the option the learner selected
                if ($optionIndex == $currentResponse->id){
                    if (isset($option->value)) {
                        $parsedQuestion->score->raw = $option->value;
                    }
                }
            }

            $scoreMax += $parsedQuestion->score->max;
            $scoreRaw += $parsedQuestion->score->raw;

            if ($parsedQuestion->score->max == 0) {
                $parsedQuestion->score->max = null;
                $parsedQuestion->score->raw = null;
            }
            else {
                $parsedQuestion->score->min = 0;
                $parsedQuestion->score->scaled = $parsedQuestion->score->raw / $parsedQuestion->score->max;
            }

            array_push(
                $parsedQuestions, 
                $parsedQuestion
            );
        }

        $scoreMin = null;
        $scoreScaled = null;
        if ($scoreMax == 0){
            $scoreMax = null;
            $scoreRaw = null;
        }
        else {
            $scoreScaled = $scoreRaw / $scoreMax;
            $scoreMin = 0;
        }

        return (object)[
            'questions' => $parsedQuestions,
            'score' => (object) [
                'max' => $scoreMax,
                'raw' => $scoreRaw,
                'min' => $scoreMin,
                'scaled' => $scoreScaled
            ] 
        ];
    }
80409
protected function buildBlock($title, $informations)
    {
        $message = '<comment>'.$title.'</comment>';
        foreach ($informations as $name => $info) {
            $message .= PHP_EOL.sprintf('  <info>%-15s</info> %s', $name, $info);
        }

        return $message;
    }
1132945
public static function barDump($var, string $title = null, array $options = null)
    {
        if (!self::isProductionMode()) {
            static $panel;
            if (!$panel) {
                self::getBar()->addPanel($panel = new Bar\DefaultPanel('dumps'), 'Tracy:dumps');
            }
            $panel->data[] = [
                'title' => $title,
                'dump' => Dumper::toHtml($var, $options + [
                        Dumper::DEPTH => self::$maxDepth,
                        Dumper::TRUNCATE => self::$maxLength,
                        Dumper::LOCATION => self::$showLocation ?: Dumper::LOCATION_CLASS | Dumper::LOCATION_SOURCE,
                    ]),
            ];
        }

        return $var;
    }
598824
public function cakephpPlugins($opts = ['format' => 'table', 'fields' => ''])
    {
        $result = $this->taskCakephpPlugins()
            ->run();
        if (!$result->wasSuccessful()) {
            $this->exitError("Failed to run the command");
        }

        return new PropertyList($result->getData()['data']);
    }
1160779
protected function showSuccess($title, $messages = '', $output)
    {
        $output->writeln("<info>$title</info>");
        $output->writeln('');
        if (is_array($messages)) {
            foreach ($messages as $message) {
                $output->writeln("$message");
            }
            $output->writeln('');
        } elseif ($messages != '') {
            $output->writeln($messages);
            $output->writeln('');
        }
    }
1267334
public function createCalendar($title, $options = array())
	{
		if ($this->isAuthenticated())
		{
			$options['summary'] = $title;
			$url                = 'https://www.googleapis.com/calendar/v3/calendars';
			$jdata              = $this->query($url, json_encode($options), array('Content-type' => 'application/json'), 'post');

			if ($data = json_decode($jdata->body, true))
			{
				return $data;
			}

			throw new UnexpectedValueException("Unexpected data received from Google: `{$jdata->body}`.");
		}

		return false;
	}
451725
public function read(array $opts) {

        $scoreRaw = (float) ($opts['grade']->grade ?: 0);
        $scoreMin = (float) ($opts['grade_items']->grademin ?: 0);
        $scoreMax = (float) ($opts['grade_items']->grademax ?: 0);
        $scorePass = (float) ($opts['grade_items']->gradepass ?: null);
        $success = false;
        //if there is no passing score then success is unknown.
        if ($scorePass == null) {
            $success = null;
        }
        elseif ($scoreRaw >= $scorePass) {
            $success = true;
        }
        //Calculate scaled score as the distance from zero towards the max (or min for negative scores).
        $scoreScaled;
        if ($scoreRaw >= 0) {
            $scoreScaled = $scoreRaw / $scoreMax;
        }
        else
        {
            $scoreScaled = $scoreRaw / $scoreMin;
        }

        return [array_merge(parent::read($opts)[0], [
            'recipe' => 'assignment_graded',
            'graded_user_id' => $opts['graded_user']->id,
            'graded_user_url' => $opts['graded_user']->url,
            'graded_user_name' => $opts['graded_user']->fullname,
            'grade_score_raw' => $scoreRaw,
            'grade_score_min' => $scoreMin,
            'grade_score_max' => $scoreMax,
            'grade_score_scaled' => $scoreScaled,
            'grade_success' => $success,
            'grade_completed' => true,
            'grade_comment' => strip_tags($opts['grade_comment']),
        ])];
    }
908841
public function toRender($title, $crud, $data)
    {
        $view       = $this->di->get("view");
        $pageRender = $this->di->get("pageRender");
        $view->add($crud, $data);
        $tempfix = "";
        $pageRender->renderPage($tempfix, ["title" => $title]);
    }
1277737
private static function _chartTitle($titleDetails,$namespacesChartMeta,$type) {
		$caption = array();
		$titleLayout = null;
		foreach($titleDetails as $titleDetailKey => $chartDetail) {
			switch ($titleDetailKey) {
				case "tx":
					$titleDetails = $chartDetail->rich->children($namespacesChartMeta['a']);
					foreach($titleDetails as $titleKey => $titleDetail) {
						switch ($titleKey) {
							case "p":
								$titleDetailPart = $titleDetail->children($namespacesChartMeta['a']);
								$caption[] = self::_parseRichText($titleDetailPart);
						}
					}
					break;
				case "layout":
					$titleLayout = self::_chartLayoutDetails($chartDetail,$namespacesChartMeta);
					break;
			}
		}

		return new PHPExcel_Chart_Title($caption, $titleLayout);
	}
1224350
public function wp_get_update_data( $update_data, $titles ) {
		if ( $this->has_update() ) {
			$update_data['counts']['plugins']++;
			$update_data['counts']['total']++;
			$titles['plugins'] = sprintf(
				/* translators: %d: Count of plugins to update */
				_n( '%d Plugin Update', '%d Plugin Updates', $update_data['counts']['plugins'], 'hametwoo' ),
				$update_data['counts']['plugins']
			);
			$update_data['title'] = esc_attr( implode( ', ', $titles ) );
		}
		return $update_data;
	}
645242
protected function getOptVal(array $opts, $option)
    {
        $ploded = explode('.', $option);
        $arr = $opts;
        $val = null;
        while ($curr = array_shift($ploded)) {
            if (isset($arr[$curr])) {
                if (is_array($arr[$curr])) {
                    $arr = $arr[$curr];
                } else {
                    return $arr[$curr];
                }
            } else {
                return null;
            }
        }
    }
1114665
public function drawWindow($title, $choices, $position, $answers)
    {
        $this->window->clearScreen();

        $this->output->writeln($this->getTitle($title));
        $this->output->writeln("");

        $lines = $this->getFormattedChoices($choices, $position, $answers);

        foreach ($lines as $line) {
            $this->output->writeln($line);
        }

        return $this;
    }
951765
public function read(array $opts) {
        return [array_merge(parent::read($opts)[0], [
            'recipe' => 'discussion_viewed',
            'discussion_url' => $opts['discussion']->url,
            'discussion_name' => $opts['discussion']->name,
            'discussion_description' => 'A Moodle discussion.',
            'discussion_type' => static::$xapiType.$opts['discussion']->type,
            'discussion_ext' => $opts['discussion'],
            'discussion_ext_key' => 'http://lrs.learninglocker.net/define/extensions/moodle_discussion',
        ])];
    }