server/src/app/Libraries/Utils.php
author ymh <ymh.work@gmail.com>
Fri, 03 Feb 2017 16:35:09 +0100
changeset 496 a53762d61c06
parent 386 c731ab9b934d
permissions -rw-r--r--
Improve filters on themes, allow to filter by lexvo + olac. Bug #0025934
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
00e2916104fe Migrate to php 5.6 + Laravel 5.1 + add phpunit test
ymh <ymh.work@gmail.com>
parents:
diff changeset
     1
<?php
00e2916104fe Migrate to php 5.6 + Laravel 5.1 + add phpunit test
ymh <ymh.work@gmail.com>
parents:
diff changeset
     2
namespace CorpusParole\Libraries;
00e2916104fe Migrate to php 5.6 + Laravel 5.1 + add phpunit test
ymh <ymh.work@gmail.com>
parents:
diff changeset
     3
130
fac22d8c2df8 add subjects to model + simple display on bo + add command to downloads documents to fixtures for test
ymh <ymh.work@gmail.com>
parents: 20
diff changeset
     4
use EasyRdf\Literal;
fac22d8c2df8 add subjects to model + simple display on bo + add command to downloads documents to fixtures for test
ymh <ymh.work@gmail.com>
parents: 20
diff changeset
     5
use EasyRdf\Resource;
261
02e2396bcbbc Migrate to ember 2.7 + correct jquery null context error + declare shim for popcorn (instead of silencing the JSHint error)
ymh <ymh.work@gmail.com>
parents: 141
diff changeset
     6
use EasyRdf\Graph;
02e2396bcbbc Migrate to ember 2.7 + correct jquery null context error + declare shim for popcorn (instead of silencing the JSHint error)
ymh <ymh.work@gmail.com>
parents: 141
diff changeset
     7
130
fac22d8c2df8 add subjects to model + simple display on bo + add command to downloads documents to fixtures for test
ymh <ymh.work@gmail.com>
parents: 20
diff changeset
     8
2
00e2916104fe Migrate to php 5.6 + Laravel 5.1 + add phpunit test
ymh <ymh.work@gmail.com>
parents:
diff changeset
     9
/**
00e2916104fe Migrate to php 5.6 + Laravel 5.1 + add phpunit test
ymh <ymh.work@gmail.com>
parents:
diff changeset
    10
 * Utilities functions
00e2916104fe Migrate to php 5.6 + Laravel 5.1 + add phpunit test
ymh <ymh.work@gmail.com>
parents:
diff changeset
    11
 */
00e2916104fe Migrate to php 5.6 + Laravel 5.1 + add phpunit test
ymh <ymh.work@gmail.com>
parents:
diff changeset
    12
class Utils {
00e2916104fe Migrate to php 5.6 + Laravel 5.1 + add phpunit test
ymh <ymh.work@gmail.com>
parents:
diff changeset
    13
496
a53762d61c06 Improve filters on themes, allow to filter by lexvo + olac. Bug #0025934
ymh <ymh.work@gmail.com>
parents: 386
diff changeset
    14
    const SUBJECT_TYPE_BNF   = 'bnf';
a53762d61c06 Improve filters on themes, allow to filter by lexvo + olac. Bug #0025934
ymh <ymh.work@gmail.com>
parents: 386
diff changeset
    15
    const SUBJECT_TYPE_LEXVO = 'lxv';
a53762d61c06 Improve filters on themes, allow to filter by lexvo + olac. Bug #0025934
ymh <ymh.work@gmail.com>
parents: 386
diff changeset
    16
    const SUBJECT_TYPE_OLAC  = 'olac';
a53762d61c06 Improve filters on themes, allow to filter by lexvo + olac. Bug #0025934
ymh <ymh.work@gmail.com>
parents: 386
diff changeset
    17
    const SUBJECT_TYPE_TXT   = 'txt';
386
c731ab9b934d implement first version of sparql client interface
ymh <ymh.work@gmail.com>
parents: 329
diff changeset
    18
19
eadaf0b8f02e Bo conception step. back to ember page
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
    19
    /**
eadaf0b8f02e Bo conception step. back to ember page
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
    20
     * convert DateIntervals to milliseconds
eadaf0b8f02e Bo conception step. back to ember page
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
    21
     * Months and year calculated by approximation based on average number
eadaf0b8f02e Bo conception step. back to ember page
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
    22
     * of days over 4 years (365*4+1)
eadaf0b8f02e Bo conception step. back to ember page
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
    23
     * @param \DateInterval $di the date interval
eadaf0b8f02e Bo conception step. back to ember page
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
    24
     * @return the number of milliseconds or 0 if $di is null
eadaf0b8f02e Bo conception step. back to ember page
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
    25
     */
eadaf0b8f02e Bo conception step. back to ember page
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
    26
    public static function dateIntervalToMillis(\DateInterval $di) {
eadaf0b8f02e Bo conception step. back to ember page
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
    27
        if(is_null($di)) {
20
a9b98b16b053 add contributor list + edition pane
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
    28
            return null;
19
eadaf0b8f02e Bo conception step. back to ember page
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
    29
        }
eadaf0b8f02e Bo conception step. back to ember page
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
    30
        $seconds = ($di->s)
eadaf0b8f02e Bo conception step. back to ember page
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
    31
         + ($di->i * 60)
eadaf0b8f02e Bo conception step. back to ember page
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
    32
         + ($di->h * 60 * 60)
eadaf0b8f02e Bo conception step. back to ember page
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
    33
         + ($di->d * 60 * 60 * 24)
eadaf0b8f02e Bo conception step. back to ember page
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
    34
         + ($di->m * (365*4+1)/48*60*60*24)
eadaf0b8f02e Bo conception step. back to ember page
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
    35
         + ($di->y * (365*4+1)/4*60*60*24);
eadaf0b8f02e Bo conception step. back to ember page
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
    36
        return $seconds*1000;
eadaf0b8f02e Bo conception step. back to ember page
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
    37
    }
eadaf0b8f02e Bo conception step. back to ember page
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
    38
eadaf0b8f02e Bo conception step. back to ember page
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
    39
    /**
eadaf0b8f02e Bo conception step. back to ember page
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
    40
     * convert iso8601 strings to milliseconds
eadaf0b8f02e Bo conception step. back to ember page
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
    41
     * Months and year calculated by approximation based on average number
eadaf0b8f02e Bo conception step. back to ember page
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
    42
     * of days over 4 years (365*4+1)
eadaf0b8f02e Bo conception step. back to ember page
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
    43
     *
eadaf0b8f02e Bo conception step. back to ember page
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
    44
     * @param str iso8601 string
eadaf0b8f02e Bo conception step. back to ember page
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
    45
     * @return the number of milliseconds or 0 if $str is null
eadaf0b8f02e Bo conception step. back to ember page
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
    46
     */
eadaf0b8f02e Bo conception step. back to ember page
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
    47
    public static function iso8601IntervalToMillis($str) {
20
a9b98b16b053 add contributor list + edition pane
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
    48
        if(is_null($str)) {
a9b98b16b053 add contributor list + edition pane
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
    49
            return null;
a9b98b16b053 add contributor list + edition pane
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
    50
        }
a9b98b16b053 add contributor list + edition pane
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
    51
        elseif( $str === '') {
19
eadaf0b8f02e Bo conception step. back to ember page
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
    52
            return 0;
eadaf0b8f02e Bo conception step. back to ember page
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
    53
        }
20
a9b98b16b053 add contributor list + edition pane
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
    54
19
eadaf0b8f02e Bo conception step. back to ember page
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
    55
        $di = new \DateInterval($str);
eadaf0b8f02e Bo conception step. back to ember page
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
    56
        return self::dateIntervalToMillis($di);
eadaf0b8f02e Bo conception step. back to ember page
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
    57
    }
eadaf0b8f02e Bo conception step. back to ember page
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
    58
2
00e2916104fe Migrate to php 5.6 + Laravel 5.1 + add phpunit test
ymh <ymh.work@gmail.com>
parents:
diff changeset
    59
    /*
00e2916104fe Migrate to php 5.6 + Laravel 5.1 + add phpunit test
ymh <ymh.work@gmail.com>
parents:
diff changeset
    60
     * From http://www.thecave.info/php-get-mime-type-from-file-extension/
00e2916104fe Migrate to php 5.6 + Laravel 5.1 + add phpunit test
ymh <ymh.work@gmail.com>
parents:
diff changeset
    61
     */
18
f2a40bbc27f6 add rdf mapper + merger + basic database model
ymh <ymh.work@gmail.com>
parents: 4
diff changeset
    62
    public static function getMimetype($file) {
2
00e2916104fe Migrate to php 5.6 + Laravel 5.1 + add phpunit test
ymh <ymh.work@gmail.com>
parents:
diff changeset
    63
00e2916104fe Migrate to php 5.6 + Laravel 5.1 + add phpunit test
ymh <ymh.work@gmail.com>
parents:
diff changeset
    64
        // our list of mime types
00e2916104fe Migrate to php 5.6 + Laravel 5.1 + add phpunit test
ymh <ymh.work@gmail.com>
parents:
diff changeset
    65
        $mime_types = array(
00e2916104fe Migrate to php 5.6 + Laravel 5.1 + add phpunit test
ymh <ymh.work@gmail.com>
parents:
diff changeset
    66
                "pdf"=>"application/pdf",
00e2916104fe Migrate to php 5.6 + Laravel 5.1 + add phpunit test
ymh <ymh.work@gmail.com>
parents:
diff changeset
    67
                "exe"=>"application/octet-stream",
00e2916104fe Migrate to php 5.6 + Laravel 5.1 + add phpunit test
ymh <ymh.work@gmail.com>
parents:
diff changeset
    68
                "zip"=>"application/zip",
00e2916104fe Migrate to php 5.6 + Laravel 5.1 + add phpunit test
ymh <ymh.work@gmail.com>
parents:
diff changeset
    69
                "docx"=>"application/msword",
00e2916104fe Migrate to php 5.6 + Laravel 5.1 + add phpunit test
ymh <ymh.work@gmail.com>
parents:
diff changeset
    70
                "doc"=>"application/msword",
00e2916104fe Migrate to php 5.6 + Laravel 5.1 + add phpunit test
ymh <ymh.work@gmail.com>
parents:
diff changeset
    71
                "xls"=>"application/vnd.ms-excel",
00e2916104fe Migrate to php 5.6 + Laravel 5.1 + add phpunit test
ymh <ymh.work@gmail.com>
parents:
diff changeset
    72
                "ppt"=>"application/vnd.ms-powerpoint",
00e2916104fe Migrate to php 5.6 + Laravel 5.1 + add phpunit test
ymh <ymh.work@gmail.com>
parents:
diff changeset
    73
                "gif"=>"image/gif",
00e2916104fe Migrate to php 5.6 + Laravel 5.1 + add phpunit test
ymh <ymh.work@gmail.com>
parents:
diff changeset
    74
                "png"=>"image/png",
00e2916104fe Migrate to php 5.6 + Laravel 5.1 + add phpunit test
ymh <ymh.work@gmail.com>
parents:
diff changeset
    75
                "jpeg"=>"image/jpg",
00e2916104fe Migrate to php 5.6 + Laravel 5.1 + add phpunit test
ymh <ymh.work@gmail.com>
parents:
diff changeset
    76
                "jpg"=>"image/jpg",
00e2916104fe Migrate to php 5.6 + Laravel 5.1 + add phpunit test
ymh <ymh.work@gmail.com>
parents:
diff changeset
    77
                "mp3"=>"audio/mpeg",
00e2916104fe Migrate to php 5.6 + Laravel 5.1 + add phpunit test
ymh <ymh.work@gmail.com>
parents:
diff changeset
    78
                "wav"=>"audio/x-wav",
00e2916104fe Migrate to php 5.6 + Laravel 5.1 + add phpunit test
ymh <ymh.work@gmail.com>
parents:
diff changeset
    79
                "mpeg"=>"video/mpeg",
00e2916104fe Migrate to php 5.6 + Laravel 5.1 + add phpunit test
ymh <ymh.work@gmail.com>
parents:
diff changeset
    80
                "mpg"=>"video/mpeg",
00e2916104fe Migrate to php 5.6 + Laravel 5.1 + add phpunit test
ymh <ymh.work@gmail.com>
parents:
diff changeset
    81
                "mpe"=>"video/mpeg",
00e2916104fe Migrate to php 5.6 + Laravel 5.1 + add phpunit test
ymh <ymh.work@gmail.com>
parents:
diff changeset
    82
                "mov"=>"video/quicktime",
00e2916104fe Migrate to php 5.6 + Laravel 5.1 + add phpunit test
ymh <ymh.work@gmail.com>
parents:
diff changeset
    83
                "avi"=>"video/x-msvideo",
00e2916104fe Migrate to php 5.6 + Laravel 5.1 + add phpunit test
ymh <ymh.work@gmail.com>
parents:
diff changeset
    84
                "3gp"=>"video/3gpp",
00e2916104fe Migrate to php 5.6 + Laravel 5.1 + add phpunit test
ymh <ymh.work@gmail.com>
parents:
diff changeset
    85
                "css"=>"text/css",
00e2916104fe Migrate to php 5.6 + Laravel 5.1 + add phpunit test
ymh <ymh.work@gmail.com>
parents:
diff changeset
    86
                "jsc"=>"application/javascript",
00e2916104fe Migrate to php 5.6 + Laravel 5.1 + add phpunit test
ymh <ymh.work@gmail.com>
parents:
diff changeset
    87
                "js"=>"application/javascript",
00e2916104fe Migrate to php 5.6 + Laravel 5.1 + add phpunit test
ymh <ymh.work@gmail.com>
parents:
diff changeset
    88
                "php"=>"text/html",
00e2916104fe Migrate to php 5.6 + Laravel 5.1 + add phpunit test
ymh <ymh.work@gmail.com>
parents:
diff changeset
    89
                "htm"=>"text/html",
4
f55970e41793 first skeleton of bo client in ember
ymh <ymh.work@gmail.com>
parents: 2
diff changeset
    90
                "html"=>"text/html",
f55970e41793 first skeleton of bo client in ember
ymh <ymh.work@gmail.com>
parents: 2
diff changeset
    91
                "mp4"=>"video/mp4",
f55970e41793 first skeleton of bo client in ember
ymh <ymh.work@gmail.com>
parents: 2
diff changeset
    92
                "ogg"=>"video/ogg",
f55970e41793 first skeleton of bo client in ember
ymh <ymh.work@gmail.com>
parents: 2
diff changeset
    93
                "xml"=>"application/xml",
f55970e41793 first skeleton of bo client in ember
ymh <ymh.work@gmail.com>
parents: 2
diff changeset
    94
                "xhtml"=>"application/xhtml+xml",
2
00e2916104fe Migrate to php 5.6 + Laravel 5.1 + add phpunit test
ymh <ymh.work@gmail.com>
parents:
diff changeset
    95
        );
00e2916104fe Migrate to php 5.6 + Laravel 5.1 + add phpunit test
ymh <ymh.work@gmail.com>
parents:
diff changeset
    96
00e2916104fe Migrate to php 5.6 + Laravel 5.1 + add phpunit test
ymh <ymh.work@gmail.com>
parents:
diff changeset
    97
        $split_ext = explode('.',$file);
00e2916104fe Migrate to php 5.6 + Laravel 5.1 + add phpunit test
ymh <ymh.work@gmail.com>
parents:
diff changeset
    98
        $extension = strtolower(end($split_ext));
00e2916104fe Migrate to php 5.6 + Laravel 5.1 + add phpunit test
ymh <ymh.work@gmail.com>
parents:
diff changeset
    99
00e2916104fe Migrate to php 5.6 + Laravel 5.1 + add phpunit test
ymh <ymh.work@gmail.com>
parents:
diff changeset
   100
        return $mime_types[$extension];
00e2916104fe Migrate to php 5.6 + Laravel 5.1 + add phpunit test
ymh <ymh.work@gmail.com>
parents:
diff changeset
   101
    }
4
f55970e41793 first skeleton of bo client in ember
ymh <ymh.work@gmail.com>
parents: 2
diff changeset
   102
130
fac22d8c2df8 add subjects to model + simple display on bo + add command to downloads documents to fixtures for test
ymh <ymh.work@gmail.com>
parents: 20
diff changeset
   103
    public static function processLiteralResourceOrString($val) {
4
f55970e41793 first skeleton of bo client in ember
ymh <ymh.work@gmail.com>
parents: 2
diff changeset
   104
        if(is_null($val)) {
f55970e41793 first skeleton of bo client in ember
ymh <ymh.work@gmail.com>
parents: 2
diff changeset
   105
            return $val;
f55970e41793 first skeleton of bo client in ember
ymh <ymh.work@gmail.com>
parents: 2
diff changeset
   106
        }
f55970e41793 first skeleton of bo client in ember
ymh <ymh.work@gmail.com>
parents: 2
diff changeset
   107
        if($val instanceof Literal) {
141
c0e8626a271c literal are now objects if one of lang or datatype is not null
ymh <ymh.work@gmail.com>
parents: 130
diff changeset
   108
            if(empty($val->getLang()) && empty($val->getDatatypeURI())) {
c0e8626a271c literal are now objects if one of lang or datatype is not null
ymh <ymh.work@gmail.com>
parents: 130
diff changeset
   109
                return $val->getValue();
c0e8626a271c literal are now objects if one of lang or datatype is not null
ymh <ymh.work@gmail.com>
parents: 130
diff changeset
   110
            }
c0e8626a271c literal are now objects if one of lang or datatype is not null
ymh <ymh.work@gmail.com>
parents: 130
diff changeset
   111
            else {
c0e8626a271c literal are now objects if one of lang or datatype is not null
ymh <ymh.work@gmail.com>
parents: 130
diff changeset
   112
                return [
c0e8626a271c literal are now objects if one of lang or datatype is not null
ymh <ymh.work@gmail.com>
parents: 130
diff changeset
   113
                    'value'=> $val->getValue(),
c0e8626a271c literal are now objects if one of lang or datatype is not null
ymh <ymh.work@gmail.com>
parents: 130
diff changeset
   114
                    'datatype'=> $val->getDatatypeURI(),
c0e8626a271c literal are now objects if one of lang or datatype is not null
ymh <ymh.work@gmail.com>
parents: 130
diff changeset
   115
                    'lang'=> $val->getLang()
c0e8626a271c literal are now objects if one of lang or datatype is not null
ymh <ymh.work@gmail.com>
parents: 130
diff changeset
   116
                ];
c0e8626a271c literal are now objects if one of lang or datatype is not null
ymh <ymh.work@gmail.com>
parents: 130
diff changeset
   117
            }
4
f55970e41793 first skeleton of bo client in ember
ymh <ymh.work@gmail.com>
parents: 2
diff changeset
   118
        }
130
fac22d8c2df8 add subjects to model + simple display on bo + add command to downloads documents to fixtures for test
ymh <ymh.work@gmail.com>
parents: 20
diff changeset
   119
        elseif ($val instanceof Resource) {
fac22d8c2df8 add subjects to model + simple display on bo + add command to downloads documents to fixtures for test
ymh <ymh.work@gmail.com>
parents: 20
diff changeset
   120
            return $val->getUri();
fac22d8c2df8 add subjects to model + simple display on bo + add command to downloads documents to fixtures for test
ymh <ymh.work@gmail.com>
parents: 20
diff changeset
   121
        }
4
f55970e41793 first skeleton of bo client in ember
ymh <ymh.work@gmail.com>
parents: 2
diff changeset
   122
        else {
f55970e41793 first skeleton of bo client in ember
ymh <ymh.work@gmail.com>
parents: 2
diff changeset
   123
            return (string)$val;
f55970e41793 first skeleton of bo client in ember
ymh <ymh.work@gmail.com>
parents: 2
diff changeset
   124
        }
f55970e41793 first skeleton of bo client in ember
ymh <ymh.work@gmail.com>
parents: 2
diff changeset
   125
    }
130
fac22d8c2df8 add subjects to model + simple display on bo + add command to downloads documents to fixtures for test
ymh <ymh.work@gmail.com>
parents: 20
diff changeset
   126
261
02e2396bcbbc Migrate to ember 2.7 + correct jquery null context error + declare shim for popcorn (instead of silencing the JSHint error)
ymh <ymh.work@gmail.com>
parents: 141
diff changeset
   127
    /**
02e2396bcbbc Migrate to ember 2.7 + correct jquery null context error + declare shim for popcorn (instead of silencing the JSHint error)
ymh <ymh.work@gmail.com>
parents: 141
diff changeset
   128
     * @param EasyRdf\Graph $graph1
02e2396bcbbc Migrate to ember 2.7 + correct jquery null context error + declare shim for popcorn (instead of silencing the JSHint error)
ymh <ymh.work@gmail.com>
parents: 141
diff changeset
   129
     * @param EasyRdf\Graph $graph2
02e2396bcbbc Migrate to ember 2.7 + correct jquery null context error + declare shim for popcorn (instead of silencing the JSHint error)
ymh <ymh.work@gmail.com>
parents: 141
diff changeset
   130
     *
02e2396bcbbc Migrate to ember 2.7 + correct jquery null context error + declare shim for popcorn (instead of silencing the JSHint error)
ymh <ymh.work@gmail.com>
parents: 141
diff changeset
   131
     * @return EasyRdf\Graph
02e2396bcbbc Migrate to ember 2.7 + correct jquery null context error + declare shim for popcorn (instead of silencing the JSHint error)
ymh <ymh.work@gmail.com>
parents: 141
diff changeset
   132
     */
02e2396bcbbc Migrate to ember 2.7 + correct jquery null context error + declare shim for popcorn (instead of silencing the JSHint error)
ymh <ymh.work@gmail.com>
parents: 141
diff changeset
   133
    public static function mergeGraphs(Graph $graph1, Graph $graph2)
02e2396bcbbc Migrate to ember 2.7 + correct jquery null context error + declare shim for popcorn (instead of silencing the JSHint error)
ymh <ymh.work@gmail.com>
parents: 141
diff changeset
   134
    {
02e2396bcbbc Migrate to ember 2.7 + correct jquery null context error + declare shim for popcorn (instead of silencing the JSHint error)
ymh <ymh.work@gmail.com>
parents: 141
diff changeset
   135
        $data1 = $graph1->toRdfPhp();
02e2396bcbbc Migrate to ember 2.7 + correct jquery null context error + declare shim for popcorn (instead of silencing the JSHint error)
ymh <ymh.work@gmail.com>
parents: 141
diff changeset
   136
        $data2 = $graph2->toRdfPhp();
02e2396bcbbc Migrate to ember 2.7 + correct jquery null context error + declare shim for popcorn (instead of silencing the JSHint error)
ymh <ymh.work@gmail.com>
parents: 141
diff changeset
   137
        $merged = array_merge_recursive($data1, $data2);
02e2396bcbbc Migrate to ember 2.7 + correct jquery null context error + declare shim for popcorn (instead of silencing the JSHint error)
ymh <ymh.work@gmail.com>
parents: 141
diff changeset
   138
        unset($data1, $data2);
02e2396bcbbc Migrate to ember 2.7 + correct jquery null context error + declare shim for popcorn (instead of silencing the JSHint error)
ymh <ymh.work@gmail.com>
parents: 141
diff changeset
   139
        return new Graph($graph1->getUri(), $merged, 'php');
02e2396bcbbc Migrate to ember 2.7 + correct jquery null context error + declare shim for popcorn (instead of silencing the JSHint error)
ymh <ymh.work@gmail.com>
parents: 141
diff changeset
   140
    }
130
fac22d8c2df8 add subjects to model + simple display on bo + add command to downloads documents to fixtures for test
ymh <ymh.work@gmail.com>
parents: 20
diff changeset
   141
329
0a2c2ad49d75 Improvce language visualization. Generalize language node selection, change language query parameters, add resolution of node name (corpus-) to lexvo controler
ymh <ymh.work@gmail.com>
parents: 261
diff changeset
   142
    /**
0a2c2ad49d75 Improvce language visualization. Generalize language node selection, change language query parameters, add resolution of node name (corpus-) to lexvo controler
ymh <ymh.work@gmail.com>
parents: 261
diff changeset
   143
     * From http://stackoverflow.com/a/834355
0a2c2ad49d75 Improvce language visualization. Generalize language node selection, change language query parameters, add resolution of node name (corpus-) to lexvo controler
ymh <ymh.work@gmail.com>
parents: 261
diff changeset
   144
     */
0a2c2ad49d75 Improvce language visualization. Generalize language node selection, change language query parameters, add resolution of node name (corpus-) to lexvo controler
ymh <ymh.work@gmail.com>
parents: 261
diff changeset
   145
    public static function startsWith($haystack, $needle)
0a2c2ad49d75 Improvce language visualization. Generalize language node selection, change language query parameters, add resolution of node name (corpus-) to lexvo controler
ymh <ymh.work@gmail.com>
parents: 261
diff changeset
   146
    {
0a2c2ad49d75 Improvce language visualization. Generalize language node selection, change language query parameters, add resolution of node name (corpus-) to lexvo controler
ymh <ymh.work@gmail.com>
parents: 261
diff changeset
   147
        $length = strlen($needle);
0a2c2ad49d75 Improvce language visualization. Generalize language node selection, change language query parameters, add resolution of node name (corpus-) to lexvo controler
ymh <ymh.work@gmail.com>
parents: 261
diff changeset
   148
        return (substr($haystack, 0, $length) === $needle);
0a2c2ad49d75 Improvce language visualization. Generalize language node selection, change language query parameters, add resolution of node name (corpus-) to lexvo controler
ymh <ymh.work@gmail.com>
parents: 261
diff changeset
   149
    }
0a2c2ad49d75 Improvce language visualization. Generalize language node selection, change language query parameters, add resolution of node name (corpus-) to lexvo controler
ymh <ymh.work@gmail.com>
parents: 261
diff changeset
   150
0a2c2ad49d75 Improvce language visualization. Generalize language node selection, change language query parameters, add resolution of node name (corpus-) to lexvo controler
ymh <ymh.work@gmail.com>
parents: 261
diff changeset
   151
    /**
0a2c2ad49d75 Improvce language visualization. Generalize language node selection, change language query parameters, add resolution of node name (corpus-) to lexvo controler
ymh <ymh.work@gmail.com>
parents: 261
diff changeset
   152
     * From http://stackoverflow.com/a/834355
0a2c2ad49d75 Improvce language visualization. Generalize language node selection, change language query parameters, add resolution of node name (corpus-) to lexvo controler
ymh <ymh.work@gmail.com>
parents: 261
diff changeset
   153
     */
0a2c2ad49d75 Improvce language visualization. Generalize language node selection, change language query parameters, add resolution of node name (corpus-) to lexvo controler
ymh <ymh.work@gmail.com>
parents: 261
diff changeset
   154
    public static function endsWith($haystack, $needle)
0a2c2ad49d75 Improvce language visualization. Generalize language node selection, change language query parameters, add resolution of node name (corpus-) to lexvo controler
ymh <ymh.work@gmail.com>
parents: 261
diff changeset
   155
    {
0a2c2ad49d75 Improvce language visualization. Generalize language node selection, change language query parameters, add resolution of node name (corpus-) to lexvo controler
ymh <ymh.work@gmail.com>
parents: 261
diff changeset
   156
        $length = strlen($needle);
0a2c2ad49d75 Improvce language visualization. Generalize language node selection, change language query parameters, add resolution of node name (corpus-) to lexvo controler
ymh <ymh.work@gmail.com>
parents: 261
diff changeset
   157
        if ($length == 0) {
0a2c2ad49d75 Improvce language visualization. Generalize language node selection, change language query parameters, add resolution of node name (corpus-) to lexvo controler
ymh <ymh.work@gmail.com>
parents: 261
diff changeset
   158
            return true;
0a2c2ad49d75 Improvce language visualization. Generalize language node selection, change language query parameters, add resolution of node name (corpus-) to lexvo controler
ymh <ymh.work@gmail.com>
parents: 261
diff changeset
   159
        }
0a2c2ad49d75 Improvce language visualization. Generalize language node selection, change language query parameters, add resolution of node name (corpus-) to lexvo controler
ymh <ymh.work@gmail.com>
parents: 261
diff changeset
   160
0a2c2ad49d75 Improvce language visualization. Generalize language node selection, change language query parameters, add resolution of node name (corpus-) to lexvo controler
ymh <ymh.work@gmail.com>
parents: 261
diff changeset
   161
        return (substr($haystack, -$length) === $needle);
0a2c2ad49d75 Improvce language visualization. Generalize language node selection, change language query parameters, add resolution of node name (corpus-) to lexvo controler
ymh <ymh.work@gmail.com>
parents: 261
diff changeset
   162
    }
0a2c2ad49d75 Improvce language visualization. Generalize language node selection, change language query parameters, add resolution of node name (corpus-) to lexvo controler
ymh <ymh.work@gmail.com>
parents: 261
diff changeset
   163
2
00e2916104fe Migrate to php 5.6 + Laravel 5.1 + add phpunit test
ymh <ymh.work@gmail.com>
parents:
diff changeset
   164
}