mirror of
https://github.com/nerzhul/ocsms.git
synced 2025-07-23 09:55:44 +00:00
Rename smsMgr to smsMapper to follow OC guidelines. Also implement saveAll alpha function
This commit is contained in:
parent
0a16d05c0d
commit
aefea6b8ff
@ -16,6 +16,9 @@ use \OCP\AppFramework\App;
|
|||||||
|
|
||||||
use \OCA\OcSms\Controller\SmsController;
|
use \OCA\OcSms\Controller\SmsController;
|
||||||
|
|
||||||
|
use \OCA\MyApp\Db\Sms;
|
||||||
|
use \OCA\MyApp\Db\SmsMapper;
|
||||||
|
|
||||||
|
|
||||||
class Application extends App {
|
class Application extends App {
|
||||||
|
|
||||||
@ -36,6 +39,16 @@ class Application extends App {
|
|||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Database Layer
|
||||||
|
*/
|
||||||
|
$container->registerService('Sms', function($c) {
|
||||||
|
return new Sms($c->query('ServerContainer')->getDb());
|
||||||
|
});
|
||||||
|
|
||||||
|
$container->registerService('SmsMapper', function($c) {
|
||||||
|
return new SmsMapper($c->query('ServerContainer')->getDb());
|
||||||
|
});
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Core
|
* Core
|
||||||
|
@ -15,7 +15,7 @@ namespace OCA\OcSms\Controller;
|
|||||||
use \OCP\IRequest;
|
use \OCP\IRequest;
|
||||||
use \OCP\AppFramework\Http\TemplateResponse;
|
use \OCP\AppFramework\Http\TemplateResponse;
|
||||||
use \OCP\AppFramework\Controller;
|
use \OCP\AppFramework\Controller;
|
||||||
use OCA\OcSms\Db\SmsMgr;
|
use OCA\OcSms\Db\SmsMapper;
|
||||||
|
|
||||||
class SmsController extends Controller {
|
class SmsController extends Controller {
|
||||||
|
|
||||||
@ -71,9 +71,11 @@ class SmsController extends Controller {
|
|||||||
return "Error: Invalid SMS date";
|
return "Error: Invalid SMS date";
|
||||||
}
|
}
|
||||||
|
|
||||||
$smsMgr = new SmsMgr();
|
|
||||||
// @ TODO: test address and body ?
|
// @ TODO: test address and body ?
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$smsMgr = new SmsMgr();
|
||||||
|
$smsMgr->saveAll($smsDAtas);
|
||||||
return "OK";
|
return "OK";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -23,7 +23,5 @@ class Sms extends Entity {
|
|||||||
$this->addType('smsRead', 'boolean');
|
$this->addType('smsRead', 'boolean');
|
||||||
$this->addType('smsSeen', 'boolean');
|
$this->addType('smsSeen', 'boolean');
|
||||||
}
|
}
|
||||||
|
|
||||||
id | user_id | added | lastmodified | sms_read | sms_date | sms_id | sms_address | sms_msg
|
|
||||||
}
|
}
|
||||||
?>
|
?>
|
||||||
|
65
db/smsmapper.php
Normal file
65
db/smsmapper.php
Normal file
@ -0,0 +1,65 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* ownCloud - ocsms
|
||||||
|
*
|
||||||
|
* This file is licensed under the Affero General Public License version 3 or
|
||||||
|
* later. See the COPYING file.
|
||||||
|
*
|
||||||
|
* @author Loic Blot <loic.blot@unix-experience.fr>
|
||||||
|
* @copyright Loic Blot 2014
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace OCA\OcSms\Db;
|
||||||
|
|
||||||
|
use \OCP\IDb;
|
||||||
|
|
||||||
|
use \OCP\AppFramework\Db\Mapper;
|
||||||
|
|
||||||
|
class SmsMapper extends Mapper {
|
||||||
|
private $db;
|
||||||
|
|
||||||
|
public function __construct(IDb $db) {
|
||||||
|
$this->db = $db;
|
||||||
|
}
|
||||||
|
|
||||||
|
// @TODO
|
||||||
|
public function saveAll($smsList) {
|
||||||
|
foreach ($smsList as $sms) {
|
||||||
|
$query = \OC_DB::prepare('INSERT INTO *PREFIX*ocsms_smsdatas ' .
|
||||||
|
'(user_id, added, lastmodified, sms_read, sms_seen, sms_date,' .
|
||||||
|
'sms_draft, sms_id, sms_address, sms_msg) VALUES ' .
|
||||||
|
'(?,?,?,?,?,?,?,?,?,?)');
|
||||||
|
$result = $query->execute(array(
|
||||||
|
\OCP\User::getUser(),"NOW()","NOW()",
|
||||||
|
$sms["read"] === "true", $sms["seen"] === "true",
|
||||||
|
$sms["date"], $sms["draft"] === "true", $sms["id"],
|
||||||
|
$sms["address"], $sms["body"]
|
||||||
|
));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected $userId;
|
||||||
|
protected $added;
|
||||||
|
protected $lastmodified;
|
||||||
|
protected $smsRead;
|
||||||
|
protected $smsSeen;
|
||||||
|
protected $smsDate;
|
||||||
|
protected $smsDraft;
|
||||||
|
protected $smsId;
|
||||||
|
protected $smsAddress;
|
||||||
|
protected $smsMsg;
|
||||||
|
|
||||||
|
public function find($id) {
|
||||||
|
$sql = 'SELECT * FROM `*PREFIX*myapp_authors` ' .
|
||||||
|
'WHERE `id` = ?';
|
||||||
|
$query = $db->prepareQuery($sql);
|
||||||
|
$query->bindParam(1, $id, \PDO::PARAM_INT);
|
||||||
|
$result = $query->execute();
|
||||||
|
|
||||||
|
while($row = $result->fetchRow()) {
|
||||||
|
return $row;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
?>
|
@ -1,41 +0,0 @@
|
|||||||
<?php
|
|
||||||
/**
|
|
||||||
* ownCloud - ocsms
|
|
||||||
*
|
|
||||||
* This file is licensed under the Affero General Public License version 3 or
|
|
||||||
* later. See the COPYING file.
|
|
||||||
*
|
|
||||||
* @author Loic Blot <loic.blot@unix-experience.fr>
|
|
||||||
* @copyright Loic Blot 2014
|
|
||||||
*/
|
|
||||||
|
|
||||||
namespace OCA\OcSms\Db;
|
|
||||||
|
|
||||||
use \OCP\IDb;
|
|
||||||
|
|
||||||
class SmsMgr {
|
|
||||||
private $db;
|
|
||||||
|
|
||||||
public function __construct(IDb $db) {
|
|
||||||
$this->db = $db;
|
|
||||||
}
|
|
||||||
|
|
||||||
// @TODO
|
|
||||||
public function saveAll($smsList) {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public function find($id) {
|
|
||||||
$sql = 'SELECT * FROM `*PREFIX*myapp_authors` ' .
|
|
||||||
'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