public function __construct($name, $label, $type) { $this->name = $name; $this->label = $label; $this->type = $type; $this->colname = Field::get_colname($name); }
public static function get_table($type) { $classname = Record::get_classname($type); $start = default_value("start", 0); $qty = default_value("qty", 50); eval('list($db_records, $start, $total) = ' . $classname . '::select_range($type, $start, $qty);'); eval('$columns = ' . $classname . '::get_fields($type);'); $min = min($start + 1, $total); $max = $start + count($db_records); $prev = "{{prev}}"; if ($min > 1) { $prev_start = max(0, $start - $qty); $prev = '<a href="?action=manage&type=' . $type . '&start=' . $prev_start . '#top_table">{{prev}}</a>'; } $next = "{{next}}"; if ($max < $total) { $next = '<a href="?action=manage&type=' . $type . '&start=' . $max . '#top_table">{{next}}</a>'; } $colspan = count($columns) + 2; $result = <<<EOF <table id="top_table" class="evt_table_record_manage"> \t<tr> \t\t<td>{$min} - {$max} {{of}} {$total} {$prev} {$next}</td> \t</tr> \t<tr> \t\t<td> <table class="evt_table_record"> \t<tr> \t\t<th><input type="checkbox" class="check_all_record" /></th> \t\t<th>Actions</th> EOF; foreach ($columns as $field) { $result .= <<<EOF \t\t<th>{$field->label}</th> EOF; } $result .= <<<EOF \t</tr> EOF; foreach ($db_records as $db_record) { $record = Record::get_from_db_record($db_record, $type); $result .= <<<EOF \t<tr> EOF; $id = $db_record["id"]; $html = <<<EOF \t\t\t<select class="evt_record_actions"> \t\t\t\t<option value="#" selected>Choose...</option> EOF; $classname = dd()->get_entity($type)->classname; foreach (dd()->get_entity($type)->get_actions() as $action) { if ($record->accept($action)) { $html .= <<<EOF \t\t\t\t<option value="?action={$action->name}&type={$type}&id={$id}">{$action->label}</option> EOF; } } $html .= <<<EOF \t\t\t</select> EOF; $result .= <<<EOF \t\t<td><input type="checkbox" name="{$id}" class="record" /></td> \t\t<td>{$html}</td> EOF; foreach ($columns as $field) { $colname = Field::get_colname($field->name); $value = $db_record[$colname]; $html = Record::format_value($value, $field, $db_record["id"]); $result .= <<<EOF \t\t<td>{$html}</td> EOF; } $result .= <<<EOF \t</tr> EOF; } $result .= <<<EOF </table> \t\t</td> \t</tr> \t<tr> \t\t<td>{$min} - {$max} {{of}} {$total} {$prev} {$next}</td> \t</tr> </table> EOF; return $result; }