Preordernotification: Can attach Borderpoint image from Mapbox API now
This commit is contained in:
@@ -847,6 +847,86 @@ class Preorder extends mfBaseModel {
|
||||
return $a;
|
||||
}
|
||||
|
||||
public function getBorderpointImageFile() {
|
||||
if(!$this->adb_hausnummer_id) return false;
|
||||
|
||||
$border_lat = $this->getProperty("adb_hausnummer")->borderpoint_lat;
|
||||
$border_long = $this->getProperty("adb_hausnummer")->borderpoint_long;
|
||||
|
||||
if(!$border_lat || !$border_long ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$filename = "borderpoint_map_h".$this->adb_hausnummer_id."_{$border_lat}_{$border_long}";
|
||||
|
||||
$bpi_file = PreorderFile::getFirst(["preorder_id" => $this->id, "filename" => $filename]);
|
||||
if($bpi_file) {
|
||||
return $bpi_file;
|
||||
}
|
||||
|
||||
|
||||
// get new Borderpoint Image from Mapbox API
|
||||
$params = [
|
||||
"gps_lat" => $border_lat,
|
||||
"gps_long" => $border_long,
|
||||
"zoom" => 19,
|
||||
"size_x" => 640,
|
||||
"size_y" => 640,
|
||||
"style" => "satellite-streets-v12",
|
||||
"pin" => [
|
||||
"gps_lat" => $border_lat,
|
||||
"gps_long" => $border_long,
|
||||
"size" => "l",
|
||||
"color" => "ee9900",
|
||||
"icon" => "embassy"
|
||||
],
|
||||
"access_token" => TT_MAPBOX_TILE_API_TOKEN
|
||||
];
|
||||
|
||||
$image_content = Mapbox_StaticImageApi::getImageFileContent($params);
|
||||
if(!$image_content) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$fs_filename = "$filename.jpg";
|
||||
if(!file_put_contents(MFUPLOAD_FILE_SAVE_PATH."/preorder-borderpoint/$fs_filename", $image_content)) {
|
||||
$this->log->error(__METHOD__.": Error saving Borderpoint Static Map Image File");
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
$file = FileModel::create([
|
||||
"name" => "borderpoint_map",
|
||||
"description" => $this->adb_hausnummer_id,
|
||||
"filename" => "$filename.jpg",
|
||||
"orig_filename" => "$filename.jpg",
|
||||
"store_filename" => $fs_filename,
|
||||
"subfolder" => "preorder-borderpoint",
|
||||
]);
|
||||
if(!$file->save()) {
|
||||
$this->log->error(__METHOD__.": Error saving File Object");
|
||||
return false;
|
||||
}
|
||||
|
||||
$file->mimetype = $file->getMimetype();
|
||||
$file->save();
|
||||
|
||||
$pf = PreorderFile::create([
|
||||
"preorder_id" => $this->id,
|
||||
"file_id" => $file->id,
|
||||
"filename" => $filename
|
||||
]);
|
||||
|
||||
if(!$pf->save()) {
|
||||
$this->log->error(__METHOD__.": Error saving PreorderFile Object");
|
||||
return false;
|
||||
}
|
||||
|
||||
return $pf;
|
||||
|
||||
|
||||
}
|
||||
|
||||
public function getApiArray($options = []) {
|
||||
if(!$this->id) {
|
||||
return false;
|
||||
|
||||
@@ -506,6 +506,8 @@ class PreorderModel {
|
||||
$status_code = $filter['status_code'];
|
||||
if(is_numeric($status_code)) {
|
||||
$where .= " AND tt_preorderstatus.code=$status_code";
|
||||
} elseif(is_array($status_code)) {
|
||||
$where .= " AND tt_preorderstatus.code IN (".implode(",", $status_code).")";
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,178 @@
|
||||
<?php
|
||||
|
||||
class PreorderFile extends mfBaseModel {
|
||||
private $file;
|
||||
private $preorder;
|
||||
|
||||
public function getProperty($name) {
|
||||
if($this->$name == null) {
|
||||
|
||||
$classname = ucfirst($name);
|
||||
$idfield = $name . "_id";
|
||||
$this->$name = mfValuecache::singleton()->get("mfObjectmodel-$name-" . $this->$idfield);
|
||||
if($this->$name === null) {
|
||||
$this->$name = new $classname($this->$idfield);
|
||||
}
|
||||
|
||||
if($this->$name->id) {
|
||||
mfValuecache::singleton()->set("mfObjectmodel-$name-" . $this->$name->id, $this->$name);
|
||||
return $this->$name;
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
return $this->$name;
|
||||
}
|
||||
|
||||
/********************************
|
||||
* Begin static Model functions
|
||||
*/
|
||||
public static function create(Array $data) {
|
||||
$model = new PreorderFile();
|
||||
|
||||
$table_fields = [
|
||||
"preorder_id", "file_id", "filename",
|
||||
"create_by","edit_by","create","edit"
|
||||
];
|
||||
|
||||
foreach($data as $field => $value) {
|
||||
if(in_array($field, $table_fields)) {
|
||||
$model->$field = $value;
|
||||
}
|
||||
}
|
||||
|
||||
$me = new User();
|
||||
$me->loadMe();
|
||||
|
||||
if($model->create_by === null) {
|
||||
$model->create_by = $me->id;
|
||||
}
|
||||
if($model->edit_by === null) {
|
||||
$model->edit_by = $me->id;
|
||||
}
|
||||
|
||||
return $model;
|
||||
}
|
||||
|
||||
public static function getAll() {
|
||||
$items = [];
|
||||
|
||||
$db = FronkDB::singleton();
|
||||
|
||||
$res = $db->select("PreorderFile", "*", "1 = 1 ORDER BY preorder_id,file_id");
|
||||
if($db->num_rows($res)) {
|
||||
while($data = $db->fetch_object($res)) {
|
||||
$items[] = new PreorderFile($data);
|
||||
}
|
||||
}
|
||||
return $items;
|
||||
|
||||
}
|
||||
|
||||
public static function getFirst($filter = []) {
|
||||
$db = FronkDB::singleton();
|
||||
|
||||
$where = self::getSqlFilter($filter);
|
||||
$res = $db->select("PreorderFile", "*", "$where ORDER BY preorder_id,file_id LIMIT 1");
|
||||
if($db->num_rows($res)) {
|
||||
$data = $db->fetch_object($res);
|
||||
$item = new PreorderFile($data);
|
||||
if($item->id) {
|
||||
return $item;
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static function count($filter) {
|
||||
$db = FronkDB::singleton();
|
||||
|
||||
$where = self::getSqlFilter($filter);
|
||||
$sql = "SELECT COUNT(*) as cnt FROM `PreorderFile`
|
||||
WHERE $where
|
||||
";
|
||||
|
||||
mfLoghandler::singleton()->debug($sql);
|
||||
$res = $db->query($sql);
|
||||
if($db->num_rows($res)) {
|
||||
$data = $db->fetch_object($res);
|
||||
return $data->cnt;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
public static function search($filter, $limit=false) {
|
||||
$items = [];
|
||||
$db = FronkDB::singleton();
|
||||
|
||||
$where = self::getSqlFilter($filter);
|
||||
|
||||
$sql = "SELECT PreorderFile.* FROM `PreorderFile`
|
||||
WHERE $where
|
||||
ORDER BY preorder_id,file_id
|
||||
";
|
||||
|
||||
mfLoghandler::singleton()->debug($sql);
|
||||
if(is_array($limit) && count($limit)) {
|
||||
if(is_numeric($limit['start']) && is_numeric($limit['count'])) {
|
||||
$sql .= " LIMIT ".$limit['start'].", ".$limit['count'];
|
||||
} elseif(is_numeric($limit['count'])) {
|
||||
$sql .= " LIMIT ".$limit['count'];
|
||||
}
|
||||
}
|
||||
|
||||
$res = $db->query($sql);
|
||||
if($db->num_rows($res)) {
|
||||
while($data = $db->fetch_object($res)) {
|
||||
$items[] = new PreorderFile($data);
|
||||
}
|
||||
}
|
||||
return $items;
|
||||
}
|
||||
|
||||
private static function getSqlFilter($filter) {
|
||||
$where = "1=1 ";
|
||||
|
||||
$db = FronkDB::singleton();
|
||||
|
||||
//var_dump($filter);exit;
|
||||
if(array_key_exists("id", $filter)) {
|
||||
$id = $db->escape($filter['id']);
|
||||
if($id) {
|
||||
$where .= " AND PreorderFile.`id` = '$id'";
|
||||
}
|
||||
}
|
||||
|
||||
if(array_key_exists("preorder_id", $filter)) {
|
||||
$preorder_id = $filter['preorder_id'];
|
||||
if(is_numeric($preorder_id)) {
|
||||
$where .= " AND preorder_id=$preorder_id";
|
||||
} elseif(is_array($preorder_id) && count($preorder_id)) {
|
||||
$where .= " AND PreorderFile.preorder_id IN (". implode(",", $preorder_id).")";
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if(array_key_exists("file_id", $filter)) {
|
||||
$file_id = $filter['file_id'];
|
||||
if(is_numeric($file_id)) {
|
||||
$where .= " AND PreorderFile.file_id=$file_id";
|
||||
} elseif(is_array($file_id) && count($file_id)) {
|
||||
$where .= " AND PreorderFile.file_id IN (". implode(",", $file_id).")";
|
||||
}
|
||||
}
|
||||
|
||||
if(array_key_exists("filename", $filter)) {
|
||||
$filename = FronkDB::singleton()->escape($filter['filename']);
|
||||
if($filename) {
|
||||
$where .= " AND filename LIKE '$filename'";
|
||||
}
|
||||
}
|
||||
|
||||
//var_dump($filter, $where);exit;
|
||||
return $where;
|
||||
}
|
||||
}
|
||||
@@ -31,7 +31,16 @@ class Preordernotification extends mfBaseModel {
|
||||
if($this->sender_replyto) {
|
||||
$reply_to = $this->sender_replyto;
|
||||
}
|
||||
|
||||
|
||||
$borderpoint_file = false;
|
||||
|
||||
if($this->attach_borderpoint) {
|
||||
$borderpoint_file = $preorder->getBorderpointImageFile();
|
||||
if(!$borderpoint_file) return false;
|
||||
|
||||
if(!file_exists($borderpoint_file->file->getFullPath())) return false;
|
||||
}
|
||||
|
||||
$to = $preorder->email;
|
||||
|
||||
if($email_to) {
|
||||
@@ -88,6 +97,9 @@ class Preordernotification extends mfBaseModel {
|
||||
$email->addAttachment($file["path"], null, $file["filename"], $file['mimetype']);
|
||||
}
|
||||
}
|
||||
if($this->attach_borderpoint && $borderpoint_file) {
|
||||
$email->addAttachment($borderpoint_file->file->getFullPath(), null, $borderpoint_file->file->filename, $borderpoint_file->file->mimetype);
|
||||
}
|
||||
$email->send();
|
||||
$this->log->info(__CLASS__."::sendToPreorder(): Sending Preordernotification for Preorder id ".$preorder->id);
|
||||
|
||||
|
||||
@@ -293,6 +293,15 @@ class PreordernotificationController extends mfBaseController {
|
||||
}
|
||||
}
|
||||
|
||||
if(is_array($r->status_id) && count($r->status_id)) {
|
||||
$filter["status_id"] = [];
|
||||
foreach($r->status_id as $status_id) {
|
||||
$test_status = new Preorderstatus($status_id);
|
||||
if(!$test_status || !$test_status->id) continue;
|
||||
$filter["status_id"][] = $status_id;
|
||||
}
|
||||
}
|
||||
|
||||
//var_dump($filter);
|
||||
$data = [];
|
||||
$data['preordercampaign_id'] = $campaign_id;
|
||||
@@ -301,6 +310,7 @@ class PreordernotificationController extends mfBaseController {
|
||||
$data['sender_replyto'] = $r->sender_replyto;
|
||||
$data['subject'] = $r->subject;
|
||||
$data['body_html'] = $r->body_html;
|
||||
$data["attach_borderpoint"] = $r->attach_borderpoint;
|
||||
$data['note'] = $r->note;
|
||||
|
||||
if($r->tosend_day) {
|
||||
|
||||
@@ -48,7 +48,7 @@ class PreordernotificationFileModel {
|
||||
|
||||
}
|
||||
|
||||
public static function getFirst() {
|
||||
public static function getFirst($filter = []) {
|
||||
$db = FronkDB::singleton();
|
||||
|
||||
$where = self::getSqlFilter($filter);
|
||||
@@ -97,7 +97,7 @@ class PreordernotificationFileModel {
|
||||
if(is_array($limit) && count($limit)) {
|
||||
if(is_numeric($limit['start']) && is_numeric($limit['count'])) {
|
||||
$sql .= " LIMIT ".$limit['start'].", ".$limit['count'];
|
||||
} elseif(is_numeric($count)) {
|
||||
} elseif(is_numeric($limit['count'])) {
|
||||
$sql .= " LIMIT ".$limit['count'];
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user