本文整理汇总了PHP中Icon::first方法的典型用法代码示例。如果您正苦于以下问题:PHP Icon::first方法的具体用法?PHP Icon::first怎么用?PHP Icon::first使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Icon
的用法示例。
在下文中一共展示了Icon::first方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: doEditTransfer
public function doEditTransfer($id)
{
$transfer = Auth::user()->transfers()->find($id);
if ($transfer) {
$transfer->amount = floatval(Input::get('amount'));
$transfer->description = Input::get('description');
$transfer->date = Input::get('date');
// account_from (special)
if (!is_null(Input::get('account_from'))) {
$account = Auth::user()->accounts()->find(Input::get('account_from'));
if (!is_null($account)) {
$transfer->account_from = $account->id;
}
}
// account_to (special)
if (!is_null(Input::get('account_to'))) {
$account = Auth::user()->accounts()->find(Input::get('account_to'));
if (!is_null($account)) {
$transfer->account_to = $account->id;
}
}
// category (special)
if (strlen(Input::get('category')) > 0) {
$categories = Auth::user()->categories()->get();
//->where('name','=',Input::get('category'))->first();
$category = null;
foreach ($categories as $cat) {
if (Crypt::decrypt($cat->name) == Input::get('category')) {
$category = $cat;
break;
}
}
unset($cat, $categories);
if (is_null($category)) {
$category = new Category();
$category->fireflyuser_id = Auth::user()->id;
$category->name = Input::get('category');
$category->showtrend = 0;
$category->icon_id = Icon::first()->id;
$validator = Validator::make($category->toArray(), Category::$rules);
if ($validator->passes()) {
$category->name = Crypt::encrypt($category->name);
$category->save();
$transfer->category_id = $category->id;
}
} else {
$transfer->category_id = $category->id;
}
} else {
$transfer->category_id = null;
}
// budget (special)
if (intval(Input::get('budget')) > 0) {
$budget = Auth::user()->budgets()->find(intval(Input::get('budget')));
if (!is_null($budget)) {
$transfer->budget_id = $budget->id;
}
}
// target (special)
if (strlen(Input::get('target')) > 0) {
$targets = Auth::user()->targets()->get();
//->where('name','=',Input::get('category'))->first();
$target = null;
foreach ($targets as $t) {
if (Crypt::decrypt($t->description) == Input::get('target')) {
$transfer->target_id = $t->id;
break;
}
}
unset($targets, $t);
} else {
$transfer->target_id = null;
}
$validator = Validator::make($transfer->toArray(), Transfer::$rules);
$transfer->description = Crypt::encrypt($transfer->description);
if ($validator->fails()) {
return Redirect::to('/home/transfer/edit/' . $transfer->id)->withErrors($validator)->withInput();
} else {
$transfer->save();
return Redirect::to('/home');
}
} else {
App::abort(404);
}
}
示例2: doImport
public function doImport()
{
var_dump($_FILES);
var_dump($_POST);
exit;
define('LESSEVENTS', true);
if (strlen(Input::get('payload_text')) == 0) {
$payload = Input::file('payload');
$raw = File::get($payload);
} else {
$raw = Input::get('payload_text');
}
$json = json_decode($raw, true);
$firstIcon = Icon::first();
$old = array(Auth::user()->accounts()->get(), Auth::user()->budgets()->get(), Auth::user()->categories()->get(), Auth::user()->beneficiaries()->get(), Auth::user()->settings()->get(), Auth::user()->targets()->get());
$mapping = array();
$order = array('account', 'beneficiary', 'budget', 'category', 'target', 'transaction', 'transfer', 'setting');
if (is_null($json)) {
Session::flash('error', 'This is not a valid JSON file.');
return View::make('home.import');
}
foreach ($order as $name) {
$names = Str::plural($name);
foreach ($json[$names] as $item) {
$class = ucfirst($name);
// overrule user ID
if (isset($item['fireflyuser_id'])) {
$item['fireflyuser_id'] = Auth::user()->id;
}
// overrule possible account ID since we might need it here:
if (isset($item['account_id'])) {
$item['account_id'] = $mapping['accounts'][intval($item['account_id'])];
}
// overrule account_from and account_to (only for transfers)
if ($class == 'Transfer') {
$item['account_from'] = $mapping['accounts'][intval($item['account_from'])];
$item['account_to'] = $mapping['accounts'][intval($item['account_to'])];
}
// overrule possible icon ID
if (isset($item['icon_id'])) {
$item['icon_id'] = intval($firstIcon->id);
}
// overrule possible beneficiary ID
if (isset($item['beneficiary_id'])) {
$item['beneficiary_id'] = $mapping['beneficiaries'][intval($item['beneficiary_id'])];
}
// overrule possible category ID
if (isset($item['category_id'])) {
$item['category_id'] = $mapping['categories'][intval($item['category_id'])];
}
// overrule possible budget ID
if (isset($item['budget_id'])) {
$item['budget_id'] = $mapping['budgets'][intval($item['budget_id'])];
}
// overrule possible target ID
if (isset($item['target_id'])) {
$item['target_id'] = $mapping['targets'][intval($item['target_id'])];
}
// overrule due date for targets:
if (isset($item['duedate']) && $item['duedate'] == '0000-00-00') {
$item['duedate'] = null;
}
// remap settings:
if ($class == 'Setting') {
if ($item['name'] == 'defaultCheckingAccount') {
$item['value'] = $mapping['accounts'][intval($item['value'])];
}
if ($item['name'] == 'defaultSavingsAccount') {
$item['value'] = $mapping['accounts'][intval($item['value'])];
}
}
// make validator:
$validator = Validator::make($item, $class::$rules);
// validate!
if ($validator->fails()) {
// fail gracefully, log error:
Log::error('Validator failed on ' . $class . ': ' . print_r($validator->messages()->all(), true));
// show error
Session::flash('error', 'There is invalid ' . $class . ' data in the file.');
return View::make('home.import');
} else {
// create the object, remember the ID.
$object = new $class($item);
// encrypt some fields:
if (isset($object->description)) {
$object->description = Crypt::encrypt($object->description);
}
if (isset($object->name) && $class != 'Setting') {
$object->name = Crypt::encrypt($object->name);
}
if ($class == 'Setting') {
$object->value = Crypt::encrypt($object->value);
}
// save:
$object->save();
// remember the mapping:
$oldID = intval($item['id']);
$newID = intval($object->id);
$mapping[$names][$oldID] = $newID;
}
//.........这里部分代码省略.........
示例3: doEditTransaction
public function doEditTransaction($id)
{
$transaction = Auth::user()->transactions()->find($id);
if ($transaction) {
// set some basic values:
$transaction->amount = floatval(Input::get('amount'));
$transaction->date = Input::get('date');
$transaction->onetime = Input::get('onetime') == 'on' ? 1 : 0;
$transaction->description = Input::get('description');
if (Input::get('type') == 'min') {
$transaction->amount = $transaction->amount * -1;
}
if (!is_null(Input::get('account'))) {
$account = Auth::user()->accounts()->find(Input::get('account'));
if (!is_null($account)) {
$transaction->account_id = $account->id;
}
}
// budget
if (intval(Input::get('budget')) > 0) {
$budget = Auth::user()->budgets()->find(intval(Input::get('budget')));
if (!is_null($budget)) {
$transaction->budget_id = $budget->id;
}
}
// category
if (strlen(Input::get('category')) != 0) {
$categories = Auth::user()->categories()->get();
//->where('name','=',Input::get('category'))->first();
$category = null;
foreach ($categories as $cat) {
if (Crypt::decrypt($cat->name) == Input::get('category')) {
$category = $cat;
break;
}
}
unset($cat, $categories);
if (is_null($category)) {
$category = new Category();
$category->fireflyuser_id = Auth::user()->id;
$category->name = Input::get('category');
$category->showtrend = 0;
$category->icon_id = Icon::first()->id;
// FIXME moet niet hardcoded
$validator = Validator::make($category->toArray(), Category::$rules);
if ($validator->passes()) {
$category->name = Crypt::encrypt($category->name);
$category->save();
$transaction->category_id = $category->id;
}
} else {
$transaction->category_id = $category->id;
}
} else {
$transaction->category_id = null;
}
// beneficiary
if (strlen(Input::get('beneficiary')) != 0) {
$beneficiaries = Auth::user()->beneficiaries()->get();
//->where('name','=',Input::get('beneficiary'))->first();
$beneficiary = null;
foreach ($beneficiaries as $ben) {
if (Crypt::decrypt($ben->name) == Input::get('beneficiary')) {
$beneficiary = $ben;
break;
}
}
unset($ben, $categories);
if (is_null($beneficiary)) {
$beneficiary = new Beneficiary();
$beneficiary->fireflyuser_id = Auth::user()->id;
$beneficiary->name = Input::get('beneficiary');
$validator = Validator::make($beneficiary->toArray(), Beneficiary::$rules);
if ($validator->passes()) {
$beneficiary->name = Crypt::encrypt($beneficiary->name);
$beneficiary->save();
$transaction->beneficiary_id = $beneficiary->id;
}
} else {
$transaction->beneficiary_id = $beneficiary->id;
}
} else {
$transaction->beneficiary_id = null;
}
$validator = Validator::make($transaction->toArray(), Transaction::$rules);
$transaction->description = Crypt::encrypt($transaction->description);
if ($validator->fails()) {
return Redirect::to('/home/transaction/edit/' . $transaction->id)->withErrors($validator)->withInput();
} else {
// work the tags
$tags = explode(',', Input::get('tags'));
$sync = array();
foreach ($tags as $tag) {
$dbTag = Tag::findOrCreate($tag);
$sync[] = $dbTag->id;
}
$transaction->tags()->sync($sync);
$transaction->save();
return Redirect::to('/home/transactions');
}
//.........这里部分代码省略.........