Change tag routines, articles saving is ok
This commit is contained in:
@@ -24,6 +24,37 @@ class Articles
|
||||
return Article::orderBy('name','asc')->get();
|
||||
}
|
||||
|
||||
public static function getFull($id)
|
||||
{
|
||||
$article = Articles::get($id);
|
||||
$data = $article->toArray();
|
||||
$data['categories'] = self::getCategoriesByArticle($article);
|
||||
$data['tags'] = self::getTagsByArticle($article);
|
||||
$data = self::getMeta($data);
|
||||
return $data;
|
||||
}
|
||||
|
||||
public static function getMeta($data = [])
|
||||
{
|
||||
$data['categories_options'] = Categories::getOptions();
|
||||
$data['families_options'] = ArticleFamilies::getOptions();
|
||||
$data['taxes_options'] = Taxes::getOptions();
|
||||
$data['attribute_families_options'] = ArticleAttributeFamilies::getOptions();
|
||||
$data['tags_list'] = TagGroups::getTreeTags();
|
||||
$data['models_options'] = ['App\Models\Botanic\Specie' => 'Espèces', 'App\Models\Botanic\Variety' => 'Variétés'];
|
||||
return $data;
|
||||
}
|
||||
|
||||
public static function getCategoriesByArticle($article)
|
||||
{
|
||||
return $article->categories->pluck('id')->toArray();
|
||||
}
|
||||
|
||||
public static function getTagsByArticle($article)
|
||||
{
|
||||
return $article->tags->pluck('id')->toArray();
|
||||
}
|
||||
|
||||
public static function get($id)
|
||||
{
|
||||
return Article::find($id);
|
||||
@@ -32,8 +63,7 @@ class Articles
|
||||
public static function store($data)
|
||||
{
|
||||
$id = isset($data['id']) ? $data['id'] : false;
|
||||
$item = $id ? self::update($data) : self::create($data);
|
||||
return $item->id;
|
||||
return $id ? self::update($data) : self::create($data);
|
||||
}
|
||||
|
||||
public static function create($data)
|
||||
@@ -41,9 +71,12 @@ class Articles
|
||||
return Article::create($data);
|
||||
}
|
||||
|
||||
public static function update($data)
|
||||
public static function update($data, $id = false)
|
||||
{
|
||||
return Article::find($id)->update($data);
|
||||
$id = $id ? $id : $data['id'];
|
||||
$article = Article::find($id);
|
||||
$ret = $article->update($data);
|
||||
return $article;
|
||||
}
|
||||
|
||||
public static function destroy($id)
|
||||
@@ -51,14 +84,57 @@ class Articles
|
||||
return Article::destroy($id);
|
||||
}
|
||||
|
||||
public static function storeCategories($article, $categories)
|
||||
{
|
||||
if ($categories)
|
||||
{
|
||||
$categories = collect($categories)->transform(function ($item, $key) {
|
||||
return (int) $item;
|
||||
})->toArray();
|
||||
return $article->attachCategories($categories);
|
||||
} else return false;
|
||||
}
|
||||
|
||||
public static function storeTags($article, $tags)
|
||||
{
|
||||
if ($tags)
|
||||
{
|
||||
return $article->attachTags($tags);
|
||||
}
|
||||
}
|
||||
|
||||
public static function storePrices($article, $prices)
|
||||
{
|
||||
return ArticlePrices::storePrices($article->id, $prices);
|
||||
}
|
||||
|
||||
public static function storeImages($article, $files)
|
||||
{
|
||||
if ($files) {
|
||||
foreach ($files as $file) {
|
||||
self::storeImage($article, $file);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static function storeImage($article, $file)
|
||||
{
|
||||
return $article->addMedia($file)->withResponsiveImages()->toMediaCollection('images');
|
||||
}
|
||||
|
||||
public static function getImages($id)
|
||||
{
|
||||
$variety = self::get($id);
|
||||
$variety->getMedia();
|
||||
foreach ($variety->media as $key => $media) {
|
||||
$variety->media[$key]['url'] = $media->getUrl();
|
||||
$article = self::get($id);
|
||||
if ($article)
|
||||
{
|
||||
$article->getMedia();
|
||||
foreach ($article->media as $key => $media) {
|
||||
$article->media[$key]['url'] = $media->getUrl();
|
||||
}
|
||||
return $article->media;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
return $variety->media;
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user