| 1 | /** |
|---|
| 2 | * Given the description of the Column's contents, this is a simple, express |
|---|
| 3 | * way of adding a column to this <%= $objTable->ClassName %> datagrid. The description of a column's |
|---|
| 4 | * content can be either a text string description of a simple field name |
|---|
| 5 | * in the <%= $objTable->ClassName %> object, or it can be any QQNode extending from QQN::<%= $objTable->ClassName %>(). |
|---|
| 6 | * |
|---|
| 7 | * MetaAddColumn will automatically pre-configure the column with the name, html |
|---|
| 8 | * and sort rules given the content being specified. |
|---|
| 9 | * |
|---|
| 10 | * Any of these things can be overridden with OverrideParameters. |
|---|
| 11 | * |
|---|
| 12 | * Finally, $mixContents can also be an array of contents, if displaying and/or |
|---|
| 13 | * sorting using two fields from the <%= $objTable->ClassName %> object. |
|---|
| 14 | * |
|---|
| 15 | * @param mixed $mixContents |
|---|
| 16 | * @param string $objOverrideParameters[] |
|---|
| 17 | * @return QFilteredDataGridColumn |
|---|
| 18 | */ |
|---|
| 19 | public function MetaAddColumn($mixContent, $objOverrideParameters = null) { |
|---|
| 20 | if (is_array($mixContent)) { |
|---|
| 21 | $objNodeArray = array(); |
|---|
| 22 | |
|---|
| 23 | try { |
|---|
| 24 | foreach ($mixContent as $mixItem) { |
|---|
| 25 | $objNodeArray[] = $this->ResolveContentItem($mixItem); |
|---|
| 26 | } |
|---|
| 27 | } catch (QCallerException $objExc) { |
|---|
| 28 | $objExc->IncrementOffset(); |
|---|
| 29 | throw $objExc; |
|---|
| 30 | } |
|---|
| 31 | |
|---|
| 32 | if (count($objNodeArray) == 0) |
|---|
| 33 | throw new QCallerException('No content specified'); |
|---|
| 34 | |
|---|
| 35 | // Create Various Arrays to be used by DGC |
|---|
| 36 | $strNameArray = ''; |
|---|
| 37 | $strHtmlArray = ''; |
|---|
| 38 | $objSort = array(); |
|---|
| 39 | $objSortDescending = array(); |
|---|
| 40 | foreach ($objNodeArray as $objNode) { |
|---|
| 41 | $strNameArray[] = QApplication::Translate(QConvertNotation::WordsFromCamelCase($objNode->_PropertyName)); |
|---|
| 42 | $strHtmlArray[] = $objNode->GetDataGridHtml(); |
|---|
| 43 | $objSort[] = $objNode->GetDataGridOrderByNode(); |
|---|
| 44 | $objSortDescending[] = $objNode->GetDataGridOrderByNode(); |
|---|
| 45 | $objSortDescending[] = false; |
|---|
| 46 | } |
|---|
| 47 | |
|---|
| 48 | $objNewColumn = new QFilteredDataGridColumn( |
|---|
| 49 | implode(', ', $strNameArray), |
|---|
| 50 | '<?=' . implode(' . ", " . ', $strHtmlArray) . '?>', |
|---|
| 51 | array( |
|---|
| 52 | 'OrderByClause' => new QQOrderBy($objNodeArray), |
|---|
| 53 | 'ReverseOrderByClause' => new QQOrderBy($objSortDescending) |
|---|
| 54 | ) |
|---|
| 55 | ); |
|---|
| 56 | } else { |
|---|
| 57 | try { |
|---|
| 58 | $objNode = $this->ResolveContentItem($mixContent); |
|---|
| 59 | } catch (QCallerException $objExc) { |
|---|
| 60 | $objExc->IncrementOffset(); |
|---|
| 61 | throw $objExc; |
|---|
| 62 | } |
|---|
| 63 | |
|---|
| 64 | $objNewColumn = new QFilteredDataGridColumn( |
|---|
| 65 | QApplication::Translate(QConvertNotation::WordsFromCamelCase($objNode->_PropertyName)), |
|---|
| 66 | '<?=' . $objNode->GetDataGridHtml() . '?>', |
|---|
| 67 | array( |
|---|
| 68 | 'OrderByClause' => QQ::OrderBy($objNode->GetDataGridOrderByNode()), |
|---|
| 69 | 'ReverseOrderByClause' => QQ::OrderBy($objNode->GetDataGridOrderByNode(), false) |
|---|
| 70 | ) |
|---|
| 71 | ); |
|---|
| 72 | |
|---|
| 73 | $objNode->SetFilteredDataGridColumnFilter($objNewColumn); |
|---|
| 74 | } |
|---|
| 75 | |
|---|
| 76 | $objOverrideArray = func_get_args(); |
|---|
| 77 | if (count($objOverrideArray) > 1) |
|---|
| 78 | try { |
|---|
| 79 | unset($objOverrideArray[0]); |
|---|
| 80 | $objNewColumn->OverrideAttributes($objOverrideArray); |
|---|
| 81 | } catch (QCallerException $objExc) { |
|---|
| 82 | $objExc->IncrementOffset(); |
|---|
| 83 | throw $objExc; |
|---|
| 84 | } |
|---|
| 85 | |
|---|
| 86 | $this->AddColumn($objNewColumn); |
|---|
| 87 | return $objNewColumn; |
|---|
| 88 | } |
|---|