/** * Among the stored selectors search those, which are matched with the * current widget's state. * * For matched selectors {@link WidgetResultSet} will be filled with the * data, passed from the user's models. * * In order to reduce the lookups of result of matching given widget with * the particular selector, intermediate caching in $GLBALS is used. * * @param WComponent widget to be analyzed * @return WidgetResultSet with the data that should be passed to this widget */ function findMatched(WComponent $widget) { $wrs = new WidgetResultSet(); foreach ($this->fors as $selectors => $v) { foreach (explode(",", $selectors) as $selector) { // hit the cache, ie SelectorMatcher::matched for this widget and selector // was called if (array_key_exists($md5 = md5($selector . $widget->getId()), $GLOBALS['__m_cache'])) { if ($GLOBALS['__m_cache'][$md5] === SelectorMatcher::FALSE_CACHE) { continue; } elseif ($GLOBALS['__m_cache'][$md5] === SelectorMatcher::TRUE_CACHE) { @$wrs->merge($this->for_values[$selectors]); @$wrs->setDef($this->default_values[$selectors]); if (isset($this->f1s[$selectors])) { unset($this->fors[$selectors]); unset($this->for_values[$selectors]); } } elseif (SelectorMatcher::matched($widget, $selector, null, null)) { @$wrs->merge($this->for_values[$selectors]); @$wrs->setDef($this->default_values[$selectors]); if (isset($this->f1s[$selectors])) { unset($this->fors[$selectors]); unset($this->for_values[$selectors]); } } } elseif ($GLOBALS['__m_cache'][$md5] = SelectorMatcher::matched($widget, $selector, null, null)) { @$wrs->merge($this->for_values[$selectors]); @$wrs->setDef($this->default_values[$selectors]); if (isset($this->f1s[$selectors])) { unset($this->fors[$selectors]); unset($this->for_values[$selectors]); } } } } //once again but now for selector with indexes foreach ($this->fors_array as $selectors => $arr) { foreach (explode(",", $selectors) as $selector) { $md5 = md5($selector . $widget->getId()); if (array_key_exists($md5, $GLOBALS['__m_cache'])) { if ($GLOBALS['__m_cache'][$md5] === SelectorMatcher::FALSE_CACHE) { continue; } elseif ($GLOBALS['__m_cache'][$md5] === SelectorMatcher::TRUE_CACHE) { @$wrs->merge($this->for_values_array[$selectors][$matched = Controller::getInstance()->getDisplayModeParams()->getMatchedIndex()]); @$wrs->setDef($this->default_values_array[$selectors][$matched]); if (isset($this->f1s[$selectors])) { unset($this->fors_array[$selectors]['index'][$matched]); unset($this->fors_array[$selectors]['scope'][$matched]); unset($this->for_values_array[$selectors][$matched]); } } elseif (SelectorMatcher::matched($widget, $selector, $arr['index'], $arr['scope'])) { @$wrs->merge($this->for_values_array[$selectors][$matched = Controller::getInstance()->getDisplayModeParams()->getMatchedIndex()]); @$wrs->setDef($this->default_values_array[$selectors][$matched]); if (isset($this->f1s[$selectors])) { unset($this->fors_array[$selectors]['index'][$matched]); unset($this->fors_array[$selectors]['scope'][$matched]); unset($this->for_values_array[$selectors][$matched]); } } } elseif ($GLOBALS['__m_cache'][$md5] = SelectorMatcher::matched($widget, $selector, $arr['index'], $arr['scope'])) { @$wrs->merge($this->for_values_array[$selectors][$matched = Controller::getInstance()->getDisplayModeParams()->getMatchedIndex()]); @$wrs->setDef($this->default_values_array[$selectors][$matched]); if (isset($this->f1s[$selectors])) { unset($this->fors_array[$selectors]['index'][$matched]); unset($this->fors_array[$selectors]['scope'][$matched]); unset($this->for_values_array[$selectors][$matched]); } } } } return $wrs; }
/** * Tries to find default data, composing it to the * {@link WidgetResultSet} and injecting this result set * to the data-setter method of particular widget, specified * by widget_id parameter. * * If no data was found, empty {@link WidgetResultSet} * will be passed to widget. * * @param string id of the widget for which to make a lookup * @return WidgetResultSet with default data */ static function findDefault($widget_id) { $wrs = new WidgetResultSet(); if (($widget = Controller::getInstance()->getWidget($widget_id)) === null) { return $wrs; } if (($data_setter = $widget->getDataSetterMethod()) === null || $widget instanceof iNotSelectable) { return $wrs; } foreach (self::$pool as $v) { $d_o = $v['data_object']; if (($def = $d_o->getData($widget_id)) !== null && !$def instanceof WidgetResultSet) { $wrs->setDef($def); } } $widget->{$data_setter}($wrs); }