本文整理汇总了PHP中Icon::save方法的典型用法代码示例。如果您正苦于以下问题:PHP Icon::save方法的具体用法?PHP Icon::save怎么用?PHP Icon::save使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Icon
的用法示例。
在下文中一共展示了Icon::save方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: doOldImport
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];
//.........这里部分代码省略.........
示例2: icons_in_post
protected function icons_in_post($full_post)
{
$post = $full_post['.postmsg'][0];
if (strpos($post->html(), '<img') === false) {
return array();
}
$post_text = self::clean_up_post($post);
$artist_name = $full_post['.postleft dt'][0]->text();
$post_imgs = $post['img.postimg'];
if (empty($post_imgs)) {
return array();
}
$icons = self::find_icon_names_in_post($post_imgs, $post_text);
$post_icons = array();
foreach ($icons as $img_src => $name) {
$icon = Make::an('Icon')->like('src', $img_src)->first();
$changed = false;
if (!$icon) {
$icon = new Icon();
$icon->src = $img_src;
$icon->theme_id = $this->theme->id;
// TODO: make this DRYer too
if ($artist_name) {
$artist = Make::an('Artist')->like('name', $artist_name)->first();
if (!$artist) {
$artist = new Artist();
$artist->name = $artist_name;
$artist->save();
}
$icon->setArtist($artist);
}
$changed = true;
}
if ($name && !$icon->app()) {
$app = Make::an('App')->like('name', $name)->first();
if (!$app) {
$app = new App();
$app->name = $name;
$app->save();
}
$icon->setApp($app);
$changed = true;
}
if ($changed) {
$icon->save();
}
$post_icons[] = $icon;
}
/*
$matches = array();
$maybe_names = array();
if (preg_match('/(([a-z0-9\-]{2,}), )+([a-z0-9\- ]{2,})/i', $post_text, $matches)) {
$maybe_names = explode(',', $matches[0]); # [0] == entire match
$maybe_names = array_map('trim', $maybe_names);
} else {
$w = self::WORD_REGEXP;
$and_match = array();
if (preg_match('/'.$w.' and '.$w.'/iu', $post_text, $and_match)) {
$maybe_names = explode(' and ', $and_match[0]);
$maybe_names = array_map('trim', $maybe_names);
}
}
if ($maybe_names) {
foreach ($post_icons as &$post_icon) {
$post_icon->maybe_names = array_merge($post_icon->maybe_names, $maybe_names);
}
}
*/
return $post_icons;
}