private function loadModel($id) { $model=Business::model()->findByPk($id); if($model===null) throw new CHttpException(404,'The requested page does not exist.'); return $model; }
public function testUpdate() { $business = Business::model()->find(array('condition' => 'name=:name', 'params' => array(':name' => 'Test Hotel'))); $business->description = "Test changing business description"; $this->assertTrue($business->save(false)); $business = Business::model()->find(array('condition' => 'name=:name', 'params' => array(':name' => 'Test Hotel'))); $this->assertEquals($business->description, "Test changing business description"); }
public function actionImport() { $total_records = 0; $inserted_records = 0; $msg = ""; $model = new Business(); $model->setScenario('importFile'); //$file = CUploadedFile::getInstance($model,'csv_file'); if (isset($_POST['Business'])) { // echo $_POST['Business']['import_option']; die(); if (!empty($_FILES['Business']['tmp_name']['import_file'])) { $file = CUploadedFile::getInstance($model, 'import_file'); $fp = fopen($file->tempName, 'r'); $row = 1; if ($fp) { $line = fgetcsv($fp, 1000, ";"); $first_time = true; $c = 1; if ($_POST['Business']['import_option'] == "Insert") { do { if ($first_time == true) { $first_time = false; $headerLine = $line; continue; } //$data = explode(",",$line); //$data = $line[0]; // $data = explode(';',$line); $fData = array_combine($headerLine, $line); //echo '<pre>'; var_dump($fData); echo '</pre>'; die(); $email_id = $fData['business_email_id1']; $modelObj = Business::model()->findByAttributes(array('business_email_id1' => $email_id)); if (isset($modelObj->business_email_id1)) { $modelObj = new Business(); $modelObj->setIsNewRecord(true); $modelObj->attributes = $fData; $modelObj->logo_photo_name = $fData['logo_photo_name']; $modelObj->cover_photo_name = $fData['cover_photo_name']; // echo '<pre>'; var_dump($modelObj); echo '</pre>'; die(); if ($modelObj->validate()) { $modelObj->save(); var_dump($model->getErrors()); } else { die(CVarDumper::dump($modelObj->errors, 10, true)); } $modelObj->business_id; $inserted_records = $inserted_records + 1; } $total_records = $total_records + 1; } while (($line = fgetcsv($fp, 1000, ";")) != FALSE); $msg = $inserted_records . " records are inserted" . " out of " . $total_records; $this->render('import', array('model' => $model, 'total_records' => $total_records, 'inserted_records' => $inserted_records, 'msg' => $msg)); } if ($_POST['Business']['import_option'] == "Update") { do { if ($first_time == true) { $first_time = false; $headerLine = $line; continue; } //$data = explode(",",$line); $data = $line[0]; $data = explode(',', $data); //echo '<pre>'; var_dump($headerLine); echo '</pre>'; die(); $fData = array_combine($headerLine, $data); $email_id = $fData['business_email_id1']; $modelObj = Business::model()->find('business_email_id1=:business_email_id1', array(':business_email_id1' => $email_id)); // echo '<pre>'; var_dump($modelObj); echo '</pre>'; die(); // echo var_dump($modelObj); if ($modelObj) { $modelObj->attributes = $fData; $modelObj->logo_photo_name = $fData['logo_photo_name']; $modelObj->cover_photo_name = $fData['cover_photo_name']; // echo '<pre>'; var_dump($modelObj); echo '</pre>'; die(); $modelObj->save(); $modelObj->business_id; $inserted_records = $inserted_records + 1; } $total_records = $total_records + 1; } while (($line = fgetcsv($fp, 1000, ";")) != FALSE); // echo "count:".$inserted_records.'---'.$total_records; die(); $msg = $inserted_records . " records are updated" . " out of " . $total_records; $this->render('import', array('model' => $model, 'total_records' => $total_records, 'inserted_records' => $inserted_records, 'msg' => $msg)); //$this->redirect('././view'); } } $msg = "Please select insert or update option for import file."; $this->render('import', array('model' => $model, 'total_records' => $total_records, 'inserted_records' => $inserted_records, 'msg' => $msg)); } $msg = "Please upload file."; $this->render('import', array('model' => $model, 'total_records' => $total_records, 'inserted_records' => $inserted_records, 'msg' => $msg)); } $this->render('import', array('model' => $model, 'total_records' => $total_records, 'inserted_records' => $inserted_records, 'msg' => $msg)); }
public function actionLogin() { $model = new LoginForm('Front'); if (isset($_POST['LoginForm'])) { Yii::app()->user->setState("user_type", "BUSINESS"); $model->attributes = $_POST['LoginForm']; if ($model->validate() && $model->login()) { $bussinessId = Business::model()->getBusinessIdByEmail($_POST['LoginForm']['username']); $this->redirect('profile/' . $bussinessId); //$this->render('login',array('model'=>$model)); } } $this->render('login', array('model' => $model)); }
/** * Protected method to load the associated Business model class * @business_id the primary identifier of the associated Business * @return object the Business data model based on the primary key */ protected function loadBusiness($business_id) { //if the project property is null, create it based on input id if ($this->_business === null) { $this->_business = Business::model()->findbyPk($business_id); if ($this->_business === null) { // Temporary error // Will redirect to new business creation page throw new CHttpException(404, 'The requested business does not exist.'); } } return $this->_business; }
public function loadModel($id) { $model = Business::model()->findByPk($id); if ($model === null) { throw new CHttpException(404, Yii::t('app', 'The requested page does not exist.')); } return $model; }
public function _update($data) { $model = new Business(); unset($data['uploadmode']); //echo '<pre>'; var_dump($data); echo '</pre>'; die(); $file = CUploadedFile::getInstance($model, 'csv_file'); if (!empty($file)) { $fp = fopen($file->tempName, 'r'); $row = 1; $headerLine = 1; $r = 0; $dataHead = array(); try { $flag = false; $newrow = 0; if ($fp !== FALSE) { while (($upload_data = fgetcsv($fp)) !== FALSE) { $num = count($upload_data); if ($row !== $headerLine) { if (count($dataHead) == count($upload_data)) { $newData = array_combine($dataHead, $upload_data); $result = Business::model()->findByAttributes(array('business_email_id1' => $newData['business_email_id1'])); $modelObj = Business::model()->findByPk($result['business_id']); if ($modelObj !== NULL) { //unset($newData['business_id']); //echo "<pre>"; var_dump($newData); die(); $modelObj->attributes = $newData; $modelObj->about_us = $newData['about_us']; $modelObj->team_details = $newData['team_details']; $modelObj->logo_photo_name = $newData['logo_photo_name']; $modelObj->cover_photo_name = $newData['cover_photo_name']; if ($modelObj->validate()) { if ($modelObj->save()) { $flag = true; $r++; } } else { die(CVarDumper::dump($modelObj->errors, 10, true)); } } else { $newrow++; $flag = true; } } } else { $dataHead = $upload_data; } $row++; } } //echo '<pre>'; var_dump($_POST['Business']); echo '</pre>'; } catch (Exception $error) { throw new CHttpException(404, 'File can\'t upload. Please check your file'); } } // end if of file is not empty return $r; }