Beispiel #1
0
 /**
  * Tests whether elements in the set are ordered.
  *
  * @return void
  */
 public function testElementsAreOrdered()
 {
     $element1 = 1;
     $element2 = 2;
     $element3 = 3;
     $element4 = 4;
     $element5 = 5;
     $orderedSet = new OrderedSet(array($element1, $element2, $element3, $element4, $element5));
     $currentValue = 1;
     foreach ($orderedSet as $element) {
         $this->assertSame($currentValue++, $element);
     }
     $orderedSet->remove($element3);
     $currentValue = 1;
     foreach ($orderedSet as $element) {
         $this->assertSame($currentValue++, $element);
         if ($element === $element2) {
             $currentValue++;
         }
     }
 }
Beispiel #2
0
 /**
  * @see \Ableron\Lib\Collections\Interfaces\SetInterface::add()
  * @throws \Ableron\Core\Exception\SystemException In case the given element does not fit the element type of this set
  */
 public function add($element)
 {
     // check whether given element is an object
     if (!is_object($element)) {
         throw new SystemException(sprintf('Unable to add non-object to object set: %s', StringUtil::toString($element)), 0, E_USER_WARNING, __FILE__, __LINE__);
     }
     // check whether given element has the correct type
     if ($this->elementType !== null && !$element instanceof $this->elementType) {
         throw new SystemException(sprintf('Unable to add object of type %s to object set of type %s', get_class($element), $this->elementType), 0, E_USER_WARNING, __FILE__, __LINE__);
     }
     // add given element to set
     parent::add($element);
 }
Beispiel #3
0
         $item = $orderedSet->next();
         printpre($order . "-" . $item);
         // Update the db
         $query = "\n\t\t\tUPDATE\n\t\t\t\tstory\n\t\t\tSET\n\t\t\t\tstory_order =  '" . addslashes($order) . "'\n\t\t\tWHERE\n\t\t\t\tstory_id = '" . addslashes($item) . "'\n\t\t";
         //printpre($query);
         $r = db_query($query);
         $order++;
     }
     $showorder = "story";
     /******************************************************************************
      * Reordering of sections
      ******************************************************************************/
 } else {
     if ($_REQUEST['reorderSection']) {
         $site_id = db_get_value("slot", "FK_site", "slot_name='" . addslashes($_REQUEST['site']) . "'");
         $orderedSet = new OrderedSet(null);
         $query = "\n\t\tSELECT\n\t\t\tsection_id, section_order\n\t\tFROM\n\t\t\tsection\n\t\tWHERE\n\t\t\tFK_site = '" . addslashes($site_id) . "'\n\t\tORDER BY section_order\t\t\t\n\t";
         printpre($query);
         $r = db_query($query);
         // Populate the Set with the original page order
         while ($a = db_fetch_assoc($r)) {
             printpre($a['section_order'] . "-" . $a['section_id']);
             $orderedSet->addItem($a['section_id']);
         }
         // Move our page to its new position
         $orderedSet->moveToPosition($_REQUEST['reorderSection'], $_REQUEST['newPosition']);
         // Save the new order
         $orderedSet->reset();
         // Make sure the iterator is at the begining.
         $order = 0;
         while ($orderedSet->hasNext()) {
 /**
  * Move the specified id toward the end of the set.
  * @param object Id $id The Id of the item to move.
  * @access public
  * @return void
  */
 function moveDown($id)
 {
     // Store the old order
     $oldOrder = $this->_items;
     // move the Item
     parent::moveDown($id);
     // update the database with the new order keys.
     $this->_updateOrders($oldOrder);
 }