mirror of
https://github.com/nerzhul/ocsms.git
synced 2025-06-07 16:06:15 +00:00
Added function to retrieve SMS ids stored on the server
This commit is contained in:
parent
0d14019e9f
commit
128167196a
@ -24,4 +24,5 @@ $application = new Application();
|
||||
$application->registerRoutes($this, array('routes' => array(
|
||||
array('name' => 'sms#index', 'url' => '/', 'verb' => 'GET'),
|
||||
array('name' => 'sms#push', 'url' => '/push', 'verb' => 'POST'),
|
||||
array('name' => 'sms#retrieve_all_ids', 'url' => '/get/ids/all', 'verb' => 'GET'),
|
||||
)));
|
||||
|
@ -39,6 +39,14 @@ class SmsController extends Controller {
|
||||
return new TemplateResponse($this->appName, 'main', $params);
|
||||
}
|
||||
|
||||
/**
|
||||
* @NoAdminRequired
|
||||
*/
|
||||
public function retrieveAllIds () {
|
||||
$smsList = $this->smsMapper->getAllIds($this->userId);
|
||||
return new JSONResponse(array("smslist" => $smsList));
|
||||
}
|
||||
|
||||
/**
|
||||
* @NoAdminRequired
|
||||
*/
|
||||
@ -51,10 +59,6 @@ class SmsController extends Controller {
|
||||
return new JSONResponse(array("status" => true, "msg" => "OK"));
|
||||
}
|
||||
|
||||
/**
|
||||
* @NoAdminRequired
|
||||
*/
|
||||
|
||||
private function checkPushStructure ($smsCount, $smsDatas) {
|
||||
if ($smsCount != count($smsDatas)) {
|
||||
$this->errorMsg = "Error: sms count invalid";
|
||||
|
@ -20,11 +20,26 @@ class SmsMapper extends Mapper {
|
||||
parent::__construct($db, 'ocsms_smsdatas');
|
||||
}
|
||||
|
||||
public function getAllIds ($userId) {
|
||||
$query = \OC_DB::prepare('SELECT sms_id, sms_mailbox FROM ' .
|
||||
'*PREFIX*ocsms_smsdatas WHERE user_id = ?');
|
||||
$result = $query->execute(array($userId));
|
||||
|
||||
$smsList = array();
|
||||
while($row = $result->fetchRow()) {
|
||||
$mbox = $row["sms_mailbox"];
|
||||
if (!isset($smsList[$mbox])) {
|
||||
$smsList[$mbox] = array();
|
||||
}
|
||||
array_push($smsList[$mbox], $row["sms_id"]);
|
||||
}
|
||||
}
|
||||
|
||||
public function writeToDB ($userId, $smsList, $purgeBeforeInsert = false) {
|
||||
\OCP\DB::beginTransaction();
|
||||
|
||||
if ($purgeBeforeInsert === true) {
|
||||
$query = \OCP\DB::prepare('DELETE FROM *PREFIX*ocsms_smsdatas ' .
|
||||
$query = \OC_DB::prepare('DELETE FROM *PREFIX*ocsms_smsdatas ' .
|
||||
'WHERE user_id = ?');
|
||||
$result = $query->execute(array($userId));
|
||||
}
|
||||
@ -35,7 +50,7 @@ class SmsMapper extends Mapper {
|
||||
$sms["seen"] === "true" ? "1" : "0"
|
||||
);
|
||||
|
||||
$query = \OCP\DB::prepare('INSERT INTO *PREFIX*ocsms_smsdatas ' .
|
||||
$query = \OC_DB::prepare('INSERT INTO *PREFIX*ocsms_smsdatas ' .
|
||||
'(user_id, added, lastmodified, sms_flags, sms_date, sms_id,' .
|
||||
'sms_address, sms_msg, sms_mailbox, sms_type) VALUES ' .
|
||||
'(?,?,?,?,?,?,?,?,?,?)');
|
||||
@ -51,18 +66,6 @@ class SmsMapper extends Mapper {
|
||||
|
||||
\OCP\DB::commit();
|
||||
}
|
||||
|
||||
public function find ($id) {
|
||||
$sql = 'SELECT * FROM `*PREFIX*ocsms_smsdatas` ' .
|
||||
'WHERE `id` = ?';
|
||||
$query = $db->prepareQuery($sql);
|
||||
$query->bindParam(1, $id, \PDO::PARAM_INT);
|
||||
$result = $query->execute();
|
||||
|
||||
while($row = $result->fetchRow()) {
|
||||
return $row;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
|
Loading…
x
Reference in New Issue
Block a user