Esempio n. 1
0
 /**
  * Updates a collection of widgets
  * 
  * @param array $input Raw widget data which comes from a form
  * @param string $webPageId
  * @param string $name Item's name
  * @return boolean
  */
 public function update(array $input, $webPageId, $name)
 {
     if (isset($input['widget'], $input['attached'])) {
         $attachedIds = json_decode($input['attached']);
         $items = $this->normalizeInput($input['widget']);
         // We might have removed items
         $removedIds = $this->getRemovedIds($items, $attachedIds);
         // So if we had them, now remove them in back-end's side
         if (!empty($removedIds)) {
             foreach ($removedIds as $removedId) {
                 // Otherwise that item was cancelled, and therefore needs to be removed
                 $this->itemMapper->deleteById($removedId) && $this->itemMapper->deleteAllByParentId($removedId);
             }
         }
         // And finally it's time to insert or update a widget
         foreach ($items as $item) {
             $item = $this->prepareItem($item, $webPageId, $name);
             // When id is empty, it means that a new item was added
             if (empty($item['id'])) {
                 $this->itemMapper->insert($item);
             } else {
                 // Otherwise it was existing item
                 $this->itemMapper->update($item);
             }
         }
     } else {
         // All menus were removed, therefore simply remove all items associated items with target web page id
         $this->itemMapper->deleteAllByWebPageId($webPageId);
     }
     return true;
 }
Esempio n. 2
0
 /**
  * Updates an item
  * 
  * @param array $input Raw input data
  * @return boolean
  */
 public function update(array $input)
 {
     $this->track('The "%s" item has been updated', $input['name']);
     return $this->itemMapper->update(ArrayUtils::arrayWithout($input, array('max_depth')));
 }