/**
  * Validate the given data
  *
  * checks for assignments
  * validates
  * returns changed data only
  *
  * @param array $data array('schema' => ( 'fieldlabel' => 'value', ...))
  * @param string $pageid
  * @param string[] $errors validation errors
  * @return AccessDataValidator[]|bool savable data or false on validation error
  */
 public static function validateDataForPage($data, $pageid, &$errors)
 {
     $tosave = array();
     $valid = true;
     $errors = array();
     $assignments = new Assignments();
     $tables = $assignments->getPageAssignments($pageid);
     foreach ($tables as $table) {
         $access = AccessTable::byTableName($table, $pageid);
         $validation = $access->getValidator($data[$table]);
         if (!$validation->validate()) {
             $valid = false;
             $errors = array_merge($errors, $validation->getErrors());
         } else {
             if ($validation->hasChanges()) {
                 $tosave[] = $validation;
             }
         }
     }
     if ($valid) {
         return $tosave;
     }
     return false;
 }
 /**
  * Replaces placeholders in the given filter value by the proper value
  *
  * @param string $filter
  * @return string|string[] Result may be an array when a multi column placeholder is used
  */
 protected function applyFilterVars($filter)
 {
     global $ID;
     // apply inexpensive filters first
     $filter = str_replace(array('$ID$', '$NS$', '$PAGE$', '$USER$', '$TODAY$'), array($ID, getNS($ID), noNS($ID), isset($_SERVER['REMOTE_USER']) ? $_SERVER['REMOTE_USER'] : '', date('Y-m-d')), $filter);
     // apply struct column placeholder (we support only one!)
     if (preg_match('/^(.*?)(?:\\$STRUCT\\.(.*?)\\$)(.*?)$/', $filter, $match)) {
         $key = $match[2];
         // we try to resolve the key via current schema aliases first, otherwise take it literally
         $column = $this->findColumn($key);
         if ($column) {
             $label = $column->getLabel();
             $table = $column->getTable();
         } else {
             list($table, $label) = explode('.', $key);
         }
         // get the data from the current page
         if ($table && $label) {
             $schemaData = AccessTable::byTableName($table, $ID, 0);
             $data = $schemaData->getDataArray();
             $value = $data[$label];
             if (is_array($value) && !count($value)) {
                 $value = '';
             }
         } else {
             $value = '';
         }
         // apply any pre and postfixes, even when multi value
         if (is_array($value)) {
             $filter = array();
             foreach ($value as $item) {
                 $filter[] = $match[1] . $item . $match[3];
             }
         } else {
             $filter = $match[1] . $value . $match[3];
         }
     }
     return $filter;
 }