Exemple #1
0
 public static function doDelete($id)
 {
     if (is_numeric($id)) {
         SettingSelect::find($id)->delete();
         Setting::reCacheSettings();
     }
 }
 public function doDeleteSettingSelect()
 {
     SettingSelect::doDelete(Input::get("id"));
     return Response::json(array('status' => 'ok', "text" => "Запись успешно удалена"));
 }
Exemple #3
0
 public static function doSaveSetting($data, $file)
 {
     if ($data['id'] == 0) {
         $settings = new Setting();
     } else {
         $settings = Setting::find($data['id']);
     }
     $settings->title = $data['title'];
     $settings->slug = $data['slug'];
     $settings->type = $data['type'];
     $settings->group_type = $data['group'];
     if ($data['type'] < 2 || $data['type'] == 6) {
         $settings->value = $data['value' . $data['type']];
     }
     //yes/no
     if ($data['type'] == 7) {
         $settings->value = $data['status'];
     }
     //если тип файл
     if ($data['type'] == 4 && $file) {
         $destinationPath = "storage/settings";
         $ext = $file->getClientOriginalExtension();
         $hashname = md5(time()) . '.' . $ext;
         $full_path_img = "/" . $destinationPath . '/' . $hashname;
         $upload_success = $file->move($destinationPath, $hashname);
         $settings->value = $full_path_img;
     }
     $settings->save();
     //если тип список
     if ($data['type'] == 2) {
         $i = 0;
         foreach ($data['select'] as $k => $el) {
             $i++;
             if ($el) {
                 if (is_numeric($k)) {
                     $el = trim($el);
                     if ($el) {
                         $SettingSelect = SettingSelect::find($k);
                         $SettingSelect->id_setting = $settings->id;
                         $SettingSelect->value = $el;
                         $SettingSelect->priority = $i;
                         $SettingSelect->save();
                     }
                 } else {
                     foreach ($data['select']['new'] as $el_new) {
                         $el_new = trim($el_new);
                         if ($el_new) {
                             $SettingSelect = new SettingSelect();
                             $SettingSelect->id_setting = $settings->id;
                             $SettingSelect->value = $el_new;
                             $SettingSelect->priority = $i;
                             $SettingSelect->save();
                             $i++;
                         }
                     }
                 }
             }
         }
     }
     //если тип двойной список
     if ($data['type'] == 3) {
         $i = 0;
         foreach ($data['select21'] as $k => $el) {
             $i++;
             if ($el) {
                 if (is_numeric($k)) {
                     $el = trim($el);
                     if ($el) {
                         $SettingSelect = SettingSelect::find($k);
                         $SettingSelect->id_setting = $settings->id;
                         $SettingSelect->value = $el;
                         $SettingSelect->value2 = $data['select22'][$k];
                         $SettingSelect->priority = $i;
                         $SettingSelect->save();
                     }
                 } else {
                     foreach ($data['select21']['new'] as $k_new => $el_new) {
                         $el_new = trim($el_new);
                         if ($el_new) {
                             $SettingSelect = new SettingSelect();
                             $SettingSelect->id_setting = $settings->id;
                             $SettingSelect->value = $el_new;
                             $SettingSelect->value2 = $data['select22']['new'][$k_new];
                             $SettingSelect->priority = $i;
                             $SettingSelect->save();
                             $i++;
                         }
                     }
                 }
             }
         }
     }
     //если тройной список
     if ($data['type'] == 5) {
         $i = 0;
         foreach ($data['select31'] as $k => $el) {
             $i++;
             if ($el) {
                 if (is_numeric($k)) {
                     $el = trim($el);
                     if ($el) {
                         $SettingSelect = SettingSelect::find($k);
                         $SettingSelect->id_setting = $settings->id;
                         $SettingSelect->value = $el;
                         $SettingSelect->value2 = $data['select32'][$k];
                         $SettingSelect->value3 = $data['select33'][$k];
                         $SettingSelect->priority = $i;
                         $SettingSelect->save();
                     }
                 } else {
                     foreach ($data['select31']['new'] as $k_new => $el_new) {
                         $el_new = trim($el_new);
                         if ($el_new) {
                             $SettingSelect = new SettingSelect();
                             $SettingSelect->id_setting = $settings->id;
                             $SettingSelect->value = $el_new;
                             $SettingSelect->value2 = $data['select32']['new'][$k_new];
                             $SettingSelect->value3 = $data['select33']['new'][$k_new];
                             $SettingSelect->priority = $i;
                             $SettingSelect->save();
                             $i++;
                         }
                     }
                 }
             }
         }
     }
     Setting::reCacheSettings();
     if ($data['id'] == 0) {
         Event::fire("setting.created", array($settings));
     } else {
         Event::fire("setting.changed", array($settings));
     }
     return $settings;
 }