public function run($args) { echo 'Run for demandes'; $demandes = Demande::model()->findAll(); foreach ($demandes as $demande) { if ($demande->id_user != null) { if (is_a($demande->id_user, "MongoId")) { $user = User::model()->findByPk($demande->id_user); if ($user != null && $user != "") { $demande->id_user = (string) $user->_id; $demande->update(); } } else { $user = User::model()->findByAttributes(array('id' => $demande->id_user)); if ($user != null && $user != "") { $demande->id_user = (string) $user->_id; $demande->update(); } $user = User::model()->findByAttributes(array('_id' => $demande->id_user)); if ($user != null && $user != "") { $demande->id_user = (string) $user->_id; $demande->update(); } } } } }
/** * Displays the login page */ public function actionLogin() { $model = new LoginForm(); // if it is ajax validation request if (isset($_POST['ajax']) && $_POST['ajax'] === 'login-form') { echo CActiveForm::validate($model); Yii::app()->end(); } // collect user input data if (isset($_POST['LoginForm'])) { $model->attributes = $_POST['LoginForm']; // validate user input and redirect to the previous page if valid if ($model->validate() && $model->login()) { $lastDemandRequest = Demande::model()->findByAttributes(array('id_user' => (string) Yii::app()->user->id, 'envoi' => 0), array('order' => 'date_demande desc')); if ($lastDemandRequest != null) { $lastDemand = $lastDemandRequest; $newDemand = false; Yii::app()->session['activeDemand'] = array($lastDemand, $newDemand); } else { $lastDemandRequest = new Demande(); $lastDemandRequest->id_user = (string) Yii::app()->user->id; $lastDemandRequest->date_demande = date("Y-m-d H:i:s"); $lastDemandRequest->envoi = 0; $lastDemandRequest->sampleList = array(); $lastDemandRequest->save(); $newDemand = true; Yii::app()->session['activeDemand'] = array($lastDemandRequest, $newDemand); } $this->redirect(Yii::app()->user->returnUrl); } } // display the login form $this->render('login', array('model' => $model)); }
/** * 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 Demande the loaded model * @throws CHttpException */ public function loadModel($id) { try { $model = Demande::model()->findByPk(new MongoID($id)); } catch (Exception $e) { $model = Demande::model()->findByPk($id); } if ($model === null) { throw new CHttpException(404, 'The requested page does not exist.'); } return $model; }