Example #1
0
 function GetSubItems($id, $types = 'all', $show_invisible = false)
 {
     //pr(debug_backtrace());die();
     global $langs;
     if (!is_array($id)) {
         $id = array($id);
     }
     foreach ($id as $k => $v) {
         $id[$k] = (int) $v;
     }
     $config_obj =& Registry::get('TConfig');
     $item_elems = array();
     $types_where = '';
     if (empty($types) || $types == 'all') {
         $item_elems = $config_obj->getAllElems();
     } elseif (is_array($types)) {
         $types_where = " AND " . $this->table . ".type IN ('" . implode("', '", $types) . "')";
         $item_elems = $config_obj->getElemsByTypes($types);
     }
     $pid_where_arr = array();
     foreach ($id as $k => $v) {
         $pid_where_arr[] = $this->table . '.pid=' . $v;
     }
     $pid_where = '(' . implode(' AND ', $pid_where_arr) . ')';
     $id_where_arr = array();
     foreach ($id as $k => $v) {
         $id_where_arr[] = $this->table . '.id!=' . $v;
     }
     $id_where = '(' . implode(' AND ', $id_where_arr) . ')';
     $sql = $this->Select('*', $item_elems, $pid_where . ' AND ' . $id_where . ($show_invisible ? ' AND ' . $this->table . '.visible>-1' : ' AND ' . $this->table . '.visible>0') . $types_where . ' GROUP BY ' . $this->table . '.id ORDER BY ' . $this->table . '.pid, ' . $this->table . '.priority, ' . (defined('LANG_SELECT') && LANG_SELECT ? $this->table . '.name_' . lang() : $this->table . '.name'));
     $rows = sql_getRows($sql, false, __FILE__, __LINE__);
     $items = array();
     foreach ($rows as $key => $value) {
         if (defined('LANG_SELECT') && LANG_SELECT) {
             $items[$key] = struct($this->getValuesWithoutLangs($value), $this->table);
         } else {
             $items[$key] = struct($value, $this->table);
         }
     }
     return $items;
 }
Example #2
0
<?php

require 'vendor/autoload.php';
Struct\Struct::$strict = false;
struct('User', ['name' => 'string', 'age' => 'int', 'active' => 'bool']);
$user = new User();
$user->fromArray(array('name' => 'George', 'age' => 36, 'extradata' => 'thisthat', 'active' => false));
struct('User', ['firstName' => 'string', 'lastName' => 'string', 'active' => 'bool', 'age' => 'int'], ['fullName' => function () {
    return $this['firstName'] . ' ' . $this['lastName'];
}, 'birthYear' => function () {
    $year = date('Y') - $this['age'];
    return $year;
}, '__toString' => function () {
    return $this->fullName() . ' is a ' . $this['age'] . ' year old ' . ($this['active'] ? 'active' : 'inactive') . ' user';
}]);
$user = new User();
echo $user;
Example #3
0
function extract_data($short)
{
    $xml_str = open_file($short);
    $reader = new XMLReader();
    if (!$reader->open($xml_str)) {
        die("Failed to open First Folio");
    }
    $mei = array();
    $num_items = 0;
    $pid = 1;
    $act = 0;
    $scene = 0;
    $line = 0;
    $play = '';
    $person = array();
    $id = $name = '';
    $pers = '';
    $sex = '';
    $role = '';
    while ($reader->read()) {
        if ($reader->nodeType == XMLReader::ELEMENT && $reader->name == 'person') {
            $id = $reader->getAttribute('xml:id');
            $sex = $reader->getAttribute('sex');
            $role = $reader->getAttribute('role');
            $pid++;
        }
        if ($reader->nodeType == XMLReader::ELEMENT && $reader->name == 'persName') {
            if ($reader->getAttribute('type') == "standard") {
                $pers = $reader->readString();
            }
        }
        if ($id) {
            $person[$id] = array('xmlid' => $id, 'name' => $pers, 'snid' => $pid, 'sex' => $sex, 'role' => $role);
        }
        // parse the play sections
        if ($reader->nodeType == XMLReader::ELEMENT && $reader->name == 'div') {
            $divtype = $reader->getAttribute('type');
            if ($divtype == 'act') {
                $act = $reader->getAttribute('n');
                array_push($mei, struct($act, $scene, $divtype, 10 + $act, '', '', ''));
            }
            if ($divtype == 'scene') {
                $scene = $reader->getAttribute('n');
                array_push($mei, struct($act, $scene, $divtype, 50 + $scene, '', '', ''));
            }
        }
        if ($reader->nodeType == XMLReader::ELEMENT && $reader->name == 'sp') {
            $speaker = substr($reader->getAttribute('who'), 1);
        }
        if ($reader->nodeType == XMLReader::ELEMENT && ($reader->name == 'l' || $reader->name == 'p')) {
            $play = 60 + $person[$speaker]['snid'];
            $rhyme = $reader->getAttribute('rhyme');
            $ln = $reader->getAttribute('n');
            if ($play > 60) {
                array_push($mei, struct($act, $scene, $reader->name, $play, $speaker, $rhyme, $ln));
            }
        }
        // get the types of stage direction
        if ($reader->nodeType == XMLReader::ELEMENT && $reader->name == 'stage') {
            $type = $reader->getAttribute('type');
            if ($type == 'entrance') {
                array_push($mei, struct($act, $scene, $reader->name, 101, '', '', ''));
            } else {
                if ($type == 'exit') {
                    array_push($mei, struct($act, $scene, $reader->name, 102, '', '', ''));
                } else {
                    if ($type == 'setting') {
                        array_push($mei, struct($act, $scene, $reader->name, 103, '', '', ''));
                    } else {
                        if ($type == 'business') {
                            array_push($mei, struct($act, $scene, $reader->name, 104, '', '', ''));
                        } else {
                            array_push($mei, struct($act, $scene, $reader->name, 105, '', '', ''));
                        }
                    }
                }
            }
        }
    }
    $reader->close();
    return $person;
}