';
+ block.append(sub_block);
+
+});
\ No newline at end of file
diff --git a/backend/web/js/option.js b/backend/web/js/option.js
index 384a1dd..1786a9a 100755
--- a/backend/web/js/option.js
+++ b/backend/web/js/option.js
@@ -58,55 +58,55 @@ $(function() {
}
return false;
});
- //$.each($('.nav-tabs.f32'), function(key, value) {
- // if($(value).find('li').length > 1) {
- // $(value).find('li').append('
');
- // }
- //});
- //$(document).on('click', '.dropdown-menu.f32:not(.old) li a[data-lang]', function() {
- // var lang = $(this).data('lang');
- // var flag = $(this).find('span').first().clone();
- // var el = $(this);
- // var id = $(this).attr('href').substr(1);
- // var path = form[id].handler;
- // var view = form[id].view;
- // var model = form[id].model;
- // $.get(path, { language_id: lang, widget_id: id, ajaxView: view, model: model }, function(data) {
- // $('#'+id+'-tabs li').removeClass('active');
- // $('#'+id+'-tabs').append('
'+$('').append($(flag)).html()+'
');
- // $('#tab-content-'+id+' .tab-pane.active').removeClass('active');
- // $('#tab-content-'+id).append($(data).find('.ajax-loaded').first());
- // $('body').append($(data).filter('script'));
- // $(el).parent().remove();
- // if(!$('#lang-'+id+' li').length) {
- // $('#'+id+'Lang').addClass('disabled');
- // }
- // if($('#'+id+'-tabs li').length > 1) {
- // $('#'+id+'-tabs li').append('
')
- // }
- // });
- //});
- //$(document).on('click', '.dropdown-menu.f32.old li a[data-lang]', function(e) {
- // e.preventDefault();
- // var lang = $(this).data('lang');
- // var flag = $(this).find('span').first().clone();
- // var el = $(this);
- // var id = $(this).attr('href').substr(1);
- // $.get(form[id], { language_id: lang, widget_id: id }, function(data) {
- // $('#'+id+'-tabs li').removeClass('active');
- // $('#'+id+'-tabs').append('
'+$('').append($(flag)).html()+'
');
- // $('#tab-content-'+id+' .tab-pane.active').removeClass('active');
- // $('#tab-content-'+id).append($(data).find('.ajax-loaded').first());
- // $('body').append($(data).filter('script'));
- // $(el).parent().remove();
- // if(!$('#lang-'+id+' li').length) {
- // $('#'+id+'Lang').addClass('disabled');
- // }
- // if($('#'+id+'-tabs li').length > 1) {
- // $('#'+id+'-tabs li').append('
')
- // }
- // });
- //});
+ $.each($('.nav-tabs.f32'), function(key, value) {
+ if($(value).find('li').length > 1) {
+ $(value).find('li').append('
');
+ }
+ });
+ $(document).on('click', '.dropdown-menu.f32:not(.old) li a[data-lang]', function() {
+ var lang = $(this).data('lang');
+ var flag = $(this).find('span').first().clone();
+ var el = $(this);
+ var id = $(this).attr('href').substr(1);
+ var path = form[id].handler;
+ var view = form[id].view;
+ var model = form[id].model;
+ $.get(path, { language_id: lang, widget_id: id, ajaxView: view, model: model }, function(data) {
+ $('#'+id+'-tabs li').removeClass('active');
+ $('#'+id+'-tabs').append('
'+$('').append($(flag)).html()+'
');
+ $('#tab-content-'+id+' .tab-pane.active').removeClass('active');
+ $('#tab-content-'+id).append($(data).find('.ajax-loaded').first());
+ $('body').append($(data).filter('script'));
+ $(el).parent().remove();
+ if(!$('#lang-'+id+' li').length) {
+ $('#'+id+'Lang').addClass('disabled');
+ }
+ if($('#'+id+'-tabs li').length > 1) {
+ $('#'+id+'-tabs li').append('
')
+ }
+ });
+ });
+ $(document).on('click', '.dropdown-menu.f32.old li a[data-lang]', function(e) {
+ e.preventDefault();
+ var lang = $(this).data('lang');
+ var flag = $(this).find('span').first().clone();
+ var el = $(this);
+ var id = $(this).attr('href').substr(1);
+ $.get(form[id], { language_id: lang, widget_id: id }, function(data) {
+ $('#'+id+'-tabs li').removeClass('active');
+ $('#'+id+'-tabs').append('
'+$('').append($(flag)).html()+'
');
+ $('#tab-content-'+id+' .tab-pane.active').removeClass('active');
+ $('#tab-content-'+id).append($(data).find('.ajax-loaded').first());
+ $('body').append($(data).filter('script'));
+ $(el).parent().remove();
+ if(!$('#lang-'+id+' li').length) {
+ $('#'+id+'Lang').addClass('disabled');
+ }
+ if($('#'+id+'-tabs li').length > 1) {
+ $('#'+id+'-tabs li').append('
')
+ }
+ });
+ });
$(document).on('click', '.remove-lang', function() {
var lang = $(this).parent().data('lang');
var flag = $(this).parent().find('span.flag').first().clone();
diff --git a/common/models/Fields.php b/common/models/Fields.php
index df68eb2..243ed4b 100644
--- a/common/models/Fields.php
+++ b/common/models/Fields.php
@@ -13,6 +13,9 @@ use Yii;
* @property string $value
* @property string $field_name
* @property string $field_type
+ * @property string $language
+ * @property string $parent_key
+ * @property string $key
*/
class Fields extends \yii\db\ActiveRecord
{
@@ -31,8 +34,8 @@ class Fields extends \yii\db\ActiveRecord
{
return [
[['table_name', 'table_id',], 'required'],
- [['table_id','language'], 'integer'],
- [['table_name', 'value', 'field_name','field_type'], 'string', 'max' => 255]
+ [['table_id','parent_key','key'], 'integer'],
+ [['table_name', 'value', 'field_name','field_type','language'], 'string', 'max' => 255]
];
}
@@ -54,4 +57,44 @@ class Fields extends \yii\db\ActiveRecord
public static function getData($id, $model, $type){
return self::find()->where(['table_id'=>$id, 'table_name'=>$model, 'field_type'=>$type])->all();
}
+
+
+ /**
+ * @param $post - array with field data
+ * @param $table_id - row id in model table
+ * @param $table_name - madel table name
+ * @param $language - language id
+ */
+
+ public static function saveFieldData($post,$table_id,$table_name, $language){
+
+ self::deleteAll(['table_id'=>$table_id, 'table_name'=>$table_name, 'language' => $language]);
+
+ if($post){
+
+
+ foreach($post as $k => $field){
+
+
+
+ foreach($field as $parent_key => $row){
+
+ foreach($row as $key => $value){
+
+ $field_model = new Fields();
+ $field_model->field_name = array_keys($value)[0];
+ $field_model->value = $value[array_keys($value)[0]];
+ $field_model->table_name = $table_name;
+ $field_model->table_id = $table_id;
+ $field_model->field_type = $k;
+ $field_model->language = 'ru';
+ $field_model->parent_key = $parent_key;
+ $field_model->key = $key;
+ $field_model->save();
+ }
+
+ }
+ }
+ }
+ }
}
diff --git a/common/models/User.php b/common/models/User.php
index 3f28841..b199db1 100755
--- a/common/models/User.php
+++ b/common/models/User.php
@@ -254,9 +254,13 @@ class User extends ActiveRecord implements IdentityInterface, UserRbacInterface
}
}
- public function afterSave ($insert, $changedAttributes)
- {
- parent::afterSave ($insert, $changedAttributes);
- \Yii::$app->options->createOptions($this->id);
+// public function afterSave ($insert, $changedAttributes)
+// {
+// parent::afterSave ($insert, $changedAttributes);
+// \Yii::$app->options->createOptions($this->id);
+// }
+
+ public function getUserInfo(){
+ return $this->hasOne(UserInfo::className(), ['user_id' => 'id']);
}
}
diff --git a/common/widgets/FieldEditor.php b/common/widgets/FieldEditor.php
index 7373c05..b939584 100644
--- a/common/widgets/FieldEditor.php
+++ b/common/widgets/FieldEditor.php
@@ -3,7 +3,7 @@ namespace common\widgets;
use common\models\Fields;
use common\models\Language;
use yii\base\Widget;
-
+use yii\helpers\ArrayHelper;
class FieldEditor extends Widget
{
@@ -27,19 +27,18 @@ class FieldEditor extends Widget
$widgetData= [new Fields()];
}
-
- return $this->render($this->template.'_field',['model'=>$widgetData]);
+ return $this->render($this->template.'_field',['model'=>ArrayHelper::toArray($widgetData)]);
}
protected function findModel()
{
+
if (($model = Fields::find()->where([
'table_id'=>$this->item_id,
'table_name'=>$this->model,
'field_type'=>$this->template,
'language'=>$this->language,
])->all())) {
-
return $model;
} else {
diff --git a/common/widgets/views/education_field.php b/common/widgets/views/education_field.php
index 94abd72..e8eca71 100644
--- a/common/widgets/views/education_field.php
+++ b/common/widgets/views/education_field.php
@@ -3,23 +3,42 @@ use yii\helpers\Html;
?>
+
+
diff --git a/console/migrations/m160128_101543_fields.php b/console/migrations/m160128_101543_fields.php
index cb5e337..cb49e9e 100644
--- a/console/migrations/m160128_101543_fields.php
+++ b/console/migrations/m160128_101543_fields.php
@@ -15,7 +15,9 @@ class m160128_101543_fields extends Migration
'value' => $this->string(255),
'field_name' => $this->string(),
'field_type' => $this->string(32)->notNull(),
- 'language' => $this->string(3)
+ 'language' => $this->string(3),
+ 'key' => $this->integer(),
+ 'parent_key' => $this->integer()
], $tableOptions);
}
diff --git a/frontend/assets/AdminAsset.php b/frontend/assets/AdminAsset.php
index 12d7393..3b345b9 100755
--- a/frontend/assets/AdminAsset.php
+++ b/frontend/assets/AdminAsset.php
@@ -30,7 +30,7 @@ class AdminAsset extends AssetBundle
'js/jquery.scrollbox.min.js',
'js/slider.js',
'js/jquery.rating.js',
- '/admin/js/option.js'
+ '/admin/js/fieldWidget.js'
];
public $depends = [
'yii\web\YiiAsset',
diff --git a/frontend/controllers/AccountsController.php b/frontend/controllers/AccountsController.php
index 78bbd08..d62641b 100755
--- a/frontend/controllers/AccountsController.php
+++ b/frontend/controllers/AccountsController.php
@@ -1,6 +1,7 @@
findUser(Yii::$app->user->identity->id);
- $user_info = $this->findUserInfo(Yii::$app->user->identity->id);
-
$langs = Language::getActiveLanguages();
+ if ($user->load(Yii::$app->request->post()) && $user->save()) {
+ $user->userInfo->load(Yii::$app->request->post());
+ $user->userInfo->save();
+ Fields::saveFieldData( Yii::$app->request->post('Fields'), $user->id, $user::className());
+ return $this->render('cabinet', [
+ 'user' => $user,
+ 'user_info' => $user->userInfo,
+ 'langs' => $langs,
+ ]);
+
+ } else {
- return $this->render('cabinet', [
- 'user' => $user,
- 'user_info' => $user_info,
- 'langs' => $langs,
- ]);
+ return $this->render('cabinet', [
+ 'user' => $user,
+ 'user_info' => $user->userInfo,
+ 'langs' => $langs,
+ ]);
+ }
}
@@ -65,12 +76,15 @@ class AccountsController extends Controller
}
-
-
+ /**
+ * @param $id
+ * @return User
+ * @throws NotFoundHttpException
+ */
protected function findUser($id)
{
- if (($model = User::findOne(["id"=>$id])) !== null) {
+ if ($model = User::findOne(["id"=>$id])) {
return $model;
} else {
throw new NotFoundHttpException('The requested page does not exist.');
@@ -79,15 +93,4 @@ class AccountsController extends Controller
- protected function findUserInfo($id)
- {
-
- if (($model = UserInfo::findOne(["user_id"=>$id])) !== null) {
- return $model;
- } else {
- throw new NotFoundHttpException('The requested page does not exist.');
- }
- }
-
-
}
diff --git a/frontend/controllers/SiteController.php b/frontend/controllers/SiteController.php
index ff76c66..c3449d1 100755
--- a/frontend/controllers/SiteController.php
+++ b/frontend/controllers/SiteController.php
@@ -94,70 +94,70 @@ class SiteController extends Controller
}
// creat new model table Social and new model User
- $social = new Social();
- $user = new User();
-
- $serviceName = Yii::$app->getRequest()->getQueryParam('service');
-
- if (isset($serviceName)) {
- /** @var $eauth \nodge\eauth\ServiceBase */
- $eauth = Yii::$app->get('eauth')->getIdentity($serviceName);
- $eauth->setRedirectUrl(Yii::$app->getUser()->getReturnUrl());
- $eauth->setCancelUrl(Yii::$app->getUrlManager()->createAbsoluteUrl('site/login'));
-
- try {
- if ($eauth->authenticate()) {
- $identity = User::findByEAuth($eauth);
- Yii::$app->getUser()->login($identity);
-
- //Save date get social network in database
- if (! $social::find()->where(['social_user_id' => $identity[profile][id], 'social_name' => $identity[profile][service]])->exists()) {
- $name = explode(' ',$identity[profile][name]);
- $user->firstname = $name[0];
- $user->lastname = $name[1];
- $user->id_system_date = date("d.m.y.H:i:s");
- $user->save();
- $social->social_name = $identity[profile][service];
- $social->social_user_id = $identity[profile][id];
- $social->user_id = $user->id;
- $social->validate();
- $social->errors;
- $social->save();
- }
-
- // special redirect with closing popup window
- $eauth->redirect();
- }
- else {
- // close popup window and redirect to cancelUrl
- $eauth->cancel();
- }
- }
- catch (\nodge\eauth\ErrorException $e) {
- // save error to show it later
- Yii::$app->getSession()->setFlash('error', 'EAuthException: '.$e->getMessage());
-
- // close popup window and redirect to cancelUrl
- // $eauth->cancel();
- $eauth->redirect($eauth->getCancelUrl());
- }
- }
-
-
-
-
- if (!\Yii::$app->user->isGuest) {
- return $this->goHome();
- }
-
- $model = new LoginForm();
- if ($model->load(Yii::$app->request->post()) && $model->login()) {
- return $this->goBack();
- } else {
- return $this->render('login', [
- 'model' => $model,
- ]);
- }
+// $social = new Social();
+// $user = new User();
+//
+// $serviceName = Yii::$app->getRequest()->getQueryParam('service');
+//
+// if (isset($serviceName)) {
+// /** @var $eauth \nodge\eauth\ServiceBase */
+// $eauth = Yii::$app->get('eauth')->getIdentity($serviceName);
+// $eauth->setRedirectUrl(Yii::$app->getUser()->getReturnUrl());
+// $eauth->setCancelUrl(Yii::$app->getUrlManager()->createAbsoluteUrl('site/login'));
+//
+// try {
+// if ($eauth->authenticate()) {
+// $identity = User::findByEAuth($eauth);
+// Yii::$app->getUser()->login($identity);
+//
+// //Save date get social network in database
+// if (! $social::find()->where(['social_user_id' => $identity[profile][id], 'social_name' => $identity[profile][service]])->exists()) {
+// $name = explode(' ',$identity[profile][name]);
+// $user->firstname = $name[0];
+// $user->lastname = $name[1];
+// $user->id_system_date = date("d.m.y.H:i:s");
+// $user->save();
+// $social->social_name = $identity[profile][service];
+// $social->social_user_id = $identity[profile][id];
+// $social->user_id = $user->id;
+// $social->validate();
+// $social->errors;
+// $social->save();
+// }
+//
+// // special redirect with closing popup window
+// $eauth->redirect();
+// }
+// else {
+// // close popup window and redirect to cancelUrl
+// $eauth->cancel();
+// }
+// }
+// catch (\nodge\eauth\ErrorException $e) {
+// // save error to show it later
+// Yii::$app->getSession()->setFlash('error', 'EAuthException: '.$e->getMessage());
+//
+// // close popup window and redirect to cancelUrl
+// // $eauth->cancel();
+// $eauth->redirect($eauth->getCancelUrl());
+// }
+// }
+//
+//
+//
+//
+// if (!\Yii::$app->user->isGuest) {
+// return $this->goHome();
+// }
+//
+// $model = new LoginForm();
+// if ($model->load(Yii::$app->request->post()) && $model->login()) {
+// return $this->goBack();
+// } else {
+// return $this->render('login', [
+// 'model' => $model,
+// ]);
+// }
}
/**
diff --git a/frontend/views/accounts/_form.php b/frontend/views/accounts/_form.php
index 689d820..e98f755 100644
--- a/frontend/views/accounts/_form.php
+++ b/frontend/views/accounts/_form.php
@@ -17,16 +17,10 @@ use yii\widgets\ActiveForm;
= $form->field($user_info, 'user_id')->textInput() ?>
-= $form->field($user_info, 'view_count')->textInput() ?>
-
= $form->field($user_info, 'busy')->textInput(['maxlength' => true]) ?>
-= $form->field($user_info, 'date_visit')->textInput() ?>
-
= $form->field($user_info, 'experience')->textInput() ?>
-= $form->field($user_info, 'rank')->textInput(['maxlength' => true]) ?>
-
= $form->field($user_info, 'salary')->textInput(['maxlength' => true]) ?>
= $form->field($user_info, 'job')->textInput(['maxlength' => true]) ?>
@@ -52,8 +46,8 @@ use yii\widgets\ActiveForm;
= \common\widgets\FieldEditor::widget([
'template'=>'education',
'item_id'=> $user->id,
- 'model'=>'User',
- 'language'=>'ru'
+ 'model'=>'common\models\User',
+ 'language'=>'0'
]); ?>
--
libgit2 0.21.4