public static function assignTarget($from_user_id, $to_user_id) { $target = new Target(); $target->setFromUserId($from_user_id); $target->setToUserId($to_user_id); $target->save(); }
public function fire($job, $data) { $file = Config::get('projeter.upload_path') . $data['file']; Log::info("Starting to add {$data['target']} to database (File: {$file})"); $target = new Target(); $target->name = $data['target']; $target->save(); $reader = new \EasyCSV\Reader($file); // There must be a Email field in CSV file /*if(!in_array('Email', $reader->getHeaders() )) throw new Exception("Email field not found", 1);*/ while ($row = $reader->getRow()) { Log::info("Adding {$row['Email']} to the target {$data['target']}"); $mailing = new Mailing(); $mailing->target()->associate($target); $mailing->email = $row['Email']; $mailing->save(); } Log::info("Mailing list {$target->name} added to database"); $job->delete(); }
public function doOldImport() { DB::delete('DELETE FROM `cache`'); // delete old data: foreach (Auth::user()->accounts()->get() as $acc) { $acc->delete(); } foreach (Auth::user()->budgets()->get() as $b) { $b->delete(); } foreach (Auth::user()->categories()->get() as $b) { $b->delete(); } foreach (Auth::user()->beneficiaries()->get() as $b) { $b->delete(); } foreach (Icon::get() as $icon) { $icon->delete(); } $data = file_get_contents('http://commondatastorage.googleapis.com/nder/import.json'); $json = json_decode($data); $map = array(); $map['accounts'] = array(); $map['icons'] = array(); // all accounts: foreach ($json->accounts as $account) { $newAccount = new Account(); $newAccount->name = Crypt::encrypt($account->name); $newAccount->balance = floatval($account->balance); $newAccount->fireflyuser_id = Auth::user()->id; $newAccount->date = $account->date; $newAccount->save(); $map['accounts'][$account->id] = $newAccount->id; } // all icons: foreach ($json->icons as $icon) { $newIcon = new Icon(); $newIcon->file = $icon->file; $newIcon->save(); $map['icons'][intval($icon->id)] = $newIcon->id; } // all beneficiaries: foreach ($json->beneficiaries as $ben) { $nb = new Beneficiary(); $nb->fireflyuser_id = Auth::user()->id; $nb->name = Crypt::encrypt($ben->name); $nb->save(); $map['beneficiaries'][$ben->id] = $nb->id; } // all budgets foreach ($json->budgets as $bd) { $nbg = new Budget(); $nbg->fireflyuser_id = Auth::user()->id; $nbg->name = Crypt::encrypt($bd->name); $nbg->date = $bd->date; $nbg->amount = floatval($bd->amount); $nbg->save(); $map['budgets'][$bd->id] = $nbg->id; } // all categories: foreach ($json->categories as $c) { $nc = new Category(); $nc->fireflyuser_id = Auth::user()->id; $nc->icon_id = intval($map['icons'][intval($c->icon_id)]); $nc->name = Crypt::encrypt($c->name); $nc->showtrend = intval($c->showtrend); $nc->save(); $map['categories'][$c->id] = $nc->id; } foreach ($json->targets as $t) { $nt = new Target(); $nt->fireflyuser_id = Auth::user()->id; $nt->account_id = $map['accounts'][$t->account_id]; $nt->description = Crypt::encrypt($t->description); $nt->amount = floatval($t->amount); $nt->duedate = $t->duedate; $nt->startdate = $t->startdate; $nt->save(); $map['targets'][$t->id] = $nt->id; } foreach ($json->transactions as $t) { $nt = new Transaction(); $nt->fireflyuser_id = Auth::user()->id; $nt->account_id = $map['accounts'][$t->account_id]; $nt->budget_id = is_null($t->budget_id) ? NULL : intval($map['budgets'][$t->budget_id]); $nt->category_id = is_null($t->category_id) ? NULL : $map['categories'][$t->category_id]; $nt->beneficiary_id = is_null($t->beneficiary_id) ? NULL : $map['beneficiaries'][$t->beneficiary_id]; $nt->description = Crypt::encrypt($t->description); $nt->amount = floatval($t->amount); $nt->date = $t->date; $nt->onetime = intval($t->onetime); $nt->save(); $map['transactions'][$t->id] = $nt->id; } foreach ($json->transfers as $t) { $nt = new Transfer(); $nt->fireflyuser_id = Auth::user()->id; $nt->account_from = $map['accounts'][$t->account_from]; $nt->account_to = $map['accounts'][$t->account_to]; $nt->category_id = is_null($t->category_id) ? NULL : $map['categories'][$t->category_id]; $nt->budget_id = is_null($t->budget_id) ? NULL : intval($map['budgets'][$t->budget_id]); $nt->target_id = is_null($t->target_id) ? NULL : intval($map['targets'][$t->target_id]); $nt->description = Crypt::encrypt($t->description); $nt->amount = floatval($t->amount); $nt->date = $t->date; $nt->save(); $map['targets'][$t->id] = $nt->id; } // //var_dump($data); // create everything from this file. // we map the old id's to the new one to save problems. return 'Old data successfully imported.'; }
public function newTarget() { $target = new Target(); $target->amount = floatval(Input::get('amount')); $target->description = Input::get('description'); $target->fireflyuser_id = Auth::user()->id; $target->duedate = Input::get('duedate'); $target->startdate = Input::get('startdate'); $target->closed = 0; if (!is_null(Input::get('account'))) { $account = Auth::user()->accounts()->find(Input::get('account')); if (!is_null($account)) { $target->account_id = $account->id; } } $validator = Validator::make($target->toArray(), Target::$rules); $target->description = Crypt::encrypt($target->description); if ($validator->fails()) { return Redirect::to('/home/target/add')->withErrors($validator)->withInput(); } else { $target->save(); return Redirect::to('/home'); } }