protected function initListRows() { $tag = "ListDrafter: initListRows()"; Log::debug("$tag"); /* // Build the results table */ $listColumnNames = array(); $listRows = array(); // convenience pointers $query = $this->entityQuery; $entityBP = $this->entityBlueprint; $listBP = $this->listBlueprint; // determine which fields to render if($listBP) {$fields = $listBP->fields(); } else { $fields = $entityBP->fields(); } try { $sql = new DatabaseQuery($query->toString()); $sql->doQuery(); $num_rows = $sql->get_num_rows(); if($num_rows > 0) { for($i=0; $i<$num_rows; $i++) { $row = $sql->get_next_row(); $id = $row->id; $listRow = new ListRow($id); foreach($fields as $f) { // NOTE: treat "f" as a generic Field $key = $f->getKey(); // add to list of column names $listColumnNames["$key"] = $f->getDisplayName(); // get field definition from entityBlueprint $entityField = $entityBP->get($key); // retrieve value for field if($entityField->isForeignKey()) { $foreignValue = str_replace(".", "_", $entityField->getForeignValue()); $value = $row->$foreignValue; } else { $value = $row->$key; } /* // Format Values */ if( (!empty($value)) || ($value=="0") ) { // first by datatype switch($entityField->getDataType()) { case "string": if($entityField->getEncType() != "plain") { $value = "********"; } break; case "text": break; case "binary": $lengthKey = $key . "_length"; $bytes = $row->$lengthKey; $value = "<a href='/blueprints/binary.php?action=file&blueprint=" . $entityBP->getKey() . "&field=$key&id=$id'>" . Binary::formatLength($bytes) . "</a>"; break; } // then, by list blueprint format string if($listBP) { $listField = $listBP->get($key); $format = $listField->getFormat(); if(!empty($format)) { switch($entityField->getDataType()) { case "string": case "text": // formatter string specifies truncation length if(strlen($value) > $format) { $value = substr($value, 0, $format) . "..."; } break; case "enum": // formatter string specifies truncation length if(strlen($value) > $format) { $value = substr($value, 0, $format); } break; case "date": case "datetime": // formatter string specifies php date format $time = strtotime($value); $value = date($format, $time); break; case "binary": break; } } } // look for additional column attributes from listBlueprint $href = null; if($listBP) { $listField = $listBP->get($key); $href = $listField->getHref(); // replace references to entity fields with their values if(!empty($href)) { $href = $this->replaceKeys($href, $row); } } } // add a new list column to the list row $listRow->addColumn($key, $value, @$href); } // END: foreach($field as $f) $listRows[$i] = $listRow; } // END: for($i=0; $i<$num_rows; $i++) $this->listColumnNames = $listColumnNames; $this->listRows = $listRows; } // END: if($num_rows > 0) } catch(Exception $e) { // ? can we throw exceptions from a / to a constructor? throw($e); } } // END: protected function initListRows()