function beforeInsert(&$data) { $c = get_class($this); $c = preg_replace('/^Model_/', '', $c); $survey = $this->add('Model_ATK_Survey'); $survey->loadBy('model', $c); if (!$survey->isInstanceLoaded()) { throw $this->exception('Survey not found')->addMoreInfo('class', $c); } $us = $this->add('Model_ATK_UserSurvey'); $us->setMasterField('user_id', $this->api->auth->get('id')); $us->loadBy('survey_id', $survey->get('id')); if (!$us->isInstanceLoaded()) { $us->update(array('survey_id' => $survey->get('id'))); } $data['user_survey_id'] = $us->get('id'); $data['is_completed'] = false; return parent::beforeInsert($data); }
function beforeInsert($data) { // even when children add more conditions, email shouldn't duplicate! $em = $data['email']; if (!$em) { $em = $this->get('email'); } $m = $this->add('Model_ATK_User')->getBy('email', $em); if ($m) { throw $this->exception('This email is already registered', 'ValidityCheck')->setField('email'); } return parent::beforeInsert($data); }
function beforeInsert(&$data){ parent::beforeInsert($data); $data['expires_at']=date('Y-m-d',strtotime('+'.$this->api->getConfig('job/expires','30 days'))); $data['token']=sha1($data['email'].rand(11111, 99999)); }