1: <?php
2: require_once('../qcubed.inc.php');
3:
4: class ExampleCheckColumn1 extends QDataGrid_CheckBoxColumn {
5: protected function GetAllIds()
6: {
7: return Person::QueryPrimaryKeys();
8: }
9: }
10:
11:
12: class ExampleCheckColumn2 extends QDataGrid_CheckBoxColumn {
13: protected function GetItemCheckedState ($item) {
14: if(null !== $item->GetVirtualAttribute('assn_item')) {
15: return true;
16: }
17: else {
18: return false;
19: }
20: }
21:
22: protected function SetItemCheckedState($itemId, $blnChecked) {
23: $objProject = Project::Load($itemId);
24: if($blnChecked)
25: {
26:
27: QApplication::DisplayAlert('Associating '.$objProject->Name);
28:
29:
30: 31: 32: 33:
34: }
35: else
36: {
37:
38: QApplication::DisplayAlert('Unassociating '.$objProject->Name);
39: }
40:
41:
42: }
43: }
44:
45:
46:
47: class ExampleForm extends QForm {
48:
49: protected $dtgPersons;
50: protected $lblResponse;
51:
52:
53: protected $colSelect;
54:
55: protected $dtgProjects;
56: protected $colProjectSelected;
57:
58: protected $btnGo;
59:
60: protected function Form_Create() {
61:
62: $this->dtgPersons_Create();
63: $this->dtgProjects_Create();
64:
65:
66:
67: $this->lblResponse = new QLabel($this);
68: $this->lblResponse->HtmlEntities = false;
69: }
70:
71: protected function dtgPersons_Create() {
72:
73: $this->dtgPersons = new QDataGrid($this);
74:
75:
76: $objPaginator = new QPaginator($this->dtgPersons);
77: $this->dtgPersons->Paginator = $objPaginator;
78: $this->dtgPersons->ItemsPerPage = 10;
79:
80:
81: $col = $this->dtgPersons->CreateNodeColumn('Person ID', QQN::Person()->Id);
82: $col->CellStyler->Width = 100;
83: $col = $this->dtgPersons->CreateNodeColumn('First Name', [QQN::Person()->FirstName, QQN::Person()->LastName]);
84: $col->CellStyler->Width = 200;
85: $col = $this->dtgPersons->CreateNodeColumn('Last Name', [QQN::Person()->LastName, QQN::Person()->LastName]);
86: $col->CellStyler->Width = 200;
87:
88:
89: $this->colSelect = new ExampleCheckColumn1('');
90: $this->colSelect->ShowCheckAll = true;
91: $this->colSelect->CellStyler->Width = 20;
92:
93: $this->dtgPersons->AddColumnAt(0, $this->colSelect);
94:
95:
96: $this->dtgPersons->SortColumnIndex = 2;
97:
98:
99: $this->dtgPersons->SetDataBinder('dtgPersons_Bind');
100:
101: $this->dtgPersons->AddAction(new QHtmlTableCheckBoxColumn_ClickEvent(), new QAjaxAction ('chkSelected_Click'));
102:
103:
104: $this->dtgPersons->Watch(QQN::Person());
105:
106: }
107:
108: protected function dtgPersons_Bind() {
109:
110: $this->dtgPersons->TotalItemCount = Person::CountAll();
111: $this->dtgPersons->DataSource = Person::LoadAll(QQ::Clause(
112: $this->dtgPersons->OrderByClause,
113: $this->dtgPersons->LimitClause
114: ));
115: }
116:
117:
118: protected function chkSelected_Click($strFormId, $strControlId, $params) {
119: $blnChecked = $params['checked'];
120:
121:
122: $idItems = explode('_', $params['id']);
123: $intPersonId = end($idItems);
124:
125: if ($intPersonId == 'all') {
126: $strResponse = QApplication::HtmlEntities('You just selected all. ');
127: }
128: else {
129: $objPerson = Person::Load($intPersonId);
130:
131:
132: if ($blnChecked)
133: $strResponse = QApplication::HtmlEntities('You just selected ' . $objPerson->FirstName . ' ' . $objPerson->LastName . '.');
134: else
135: $strResponse = QApplication::HtmlEntities('You just deselected ' . $objPerson->FirstName . ' ' . $objPerson->LastName . '.');
136: $strResponse .= '<br/>';
137: }
138:
139:
140:
141: $arrIds = $this->colSelect->GetCheckedItemIds();
142: $strNameArray = array();
143: foreach($arrIds as $strId) {
144: $objPerson = Person::Load($strId);
145: $strName = QApplication::HtmlEntities($objPerson->FirstName . ' ' . $objPerson->LastName);
146: $strNameArray[] = $strName;
147: }
148:
149: $strResponse .= 'The list of people who are currently selected: ' . implode(', ', $strNameArray);
150:
151:
152: $this->lblResponse->Text = $strResponse;
153: }
154:
155: protected function dtgProjects_Create() {
156:
157: $this->dtgProjects = new QDataGrid($this);
158: $this->dtgProjects->CssClass = 'datagrid';
159:
160:
161: $this->dtgProjects->Paginator = new QPaginator($this->dtgProjects);
162:
163:
164:
165:
166:
167: $this->dtgProjects->UseAjax = true;
168:
169:
170: $this->dtgProjects->SetDataBinder('dtgProjects_Bind', $this);
171:
172:
173: $this->colProjectSelected = new ExampleCheckColumn2(QApplication::Translate('Select'));
174:
175: $this->dtgProjects->AddColumn($this->colProjectSelected);
176:
177: $this->dtgProjects->CreateNodeColumn(QApplication::Translate('Name'), QQN::Project()->Name);
178:
179:
180: $this->dtgProjects->Watch(QQN::Project());
181: }
182:
183:
184: public function colProjectSelectedCheckbox_Created(Project $_ITEM, QCheckBox $ctl)
185: {
186:
187: if(null !== $_ITEM->GetVirtualAttribute('assn_item'))
188: $ctl->Checked = true;
189:
190:
191: }
192:
193: public function dtgProjects_Bind() {
194:
195: $this->dtgProjects->TotalItemCount = Project::CountAll();
196:
197: $objClauses = array();
198: if ($objClause = $this->dtgProjects->OrderByClause)
199: $objClauses[] = $objClause;
200: if ($objClause = $this->dtgProjects->LimitClause)
201: $objClauses[] = $objClause;
202:
203:
204: $objClauses[] = QQ::Expand(
205: QQ::Virtual('assn_item',
206: QQ::SubSql(
207: 'select
208: project_id
209: from
210: related_project_assn
211: where
212: child_project_id = {1}
213: and project_id = 1',
214: QQN::Project()->Id)
215: )
216: );
217:
218: $this->dtgProjects->DataSource = Project::LoadAll($objClauses);
219: }
220: }
221:
222: ExampleForm::Run('ExampleForm');
223: ?>
224: