mirror of
https://github.com/ZeJMaN/LBCAlerte_ynh.git
synced 2025-07-26 13:17:34 +02:00
Upgrade LBCAlerte to version 3.3
Add upgrade script
This commit is contained in:
44
sources/app/api/annonce/create.php
Normal file
44
sources/app/api/annonce/create.php
Normal file
@ -0,0 +1,44 @@
|
||||
<?php
|
||||
$ad = new App\Ad\Ad();
|
||||
|
||||
$link = "";
|
||||
|
||||
if (empty($_POST["link"])) {
|
||||
return array(
|
||||
"data" => $_POST,
|
||||
"errors" => array(
|
||||
"link" => "Ce champ est obligatoire."
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
$link = $_POST["link"];
|
||||
try {
|
||||
$siteConfig = \AdService\SiteConfigFactory::factory($link);
|
||||
$parser = \AdService\ParserFactory::factory($link);
|
||||
} catch (\Exception $e) {
|
||||
return array(
|
||||
"data" => $_POST,
|
||||
"errors" => array(
|
||||
"link" => "Cette adresse ne semble pas valide."
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
$ad = $parser->processAd(
|
||||
$client->request($link),
|
||||
parse_url($link, PHP_URL_SCHEME)
|
||||
);
|
||||
|
||||
$ad_stored = $storage->fetchById($ad->getId());
|
||||
if (!$ad_stored) {
|
||||
$ad_stored = new \App\Ad\Ad();
|
||||
}
|
||||
|
||||
$ad_stored->setFromArray($ad->toArray());
|
||||
$storage->save($ad_stored);
|
||||
|
||||
$adPhoto = new App\Storage\AdPhoto($userAuthed);
|
||||
$adPhoto->import($ad_stored);
|
||||
|
||||
return $ad_stored->toArray();
|
16
sources/app/api/annonce/delete.php
Normal file
16
sources/app/api/annonce/delete.php
Normal file
@ -0,0 +1,16 @@
|
||||
<?php
|
||||
if (empty($_POST["id"])) {
|
||||
return array(
|
||||
"data" => $_POST,
|
||||
"errors" => array(
|
||||
"id" => "Un ID doit être fourni"
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
$ad = $storage->fetchById($_POST["id"]);
|
||||
if ($ad) {
|
||||
$storage->delete($ad);
|
||||
$adPhoto = new App\Storage\AdPhoto($userAuthed);
|
||||
$adPhoto->delete($ad);
|
||||
}
|
24
sources/app/api/annonce/index.php
Normal file
24
sources/app/api/annonce/index.php
Normal file
@ -0,0 +1,24 @@
|
||||
<?php
|
||||
|
||||
$order_by = null;
|
||||
$sort = isset($_GET["sort"]) ? $_GET["sort"] : "";
|
||||
$order = isset($_GET["order"]) ? $_GET["order"] : "asc";
|
||||
|
||||
if ($sort) {
|
||||
$order_by = $sort." ".$order;
|
||||
}
|
||||
|
||||
$ads = $storage->fetchAll($order_by);
|
||||
|
||||
$baseurl = $config->get("general", "baseurl", "");
|
||||
$adPhoto = new App\Storage\AdPhoto($userAuthed);
|
||||
$return = array();
|
||||
foreach ($ads AS $ad) {
|
||||
$params = $ad->toArray();
|
||||
foreach ($params["photos"] AS $i => $photo) {
|
||||
$params["photos"][$i]["local"] = $baseurl.$adPhoto->getPublicDestination($photo["local"]);
|
||||
}
|
||||
$return[$ad->getId()] = $params;
|
||||
}
|
||||
|
||||
return $return;
|
Reference in New Issue
Block a user