Proyectos de Subversion Moodle

Rev

| Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
1441 ariadna 1
<?php
2
 
3
namespace PhpOffice\PhpSpreadsheet\Calculation\LookupRef;
4
 
5
use PhpOffice\PhpSpreadsheet\Calculation\Functions;
6
use PhpOffice\PhpSpreadsheet\Calculation\Information\ExcelError;
7
use PhpOffice\PhpSpreadsheet\Cell\Cell;
8
 
9
class Hyperlink
10
{
11
    /**
12
     * HYPERLINK.
13
     *
14
     * Excel Function:
15
     *        =HYPERLINK(linkURL, [displayName])
16
     *
17
     * @param mixed $linkURL Expect string. Value to check, is also the value returned when no error
18
     * @param mixed $displayName Expect string. Value to return when testValue is an error condition
19
     * @param ?Cell $cell The cell to set the hyperlink in
20
     *
21
     * @return string The value of $displayName (or $linkURL if $displayName was blank)
22
     */
23
    public static function set(mixed $linkURL = '', mixed $displayName = null, ?Cell $cell = null): string
24
    {
25
        $linkURL = ($linkURL === null) ? '' : Functions::flattenSingleValue($linkURL);
26
        $displayName = ($displayName === null) ? '' : Functions::flattenSingleValue($displayName);
27
 
28
        if ((!is_object($cell)) || (trim($linkURL) == '')) {
29
            return ExcelError::REF();
30
        }
31
 
32
        if ((is_object($displayName)) || trim($displayName) == '') {
33
            $displayName = $linkURL;
34
        }
35
 
36
        $cell->getHyperlink()->setUrl($linkURL);
37
        $cell->getHyperlink()->setTooltip($displayName);
38
 
39
        return $displayName;
40
    }
41
}