コード例 #1
0
 public function store(Request $request)
 {
     $input = $request->all();
     $unit = Units::findOrFail($input['unit_id']);
     $item = Items::findOrFail($input['item_id']);
     if (array_key_exists('default', $input)) {
         DB::table('item_units')->where(['default' => 1, 'item_id' => $input['item_id']])->update(['default' => 0]);
         $input['default'] = 1;
         DB::statement('INSERT INTO item_units (`item_id`, `unit_id`, `factor`, `default`, `updated_at`, `created_at`) VALUES (' . $input['item_id'] . ', ' . $input['unit_id'] . ', ' . $input['factor'] . ', ' . $input['default'] . ', NOW(), NOW())');
         Helper::add(DB::getPdo()->lastInsertId(), 'added unit ' . $unit->title . ' for item ' . $item->title . ' (ID ' . $input['item_id'] . ')');
         Helper::add(DB::getPdo()->lastInsertId(), 'changed item ' . $item->title . ' (ID ' . $input['item_id'] . ') default unit to ' . $unit->title);
         ItemUnits::where(['item_id' => $input['item_id']])->update(['factor' => DB::raw('factor/' . $input['factor'])]);
         StockItem::where(['item_id' => $input['item_id']])->update(['stock' => DB::raw('stock/' . $input['factor'])]);
         RecipeItems::where(['item_id' => $input['item_id']])->update(['value' => DB::raw('value/' . $input['factor'])]);
         Menu::where(['item_id' => $input['item_id']])->update(['value' => DB::raw('value/' . $input['factor'])]);
         ItemPurchases::where(['item_id' => $input['item_id']])->update(['value' => DB::raw('value/' . $input['factor'])]);
         StockCheck::where(['item_id' => $input['item_id']])->update(['before' => DB::raw('`before` / ' . $input['factor']), 'after' => DB::raw('`after` / ' . $input['factor'])]);
     } else {
         $input['default'] = 0;
         DB::statement('INSERT INTO item_units (`item_id`, `unit_id`, `factor`, `default`, `updated_at`, `created_at`) VALUES (' . $input['item_id'] . ', ' . $input['unit_id'] . ', ' . $input['factor'] . ', ' . $input['default'] . ', NOW(), NOW())');
         Helper::add(DB::getPdo()->lastInsertId(), 'added unit ' . $unit->title . ' for item ' . $item->title . ' (ID ' . $input['item_id'] . ')');
     }
     //Units::create($input);
     Session::flash('flash_message', $this->title . ' successfully added!');
     return Redirect::action('ItemsController@index');
 }
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        DB::transaction(function () {
            $newDate = '2016-01-01 00:00:00';
            if (Schema::hasTable('comments')) {
                if (!Schema::hasColumn('comments', 'companionship_id')) {
                    Schema::table('comments', function (Blueprint $table) {
                        $table->integer('companionship_id')->unsigned()->after('member_id');
                    });
                }
                DB::update('UPDATE comments SET created_at = ?, updated_at = ? WHERE created_at = ?', [$newDate, $newDate, '0000-00-00 00:00:00']);
                DB::update('UPDATE ward_companions SET created_at = ?, updated_at = ? WHERE created_at = ?', [$newDate, $newDate, '0000-00-00 00:00:00']);
                $companionships = DB::select('
					SELECT c.id AS commentId, c.member_id AS commentMemberId, c.companion_id AS commentCompanion, wc.*, c.family_id
					FROM comments AS c
					LEFT JOIN ward_companions AS wc
					ON (ht_one_id = c.member_id OR ht_one_id = c.companion_id)
					AND (ht_two_id = c.member_id OR ht_two_id = c.companion_id)
					ORDER BY commentId ASC');
                $date = '2000-01-01 00:00:00';
                foreach ($companionships as $companionship) {
                    if (empty($companionship->id)) {
                        $member = DB::table('members')->find($companionship->commentMemberId);
                        DB::table('ward_companions')->insert(['ht_one_id' => $companionship->commentMemberId, 'ht_two_id' => $companionship->commentCompanion, 'ward_id' => $member->ward_id, 'district_id' => 0, 'quorum_id' => $member->quorum_id, 'family_id' => $companionship->family_id, 'created_at' => $date, 'updated_at' => $date, 'deleted_at' => $date]);
                        $companionship->id = DB::getPdo()->lastInsertId();
                    }
                    DB::update('UPDATE comments SET companionship_id = ? WHERE id = ?', [$companionship->id, $companionship->commentId]);
                }
                Schema::table('comments', function (Blueprint $table) {
                    $table->dropColumn(['ward_id', 'companion_id']);
                });
            }
        });
    }
コード例 #3
0
 /**
  * Run the database seeds.
  *
  * @return void
  */
 public function run()
 {
     Model::unguard();
     // Creando modulo de contabilidad
     DB::table('modules')->insert([['module_name' => 'Contabilidad']]);
     $idContabilidad = DB::getPdo()->lastInsertId();
     DB::table('modules_permissions')->insert([['module_id' => $idContabilidad, 'display_name' => 'Ver ventas', 'permission' => 'ventas.view'], ['module_id' => $idContabilidad, 'display_name' => 'Ver pendientes', 'permission' => 'pendientes.view'], ['module_id' => $idContabilidad, 'display_name' => 'Ver depositos', 'permission' => 'depositos.view'], ['module_id' => $idContabilidad, 'display_name' => 'Ver cancelaciones', 'permission' => 'cancelaciones.view'], ['module_id' => $idContabilidad, 'display_name' => 'Ver polizas', 'permission' => 'polizas.view'], ['module_id' => $idContabilidad, 'display_name' => 'Ver antigüedad de saldos', 'permission' => 'antiguedad.view'], ['module_id' => $idContabilidad, 'display_name' => 'Ver auxiliar de movimientos', 'permission' => 'auxmovimientos.view'], ['module_id' => $idContabilidad, 'display_name' => 'Ver estado de cuenta', 'permission' => 'estadocuenta.view']]);
 }
コード例 #4
0
 /**
  * Run the database seeds.
  *
  * @return void
  */
 public function run()
 {
     Model::unguard();
     DB::table('modules')->insert([['module_name' => 'Tareas']]);
     $module_id = DB::getPdo()->lastInsertId();
     DB::table('modules_permissions')->insert([['module_id' => $module_id, 'display_name' => 'Ver tareas', 'permission' => 'task.view'], ['module_id' => $module_id, 'display_name' => 'Crear tarea', 'permission' => 'task.create'], ['module_id' => $module_id, 'display_name' => 'Actualizar tarea', 'permission' => 'task.update'], ['module_id' => $module_id, 'display_name' => 'Eliminar tarea', 'permission' => 'task.delete']]);
     // $this->call("OthersTableSeeder");
 }
コード例 #5
0
 /**
  * Store a newly created resource in storage.
  *
  * @return Response
  */
 public function store(Request $request)
 {
     $this->validate($request, ['reason' => 'required|max:500']);
     $input = $request->all();
     WasteReasons::create($input);
     Helper::add(DB::getPdo()->lastInsertId(), 'added new waste reason (ID ' . DB::getPdo()->lastInsertId() . ')');
     Session::flash('flash_message', $this->title . ' successfully added!');
     return Redirect::action('WasteReasonsController@index');
 }
コード例 #6
0
ファイル: Entry.php プロジェクト: grit45/EEISTI-Tournaments
 static function create($entry)
 {
     DB::insert('INSERT INTO Entries(name, real_name, email, id_game, campus, time, id_team, password, is_approved) VALUES (:name, :real_name, :email, :id_game, :campus, :time, :id_team, :password, :is_approved)', $entry);
     $id = DB::getPdo()->lastInsertId();
     //		if (!empty($entry->extra_fields)) {
     //			this.insertFieldEntries($id, $entry->extra_entries);
     //		}
     return $id;
 }
コード例 #7
0
 public function store(Request $request)
 {
     $this->validate($request, ['title' => 'required|unique:unit_groups|max:100']);
     $input = $request->all();
     UnitGroups::create($input);
     Helper::add(DB::getPdo()->lastInsertId(), 'added new unit group ' . $input['title'] . ' (ID ' . DB::getPdo()->lastInsertId() . ')');
     Session::flash('flash_message', $this->title . ' successfully added!');
     return Redirect::action('UnitGroupsController@index');
 }
コード例 #8
0
 /**
  * Store a newly created resource in storage.
  *
  * @return Response
  */
 public function store(Request $request)
 {
     $this->validate($request, ['vat' => 'max:20']);
     $input = $request->all();
     Suppliers::create($input);
     Helper::add(DB::getPdo()->lastInsertId(), 'added new suppliers ' . $input['title'] . ' (ID ' . DB::getPdo()->lastInsertId() . ')');
     Session::flash('flash_message', $this->title . ' successfully added!');
     return Redirect::action('SuppliersController@index');
 }
コード例 #9
0
ファイル: Game.php プロジェクト: grit45/EEISTI-Tournaments
 static function create($game)
 {
     DB::insert('INSERT INTO Games(name, num_players, nickname_field, multicampus) VALUES (:name, :num_players, :nickname_field, :multicampus)', $game);
     $id = DB::getPdo()->lastInsertId();
     //		if (!empty($game->extra_fields)) {
     //			this.insertFields($id, $game->extra_fields);
     //		}
     return $id;
 }
コード例 #10
0
 public function update($id, Request $request)
 {
     $ItemCategories = ItemCategories::findOrFail($id);
     $this->validate($request, ['title' => 'required|max:100']);
     $input = $request->all();
     DB::statement('UPDATE item_categories SET parent_id = ' . ($input['parent_id'] ? $input['parent_id'] : 'NULL') . ', title = "' . $input['title'] . '", updated_at = NOW() WHERE id = ' . $ItemCategories->id);
     Helper::add(DB::getPdo()->lastInsertId(), 'updated items category ' . $input['title']);
     Session::flash('flash_message', $this->title . ' successfully updated!');
     return Redirect::action('ItemCategoriesController@index');
 }
コード例 #11
0
ファイル: ModelBase.php プロジェクト: phamxuancan/truck
 public function insert($input = array())
 {
     foreach ($input as $key => $value) {
         $fieldDB[] = $key;
         $valueData[] = $value;
     }
     $infields = implode(",", $fieldDB);
     $inValues = implode("','", $valueData);
     $insert = app('db')->insert("INSERT INTO {$this->table_name}({$infields}) VALUE ('" . $inValues . "')");
     return DB::getPdo()->lastInsertId();
 }
コード例 #12
0
 /**
  * Store a newly created resource in storage.
  *
  * @return Response
  */
 public function store(Request $request)
 {
     $this->validate($request, ['name' => 'required|unique:users|max:100']);
     $input = $request->all();
     $active = array_key_exists('active', $input) ? 1 : 0;
     $input['active'] = $active;
     $input['password'] = Hash::make($input['password']);
     User::create($input);
     Helper::add(DB::getPdo()->lastInsertId(), 'added user ' . $input['name'] . ' (ID ' . DB::getPdo()->lastInsertId() . ')');
     Session::flash('flash_message', $this->title . ' successfully added!');
     return Redirect::action('UsersController@index');
 }
コード例 #13
0
 /**
  * Store a newly created resource in storage.
  *
  * @return Response
  */
 public function store(Request $request)
 {
     $input = $request->all();
     $recipe = Recipes::findOrFail($input['recipe_id']);
     if ($input['type'] == 'recipe') {
         $item = Recipes::findOrFail($input['sub_recipe']);
     } else {
         $item = Items::findOrFail($input['item_id']);
     }
     RecipeItems::create($input);
     Helper::add(DB::getPdo()->lastInsertId(), 'added ' . $input['type'] . ' ' . $item->title . ' (ID ' . $recipe->id . ') to recipe ' . $recipe->title . ' (ID ' . $recipe->id . ')');
     Session::flash('flash_message', $this->title . ' successfully added!');
     return Redirect::action('RecipeItemsController@index', $request->get('recipe_id'));
 }
コード例 #14
0
 /**
  * Store a newly created resource in storage.
  *
  * @return Response
  */
 public function store(Request $request)
 {
     $input = $request->all();
     $periods = StockPeriods::orderBy('date_from', 'DESC')->get();
     $input['number'] = 1;
     if (count($periods) > 0) {
         $input['number'] = $periods->first()->number + 1;
     }
     if (array_key_exists('last_period', $input)) {
         $last_period = StockPeriods::findOrFail($input['last_period']);
         $last_period->update(['date_to' => $input['date_from']]);
         $last_period->save();
     }
     StockPeriods::create($input);
     Helper::add(DB::getPdo()->lastInsertId(), '');
     return Redirect::action('StockPeriodsController@index');
 }
コード例 #15
0
 public function store(Request $request)
 {
     $this->validate($request, ['title' => 'required|unique:units|max:100']);
     $input = $request->all();
     $group = UnitGroups::findOrFail($input['group_id']);
     if (array_key_exists('default', $input)) {
         DB::table('units')->where(['default' => 1, 'group_id' => $input['group_id']])->update(['default' => 0]);
         $input['default'] = 1;
         Units::create($input);
         Helper::add(DB::getPdo()->lastInsertId(), 'added new unit ' . $input['title'] . ' (ID ' . DB::getPdo()->lastInsertId() . ')');
         Helper::add(DB::getPdo()->lastInsertId(), 'changed default unit to ' . $input['title'] . ' (ID ' . DB::getPdo()->lastInsertId() . ') in group ' . $group->title . ' (ID ' . $group->id . ')');
         Units::where(['group_id' => $input['group_id']])->update(['factor' => DB::raw('factor/' . $input['factor'])]);
     } else {
         Units::create($input);
         Helper::add(DB::getPdo()->lastInsertId(), 'added new unit ' . $input['title'] . ' (ID ' . DB::getPdo()->lastInsertId() . ')');
     }
     Session::flash('flash_message', $this->title . ' successfully added!');
     return Redirect::action('UnitsController@index');
 }
コード例 #16
0
/**
 * Escape strings for mysql
 *
 * @param $string
 * @return string
 */
function dbEscape($string)
{
    return trim(DB::getPdo()->quote($string), '\'');
}
コード例 #17
0
 public function save($params)
 {
     $force = false;
     if (defined('MW_FORCE_USER_SAVE')) {
         $force = MW_FORCE_USER_SAVE;
     } elseif ($this->force_save) {
         $force = $this->force_save;
     } elseif (mw_var('force_save_user')) {
         $force = mw_var('force_save_user');
     }
     if (!$force) {
         if (defined("MW_API_CALL") and mw_is_installed() == true) {
             if (isset($params['is_admin']) and $this->is_admin() == false and !is_null(User::first())) {
                 unset($params['is_admin']);
             }
         }
     }
     if ($force == false) {
         if (isset($params['id']) and $params['id'] != 0) {
             $adm = $this->is_admin();
             if ($adm == false) {
                 $is_logged = user_id();
                 if ($is_logged == false or $is_logged == 0) {
                     return array('error' => 'You must be logged to save user');
                 } elseif (intval($is_logged) == intval($params['id']) and intval($params['id']) != 0) {
                     // the user is editing their own profile
                 } else {
                     return array('error' => 'You must be logged to as admin save this user');
                 }
             }
         } else {
             if (defined('MW_API_CALL') and mw_is_installed() == true) {
                 $adm = $this->is_admin();
                 if ($adm == false) {
                     $params['id'] = $this->id();
                     $is_logged = user_id();
                     if (intval($params['id']) != 0 and $is_logged != $params['id']) {
                         return array('error' => 'You must be logged save your settings');
                     }
                 } else {
                     if (!isset($params['id'])) {
                         $params['id'] = $this->id();
                     }
                 }
             }
         }
     }
     $data_to_save = $params;
     if (isset($data_to_save['id']) and $data_to_save['id'] != 0 and isset($data_to_save['email']) and $data_to_save['email'] != false) {
         $old_user_data = $this->get_by_id($data_to_save['id']);
         if (isset($old_user_data['email']) and $old_user_data['email'] != false) {
             if ($data_to_save['email'] != $old_user_data['email']) {
                 if (isset($old_user_data['password_reset_hash']) and $old_user_data['password_reset_hash'] != false) {
                     $hash_cache_id = md5(serialize($old_user_data)) . uniqid() . rand();
                     $data_to_save['password_reset_hash'] = $hash_cache_id;
                 }
             }
         }
     }
     if (isset($data_to_save['email']) and isset($data_to_save['id'])) {
         $email = trim($data_to_save['email']);
         if (filter_var($email, FILTER_VALIDATE_EMAIL)) {
             $check_existing = array();
             $check_existing['email'] = $email;
             $check_existing['single'] = 1;
             $check_existing = $this->get_all($check_existing);
             if (isset($check_existing['id']) and $check_existing['id'] != $data_to_save['id']) {
                 return array('error' => 'User with this email already exists! Try different email address!');
             }
         }
     }
     if (isset($data_to_save['username']) and $data_to_save['username'] != false and isset($data_to_save['id']) and $data_to_save['id'] != false) {
         $check_existing = array();
         $check_existing['username'] = $data_to_save['username'];
         $check_existing['single'] = 1;
         $check_existing = $this->get_all($check_existing);
         if (isset($check_existing['id']) and $check_existing['id'] != $data_to_save['id']) {
             return array('error' => 'User with this username already exists! Try different username!');
         }
     }
     if (isset($params['id']) and intval($params['id']) != 0) {
         $user = User::find($params['id']);
     } else {
         $user = new User();
     }
     $id_to_return = false;
     $data_to_save = $this->app->format->clean_xss($data_to_save);
     if ($user->validateAndFill($data_to_save)) {
         $save = $user->save();
         if (isset($user->id)) {
             $data_to_save['id'] = $params['id'] = $user->id;
         }
         if (isset($params['attributes']) or isset($params['data_fields'])) {
             $params['extended_save'] = true;
         }
         if (isset($params['extended_save'])) {
             if (isset($data_to_save['password'])) {
                 unset($data_to_save['password']);
             }
             if (isset($data_to_save['id'])) {
                 $data_to_save['table'] = 'users';
                 $this->app->database->extended_save($data_to_save);
             }
         }
         if (isset($params['id']) and intval($params['id']) != 0) {
             $id_to_return = intval($params['id']);
         } else {
             $id_to_return = DB::getPdo()->lastInsertId();
         }
         $params['id'] = $id_to_return;
         $this->app->event_manager->trigger('mw.user.save', $params);
     } else {
         return array('error' => 'Error saving the user!');
     }
     $this->app->cache_manager->delete('users' . DIRECTORY_SEPARATOR . 'global');
     $this->app->cache_manager->delete('users' . DIRECTORY_SEPARATOR . '0');
     $this->app->cache_manager->delete('users' . DIRECTORY_SEPARATOR . $id_to_return);
     return $id_to_return;
 }
コード例 #18
0
 /**
  * Update the specified resource in storage.
  *
  * @param  Request  $request
  * @return Redirect
  */
 public function update($id, Request $request)
 {
     $item = Purchases::findOrFail($id);
     $input = $request->all();
     if (array_key_exists('status', $input)) {
         $input['status'] = 1;
         $input['date_paid'] = date('Y-m-d H:i:s', time());
     } else {
         $input['status'] = 0;
     }
     if ($input['category_id'] == 0) {
         $input['category_id'] = null;
     }
     if (array_key_exists('file', $input)) {
         if ($input['file']->isValid()) {
             $filename = 'invoice_' . date('Y_m_d_His') . '.' . $input['file']->getClientOriginalExtension();
             $input['file']->move(storage_path() . '/upload', $filename);
             $file = Files::create(['filename' => $filename]);
             $input['invoice_id'] = $file->id;
         }
     }
     $currentPeriodId = array_key_exists('stock_period_id', $input) ? $input['stock_period_id'] : Helper::currentPeriodId();
     $input['stock_period_id'] = $currentPeriodId;
     $item->update($input);
     $item->save();
     Helper::add(DB::getPdo()->lastInsertId(), 'updated invoice ID ' . DB::getPdo()->lastInsertId());
     return Redirect::action('ItemPurchasesController@index', $item->id);
 }
コード例 #19
0
 /**
  * Remove the specified resource from storage.
  *
  * @param  int  $id
  * @return Response
  */
 public function destroy($id, Request $request)
 {
     $waste = Wastes::findOrFail($id);
     $waste->delete();
     Helper::add(DB::getPdo()->lastInsertId(), 'deleted waste (ID: ' . DB::getPdo()->lastInsertId() . ')');
     Session::flash('flash_message', $this->title . ' successfully deleted!');
     $input = $request->all();
     $variables = [];
     if (array_key_exists('stock_period', $input)) {
         $variables['stock_period'] = $input['stock_period'];
     }
     return Redirect::action('WastesController@index', $variables);
 }
コード例 #20
0
 public function store(Request $request)
 {
     $input = $request->all();
     $item = Items::findOrFail($input['item_id']);
     $unit = ItemUnits::findOrFail($input['unit_id']);
     $value = $input['value'];
     $default_unit = $item->units()->where(['default' => 1])->first();
     if ($default_unit->id != $input['unit_id']) {
         $value = $unit->factor * $value;
     }
     $currentPeriodId = array_key_exists('stock_period_id', $input) ? $input['stock_period_id'] : Helper::currentPeriodId();
     $stockItem = StockItem::where(['stock_period_id' => $currentPeriodId, 'item_id' => $item->id])->get();
     if (count($stockItem) == 0) {
         $stockItem = StockItem::create(['stock_period_id' => $currentPeriodId, 'item_id' => $item->id, 'stock' => 0]);
     } else {
         $stockItem = $stockItem->first();
     }
     switch ($input['action']) {
         case 'add':
             $new_stock = $stockItem->stock + $value;
             break;
         case 'reduce':
             $new_stock = $stockItem->stock - $value;
             break;
         case 'change':
             $new_stock = $value;
             break;
         default:
             $new_stock = $item->stock + $value;
             break;
     }
     $data = ['item_id' => $item->id, 'unit_id' => $unit->unit()->first()->id, 'value' => $input['value'], 'action' => $input['action'], 'before' => $stockItem->stock, 'after' => $new_stock, 'stock_item_id' => $stockItem->id];
     $stockItem->update(['stock' => $new_stock]);
     $stockItem->save();
     $item->touch();
     StockCheck::create($data);
     Helper::add(DB::getPdo()->lastInsertId(), $input['action'] . 'ed stock for ' . $item->title . ' (ID ' . $item->id . ')' . ' with value ' . $data['value'] . ' ' . $unit->unit()->first()->title . ($default_unit->id != $input['unit_id'] ? ' (' . $value . ' ' . $default_unit->unit()->first()->title . ')' : ''));
     return Redirect::action('StockCheckController@edit', ['item_id' => $item->id, 'stock_period' => $currentPeriodId]);
 }
コード例 #21
0
ファイル: ApiController.php プロジェクト: nelsonsar/lumen-tdd
 /**
  * @param Request $request
  */
 public function newGirl(Request $request)
 {
     $id = $this->girl->create($request->all());
     return DB::getPdo()->lastInsertId();
 }
コード例 #22
0
ファイル: Tp.php プロジェクト: solarcms/table-properties
 public function insert()
 {
     if ($this->permission['c'] != true || $this->just_info == true) {
         return Response::json('permission denied', 400);
     }
     $formData = Request::input('data');
     $translateData = Request::input('translateData');
     $multiItems = Request::input('multiItems');
     $rules = [];
     $insertQuery = $this->hidden_values;
     foreach ($this->form_input_control as $formControl) {
         if ($formControl['type'] == '--group') {
             $rules_pre = $this->getRule($formControl['controls']);
             $rules = array_merge($rules, $rules_pre);
             foreach ($formControl['controls'] as $subformControl) {
                 if ($subformControl['type'] == '--group') {
                 } else {
                     if ($subformControl['type'] == '--checkbox') {
                         $checkBoxValue = $formData[$subformControl['column']];
                         if ($checkBoxValue == 1) {
                             $checkBoxValue = 1;
                         } else {
                             $checkBoxValue = 0;
                         }
                         $insertQuery[$subformControl['column']] = $checkBoxValue;
                     } else {
                         $insertQuery[$subformControl['column']] = $formData[$subformControl['column']];
                     }
                 }
             }
         } else {
             if ($formControl['type'] == '--checkbox') {
                 $checkBoxValue = $formData[$formControl['column']];
                 if ($checkBoxValue == 1) {
                     $checkBoxValue = 1;
                 } else {
                     $checkBoxValue = 0;
                 }
                 $insertQuery[$formControl['column']] = $checkBoxValue;
             } elseif ($formControl['type'] == '--password') {
                 $insertQuery[$formControl['column']] = bcrypt($formData[$formControl['column']]);
             } elseif ($formControl['type'] == '--password-confirm') {
                 //                          /  $insertQuery[$formControl['column']] = bcrypt($multiItem[$formControl['column']]);
             } else {
                 $insertQuery[$formControl['column']] = $formData[$formControl['column']];
             }
         }
     }
     $rules_pre = $this->getRule($this->form_input_control);
     $rules = array_merge($rules, $rules_pre);
     // transltation table save action
     if (!empty($this->translate_form_input_control)) {
         $rules_pre = $this->getRule($this->translate_form_input_control);
         $rules = array_merge($rules, $rules_pre);
         foreach ($this->translate_form_input_control as $translationformControl) {
             $translationformControl['trans_value'] = [];
             foreach ($translateData as $translate) {
                 $translate_value = [];
                 $translate_value['locale'] = $translate['locale'];
                 if ($translationformControl['type'] == '--checkbox') {
                     $checkBoxValue = $formData[$translationformControl['column']];
                     if ($checkBoxValue == 1) {
                         $checkBoxValue = 1;
                     } else {
                         $checkBoxValue = 0;
                     }
                     $translate_value['value'] = $checkBoxValue;
                 } else {
                     $translate_value['value'] = $translate['data'][$translationformControl['column']];
                 }
                 $translationformControl['trans_value'][] = $translate_value;
             }
             $insertQuery[$translationformControl['column']] = json_encode($translationformControl['trans_value']);
         }
     }
     //subitems count
     if (!empty($this->save_sub_items_count)) {
         $posted_sub_items = Request::input('subItems');
         foreach ($posted_sub_items as $posted_sub_item) {
             if ($posted_sub_item['connect_column'] == $this->save_sub_items_count['child_connect_column']) {
                 $subitmesCount = count($posted_sub_item['items']);
                 $insertQuery[$this->save_sub_items_count['parent_column']] = $subitmesCount;
             }
         }
     }
     //timestamp
     if ($this->created_at != null) {
         $insertQuery[$this->created_at] = \Carbon\Carbon::now();
     }
     if ($this->updated_at != null) {
         $insertQuery[$this->updated_at] = \Carbon\Carbon::now();
     }
     $response = null;
     //multi items
     if (!empty($this->multi_items_form_input_control)) {
         $rules_pre = $this->getRule($this->multi_items_form_input_control);
         $rules = array_merge($rules, $rules_pre);
         $checkFirst = 0;
         $insertedId = null;
         foreach ($multiItems as $multiItem) {
             foreach ($this->multi_items_form_input_control as $formControl) {
                 if ($formControl['type'] == '--group') {
                     foreach ($formControl['controls'] as $subformControl) {
                         if ($subformControl['type'] == '--group') {
                         } else {
                             if ($subformControl['type'] == '--checkbox') {
                                 $checkBoxValue = $multiItem[$subformControl['column']];
                                 if ($checkBoxValue == 1) {
                                     $checkBoxValue = 1;
                                 } else {
                                     $checkBoxValue = 0;
                                 }
                                 $insertQuery[$subformControl['column']] = $checkBoxValue;
                             } else {
                                 $insertQuery[$subformControl['column']] = $multiItem[$subformControl['column']];
                             }
                         }
                     }
                 } else {
                     if ($formControl['type'] == '--checkbox') {
                         $checkBoxValue = $multiItem[$formControl['column']];
                         if ($checkBoxValue == 1) {
                             $checkBoxValue = 1;
                         } else {
                             $checkBoxValue = 0;
                         }
                         $insertQuery[$formControl['column']] = $checkBoxValue;
                     } elseif ($formControl['type'] == '--password') {
                         $insertQuery[$formControl['column']] = bcrypt($multiItem[$formControl['column']]);
                     } elseif ($formControl['type'] == '--password-confirm') {
                         //                          /  $insertQuery[$formControl['column']] = bcrypt($multiItem[$formControl['column']]);
                     } else {
                         $insertQuery[$formControl['column']] = $multiItem[$formControl['column']];
                     }
                 }
             }
             if ($checkFirst == 0) {
                 $validator = Validator::make($insertQuery, $rules);
                 if ($validator->fails()) {
                     return Response::json(['errors' => [$validator->messages()]], 400);
                 }
                 if ($this->before_insert != null) {
                     $pre_values = $this->beforeInsertCaller($this->before_insert, $insertQuery);
                     if ($pre_values == 'success') {
                         return Response::json('success', 200);
                     } elseif ($pre_values == 'fail') {
                         return Response::json('before insert error', 400);
                     } else {
                         $insertQuery = array_merge($insertQuery, $pre_values);
                     }
                 }
                 $saved = DB::table($this->table)->insert($insertQuery);
                 $insertedId = DB::getPdo()->lastInsertId();
                 $firstItem[$this->save_first_id_column] = $insertedId;
                 DB::table($this->table)->where($this->identity_name, '=', $insertedId)->update($firstItem);
             } else {
                 $insertQuery[$this->save_first_id_column] = $insertedId;
                 $validator = Validator::make($insertQuery, $rules);
                 if ($validator->fails()) {
                     return Response::json(['errors' => [$validator->messages()]], 400);
                 }
                 if ($this->before_insert != null) {
                     $pre_values = $this->beforeInsertCaller($this->before_insert, $insertQuery);
                     if ($pre_values == 'success') {
                         return Response::json('success', 200);
                     } elseif ($pre_values == 'fail') {
                         return Response::json('before insert error', 400);
                     } else {
                         $insertQuery = array_merge($insertQuery, $pre_values);
                     }
                 }
                 $saved = DB::table($this->table)->insert($insertQuery);
             }
             $checkFirst++;
         }
         $saved = true;
     } else {
         $validator = Validator::make($insertQuery, $rules);
         if ($validator->fails()) {
             return Response::json(['errors' => [$validator->messages()]], 400);
         }
         if ($this->before_insert != null) {
             $pre_values = $this->beforeInsertCaller($this->before_insert, $insertQuery);
             if ($pre_values == 'success') {
                 return Response::json('success', 200);
             } elseif ($pre_values == 'fail') {
                 return Response::json('before insert error', 400);
             } else {
                 $insertQuery = array_merge($insertQuery, $pre_values);
             }
         }
         $saved = DB::table($this->table)->insert($insertQuery);
         $insertedId = DB::getPdo()->lastInsertId();
     }
     if (count($this->subItems) >= 1) {
         $this->saveSubItems($insertedId, $this->subItems, Request::input('subItems'));
     }
     if ($this->generateLocaleFile == true) {
         $this->generateLocale();
     }
     if ($saved) {
         if ($this->insert_response_function == null) {
             return Response::json('success', 200);
         } else {
             $insertQuery['insertedId'] = $insertedId;
             return $this->responseCaller($this->insert_response_function, $insertQuery);
         }
     } else {
         return Response::json('error', 400);
     }
 }
コード例 #23
0
 /**
  * Se prepara la instancia del procedimiento junto con los parámetros de entrada y salida que recibirá.
  */
 private function prepareSql()
 {
     $params = array_merge($this->paramsIn, $this->paramsOut);
     $formatedParams = $this->formatParams($params);
     $this->stmt = DB::getPdo()->prepare("BEGIN {$this->procedure}({$formatedParams}); END;");
 }