1: <?php
2:
3: /**
4: * Accordion Base File
5: *
6: * The QAccordionBase class defined here provides an interface between the generated
7: * QAccordianGen class, and QCubed. This file is part of the core and will be overwritten
8: * when you update QCubed. To override, make your changes to the QAccordion.class.php file instead.
9: */
10:
11:
12: /**
13: * Implements the JQuery UI Accordion
14: *
15: * An accordion is a series of panels, only one of which is shown at a time. Each panel has a trigger, and
16: * when the user clicks on the trigger, its corresponding panel is shown, and the others hidden.
17: *
18: * The Accordion decends from QPanel. There are a number of ways to create an Accordion,
19: * but the basics are that you put a series of block level items inside the Accordion (like divs, or h1, QPanels, etc.)
20: * and it will automatically pick the first item as the header and the second item as the content that will be collapsed
21: * or expanded, and will repeat that until the end of the Accordion block.
22: *
23: * If you want more control, you can assign a jQuery selector to the Header item and that selector
24: * will be used to find the headers within the Accordion. In this case, the next block level sibling to
25: * the header will be used as the content for that header. For example, to use all the items with class ItemHeader
26: * inside the Accordion panel as the headers for the accordion, do this:
27: *
28: * <code>$accordion->Header = '.ItemHeader';</code>
29: *
30: * To get or set the index of the item that is currently open, use the inherited <code>->Active</code> value.
31: *
32: * The Accordion will generate a QChangeEvent when a new header is selected.
33: *
34: * See the jQuery UI documentation for additional events, methods and options that may be useful.
35: *
36: * @link http://jqueryui.com/accordion/
37: * @package Controls\Base
38: */
39:
40: class QAccordionBase extends QAccordionGen
41: {
42: /** @var bool Should the children be rendered automatically? */
43: protected $blnAutoRenderChildren = true;
44:
45: /**
46: * Rendered the children of this control
47: * @param bool $blnDisplayOutput Send the output to client?
48: *
49: * @return null|string
50: */
51: protected function RenderChildren($blnDisplayOutput = true) {
52: $strToReturn = "";
53:
54: foreach ($this->GetChildControls() as $objControl) {
55: if (!$objControl->Rendered) {
56: $renderMethod = $objControl->strPreferredRenderMethod;
57: $strToReturn .= QHtml::RenderTag('div', null, $objControl->$renderMethod(false));
58: }
59: }
60:
61: if ($blnDisplayOutput) {
62: print($strToReturn);
63: return null;
64: } else
65: return $strToReturn;
66: }
67:
68: /**
69: * Returns the Javascript needed as the part of control's behavior
70: * @return string The control's JS
71: */
72: public function GetEndScript() {
73: $strJS = parent::GetEndScript();
74: QApplication::ExecuteJsFunction('qcubed.accordion', $this->GetJqControlId(), QJsPriority::High);
75: return $strJS;
76: }
77:
78: /**
79: * Returns the state data to restore later.
80: * @return mixed
81: */
82: protected function GetState() {
83: return ['active'=>$this->Active];
84: }
85:
86: /**
87: * Restore the state of the control.
88: * @param mixed $state
89: */
90: protected function PutState($state) {
91: if (isset($state['active'])) {
92: $this->Active = $state['active'];
93: }
94: }
95:
96:
97: /**
98: * PHP __set magic method implementation
99: *
100: * @param string $strName Name of the property
101: * @param string $mixValue Value of the property
102: *
103: * @return mixed|void
104: * @throws Exception|QInvalidCastException
105: */
106: public function __set($strName, $mixValue) {
107: switch ($strName) {
108: case '_SelectedIndex': // Internal Only. Used by JS above. Do Not Call.
109: try {
110: $this->mixActive = QType::Cast($mixValue, QType::Integer); // will cause ->Active getter to always return index of content item that is currently active
111: } catch (QInvalidCastException $objExc) {
112: try {
113: $this->mixActive = QType::Cast($mixValue, QType::Boolean);
114: } catch (QInvalidCastException $objExc) {
115: $objExc->IncrementOffset();
116: throw $objExc;
117: }
118: }
119: break;
120:
121: default:
122: try {
123: parent::__set($strName, $mixValue);
124: } catch (QInvalidCastException $objExc) {
125: $objExc->IncrementOffset();
126: throw $objExc;
127: }
128: break;
129: }
130:
131: }
132: }