00001 <?php
00002
00012 class CSERDcomment extends CSERDModelBase {
00014 public static $ATTRIBUTES = array(
00015 'commentId' => array(
00016 'nullable' => false,
00017 'commit' => SModel2::COMMIT_NEVER,
00018 'type' => 'int'
00019 ),
00020 'comment' => array(
00021 'type' => 'string'
00022 ),
00023 'timestamp' => array(
00024 'nullable' => false,
00025 'commit' => SModel2::COMMIT_CHANGED,
00026 'type' => 'time',
00027 'default' => ''
00028 ),
00029 'reviewId' => array(
00030 'commit' => SModel2::COMMIT_FIRST,
00031 'type' => 'int',
00032 'default' => null,
00033 'foreign' => array('table' => 'review', 'on' => 'reviewId', 'object' => 'review')
00034 ),
00035 'ownerId' => array(
00036 'commit' => SModel2::COMMIT_FIRST,
00037 'type' => 'int',
00038 'default' => null,
00039 'foreign' => array('table' => 'user', 'on' => 'userId', 'object' => 'owner')
00040 ),
00041 'authorId' => array(
00042 'commit' => SModel2::COMMIT_FIRST,
00043 'type' => 'int',
00044 'default' => null,
00045 'foreign' => array('table' => 'user', 'on' => 'userId', 'object' => 'author')
00046 ),
00047 'review' => array(
00048 'commit' => SModel2::COMMIT_FOREIGN,
00049 'type' => 'CSERDreview'
00050 ),
00051 'owner' => array(
00052 'commit' => SModel2::COMMIT_FOREIGN,
00053 'type' => 'CSERDuser'
00054 ),
00055 'author' => array(
00056 'commit' => SModel2::COMMIT_FOREIGN,
00057 'type' => 'CSERDuser'
00058 )
00059 );
00060
00070 public function __construct($constraints = null, $multi = false) {
00071 parent::__construct();
00072
00073 $this->registerAttributes(self::$ATTRIBUTES);
00074 $this->registerTableName('comment');
00075 $this->registerPrimaryKey('commentId', true);
00076
00077 if($constraints !== null)
00078 $this->populate($constraints, $multi);
00079 }
00080
00090 public static function getAttributesStatic() {
00091 return self::$ATTRIBUTES;
00092 }
00093
00099 public static function getTableNameStatic() {
00100 return 'comment';
00101 }
00102
00114 public static function retrieve($constraints = array(), $checkOnly = false) {
00115 $list = self::getList($constraints, array(1), array(), $checkOnly);
00116 if(!$list || count($list) == 0)
00117 return $checkOnly ? false : null;
00118 else if($checkOnly)
00119 return $list > 0;
00120 else
00121 return $list[0];
00122 }
00123
00132 public static function exists($constraints = array()) {
00133 return self::retrieve($constraints, true);
00134 }
00135
00148 public static function retrieveMulti($constraints = array(), $checkOnly = false, $depth = 1) {
00149 $list = self::getListMulti($constraints, array(1), array(), $checkOnly, $depth);
00150 if(!$list || count($list) == 0)
00151 return $checkOnly ? false : null;
00152 else if($checkOnly)
00153 return $list > 0;
00154 else
00155 return $list[0];
00156 }
00157
00166 public static function existsMulti($constraints = array()) {
00167 return self::retrieveMulti($constraints, true);
00168 }
00169
00183 public static function getList($constraints = array(), $limit = array(), $order = array(), $count = false) {
00184 return parent::getListBase(self::getDBI(), $constraints, $limit, $order, $count, 'CSERDcomment', true);
00185 }
00186
00202 public static function getListMulti($constraints = array(), $limit = array(), $order = array(), $count = false, $depth = 1) {
00203 return parent::getListBaseMulti(self::getDBI(), $constraints, $limit, $order, $count,
00204 'CSERDcomment', true, $depth);
00205 }
00206
00207
00216 public function getParentReview() {
00217 return CSERDreview::retrieve(array('reviewId' => $this->reviewId));
00218 }
00219
00229 public function getParentReviewMulti($depth = 1) {
00230 return CSERDreview::retrieveMulti(array('Base.reviewId' => $this->reviewId), false, $depth);
00231 }
00232
00241 public function getParentOwner() {
00242 return CSERDuser::retrieve(array('userId' => $this->ownerId));
00243 }
00244
00254 public function getParentOwnerMulti($depth = 1) {
00255 return CSERDuser::retrieveMulti(array('Base.userId' => $this->ownerId), false, $depth);
00256 }
00257
00266 public function getParentAuthor() {
00267 return CSERDuser::retrieve(array('userId' => $this->authorId));
00268 }
00269
00279 public function getParentAuthorMulti($depth = 1) {
00280 return CSERDuser::retrieveMulti(array('Base.userId' => $this->authorId), false, $depth);
00281 }
00282 }
00283
00284 ?>