Subversion Repositories Applications.papyrus

Rev

Rev 320 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 320 Rev 443
Line 15... Line 15...
15
// +----------------------------------------------------------------------+
15
// +----------------------------------------------------------------------+
16
// | Authors: Adam Daniel <adaniel1@eesus.jnj.com>                        |
16
// | Authors: Adam Daniel <adaniel1@eesus.jnj.com>                        |
17
// |          Bertrand Mansion <bmansion@mamasam.com>                     |
17
// |          Bertrand Mansion <bmansion@mamasam.com>                     |
18
// +----------------------------------------------------------------------+
18
// +----------------------------------------------------------------------+
19
//
19
//
20
// $Id: group.php,v 1.1 2005-03-30 08:50:33 jpm Exp $
20
// $Id: group.php,v 1.2 2005-09-20 17:01:22 ddelon Exp $
Line 21... Line 21...
21
 
21
 
Line 22... Line 22...
22
require_once("HTML/QuickForm/element.php");
22
require_once("HTML/QuickForm/element.php");
23
 
23
 
Line 149... Line 149...
149
     * @access    public
149
     * @access    public
150
     * @return    void
150
     * @return    void
151
     */
151
     */
152
    function setValue($value)
152
    function setValue($value)
153
    {
153
    {
154
        if (empty($this->_elements)) {
-
 
155
            $this->_createElements();
154
        $this->_createElementsIfNotExist();
156
        }
-
 
157
        foreach (array_keys($this->_elements) as $key) {
155
        foreach (array_keys($this->_elements) as $key) {
158
            if (!$this->_appendName) {
156
            if (!$this->_appendName) {
159
                $v = $this->_elements[$key]->_findValue($value);
157
                $v = $this->_elements[$key]->_findValue($value);
160
                if (null !== $v) {
158
                if (null !== $v) {
161
                    $this->_elements[$key]->onQuickFormEvent('setGroupValue', $v, $this);
159
                    $this->_elements[$key]->onQuickFormEvent('setGroupValue', $v, $this);
162
                }
160
                }
Line 163... Line 161...
163
 
161
 
164
            } else {
162
            } else {
165
                $elementName = $this->_elements[$key]->getName();
163
                $elementName = $this->_elements[$key]->getName();
166
                $index       = (!empty($elementName)) ? $elementName : $key;
164
                $index       = strlen($elementName) ? $elementName : $key;
167
                if (is_array($value)) {
165
                if (is_array($value)) {
168
                    if (isset($value[$index])) {
166
                    if (isset($value[$index])) {
169
                        $this->_elements[$key]->onQuickFormEvent('setGroupValue', $value[$index], $this);
167
                        $this->_elements[$key]->onQuickFormEvent('setGroupValue', $value[$index], $this);
170
                    }
168
                    }
Line 206... Line 204...
206
                    $value = $v;
204
                    $value = $v;
207
                } else {
205
                } else {
208
                    if (!is_array($value)) {
206
                    if (!is_array($value)) {
209
                        $value = is_null($value)? array(): array($value);
207
                        $value = is_null($value)? array(): array($value);
210
                    }
208
                    }
211
                    if ('' == $elementName) {
209
                    if ('' === $elementName) {
212
                        $value[] = $v;
210
                        $value[] = $v;
213
                    } else {
211
                    } else {
214
                        $value[$elementName] = $v;
212
                        $value[$elementName] = $v;
215
                    }
213
                    }
216
                }
214
                }
Line 248... Line 246...
248
     * @access    public
246
     * @access    public
249
     * @return    array
247
     * @return    array
250
     */
248
     */
251
    function &getElements()
249
    function &getElements()
252
    {
250
    {
-
 
251
        $this->_createElementsIfNotExist();
253
        return $this->_elements;
252
        return $this->_elements;
254
    } // end func getElements
253
    } // end func getElements
Line 255... Line 254...
255
 
254
 
256
    // }}}
255
    // }}}
Line 264... Line 263...
264
     * @access    public
263
     * @access    public
265
     * @return    string    group elements type
264
     * @return    string    group elements type
266
     */
265
     */
267
    function getGroupType()
266
    function getGroupType()
268
    {
267
    {
269
        if (empty($this->_elements)) {
-
 
270
            $this->_createElements();
268
        $this->_createElementsIfNotExist();
271
        }
-
 
272
        $prevType = '';
269
        $prevType = '';
273
        foreach (array_keys($this->_elements) as $key) {
270
        foreach (array_keys($this->_elements) as $key) {
274
            $type = $this->_elements[$key]->getType();
271
            $type = $this->_elements[$key]->getType();
275
            if ($type != $prevType && $prevType != '') {
272
            if ($type != $prevType && $prevType != '') {
276
                return 'mixed';
273
                return 'mixed';
Line 310... Line 307...
310
     * @access    public
307
     * @access    public
311
     * @return    mixed     string with element name, false if not found
308
     * @return    mixed     string with element name, false if not found
312
     */
309
     */
313
    function getElementName($index)
310
    function getElementName($index)
314
    {
311
    {
315
        if (empty($this->_elements)) {
-
 
316
            $this->_createElements();
312
        $this->_createElementsIfNotExist();
317
        }
-
 
318
        $elementName = false;
313
        $elementName = false;
319
        if (is_int($index) && isset($this->_elements[$index])) {
314
        if (is_int($index) && isset($this->_elements[$index])) {
320
            $elementName = $this->_elements[$index]->getName();
315
            $elementName = $this->_elements[$index]->getName();
321
            if (isset($elementName) && $elementName == '') {
316
            if (isset($elementName) && $elementName == '') {
322
                $elementName = $index;
317
                $elementName = $index;
Line 356... Line 351...
356
     * @return    string
351
     * @return    string
357
     */
352
     */
358
    function getFrozenHtml()
353
    function getFrozenHtml()
359
    {
354
    {
360
        $flags = array();
355
        $flags = array();
361
        if (empty($this->_elements)) {
-
 
362
            $this->_createElements();
356
        $this->_createElementsIfNotExist();
363
        }
-
 
364
        foreach (array_keys($this->_elements) as $key) {
357
        foreach (array_keys($this->_elements) as $key) {
365
            if (false === ($flags[$key] = $this->_elements[$key]->isFrozen())) {
358
            if (false === ($flags[$key] = $this->_elements[$key]->isFrozen())) {
366
                $this->_elements[$key]->freeze();
359
                $this->_elements[$key]->freeze();
367
            }
360
            }
368
        }
361
        }
Line 390... Line 383...
390
     */
383
     */
391
    function onQuickFormEvent($event, $arg, &$caller)
384
    function onQuickFormEvent($event, $arg, &$caller)
392
    {
385
    {
393
        switch ($event) {
386
        switch ($event) {
394
            case 'updateValue':
387
            case 'updateValue':
395
                if (empty($this->_elements)) {
-
 
396
                    $this->_createElements();
388
                $this->_createElementsIfNotExist();
397
                }
-
 
398
                foreach (array_keys($this->_elements) as $key) {
389
                foreach (array_keys($this->_elements) as $key) {
399
                    if ($this->_appendName) {
390
                    if ($this->_appendName) {
400
                        $elementName = $this->_elements[$key]->getName();
391
                        $elementName = $this->_elements[$key]->getName();
401
                        if (is_null($elementName)) {
392
                        if (is_null($elementName)) {
402
                            $this->_elements[$key]->setName($this->getName());
393
                            $this->_elements[$key]->setName($this->getName());
403
                        } elseif ('' == $elementName) {
394
                        } elseif ('' === $elementName) {
404
                            $this->_elements[$key]->setName($this->getName() . '[' . $key . ']');
395
                            $this->_elements[$key]->setName($this->getName() . '[' . $key . ']');
405
                        } else {
396
                        } else {
406
                            $this->_elements[$key]->setName($this->getName() . '[' . $elementName . ']');
397
                            $this->_elements[$key]->setName($this->getName() . '[' . $elementName . ']');
407
                        }
398
                        }
408
                    }
399
                    }
Line 431... Line 422...
431
    * @access public
422
    * @access public
432
    * @return void 
423
    * @return void 
433
    */
424
    */
434
    function accept(&$renderer, $required = false, $error = null)
425
    function accept(&$renderer, $required = false, $error = null)
435
    {
426
    {
436
        if (empty($this->_elements)) {
-
 
437
            $this->_createElements();
427
        $this->_createElementsIfNotExist();
438
        }
-
 
439
        $renderer->startGroup($this, $required, $error);
428
        $renderer->startGroup($this, $required, $error);
440
        $name = $this->getName();
429
        $name = $this->getName();
441
        foreach (array_keys($this->_elements) as $key) {
430
        foreach (array_keys($this->_elements) as $key) {
442
            $element =& $this->_elements[$key];
431
            $element =& $this->_elements[$key];
Line 475... Line 464...
475
        foreach (array_keys($this->_elements) as $key) {
464
        foreach (array_keys($this->_elements) as $key) {
476
            $elementName = $this->_elements[$key]->getName();
465
            $elementName = $this->_elements[$key]->getName();
477
            if ($this->_appendName) {
466
            if ($this->_appendName) {
478
                if (is_null($elementName)) {
467
                if (is_null($elementName)) {
479
                    $this->_elements[$key]->setName($this->getName());
468
                    $this->_elements[$key]->setName($this->getName());
480
                } elseif ('' == $elementName) {
469
                } elseif ('' === $elementName) {
481
                    $this->_elements[$key]->setName($this->getName() . '[' . $key . ']');
470
                    $this->_elements[$key]->setName($this->getName() . '[' . $key . ']');
482
                } else {
471
                } else {
483
                    $this->_elements[$key]->setName($this->getName() . '[' . $elementName . ']');
472
                    $this->_elements[$key]->setName($this->getName() . '[' . $elementName . ']');
484
                }
473
                }
485
            }
474
            }
Line 497... Line 486...
497
                    $value = HTML_QuickForm::arrayMerge($value, $v);
486
                    $value = HTML_QuickForm::arrayMerge($value, $v);
498
                } else {
487
                } else {
499
                    // just like getValue(), but should work OK every time here
488
                    // just like getValue(), but should work OK every time here
500
                    if (is_null($elementName)) {
489
                    if (is_null($elementName)) {
501
                        $value = $v;
490
                        $value = $v;
502
                    } elseif ('' == $elementName) {
491
                    } elseif ('' === $elementName) {
503
                        $value[] = $v;
492
                        $value[] = $v;
504
                    } else {
493
                    } else {
505
                        $value[$elementName] = $v;
494
                        $value[$elementName] = $v;
506
                    }
495
                    }
507
                }
496
                }
Line 529... Line 518...
529
    {
518
    {
530
        // abstract
519
        // abstract
531
    }
520
    }
Line 532... Line 521...
532
 
521
 
-
 
522
    // }}}
-
 
523
    // {{{ _createElementsIfNotExist()
-
 
524
 
-
 
525
   /**
-
 
526
    * A wrapper around _createElements()
-
 
527
    *
-
 
528
    * This method calls _createElements() if the group's _elements array
-
 
529
    * is empty. It also performs some updates, e.g. freezes the created
-
 
530
    * elements if the group is already frozen.
-
 
531
    *
-
 
532
    * @access private
-
 
533
    */
-
 
534
    function _createElementsIfNotExist()
-
 
535
    {
-
 
536
        if (empty($this->_elements)) {
-
 
537
            $this->_createElements();
-
 
538
            if ($this->_flagFrozen) {
-
 
539
                $this->freeze();
-
 
540
            }
-
 
541
        }
-
 
542
    }
-
 
543
 
533
    // }}}
544
    // }}}
Line 534... Line 545...
534
    // {{{ freeze()
545
    // {{{ freeze()
535
 
546
 
536
    function freeze()
547
    function freeze()