* @package WB */ WBClass::load( 'WBFormProcessor_Fiddler' ); /** * Wombat Form Processor Fiddler * * @version 0.3.0 * @package WB */ class WBFormProcessor_Fiddler_Mandator extends WBFormProcessor_Fiddler { /** * Mandator * * @var WBMandator */ private $mandator; /** * Constructor * * Empty function * * @param array */ public function __construct($parameter = array()) { if (!is_array($parameter)) { $parameter = array(); } if (empty($parameter['mandator'])) { $parameter['mandator'] = WBClass::create('WBMandator'); } $this->mandator = $parameter['mandator']; } /** * Adjust Form Element List * * @param string name * @param array form values * @param array list of form elements to alter */ public function mangleFormElementList($name, $values, &$list) { if (WBMandator::INVALID_ID == $this->mandator->getId()) { return; } $pMandator = $this->mandator->getIdentifier(); foreach ($list as $element => &$l) { if (empty($l['attributesource'])) { continue; } foreach($l['attributesource'] as &$s) { if ('Table' != $s['name']) { continue; } $primary = $this->mandator->getIdentifier($s['table']); // has table mandator feature? if (!is_array($primary) || !in_array($pMandator, $primary)) { continue; } // force clause to be array if (empty($s['clause']) || !is_array($s['clause'])) { $s['clause'] = array(); } // don't add mandator twice foreach ($s['clause'] as $c) { if (!empty($c['field']) && $pMandator == $c['field']) { continue 2; } } // add mandator id $s['clause'][] = array( 'field' => $pMandator, 'value' => $this->mandator->getId() ); // JOIN USING primary key? if (!empty($s['options']) && !empty($s['options']['join'])) { foreach ($s['options']['join'] as &$j) { if (empty($j['using'])) { continue; } if (in_array($j['using'], $primary)) { $j['using'] = $primary; } } } } } // there is no table if (empty($this->config['table'])) { return; } $primary = $this->mandator->getIdentifier($this->config['table']); if (!is_array($primary) || !in_array($pMandator, $primary)) { return; } // add mandator filter $el = array( 'type' => 'Constant', 'attributes' => array( 'default' => $this->mandator->getId(), 'value' => $this->mandator->getId() ) ); if ('filter' == $name) { $list['filter_' . $pMandator] = $el; } else { $list[$pMandator] = $el; } } }