Ejemplo n.º 1
0
 public function noteListAction()
 {
     $this->checkPermission("notes_events");
     $list = new Element\Note\Listing();
     $list->setLimit($this->getParam("limit"));
     $list->setOffset($this->getParam("start"));
     $sortingSettings = \Pimcore\Admin\Helper\QueryParams::extractSortingSettings($this->getAllParams());
     if ($sortingSettings['orderKey'] && $sortingSettings['order']) {
         $list->setOrderKey($sortingSettings['orderKey']);
         $list->setOrder($sortingSettings['order']);
     } else {
         $list->setOrderKey(["date", "id"]);
         $list->setOrder(["DESC", "DESC"]);
     }
     $conditions = [];
     if ($this->getParam("filter")) {
         $conditions[] = "(`title` LIKE " . $list->quote("%" . $this->getParam("filter") . "%") . " OR `description` LIKE " . $list->quote("%" . $this->getParam("filter") . "%") . " OR `type` LIKE " . $list->quote("%" . $this->getParam("filter") . "%") . ")";
     }
     if ($this->getParam("cid") && $this->getParam("ctype")) {
         $conditions[] = "(cid = " . $list->quote($this->getParam("cid")) . " AND ctype = " . $list->quote($this->getParam("ctype")) . ")";
     }
     if (!empty($conditions)) {
         $list->setCondition(implode(" AND ", $conditions));
     }
     $list->load();
     $notes = [];
     foreach ($list->getNotes() as $note) {
         $cpath = "";
         if ($note->getCid() && $note->getCtype()) {
             if ($element = Element\Service::getElementById($note->getCtype(), $note->getCid())) {
                 $cpath = $element->getRealFullPath();
             }
         }
         $e = ["id" => $note->getId(), "type" => $note->getType(), "cid" => $note->getCid(), "ctype" => $note->getCtype(), "cpath" => $cpath, "date" => $note->getDate(), "title" => $note->getTitle(), "description" => $note->getDescription()];
         // prepare key-values
         $keyValues = [];
         if (is_array($note->getData())) {
             foreach ($note->getData() as $name => $d) {
                 $type = $d["type"];
                 $data = $d["data"];
                 if ($type == "document" || $type == "object" || $type == "asset") {
                     if ($d["data"] instanceof Element\ElementInterface) {
                         $data = ["id" => $d["data"]->getId(), "path" => $d["data"]->getRealFullPath(), "type" => $d["data"]->getType()];
                     }
                 } elseif ($type == "date") {
                     if (is_object($d["data"])) {
                         $data = $d["data"]->getTimestamp();
                     }
                 }
                 $keyValue = ["type" => $type, "name" => $name, "data" => $data];
                 $keyValues[] = $keyValue;
             }
         }
         $e["data"] = $keyValues;
         // prepare user data
         if ($note->getUser()) {
             $user = Model\User::getById($note->getUser());
             if ($user) {
                 $e["user"] = ["id" => $user->getId(), "name" => $user->getName()];
             } else {
                 $e["user"] = "";
             }
         }
         $notes[] = $e;
     }
     $this->_helper->json(["data" => $notes, "success" => true, "total" => $list->getTotalCount()]);
 }
Ejemplo n.º 2
0
 /**
  * @return Note[]
  */
 public function getFullChangeLog()
 {
     if (!$this->fullChangeLog) {
         // init
         $order = $this->getOrder();
         // load order events
         $noteList = new NoteListing();
         /* @var \Pimcore\Model\Element\Note\Listing $noteList */
         $cid = [$order->getId()];
         foreach ($order->getItems() as $item) {
             $cid[] = $item->getId();
         }
         $noteList->addConditionParam('type = ?', 'order-agent');
         $noteList->addConditionParam(sprintf('cid in(%s)', implode(',', $cid)), '');
         $noteList->setOrderKey('date');
         $noteList->setOrder('desc');
         $this->fullChangeLog = $noteList->load();
     }
     return $this->fullChangeLog;
 }