本文整理汇总了PHP中app\helpers\Helper::array_smart_fetch方法的典型用法代码示例。如果您正苦于以下问题:PHP Helper::array_smart_fetch方法的具体用法?PHP Helper::array_smart_fetch怎么用?PHP Helper::array_smart_fetch使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类app\helpers\Helper
的用法示例。
在下文中一共展示了Helper::array_smart_fetch方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: postImportHistory
/**
* Import history
*
* This needs a LOT of love. It's done very inelegantly right now, and there are
* a ton of optimizations that could (and should) be done.
*
* @author [A. Gianotto] [<snipe@snipe.net>]
* @since [v3.3]
* @return View
*/
public function postImportHistory(Request $request)
{
if (!ini_get("auto_detect_line_endings")) {
ini_set("auto_detect_line_endings", '1');
}
$assets = Asset::all(['asset_tag']);
$csv = Reader::createFromPath(Input::file('user_import_csv'));
$csv->setNewline("\r\n");
//get the first row, usually the CSV header
//$headers = $csv->fetchOne();
$results = $csv->fetchAssoc();
$item = array();
$status = array();
foreach ($results as $row) {
if (is_array($row)) {
$row = array_change_key_case($row, CASE_LOWER);
$asset_tag = Helper::array_smart_fetch($row, "asset tag");
if (!array_key_exists($asset_tag, $item)) {
$item[$asset_tag] = array();
}
$batch_counter = count($item[$asset_tag]);
$item[$asset_tag][$batch_counter]['checkout_date'] = Carbon::parse(Helper::array_smart_fetch($row, "date"))->format('Y-m-d H:i:s');
$item[$asset_tag][$batch_counter]['asset_tag'] = Helper::array_smart_fetch($row, "asset tag");
$item[$asset_tag][$batch_counter]['name'] = Helper::array_smart_fetch($row, "name");
$item[$asset_tag][$batch_counter]['email'] = Helper::array_smart_fetch($row, "email");
$asset = Asset::where('asset_tag', '=', $asset_tag)->first();
$item[$asset_tag][$batch_counter]['asset_id'] = $asset->id;
$base_username = User::generateFormattedNameFromFullName(Setting::getSettings()->username_format, $item[$asset_tag][$batch_counter]['name']);
$user = User::where('username', '=', $base_username['username']);
$user_query = ' on username ' . $base_username['username'];
if ($request->input('match_firstnamelastname') == '1') {
$firstnamedotlastname = User::generateFormattedNameFromFullName('firstname.lastname', $item[$asset_tag][$batch_counter]['name']);
$item[$asset_tag][$batch_counter]['username'][] = $firstnamedotlastname['username'];
$user->orWhere('username', '=', $firstnamedotlastname['username']);
$user_query .= ', or on username ' . $firstnamedotlastname['username'];
}
if ($request->input('match_flastname') == '1') {
$flastname = User::generateFormattedNameFromFullName('filastname', $item[$asset_tag][$batch_counter]['name']);
$item[$asset_tag][$batch_counter]['username'][] = $flastname['username'];
$user->orWhere('username', '=', $flastname['username']);
$user_query .= ', or on username ' . $flastname['username'];
}
if ($request->input('match_firstname') == '1') {
$firstname = User::generateFormattedNameFromFullName('firstname', $item[$asset_tag][$batch_counter]['name']);
$item[$asset_tag][$batch_counter]['username'][] = $firstname['username'];
$user->orWhere('username', '=', $firstname['username']);
$user_query .= ', or on username ' . $firstname['username'];
}
if ($request->input('match_email') == '1') {
if ($item[$asset_tag][$batch_counter]['email'] == '') {
$item[$asset_tag][$batch_counter]['username'][] = $user_email = User::generateEmailFromFullName($item[$asset_tag][$batch_counter]['name']);
$user->orWhere('username', '=', $user_email);
$user_query .= ', or on username ' . $user_email;
}
}
// A matching user was found
if ($user = $user->first()) {
$item[$asset_tag][$batch_counter]['checkedout_to'] = $user->id;
$status['success'][] = 'Found user ' . Helper::array_smart_fetch($row, "name") . $user_query;
if ($asset) {
$item[$asset_tag][$batch_counter]['user_id'] = $user->id;
Actionlog::firstOrCreate(array('asset_id' => $asset->id, 'asset_type' => 'hardware', 'user_id' => Auth::user()->id, 'note' => 'Checkout imported by ' . Auth::user()->fullName() . ' from history importer', 'checkedout_to' => $item[$asset_tag][$batch_counter]['user_id'], 'created_at' => $item[$asset_tag][$batch_counter]['checkout_date'], 'action_type' => 'checkout'));
$asset->assigned_to = $user->id;
$asset->save();
} else {
$status['error'][] = 'Asset does not exist so no checkin log was created.';
}
} else {
$item[$asset_tag][$batch_counter]['checkedout_to'] = null;
$status['error'][] = 'No matching user for ' . Helper::array_smart_fetch($row, "name");
}
}
}
// Loop through and backfill the checkins
foreach ($item as $key => $asset_batch) {
$total_in_batch = count($asset_batch);
for ($x = 0; $x < $total_in_batch; $x++) {
$next = $x + 1;
// Only do this if a matching user was found
if ($asset_batch[$x]['checkedout_to'] != '') {
if ($total_in_batch > 1 && $x < $total_in_batch && array_key_exists($next, $asset_batch)) {
$checkin_date = Carbon::parse($asset_batch[$next]['checkout_date'])->subDay(1)->format('Y-m-d H:i:s');
$asset_batch[$x]['real_checkin'] = $checkin_date;
Actionlog::firstOrCreate(array('asset_id' => $asset_batch[$x]['asset_id'], 'asset_type' => 'hardware', 'user_id' => Auth::user()->id, 'note' => 'Checkin imported by ' . Auth::user()->fullName() . ' from history importer', 'checkedout_to' => null, 'created_at' => $checkin_date, 'action_type' => 'checkin'));
}
}
}
}
return View::make('hardware/history')->with('status', $status);
}