2024-09-04 22:06:38 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
class Agent {
|
|
|
|
private $db;
|
|
|
|
|
|
|
|
public function __construct($database) {
|
|
|
|
$this->db = $database->getConnection();
|
|
|
|
}
|
|
|
|
|
|
|
|
// get details of a specified agent ID (or all) in a specified platform ID
|
|
|
|
public function getAgentDetails($platform_id, $agent_id = '') {
|
|
|
|
$sql = 'SELECT * FROM jilo_agents
|
|
|
|
WHERE
|
|
|
|
platform_id = :platform_id';
|
|
|
|
if ($agent_id !== '') {
|
|
|
|
$sql .= ' AND id = :agent_id';
|
|
|
|
$query = $this->db->prepare($sql);
|
|
|
|
$query->execute([
|
|
|
|
':platform_id' => $platform_id,
|
|
|
|
':agent_id' => $agent_id,
|
|
|
|
]);
|
|
|
|
} else {
|
|
|
|
$query = $this->db->prepare($sql);
|
|
|
|
$query->bindParam(':platform_id', $platform_id);
|
|
|
|
}
|
|
|
|
|
|
|
|
$query->execute();
|
|
|
|
|
|
|
|
return $query->fetchAll(PDO::FETCH_ASSOC);
|
|
|
|
}
|
|
|
|
|
|
|
|
// add new agent
|
|
|
|
public function addAgent($platform_id, $newAgent) {
|
|
|
|
try {
|
|
|
|
$sql = 'INSERT INTO jilo_agents
|
2024-09-23 09:39:33 +00:00
|
|
|
(platform_id, agent_type_id, url, secret_key)
|
2024-09-04 22:06:38 +00:00
|
|
|
VALUES
|
2024-09-23 09:39:33 +00:00
|
|
|
(:platform_id, :agent_type_id, :url, :secret_key)';
|
2024-09-04 22:06:38 +00:00
|
|
|
|
|
|
|
$query = $this->db->prepare($sql);
|
|
|
|
$query->execute([
|
|
|
|
':platform_id' => $platform_id,
|
2024-09-23 09:39:33 +00:00
|
|
|
':agent_type_id' => $newAgent['type_id'],
|
2024-09-04 22:06:38 +00:00
|
|
|
':url' => $newAgent['url'],
|
|
|
|
':secret_key' => $newAgent['secret_key'],
|
|
|
|
]);
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
|
|
|
} catch (Exception $e) {
|
|
|
|
return $e->getMessage();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// edit an existing agent
|
|
|
|
public function editAgent($platform_id, $updatedAgent) {
|
|
|
|
try {
|
|
|
|
$sql = 'UPDATE jilo_agents SET
|
2024-09-23 09:39:33 +00:00
|
|
|
agent_type_id = :agent_type_id,
|
2024-09-04 22:06:38 +00:00
|
|
|
url = :url,
|
|
|
|
secret_key = :secret_key
|
|
|
|
WHERE
|
|
|
|
id = :agent_id
|
|
|
|
AND
|
|
|
|
platform_id = :platform_id';
|
|
|
|
|
|
|
|
$query = $this->db->prepare($sql);
|
|
|
|
$query->execute([
|
2024-09-23 09:39:33 +00:00
|
|
|
':agent_type_id' => $updatedAgent['agent_type_id'],
|
2024-09-04 22:06:38 +00:00
|
|
|
':url' => $updatedAgent['url'],
|
|
|
|
':secret_key' => $updatedAgent['secret_key'],
|
|
|
|
':agent_id' => $updatedAgent['id'],
|
|
|
|
':platform_id' => $platform_id,
|
|
|
|
]);
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
|
|
|
} catch (Exception $e) {
|
|
|
|
return $e->getMessage();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// delete an agent
|
|
|
|
public function deleteAgent($agent_id) {
|
|
|
|
try {
|
|
|
|
$sql = 'DELETE FROM jilo_agents
|
|
|
|
WHERE
|
|
|
|
id = :agent_id';
|
|
|
|
|
|
|
|
$query = $this->db->prepare($sql);
|
|
|
|
$query->bindParam(':agent_id', $agent_id);
|
|
|
|
|
|
|
|
$query->execute();
|
|
|
|
return true;
|
|
|
|
|
|
|
|
} catch (Exception $e) {
|
|
|
|
return $e->getMessage();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
?>
|