10 public static function model($className=__CLASS__)
31 array(
'json, html',
'required'),
32 array(
'name, user thankyoupage',
'length',
'max'=>255),
33 array(
'salt',
'length',
'max'=>32),
36 array(
'id, name, json, html, user, salt, creator_email thankyoupage nextpage prevpage',
'safe',
'on'=>
'search'),
48 'formdata' => array(self::HAS_MANY,
'FGFormdata',
'form_id')
52 public function defaultScope()
54 return array(
'order'=>
'id DESC');
68 'creator_email' =>
'Creator Email',
70 'thankyoupage' =>
'Thankyoupage',
74 public function validateInput($inputData = null)
76 if($inputData === null)
78 $formObject = $this->JSONToArray();
80 foreach($formObject[
'elements'] as $element)
82 if(isset($element[
'name']))
84 $value = isset($_POST[$element[
'name']])? strval($_POST[$element[
'name']]) :
'';
85 if(isset($element[
'mandatory']) && $element[
'mandatory'] ==
true && trim($value) ===
'')
87 $message = Yii::t(
'yii',
'{attribute} cannot be blank.');
88 $validator->addError($this, $element[
'name'], $message);
90 elseif(isset($element[
'validation']) && $element[
'validation'] !=
'' && $value !==
'')
92 $validator->validate($element[
'validation'], $this, $element[
'name'], $value);
96 $validator->validateElement($element[
'type'], $this, $element[
'name'], $value);
100 return !$this->hasErrors();
103 public function JSONToArray()
105 return CJSON::decode($this->json);
108 public function getElementFromJSONByName($name)
110 $object = $this->JSONToArray();
111 foreach($object[
'elements'] as $element) {
112 if(isset($element[
'name']) && $element[
'name'] == $name) {
119 public function getElementLabel($name)
121 $element = $this->getElementFromJSONByName($name);
122 if($element && isset($element[
'label'])) {
123 return $element[
'label'];
137 $criteria=
new CDbCriteria;
139 $criteria->compare(
'id',$this->
id,
true);
140 $criteria->compare(
'name',$this->name,
true);
141 $criteria->compare(
'json',$this->json,
true);
142 $criteria->compare(
'html',$this->html,
true);
143 $criteria->compare(
'user',$this->user,
true);
144 $criteria->compare(
'salt',$this->salt,
true);
154 return new CActiveDataProvider($this, array(
155 'criteria'=>$criteria,
166 public function searchAllForUser($user_email = null)
168 $criteria =
new CDbCriteria();
169 if($user_email != null){
170 $criteria->compare(
'creator_email', $user_email,
true);
173 return new CActiveDataProvider($this,array(
174 'criteria' => $criteria,
175 'Pagination' =>
false