102 lines
2.0 KiB
PHP
Executable File
102 lines
2.0 KiB
PHP
Executable File
<?php
|
|
|
|
class View extends Entity {
|
|
|
|
protected static
|
|
$type,
|
|
$subType,
|
|
$rootType,
|
|
$parentType = 'Model';
|
|
|
|
protected function __construct ( $data, Model $model ) {
|
|
|
|
//~ echo $model . ":\n";
|
|
//~ print_r($data);
|
|
//~ echo "\n";
|
|
|
|
parent::__construct($data, $model);
|
|
|
|
$fields = $this->getParent()->getChildrenData('Field');
|
|
unset($fields['id']);
|
|
|
|
$f = array();
|
|
foreach ( $fields as $n => $field )
|
|
$f[$n] = 0;
|
|
|
|
$ff = array();
|
|
foreach ( $fields as $n => $field )
|
|
$ff[$n] = 1;
|
|
|
|
if ( $this->data['list'] === '*' )
|
|
$this->data['list'] = $f;
|
|
|
|
elseif ( is_string($this->data['list']) ) {
|
|
|
|
$tokens = preg_split('!\s+!', $this->data['list']);
|
|
|
|
if ( $tokens && $tokens[0] === '*' ) {
|
|
$first = array_shift($tokens);
|
|
$this->data['list'] = $f;
|
|
} else $this->data['list'] = array();
|
|
|
|
while ( count($tokens) ) {
|
|
|
|
$a = array_shift($tokens);
|
|
$b = explode(':', array_shift($tokens));
|
|
|
|
if ( $a === '-' ) {
|
|
|
|
unset($this->data['list'][$b[0]]);
|
|
|
|
} elseif ( $model->getChild('Field', $b[0]) ) {
|
|
|
|
$this->data['list'][$b[0]] = empty($b[1]) ? null : (
|
|
$b[1] === '1' ? 1 : 0
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if ( $this->data['edit'] === '*' )
|
|
$this->data['edit'] = $ff;
|
|
|
|
elseif ( is_string($this->data['edit']) ) {
|
|
|
|
$tokens = preg_split('!\s+!', $this->data['edit']);
|
|
|
|
if ( $tokens && $tokens[0] === '*' ) {
|
|
$first = array_shift($tokens);
|
|
$this->data['edit'] = $ff;
|
|
} else $this->data['edit'] = array();
|
|
|
|
//~ $tokens = preg_split('!\s!', $this->data['edit']);
|
|
//~ $first = array_shift($tokens);
|
|
|
|
//~ $this->data['edit'] = $ff;
|
|
while ( count($tokens) ) {
|
|
|
|
$a = array_shift($tokens);
|
|
$b = explode(':', array_shift($tokens));
|
|
|
|
if ( $a === '-' ) {
|
|
|
|
unset($this->data['edit'][$b[0]]);
|
|
|
|
} elseif ( array_key_exists($b[0], $ff) ) {
|
|
$this->data['edit'][$b[0]] = ( !isset($b[1]) || $b[1] === '1' ) ? 1 : null;
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
//~ print_r($this->data);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
?>
|