public function checkRule($attribute, $params) { /*check db if it exists*/ /* @var $dispoModel Disposale*/ if (!isset($this->{$attribute}) || empty($this->{$attribute})) { $this->addError($attribute, "Can't check rule. You must provide a mobile number"); } $criteria = new CDbCriteria(); $criteria->compare("phone_number", $this->{$attribute}); $criteria->order = "date_created DESC"; $dispoModel = Disposale::model()->find($criteria); $isValid = true; if ($dispoModel && !empty($dispoModel)) { $dt1Str = date("Y-m-d H:i:s", strtotime($dispoModel->date_created)); $dt2Str = date("Y-m-d H:i:s", strtotime("+0 day")); $dt1Obj = new DateTime($dt1Str); $dt2Obj = new DateTime($dt2Str); $dateDifference = $dt2Obj->diff($dt1Obj)->format("%a"); $dateDifference = intval($dateDifference); $limitDays = intval(\Yii::app()->params['time_limit']); /*After 182 days , if equal to 182 still not valid*/ if ($dateDifference <= $limitDays) { $lastInsertData = $dispoModel->date_created; $this->addError($attribute, "Sorry we cant process your data . You must wait {$limitDays} days before we accept your submittion. Last insert was {$lastInsertData}. Difference is {$dateDifference} and limit is {$limitDays}"); } } return $isValid; }
/** * Returns the data model based on the primary key given in the GET variable. * If the data model is not found, an HTTP exception will be raised. * @param integer $id the ID of the model to be loaded * @return Disposale the loaded model * @throws CHttpException */ public function loadModel($id) { $model = Disposale::model()->findByPk($id); if ($model === null) { throw new CHttpException(404, 'The requested page does not exist.'); } return $model; }
protected function tearDown() { \Disposale::model()->deleteAll(); }