59 lines
1.4 KiB
PHP
59 lines
1.4 KiB
PHP
<?php
|
|
|
|
|
|
class CommentoModel extends Model{
|
|
const STATUS_PENDING = 1;
|
|
const STATUS_ACCEPTED = 2;
|
|
const STATUS_REJECTED = 3;
|
|
|
|
public static $COMMENTO_STATUS = array(
|
|
self::STATUS_PENDING=>array("label"=>"Valutazione"),
|
|
self::STATUS_ACCEPTED=>array("label"=>"Accettata"),
|
|
self::STATUS_REJECTED=>array("label"=>"Respinta")
|
|
);
|
|
|
|
/**
|
|
* saveableObject deve avere alemeno il campo notizia = notiziaId e il campo user = userId;
|
|
* @param stdClass $saveableObject
|
|
* @throws CoreException
|
|
*/
|
|
public function __construct($saveableObject){
|
|
parent::__construct($saveableObject);
|
|
|
|
if (!$this->hasProperty("notizia") || strcmp($this->notizia,"")==0){
|
|
throw new CoreException("Impossible to build CommentoModel without field notizia");
|
|
}
|
|
|
|
if (!$this->hasProperty("user") || strcmp($this->user,"")==0){
|
|
throw new CoreException("Impossible to build CommentoModel without field user");
|
|
}
|
|
|
|
if (!$this->hasProperty("status") || strcmp($this->status,"")==0){
|
|
$this->status = self::STATUS_PENDING;
|
|
}
|
|
|
|
if (!$this->hasProperty("mailSent")){
|
|
$this->mailSent = false;
|
|
}
|
|
|
|
if (!$this->hasProperty("date")){
|
|
// $this->date = new MongoDate();
|
|
$this->date = new MongoDB\BSON\UTCDateTime( time() * 1000 );
|
|
}
|
|
|
|
}
|
|
|
|
public function __set($attr,$value){
|
|
if (strcmp("status", $attr)==0){
|
|
$value = intval($value);
|
|
}
|
|
return parent::__set($attr, $value);
|
|
}
|
|
|
|
public static function getCollectionName(){
|
|
return "commenti";
|
|
}
|
|
|
|
|
|
}
|
|
?>
|