Skip to content
This repository has been archived by the owner on Oct 19, 2020. It is now read-only.

Commit

Permalink
Merge pull request #4 from Yivan/bugs_improvements
Browse files Browse the repository at this point in the history
Dates model bug and improvements
  • Loading branch information
kkarkus authored Feb 2, 2017
2 parents 8ce04e0 + 340b2e6 commit 95994cb
Show file tree
Hide file tree
Showing 6 changed files with 195 additions and 13 deletions.
107 changes: 107 additions & 0 deletions controllers/IndexController.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,100 @@ public function listAction()
$notifications = new Notification\Listing();
$notifications
->setCondition('user = ?', $this->user->getId())
->setOrderKey("creationDate") // default order
->setOrder("DESC")
->setOffset($offset)
->setLimit($limit);

// Sorting
$sortingSettings = \Pimcore\Admin\Helper\QueryParams::extractSortingSettings($this->getAllParams());
if ($sortingSettings['orderKey']) {
if ($sortingSettings['orderKey'] == "date") $sortingSettings['orderKey'] = "creationDate";
if ($sortingSettings['orderKey'] == "from") $sortingSettings['orderKey'] = "fromUser";
$notifications->setOrderKey($sortingSettings['orderKey']);
$notifications->setOrder($sortingSettings['order']);
}

// Filtering (see: /pimcore/modules/admin/controllers/RecyclebinController.php for instance)
$db = \Pimcore\Db::get();
$conditionFilters = [];

if ($this->getParam("filterFullText")) {
$conditionFilters[] = "path LIKE " . $notifications->quote("%".$this->getParam("filterFullText")."%");
}

$filters = $this->getParam("filter");
if ($filters) {
$filters = \Zend_Json::decode($filters);

foreach ($filters as $filter) {
$operator = "=";

$filterField = $filter["field"];
$filterOperator = $filter["comparison"];
if (\Pimcore\Tool\Admin::isExtJS6()) {
$filterField = $filter["property"];
$filterOperator = $filter["operator"];
}

// custom field name
if ($filterField == "date") $filterField = "creationDate";
if ($filterField == "from") {
$conditionFilters[] = "fromUser IN (SELECT `id` FROM `users` WHERE CONCAT(`firstname`, ' ', `lastname`) LIKE " . $db->quote("%".$filter["value"]."%") . ")";
continue;
}

if ($filter["type"] == "string") {
$operator = "LIKE";
} elseif ($filter["type"] == "numeric") {
if ($filterOperator == "lt") {
$operator = "<";
} elseif ($filterOperator == "gt") {
$operator = ">";
} elseif ($filterOperator == "eq") {
$operator = "=";
}
} elseif ($filter["type"] == "date") {
if ($filterOperator == "lt") {
$operator = "<";
} elseif ($filterOperator == "gt") {
$operator = ">";
} elseif ($filterOperator == "eq") {
$operator = "=";
}
$filter["value"] = strtotime($filter["value"]);
} elseif ($filter["type"] == "list") {
$operator = "=";
} elseif ($filter["type"] == "boolean") {
$operator = "=";
$filter["value"] = (int) $filter["value"];
}
// system field
$value = $filter["value"];
if ($operator == "LIKE") {
$value = "%" . $value . "%";
}

$field = "`" . $filterField . "` ";
if ($filter["field"] == "fullpath") {
$field = "CONCAT(path,filename)";
}

if ($filter["type"] == "date" && $operator == "=") {
$maxTime = $value + (86400 - 1); //specifies the top point of the range used in the condition
$condition = $field . " BETWEEN " . $db->quote($value) . " AND " . $db->quote($maxTime);
$conditionFilters[] = $condition;
} else {
$conditionFilters[] = $field . $operator . " '" . $value . "' ";
}
}
}

if (!empty($conditionFilters)) {
$condition = implode(" AND ", $conditionFilters);
$notifications->setCondition($condition);
}

$data = [];
/** @var Notification $notification */
foreach ($notifications->load() as $notification) {
Expand Down Expand Up @@ -109,6 +201,11 @@ public function detailsAction()
throw new Exception('Notification not found');
}

// Security check: only recipient user
if (\Project\Tools::getAdminUser()->getId() !== $notification->getUser()) {
throw new Exception('Not allowed');
}

$date = new Zend_Date($notification->getCreationDate());
$data = [
'id' => $notification->getId(),
Expand Down Expand Up @@ -155,6 +252,11 @@ public function deleteAction()
throw new Exception('Notification not found');
}

// Security check: only recipient user
if (\Project\Tools::getAdminUser()->getId() !== $notification->getUser()) {
throw new Exception('Not allowed');
}

$notification->delete();
$this->_helper->json([
"success" => true,
Expand Down Expand Up @@ -197,6 +299,11 @@ public function markAsReadAction()
throw new Exception('Notification not found');
}

// Security check: only recipient user
if (\Project\Tools::getAdminUser()->getId() !== $notification->getUser()) {
throw new Exception('Not allowed');
}

$this->changeStatus($notification);
$this->_helper->json([
"success" => true,
Expand Down
22 changes: 22 additions & 0 deletions lib/PimcoreNotifications/Model/Notification.php
Original file line number Diff line number Diff line change
Expand Up @@ -323,6 +323,17 @@ public function getCreationDate()
return $this->creationDate;
}

/**
* @param int $creationDate
*
* @return $this
*/
public function setCreationDate($creationDate)
{
$this->creationDate = $creationDate;
return $this;
}

/**
* @return int
*/
Expand All @@ -331,6 +342,17 @@ public function getModificationDate()
return $this->modificationDate;
}

/**
* @param int $modificationDate
*
* @return $this
*/
public function setModificationDate($modificationDate)
{
$this->modificationDate = $modificationDate;
return $this;
}

/**
* @return \Pimcore\Model\Asset|\Pimcore\Model\Document|\Pimcore\Model\Object
*/
Expand Down
38 changes: 31 additions & 7 deletions static/js/panel.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,18 +63,36 @@ pimcore.plugin.notifications.panel = Class.create({
{
header: t("title"),
flex: 10,
sortable: false,
sortable: true,
filter: 'string',
dataIndex: 'title',
renderer: function (val, metaData, record, rowIndex, colIndex, store) {
var unread = parseInt(store.getAt(rowIndex).get("unread"));
if (unread) {
return '<strong>' + val + '</strong>';
return '<strong style="font-weight: bold;">' + val + '</strong>'; // css style need to be added
}
return val;
}
},
{header: t("from"), flex: 2, sortable: false, dataIndex: 'from'},
{header: t("date"), flex: 3, sortable: false, dataIndex: 'date'},
{header: t("from"), flex: 2, sortable: true, filter: 'string', dataIndex: 'from'},
{header: t("date"), flex: 3, sortable: true, filter: 'date', dataIndex: 'date'},
{
header: t("element"),
xtype: 'actioncolumn',
flex: 1,
items: [
{
tooltip: t('open_linked_element'),
icon: "/pimcore/static6/img/flat-color-icons/cursor.svg",
handler: function (grid, rowIndex) {
pimcore.plugin.notifications.helpers.openLinkedElement(grid.getStore().getAt(rowIndex).data);
}.bind(this),
isDisabled: function (grid, rowIndex) {
return !parseInt(grid.getStore().getAt(rowIndex).data['linkedElementId']);
}.bind(this)
}
]
},
{
xtype: 'actioncolumn',
flex: 1,
Expand Down Expand Up @@ -123,9 +141,14 @@ pimcore.plugin.notifications.panel = Class.create({
text: t("delete_all"),
iconCls: "pimcore_icon_delete",
handler: function() {
pimcore.plugin.notifications.helpers.deleteAll(function () {
this.reload();
}.bind(this));
Ext.MessageBox.confirm(t("are_you_sure"), t("all_content_will_be_lost"),
function (buttonValue) {
if (buttonValue == "yes") {
pimcore.plugin.notifications.helpers.deleteAll(function () {
this.reload();
}.bind(this));
}
}.bind(this));
}.bind(this)
}
]
Expand All @@ -135,6 +158,7 @@ pimcore.plugin.notifications.panel = Class.create({
frame: false,
autoScroll: true,
store: this.store,
plugins: ['pimcore.gridfilters'],
columns: typesColumns,
trackMouseOver: true,
bbar: this.pagingtoolbar,
Expand Down
25 changes: 21 additions & 4 deletions static/js/portlet.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,19 +30,36 @@ pimcore.layout.portlets.notifications = Class.create(pimcore.layout.portlets.abs
{header: "ID", flex: 1, sortable: false, hidden: true, dataIndex: 'id'},
{
header: t("title"),
flex: 6,
flex: 4,
sortable: false,
dataIndex: 'title',
renderer: function (val, metaData, record, rowIndex, colIndex, store) {
var unread = parseInt(store.getAt(rowIndex).get("unread"));
if (unread) {
return '<strong>' + val + '</strong>';
return '<strong style="font-weight: bold;">' + val + '</strong>'; // css style need to be added
}
return val;
}
},
{header: t("from"), flex: 2, sortable: false, dataIndex: 'from'},
{header: t("date"), flex: 3, sortable: false, dataIndex: 'date'},
{header: t("date"), flex: 2, sortable: false, dataIndex: 'date'},
{
header: t("element"),
xtype: 'actioncolumn',
flex: 0.5,
items: [
{
tooltip: t('open_linked_element'),
icon: "/pimcore/static6/img/flat-color-icons/cursor.svg",
handler: function (grid, rowIndex) {
pimcore.plugin.notifications.helpers.openLinkedElement(grid.getStore().getAt(rowIndex).data);
}.bind(this),
isDisabled: function (grid, rowIndex) {
return !parseInt(grid.getStore().getAt(rowIndex).data['linkedElementId']);
}.bind(this)
}
]
},
{
xtype: 'actioncolumn',
flex: 1,
Expand All @@ -51,7 +68,7 @@ pimcore.layout.portlets.notifications = Class.create(pimcore.layout.portlets.abs
tooltip: t('open'),
icon: "/pimcore/static6/img/flat-color-icons/right.svg",
handler: function (grid, rowIndex) {
this.openDetails(grid.getStore().getAt(rowIndex).get("id"));
pimcore.plugin.notifications.helpers.openDetails(grid.getStore().getAt(rowIndex).get("id"));
}.bind(this)
},
{
Expand Down
11 changes: 9 additions & 2 deletions static/js/startup.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ pimcore.plugin.notifications = Class.create(pimcore.plugin.admin, {
},

startAjaxConnection: function () {
pimcore["intervals"]["checkNewNotification"] = window.setInterval(function () {
function runAjaxConnection () {
Ext.Ajax.request({
url: "/plugin/PimcoreNotifications/index/unread?interval=" + 30,
success: function (response) {
Expand All @@ -22,7 +22,12 @@ pimcore.plugin.notifications = Class.create(pimcore.plugin.admin, {
pimcore.plugin.notifications.helpers.showNotifications(data.data);
}
});
}

pimcore["intervals"]["checkNewNotification"] = window.setInterval(function (elt) {
runAjaxConnection();
}, 30000);
runAjaxConnection(); // run at the Pimcore login
},

startConnection: function () {
Expand All @@ -31,7 +36,9 @@ pimcore.plugin.notifications = Class.create(pimcore.plugin.admin, {
success: function (response) {
var data = Ext.decode(response.responseText);

this.socket = new WebSocket("ws://" + location.host + ":8080/?token=" + data['token'] + "&user=" + data['user']);
var websocketProtocol = "ws:";
if (location.protocol === "https:") websocketProtocol = "wss:";
this.socket = new WebSocket(websocketProtocol + "//" + location.host + ":8080/?token=" + data['token'] + "&user=" + data['user']);
this.socket.onopen = function (event) {
};
this.socket.onclose = function (event) {
Expand Down
5 changes: 5 additions & 0 deletions texts/fr.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
pimcore_status_notification,Notifications
mark_as_read,Marqué comme lu
notifications,Notifications
delete_all,Supprimer tout
open_linked_element,Ouvrir élément

0 comments on commit 95994cb

Please sign in to comment.