Changeset 17814
- Timestamp:
- 10/01/08 00:50:43 (2 months ago)
- Files:
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/midcom/midcom.helper.datamanager2/renderer/simple.php
r17556 r17814 130 130 * @access private 131 131 */ 132 var $_groupWraps = array( 133 ); 132 var $_groupWraps = array(); 134 133 135 134 /** … … 138 137 * @access private 139 138 */ 140 var $_groupTemplates = array( 139 var $_groupTemplates = array 140 ( 141 141 'datamanager_table' => "<label id='{element_name}_label'<!-- BEGIN required --> class='required'<!-- END required -->> </label>\n\t\t 142 142 <span class=\"field_text\"> … … 167 167 * @access private 168 168 */ 169 var $_groupElements = array( 170 ); 169 var $_groupElements = array(); 171 170 172 171 /** … … 251 250 $this->_html = ''; 252 251 $this->_hiddenHtml = ''; 253 } // end func startForm252 } 254 253 255 254 /** … … 264 263 { 265 264 // add a required note, if one is needed 266 if (!empty($form->_required) && !$form->_freezeAll) { 265 if (!empty($form->_required) && !$form->_freezeAll) 266 { 267 267 $this->_html .= str_replace('{requiredNote}', $form->getRequiredNote(), $this->_requiredNoteTemplate); 268 268 } 269 269 // add form attributes and content 270 270 $html = str_replace('{attributes}', $form->getAttributes(true), $this->_formTemplate); 271 if (strpos($this->_formTemplate, '{hidden}')) { 271 if (strpos($this->_formTemplate, '{hidden}')) 272 { 272 273 $html = str_replace('{hidden}', $this->_hiddenHtml, $html); 273 } else { 274 } 275 else 276 { 274 277 $this->_html .= $this->_hiddenHtml; 275 278 } 276 279 $this->_html = str_replace('{content}', $this->_html, $html); 277 280 // add a validation script 278 if ('' != ($script = $form->getValidationScript())) { 281 if ('' != ($script = $form->getValidationScript())) 282 { 279 283 $this->_html = $script . "\n" . $this->_html; 280 284 } 281 } // end func finishForm285 } 282 286 283 287 /** … … 291 295 { 292 296 $name = $header->getName(); 293 if (!empty($name) && isset($this->_templates[$name])) { 297 if (!empty($name) && isset($this->_templates[$name])) 298 { 294 299 $this->_html .= str_replace('{header}', $header->toHtml(), $this->_templates[$name]); 295 } else { 300 } 301 else 302 { 296 303 $this->_html .= str_replace('{header}', $header->toHtml(), $this->_headerTemplate); 297 304 } 298 } // end func renderHeader305 } 299 306 300 307 /** … … 306 313 * @param string Error message associated with the element 307 314 * @param string Element type (optional) 308 * @access private 315 * @access private†309 316 * @see renderElement() 310 317 * @return string Html for element … … 312 319 function _prepareTemplate($name, $label, $required, $error, $type = false) 313 320 { 314 if (is_array($label)) { 321 if (is_array($label)) 322 { 315 323 $nameLabel = array_shift($label); 316 } else { 324 } 325 else 326 { 317 327 $nameLabel = $label; 318 328 } 319 329 320 if (isset($this->_templates[$name])) { 330 if (isset($this->_templates[$name])) 331 { 321 332 $html = str_replace('{label}', $nameLabel, $this->_templates[$name]); 322 } else if ($this->_inGroup) { 333 } 334 else if ($this->_inGroup) 335 { 323 336 /* rambo: I'm pretty sure this is never reached... */ 324 337 $html = str_replace('{label}', $nameLabel, $this->_defaultGroupTemplate); 325 } else { 338 } 339 else 340 { 326 341 switch ($type) 327 342 { … … 336 351 } 337 352 338 if ($required) { 353 if ($required) 354 { 339 355 $html = str_replace('<!-- BEGIN required -->', '', $html); 340 356 $html = str_replace('<!-- END required -->', '', $html); 341 } else { 357 } 358 else 359 { 342 360 $html = preg_replace("/([ \t\n\r]*)?<!-- BEGIN required -->.*?<!-- END required -->([ \t\n\r]*)?/is", '', $html); 343 361 } 344 362 345 if (isset($error)) { 363 if (isset($error)) 364 { 346 365 $html = str_replace('{error}', $error, $html); 347 366 $html = str_replace('<!-- BEGIN error -->', '', $html); 348 367 $html = str_replace('<!-- END error -->', '', $html); 349 } else { 368 } 369 else 370 { 350 371 //$html = preg_replace("/([ \t\n\r]*)?<!-- BEGIN error -->.*?<!-- END error -->([ \t\n\r]*)?/is", '', $html); 351 372 … … 353 374 } 354 375 355 if (is_array($label)) { 356 foreach($label as $key => $text) { 376 if (is_array($label)) 377 { 378 foreach($label as $key => $text) 379 { 357 380 $key = is_int($key)? $key + 2: $key; 358 381 $html = str_replace("{label_{$key}}", $text, $html); … … 363 386 364 387 $html = str_replace('{element_name}', $name , $html); 365 if (strpos($html, '{label_')) { 388 if (strpos($html, '{label_')) 389 { 366 390 $html = preg_replace('/\s*<!-- BEGIN label_(\S+) -->.*<!-- END label_\1 -->\s*/i', '', $html); 367 391 } 368 392 369 393 return $html; 370 } // end func _prepareTemplate394 } 371 395 372 396 /** … … 382 406 function renderElement(&$element, $required, $error) 383 407 { 384 if (!$this->_inGroup) { 408 if (!$this->_inGroup) 409 { 385 410 $html = $this->_prepareTemplate($element->getName(), $element->getLabel(), $required, $error, $element->getType()); 386 411 $this->_html .= str_replace('{element}', $element->toHtml(), $html); 387 412 388 413 389 } elseif (!empty($this->_groupElementTemplate)) { 414 } 415 else if (!empty($this->_groupElementTemplate)) 416 { 390 417 391 418 $html = str_replace('{label}', $element->getLabel(), $this->_groupElementTemplate); 392 if ($required) { 419 if ($required) 420 { 393 421 $html = str_replace('<!-- BEGIN required -->', '', $html); 394 422 $html = str_replace('<!-- END required -->', '', $html); 395 } else { 423 } 424 else 425 { 396 426 $html = preg_replace("/([ \t\n\r]*)?<!-- BEGIN required -->(\s|\S)*<!-- END required -->([ \t\n\r]*)?/i", '', $html); 397 427 } 398 428 $this->_groupElements[] = str_replace('{element}', $element->toHtml(), $html); 399 429 400 } else { 430 } 431 else 432 { 401 433 $this->_groupElements[] = $element->toHtml(); 402 434 } 403 } // end func renderElement435 } 404 436 405 437 /** … … 414 446 { 415 447 $this->_hiddenHtml .= $element->toHtml() . "\n"; 416 } // end func renderHidden448 } 417 449 418 450 /** … … 426 458 { 427 459 $this->_html .= $data->toHtml(); 428 } // end func renderHtml460 } 429 461 430 462 /** … … 441 473 $name = $group->getName(); 442 474 443 if ($this->_inGroup) { 475 if ($this->_inGroup) 476 { 444 477 // the rest of the variables are set in the other groups run of the startGroup function. 445 // $this->_currentGroupTemplates[$this->_currentGroupName]['_groupElements'] = $this->_groupElements; 446 } 447 448 449 $this->_currentGroupTemplates[$name] = array ( 478 //$this->_currentGroupTemplates[$this->_currentGroupName]['_groupElements'] = $this->_groupElements; 479 } 480 481 482 $this->_currentGroupTemplates[$name] = array 483 ( 450 484 // '_groupTemplate' => $this->_prepareTemplate($name, $group->getLabel(), $required, $error), 451 485 '_groupTemplate' => $this->_prepareTemplate($name, $group->getLabel(), $required, $error, 'dummy:group'), … … 459 493 $this->_currentGroupName = $name; 460 494 $this->_currentGroups[] = $name; 461 } // end func startGroup495 } 462 496 463 497 … … 483 517 { 484 518 $separator = $group->_separator; 485 if (is_array($separator)) { 519 if (is_array($separator)) 520 { 486 521 $count = count($separator); 487 522 $html = ''; 488 for ($i = 0; $i < count($this->_groupElements); $i++) { 523 for ($i = 0; $i < count($this->_groupElements); $i++) 524 { 489 525 $html .= (0 == $i? '': $separator[($i - 1) % $count]) . $this->_groupElements[$i]; 490 526 491 527 } 492 } else { 528 } 529 else 530 { 493 531 if (is_null($separator)) 494 532 { … … 498 536 } 499 537 500 if (!empty($this->_groupWrap)) { 538 if (!empty($this->_groupWrap)) 539 { 501 540 $html = str_replace('{content}', $html, $this->_groupWrap); 502 541 } … … 507 546 508 547 array_pop($this->_currentGroups); 509 $currentGroupId = count($this->_currentGroups) -1;548 $currentGroupId = count($this->_currentGroups) - 1; 510 549 if ($currentGroupId > -1 ) 511 550 { … … 515 554 $this->_setGroupTemplates($this->_currentGroupName); 516 555 $this->_inGroup = true; 517 } else 556 } 557 else 518 558 { 519 559 $this->_currentGroupName = ""; … … 522 562 } 523 563 524 } // end func finishGroup564 } 525 565 526 566 /** … … 534 574 function setElementTemplate($html, $element = null) 535 575 { 536 if (is_null($element)) { 576 if (is_null($element)) 577 { 537 578 $this->_elementTemplate = $html; 538 } else { 579 } 580 else 581 { 539 582 $this->_templates[$element] = $html; 540 583 } 541 } // end func setElementTemplate584 } 542 585 543 586 … … 557 600 { 558 601 $this->_groupWraps[$group] = $html; 559 } // end func setGroupTemplate602 } 560 603 561 604 /** … … 570 613 { 571 614 $this->_groupTemplates[$group] = $html; 572 } // end func setGroupElementTemplate615 } 573 616 574 617 /** … … 582 625 { 583 626 $this->_headerTemplate = $html; 584 } // end func setHeaderTemplate627 } 585 628 586 629 /** … … 594 637 { 595 638 $this->_formTemplate = $html; 596 } // end func setFormTemplate639 } 597 640 598 641 /** … … 606 649 { 607 650 $this->_requiredNoteTemplate = $html; 608 } // end func setRequiredNoteTemplate651 } 609 652 610 653 /** … … 621 664 $this->setRequiredNoteTemplate(''); 622 665 $this->_templates = array(); 623 } // end func clearAllTemplates624 } // end class HTML_QuickForm_Renderer_Default666 } 667 } 625 668 ?>
