00001 <?php
00002
00003
00004
00005
00006
00007
00008 abstract class DataObjectPostBase extends DataObjectTimestampedCached implements ISelfDescribing {
00009 private static $global_extensions = array();
00010
00011 public $id;
00012 public $title;
00013 public $teaser;
00014 public $text;
00015 public $meta_title;
00016 public $meta_keywords;
00017 public $meta_description;
00018
00019
00020
00021
00022
00023
00024 protected function create_table_object() {
00025 return new DBTable(
00026 $this->get_model_name(),
00027 $this->collect_field_definitions(),
00028 'id',
00029 $this->collect_relations()
00030 );
00031 }
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041 protected function collect_field_definitions() {
00042 return array_merge(
00043 array(
00044 new DBFieldInt('id', null, DBFieldInt::PRIMARY_KEY),
00045 new DBFieldText('title', 200, null, DBField::NOT_NULL),
00046 new DBFieldTextHtml('text', DBFieldText::BLOB_LENGTH_LARGE, null, $this->get_text_field_policy()),
00047 ),
00048 $this->get_teaser_field(),
00049 $this->get_meta_tag_fields(),
00050 $this->get_global_field_definitions(),
00051 $this->get_timestamp_field_declarations(),
00052 $this->get_additional_field_definitions()
00053 );
00054 }
00055
00056
00057
00058
00059
00060
00061
00062 protected function collect_relations() {
00063 return $this->get_additional_relations();
00064 }
00065
00066
00067
00068
00069
00070
00071 public static function extend_table($arr_fields) {
00072 self::$global_extensions = $arr_fields;
00073 }
00074
00075
00076
00077
00078
00079
00080 abstract protected function get_model_name();
00081
00082
00083
00084
00085
00086
00087 protected function get_additional_field_definitions() {
00088 return array();
00089 }
00090
00091
00092
00093
00094
00095
00096 protected function get_additional_relations() {
00097 return array();
00098 }
00099
00100
00101
00102
00103
00104
00105 protected function get_teaser_field_policy() {
00106 return DBField::NOT_NULL;
00107 }
00108
00109
00110
00111
00112
00113
00114 protected function get_text_field_policy() {
00115 return DBField::NOT_NULL;
00116 }
00117
00118
00119
00120
00121
00122
00123 protected function get_global_field_definitions() {
00124 return self::$global_extensions;
00125 }
00126
00127
00128
00129
00130
00131
00132 protected function get_meta_tag_fields() {
00133 return array(
00134 new DBFieldText('meta_title', 200, null, DBField::NONE),
00135 new DBFieldText('meta_keywords', 255, null, DBField::NONE),
00136 new DBFieldText('meta_description', DBFieldText::BLOB_LENGTH_SMALL, null, DBField::NONE),
00137 );
00138 }
00139
00140
00141
00142
00143
00144
00145 protected function get_teaser_field() {
00146 return array(
00147 new DBFieldText('teaser', DBFieldText::BLOB_LENGTH_SMALL, null, $this->get_teaser_field_policy()),
00148 );
00149 }
00150
00151
00152
00153
00154
00155
00156
00157
00158
00159 public function get_text() {
00160 return HtmlText::apply_conversion(HtmlText::OUTPUT, $this->text, $this->get_table_name());
00161 }
00162
00163
00164
00165
00166
00167
00168 public function get_teaser() {
00169 return ($this->teaser) ? $this->teaser : String::substr_word(strip_tags($this->text), 0, 300);
00170 }
00171
00172
00173
00174
00175 public function get_meta_title() {
00176 return $this->meta_title ? $this->meta_title : $this->get_title();
00177 }
00178
00179
00180
00181
00182 public function get_meta_description() {
00183 return $this->meta_description ? $this->meta_description : String::unescape($this->get_teaser());
00184 }
00185
00186
00187
00188
00189
00190
00191
00192
00193 public function get_sortable_columns() {
00194 return array(
00195 'title' => new DBSortColumn('title', tr('Title', 'postbase'), DBSortColumn::TYPE_TEXT),
00196 'creationdate' => new DBSortColumn('creationdate', tr('Creation Date'), DBSortColumn::TYPE_DATE, DBSortColumn::ORDER_BACKWARD),
00197 );
00198 }
00199
00200
00201
00202
00203 public function get_sort_default_column() {
00204 return 'title';
00205 }
00206
00207
00208
00209
00210
00211
00212
00213
00214
00215
00216
00217
00218
00219 protected function get_actions_for_context($context, $user, $params) {
00220 $ret = array();
00221 $ret['edit'] = tr('Edit');
00222 return $ret;
00223 }
00224
00225
00226
00227
00228
00229
00230
00231
00232
00233
00234 public function get_title() {
00235 return $this->title;
00236 }
00237
00238
00239
00240
00241
00242
00243 public function get_description() {
00244 return $this->teaser;
00245 }
00246 }