00001 <?php
00002
00012 class CSERDquestion extends CSERDModelBase {
00014 public static $ATTRIBUTES = array(
00015 'questionId' => array(
00016 'nullable' => false,
00017 'commit' => SModel2::COMMIT_NEVER,
00018 'type' => 'int'
00019 ),
00020 'active' => array(
00021 'type' => 'int',
00022 'default' => 1
00023 ),
00024 'qOrder' => array(
00025 'type' => 'int',
00026 'default' => null
00027 ),
00028 'type' => array(
00029 'type' => 'string',
00030 'default' => null
00031 ),
00032 'ref' => array(
00033 'nullable' => false,
00034 'type' => 'string'
00035 ),
00036 'required' => array(
00037 'type' => 'int',
00038 'default' => 0
00039 )
00040 );
00041
00050 public function __construct($constraints = null) {
00051 parent::__construct();
00052
00053 $this->registerAttributes(self::$ATTRIBUTES);
00054 $this->registerTableName('question');
00055 $this->registerPrimaryKey('questionId', true);
00056
00057 if($constraints !== null)
00058 $this->populate($constraints);
00059 }
00060
00072 public static function retrieve($constraints = array(), $checkOnly = false) {
00073 $list = self::getList($constraints, array(1), array(), $checkOnly);
00074 if(!$list || count($list) == 0)
00075 return $checkOnly ? false : null;
00076 else if($checkOnly)
00077 return $list > 0;
00078 else
00079 return $list[0];
00080 }
00081
00090 public static function exists($constraints = array()) {
00091 return self::retrieve($constraints, true);
00092 }
00093
00107 public static function getList($constraints = array(), $limit = array(), $order = array(), $count = false) {
00108 return parent::getListBase(self::getDBI(), $constraints, $limit, $order, $count, 'CSERDquestion', true);
00109 }
00110
00120 public static function getAttributesStatic() {
00121 return self::$ATTRIBUTES;
00122 }
00123
00129 public static function getTableNameStatic() {
00130 return 'question';
00131 }
00132
00133
00150 public function listresponses($constraints = array(), $limit = array(), $order = array(), $count = false) {
00151 return parent::getListBase(self::getDBI(),
00152 array_merge($constraints, array('questionId' => $this->questionId)),
00153 $limit, $order, $count, 'CSERDresponse', true);
00154 }
00155
00174 public function listresponsesMulti($constraints = array(), $limit = array(), $order = array(), $count = false, $depth = 1) {
00175 return parent::getListBaseMulti(self::getDBI(),
00176 array_merge($constraints, array('Base.questionId' => $this->questionId)),
00177 $limit, $order, $count, 'CSERDresponse', true, $depth);
00178 }
00179
00195 public function addresponse($review, $response = '') {
00196 $obj = new CSERDresponse();
00197
00198 $obj->questionId = $this->questionId;
00199 if(is_object($review))
00200 $obj->review = $review;
00201 else
00202 $obj->reviewId = $review;
00203 if($response != '')
00204 $obj->response = $response;
00205
00206 if(!$obj->commit())
00207 return null;
00208
00209 return $obj;
00210 }
00211
00212
00213 public function isValidQuestion()
00214 {
00215 return (
00216 ($this->active !== "")
00217 && ($this->ref !== "")
00218 && ($this->required !== "")
00219 );
00220 }
00221
00222 public function getXFormsOpenCloseTag() {
00223 $ref = $this->ref;
00224 $attributes = $this->getTagAttributes();
00225 return <<<END_XML
00226 <$ref $attributes />
00227 END_XML;
00228 }
00229
00230 public function getXFormsOpenTag($dbid = "") {
00231 $ref = $this->ref;
00232 $db = ($dbid == "") ? "" : " dbid=\"$dbid\" ";
00233 $attributes = $this->getTagAttributes();
00234 return <<<END_XML
00235 <$ref $attributes $db>
00236 END_XML;
00237 }
00238
00239 public function getXFormsCloseTag() {
00240 $ref = $this->ref;
00241 return <<<END_XML
00242 </$ref>
00243 END_XML;
00244 }
00245
00246 public function getTagAttributes() {
00247 $req = ($this->required) ? " required=\"true()\" " : "";
00248 $type = ($this->type != "") ? " type=\"" . $this->type . "\" " : "";
00249 return <<<END_XML
00250 $type $req
00251 END_XML;
00252 }
00253
00254 }
00255
00256 ?>