예제 #1
0
 function testAddSameElementTwice()
 {
     $list = new ArrayList("string");
     $list->add("Hello there");
     $list->add("Hello there");
     $this->assertEqual(2, $list->size());
 }
예제 #2
0
 function testNormalList()
 {
     $list = new ArrayList("string");
     $list->add("a");
     $list->add("b");
     $this->assertEqual("[a,b]", $list->__toString());
 }
예제 #3
0
 public function testUpdateElementCheckChanged()
 {
     $list = new ArrayList("SomePojo");
     $list->add(new SomePojo(5));
     $list->add(new SomePojo(8));
     $list->get(1)->setField(7);
     $this->assertEqual(5, $list->get(0)->getField());
     $this->assertEqual(7, $list->get(1)->getField());
 }
예제 #4
0
 function testSortObjectsComparator()
 {
     $oList = new ArrayList("SampleSortableObject");
     $oList->add(new SampleSortableObject(new String("b")));
     $oList->add(new SampleSortableObject(new String("a")));
     $oList->add(new SampleSortableObject(new String("c")));
     $oList->sort(new SampleSortableObjectComparator());
     $this->assertEqual(new String("c"), $oList->get(0)->getField());
     $this->assertEqual(new String("b"), $oList->get(1)->getField());
     $this->assertEqual(new String("a"), $oList->get(2)->getField());
 }
 /**
  * Get all Discussion Groups and set relevent links for each
  *
  * @return DataList
  */
 public function getMenu()
 {
     // Get the current associated discussion holder
     $discussion_holder = DiscussionHolder::get()->filter("SideBar.ID", $this->ParentID)->first();
     $menu = new ArrayList();
     $menu->add(new ArrayData(array("ID" => 0, "Title" => _t('Discussions.All', "All"), "Link" => $discussion_holder->Link())));
     $menu->add(new ArrayData(array("ID" => 10, "Title" => _t('Discussions.Liked', "Liked"), "Link" => $discussion_holder->Link("liked"))));
     $menu->add(new ArrayData(array("ID" => 20, "Title" => _t('Discussions.Started', "I started"), "Link" => $discussion_holder->Link("my"))));
     $this->extend("updateMenu", $menu);
     return $menu->sort("ID", "ASC");
 }
 /**
  * Get a filtered list of discussions by can view rights.
  *
  * This method is basically the meat and potates of this module and does most
  * of the crunch work of finding the relevant discussion list and ensuring
  * the current user is allowed to view it.
  *
  * @return DataList
  */
 public function ViewableDiscussions()
 {
     $tag = $this->getTag();
     $category = $this->getCategory();
     $member = Member::currentUser();
     $discussions_to_view = new ArrayList();
     if ($tag) {
         $SQL_tag = Convert::raw2sql($tag);
         $discussions = Discussion::get()->filter("ParentID", $this->ID)->where("\"Discussion\".\"Tags\" LIKE '%{$SQL_tag}%'");
     } elseif ($category) {
         $discussions = Discussion::get()->filter(array("ParentID" => $this->ID, "Categories.ID:ExactMatch" => $category->ID));
     } elseif ($this->request->param('Action') == 'liked') {
         $discussions = $member->LikedDiscussions();
     } elseif ($this->request->param('Action') == 'my') {
         $discussions = Discussion::get()->filter(array("ParentID" => $this->ID, "AuthorID" => $member->ID));
     } else {
         $discussions = $this->Discussions();
     }
     foreach ($discussions as $discussion) {
         if ($discussion->canView($member)) {
             $discussions_to_view->add($discussion);
         }
     }
     $this->extend("updateViewableDiscussions", $discussions_to_view);
     return new PaginatedList($discussions_to_view, $this->request);
 }
 /**
  * Add an item to the shopping cart. To make this process as generic
  * as possible, we require that an object is submitted. This object
  * can have any params, but by default we usually use:
  * 
  * "Title": The Title to appear in the cart
  * "Content": A description of the item
  * "Price": Our item's base price
  * "Image": Image to display in cart
  * "Customisations": array of customisations
  * "ID": Unique identifier for this object
  * 
  * @param $object Object that we will add to the shopping cart
  * @param $quantity Number of these objects to add
  */
 public function add($data, $quantity = 1)
 {
     if (array_key_exists("Key", $data)) {
         $added = false;
         $item_key = $data['Key'];
         // Check if object already in the cart and update quantity
         foreach ($this->items as $item) {
             if ($item->Key == $item_key) {
                 $this->update($item->Key, $item->Quantity + $quantity);
                 $added = true;
             }
         }
         // If no update was sucessfull then add to cart items
         if (!$added) {
             $cart_item = self::config()->item_class;
             $cart_item = $cart_item::create();
             foreach ($data as $key => $value) {
                 $cart_item->{$key} = $value;
             }
             // If we need to track stock, do it now
             if ($this->config()->check_stock_levels) {
                 $cart_item->checkStockLevel($quantity);
             }
             $cart_item->Key = $item_key;
             $cart_item->Quantity = $quantity;
             $this->extend("onBeforeAdd", $cart_item);
             $this->items->add($cart_item);
             $this->save();
         }
     }
 }
 /**
  * @return FieldList
  */
 public function getCMSFields()
 {
     $f = new FieldList($rootTab = new TabSet("Root", $tabMain = new Tab('Main')));
     $f->addFieldToTab('Root.Main', new TextField('Name', 'Name'));
     $f->addFieldToTab('Root.Main', $ddl = new DropdownField('ListType', 'ListType', $this->dbObject('ListType')->enumValues()));
     $f->addFieldToTab('Root.Main', $ddl2 = new DropdownField('CategoryID', 'Category', PresentationCategory::get()->filter('SummitID', $_REQUEST['SummitID'])->map('ID', 'Title')));
     $ddl->setEmptyString('-- Select List Type --');
     $ddl2->setEmptyString('-- Select Track  --');
     if ($this->ID > 0) {
         $config = GridFieldConfig_RecordEditor::create(25);
         $config->addComponent(new GridFieldAjaxRefresh(1000, false));
         $config->addComponent(new GridFieldPublishSummitEventAction());
         $config->removeComponentsByType('GridFieldDeleteAction');
         $config->removeComponentsByType('GridFieldAddNewButton');
         $config->addComponent($bulk_summit_types = new GridFieldBulkActionAssignSummitTypeSummitEvents());
         $bulk_summit_types->setTitle('Set Summit Types');
         $result = DB::query("SELECT DISTINCT SummitEvent.*, Presentation.*\nFROM SummitEvent\nINNER JOIN Presentation ON Presentation.ID = SummitEvent.ID\nINNER JOIN SummitSelectedPresentation ON SummitSelectedPresentation.PresentationID = Presentation.ID\nINNER JOIN SummitSelectedPresentationList ON SummitSelectedPresentation.SummitSelectedPresentationListID = {$this->ID}\nORDER BY SummitSelectedPresentation.Order ASC\n");
         $presentations = new ArrayList();
         foreach ($result as $row) {
             $presentations->add(new Presentation($row));
         }
         $gridField = new GridField('SummitSelectedPresentations', 'Selected Presentations', $presentations, $config);
         $gridField->setModelClass('Presentation');
         $f->addFieldToTab('Root.Main', $gridField);
     }
     return $f;
 }
예제 #9
0
 private function getPossibleCombinations(BoggleGrid $grid)
 {
     $results = new ArrayList("ArrayList");
     $results->add(new ArrayList("integer"));
     foreach ($this->word as $char) {
         $newResults = new ArrayList("ArrayList");
         foreach ($grid->getIndices($char) as $index) {
             foreach ($results as $result) {
                 if ($result->contains($index) || !$result->isEmpty() && !$grid->isIndicesAdjacent($result->getLast(), $index)) {
                     continue;
                 }
                 /*
                 $newResult = new ArrayList("integer");
                 $newResult->addAll($result);
                 $newResult->add($index);
                 */
                 $newResult = clone $result;
                 $newResult->add($index);
                 $newResults->add($newResult);
             }
         }
         $results = clone $newResults;
         //$results = new ArrayList("ArrayList");
         //$results->addAll($newResults);
     }
     return $results;
 }
예제 #10
0
 /**
  * Initializes the items to use in template
  * 
  * @return ArrayList
  * 
  * @author Sebastian Diel <*****@*****.**>
  * @since 22.03.2013
  */
 public function initItems()
 {
     $this->items = new ArrayList();
     foreach ($this->getDataList() as $item) {
         $arrayItem = array('Columns' => new ArrayList());
         foreach ($this->getFieldList() as $field => $fieldLabel) {
             if (strpos($field, '.') !== false) {
                 $parts = explode('.', $field);
                 $value = $item;
                 $index = 1;
                 foreach ($parts as $part) {
                     if ($index == count($parts)) {
                         $value = $value->{$part};
                     } else {
                         $value = $value->{$part}();
                     }
                     $index++;
                 }
             } else {
                 $value = $item->{$field};
             }
             $arrayItem['Columns']->add(new ArrayData(array('Value' => $value, 'Title' => $fieldLabel, 'Type' => $field)));
         }
         $this->items->add(new ArrayData($arrayItem));
     }
     return $this->items;
 }
 public function testAddRemove()
 {
     $list = new ArrayList(array(array('Key' => 1), array('Key' => 2)));
     $list->add(array('Key' => 3));
     $this->assertEquals($list->toArray(), array(array('Key' => 1), array('Key' => 2), array('Key' => 3)));
     $list->remove(array('Key' => 2));
     $this->assertEquals(array_values($list->toArray()), array(array('Key' => 1), array('Key' => 3)));
 }
예제 #12
0
 public function testLastIndexOf()
 {
     // Remove the following lines when you implement this test.
     $this->object->add(5);
     $this->object->add(5);
     $this->assertTrue($this->object->indexOf(5) == 5);
     $this->assertTrue($this->object->lastIndexOf(5) == 11);
 }
 /**
  * Used in the template to create filter categories
  *
  * @return ArrayList
  */
 public function getTag()
 {
     $arrayList = new ArrayList();
     foreach ($this->ImageTag() as $object) {
         $arrayList->add($object);
     }
     return $arrayList;
 }
예제 #14
0
 public function __toString()
 {
     $pairs = new ArrayList("string");
     foreach ($this as $key => $value) {
         $pairs->add("{$key}:{$value}");
     }
     return "{" . $pairs->join(",") . "}";
 }
예제 #15
0
 public function Transactions()
 {
     $GnuCashTransactions = GnuCashTransactionObject::get()->filter(array('SourceAccount' => $this->Title))->sort('Index', 'DESC');
     $transactions = new ArrayList();
     foreach ($GnuCashTransactions as $GnuCashTransaction) {
         $transactions->add(new ArrayData(['Date' => $GnuCashTransaction->Date, 'Description' => $GnuCashTransaction->Description, 'DestinationAccount' => $GnuCashTransaction->DestinationAccount, 'Amount' => $GnuCashTransaction->Amount, 'AmountNice' => number_format($GnuCashTransaction->Amount, 2) . ' ' . $this->CurrencySymbol, 'Balance' => $GnuCashTransaction->Balance, 'BalanceNice' => number_format($GnuCashTransaction->Balance, 2) . ' ' . $this->CurrencySymbol]));
     }
     return $transactions;
 }
 /**
  *	Retrieves a map of a page and it's direct descendants
  *
  *	@params int $pid Parent ID of the page(s) to start recursively displaying
  *	@return ArrayList
  */
 public static function getSiteMap($pid = 0)
 {
     $tmp = new ArrayList();
     $dl = SiteTree::get()->filter(array("ParentID" => $pid));
     foreach ($dl as $d) {
         //Should we display this? If not, don't forget it's children
         if (!$d->canSiteMap()) {
             $children = self::getSiteMap($d->ID);
             if ($children) {
                 foreach ($children as $c) {
                     $tmp->add(ArrayData::create(array('ParentMap' => $c->ParentMap, 'ChildrenMap' => $c->ChildrenMap)));
                 }
             }
         } else {
             $tmp->add(ArrayData::create(array('ParentMap' => $d, 'ChildrenMap' => ($ar = self::getSiteMap($d->ID)) ? $ar : null)));
         }
     }
     return $tmp;
 }
예제 #17
0
 public static function create($lang)
 {
     $content = String::create(file_get_contents("bean/games/boggle/data/blocks/{$lang}"));
     $layout = new ArrayList("String");
     foreach ($content->split("\n") as $die) {
         $layout->add($die->split(" ")->getRandomElement());
     }
     $layout->shuffle();
     return new BoggleGrid($layout);
 }
예제 #18
0
 private function getChildrenWithTag($tagName)
 {
     $tagNameStr = String::create($tagName);
     $result = new ArrayList("XmlElement");
     foreach ($this->children as $child) {
         if ($child->getName()->equals($tagNameStr)) {
             $result->add($child);
         }
     }
     return $result;
 }
 public function getMissingCoreComponents()
 {
     $res = new ArrayList();
     $release_component = $this->Release()->getOpenStackCoreComponents();
     foreach ($release_component as $rc) {
         if (intval($this->OpenStackComponents()->filter(array('IsCoreService' => 1, 'ID' => $rc->ID))->count()) === 0) {
             $res->add($rc);
         }
     }
     return $res;
 }
예제 #20
0
 public function EntitiesSurveys()
 {
     $res = new ArrayList();
     foreach ($this->Steps() as $step) {
         if ($step instanceof SurveyDynamicEntityStep) {
             foreach ($step->EntitySurveys() as $sub_surveys) {
                 $res->add($sub_surveys);
             }
         }
     }
     return $res;
 }
예제 #21
0
 public function sortedOptions()
 {
     $options = $this->Options();
     $newList = new ArrayList();
     // Add to new list
     foreach ($options as $option) {
         //$option->Position = $option->getPos();
         $newList->add($option);
         $newList->byID($option->ID)->Position = $option->getPos();
     }
     return $newList->sort('Position DESC');
 }
 public function testArrayListInput()
 {
     $button = new GridFieldExportButton();
     $this->gridField->getConfig()->addComponent(new GridFieldPaginator());
     //Create an ArrayList 1 greater the Paginator's default 15 rows
     $arrayList = new ArrayList();
     for ($i = 1; $i <= 16; $i++) {
         $dataobject = new DataObject(array('ID' => $i));
         $arrayList->add($dataobject);
     }
     $this->gridField->setList($arrayList);
     $this->assertEquals("\"ID\"\n\"1\"\n\"2\"\n\"3\"\n\"4\"\n\"5\"\n\"6\"\n\"7\"\n\"8\"\n" . "\"9\"\n\"10\"\n\"11\"\n\"12\"\n\"13\"\n\"14\"\n\"15\"\n\"16\"\n", $button->generateExportFileData($this->gridField));
 }
예제 #23
0
 public function indexesOf($search)
 {
     $result = new ArrayList("integer");
     $offset = 0;
     do {
         $index = $this->indexOf($search, $offset);
         if ($index == -1) {
             break;
         }
         $result->add($index);
         $offset = $index + 1;
     } while (true);
     return $result;
 }
예제 #24
0
 public function getFolderImages()
 {
     $templist = new ArrayList();
     $images = $this->ImageFolderID ? DataObject::get('Image', "ParentID = {$this->ImageFolderID}") : false;
     //remove first image from list which is used as preview in ProjectsPage.ss
     if ($this->FirstImageIsPreview) {
         foreach ($images as $image) {
             $templist->add($image);
         }
         $templist->shift();
         return $templist;
     }
     return $images;
 }
예제 #25
0
 /**
  * Finds all the items in shoppingcart session
  *
  * @return  ArrayList
  */
 public function CartItems()
 {
     $cartItems = Session::get("shoppingcart");
     $items = array();
     $products = new ArrayList();
     if ($cartItems) {
         $items = array_unique(explode(",", $cartItems));
         if (!empty($items)) {
             foreach ($items as $item) {
                 $products->add(Products::get_by_id('Products', (int) $item));
             }
         }
     }
     return $products;
 }
예제 #26
0
 public function doRender($rowIndex = null)
 {
     $context = parent::$settings->getContextPath();
     $view = $this->getConvertedValue($this->view, $rowIndex);
     $value = $this->getConvertedValue($this->value, $rowIndex);
     $params = new ArrayList("string");
     foreach ($this->getChildrenOfType("Param") as $param) {
         $paramVal = $this->getConvertedValue($param->getValue(), $rowIndex);
         $params->add(strval($paramVal));
     }
     $url = $view;
     if (!$params->isEmpty()) {
         $url .= ViewForward::URL_DELIMITER . $params->join("/")->getPrimitive();
     }
     $selPrefix = empty($this->selectedPrefix) ? $url : $this->selectedPrefix;
     $cl = empty($this->class) ? "" : " " . $this->class;
     return "<a selectedPrefix=\"{$selPrefix}\" class=\"RenderLink{$cl}\" href=\"{$context}/{$url}\">{$value}{$this->renderChildren(array(), array("Param"), $rowIndex)}</a>";
 }
 public function Field($properties = array())
 {
     Requirements::css('survey_builder/css/survey.radio.button.matrix.field.css');
     Requirements::javascript('survey_builder/js/survey.radio.button.matrix.field.js');
     Requirements::customScript("\n                jQuery(document).ready(function(\$){\n                    \$('#{$this->name}').survey_radio_button_matrix_field();\n                });\n            ");
     $cols = new ArrayList($this->question->getColumns());
     $rows = new ArrayList($this->question->getRows());
     $already_added_additional_rows = new ArrayList();
     $additional_rows = new ArrayList($this->question->getAlternativeRows());
     $answer_value = $this->AnswerValue();
     if (!empty($answer_value)) {
         $tuples = explode(',', $answer_value);
         $exclude_row_list = array();
         foreach ($tuples as $t) {
             list($row_id, $col_id) = explode(':', $t);
             if ($this->question->isAlternativeRow($row_id)) {
                 //already added
                 $already_added_additional_rows->add($this->question->getAlternativeRow($row_id));
                 array_push($exclude_row_list, $row_id);
             }
         }
         if (count($exclude_row_list)) {
             $additional_rows = new ArrayList($this->question->getAlternativeRows(implode(',', $exclude_row_list)));
         }
     }
     foreach ($rows as $r) {
         $r->Columns = $cols;
     }
     foreach ($additional_rows as $r) {
         $r->Columns = $cols;
     }
     foreach ($already_added_additional_rows as $r) {
         $r->Columns = $cols;
     }
     $properties['Columns'] = $cols;
     $properties['Rows'] = $rows;
     $properties['AdditionalRows'] = $additional_rows;
     $properties['AlreadyAddedAdditionalRows'] = $already_added_additional_rows;
     $properties['RowsLabel'] = $this->question->RowsLabel;
     $properties['AdditionalRowsLabel'] = $this->question->AdditionalRowsLabel;
     $properties['AdditionalRowsDescription'] = $this->question->AdditionalRowsDescription;
     $properties['EmptyString'] = $this->question->EmptyString;
     return $this->customise($properties)->renderWith(array("SurveyRadioButtonMatrixField"));
 }
    public function CommitsPerCountry()
    {
        SangriaPage_Controller::generateDateFilters('C', 'CreatedDate');
        $date_filter = SangriaPage_Controller::$date_filter_query;
        $sql = <<<SQL
SELECT COUNT(C.ID) AS Commits , M.Country FROM GerritChangeInfo C INNER JOIN Member M on M.ID = C.MemberId
WHERE {$date_filter}
GROUP BY M.Country ORDER BY Commits DESC;
SQL;
        $res = DB::query($sql);
        $list = new ArrayList();
        foreach ($res as $row) {
            $country_code = $row['Country'];
            $country_name = isset(CountryCodes::$iso_3166_countryCodes[$country_code]) ? CountryCodes::$iso_3166_countryCodes[$country_code] : 'NOT SET';
            $country_code = isset(CountryCodes::$iso_3166_countryCodes[$country_code]) ? $country_code : 'NOT SET';
            $list->add(new ArrayData(array('Commits' => $row['Commits'], 'CountryName' => $country_name, 'Country' => $country_code)));
        }
        return $list;
    }
예제 #29
0
 /**
  * Splits a string, an array or an ArrayList by one of 4 different methods.
  *      ArrayList (Of any of the 4 object types)
  *      Array (Of any of the 4 object types)
  *      String (To explode by)
  *      Regular Expression (To split by)
  * 
  * This is a powerful tool, but a lot of recursion will occur if using an
  * array and/or an ArrayList.
  * 
  * And 4 basic use cases:
  *      Split a String by a String
  *      Split a String by an Array (nested?) of Strings
  *      Split an Array (nested?) of Strings by a String
  *      Split an Array (nested?) of Strings by an Array (nested?) of Strings
  * 
  * Using Arrays as one of the two parameters can be a tad messy, but easy
  * once you figure it out.
  * 
  * No Matter what an array is returned for each delimiter string and each
  * "split" string, no matter how nested. Using multiple delimiters will not
  * cause the string to be split by multiple delimiters, but instead to split
  * each delimiter into another set of split strings (Refer to line 43).
  * 
  * @param ArrayList|string|array $delimiters The character(s) you're splitting by, can be inside arrays/nested arrays.
  * @param string $string The string you are trying to split.
  * @param bool $allowDuplicates If true then the normal ArrayList "remove duplicate objects" will be ignored, and instead the same value/object may appear in the ArrayList twice.
  * @return ArrayList Split String as an ArrayList, may contain sub-arraylists.
  * @throws Exception
  */
 public static function explode($delimiters, &$string, $allowDuplicates = true)
 {
     if (!is_string($string) && !is_array($string) && !$string instanceof ArrayList) {
         throw new Exception('String is invalid.');
     }
     //$delimiters may be a String (1 delimiter), an ArrayList, an Array or a Regular Expression
     //Array/ArrayList Delimiters
     if ($delimiters instanceof ArrayList) {
         $x = new ArrayList();
         foreach ($delimiters as $delimiter) {
             $x->add($string = ArrayList::explode($delimiter, $string), false, true);
         }
         return $x;
     } else {
         if (is_array($delimiters)) {
             return ArrayList::explode(new ArrayList($delimiters), $string);
             //CHEAP
         } else {
             if (is_string($delimiters)) {
                 if (is_string($string)) {
                     return new ArrayList(explode($delimiters, $string));
                 } else {
                     if (is_array($string)) {
                         return ArrayList::explode($delimiters, new ArrayList($string));
                     } else {
                         if ($string instanceof ArrayList) {
                             $x = new ArrayList();
                             foreach ($string as $str) {
                                 $x->add(ArrayList::explode($delimiters, $str), false, true);
                             }
                             return $x;
                         }
                     }
                 }
             } else {
                 if (@preg_match($delimiters, null) !== false) {
                     //return new ArrayList(preg_split($delimiters, $string));
                 }
             }
         }
     }
     throw new Exception('Invalid Delimiters (Must be Array, ArrayList, Regular Expression or String)');
 }
 private static function toCollection($data)
 {
     if (is_object($data)) {
         $map = new Map();
         foreach ($data as $k => $v) {
             if (is_object($v) || is_array($v)) {
                 $map->set($k, self::toCollection($v));
             } else {
                 $map->set($k, $v);
             }
         }
         return $map;
     } else {
         if (is_array($data)) {
             $list = new ArrayList();
             foreach ($data as $v) {
                 $list->add(is_object($v) || is_array($v) ? self::toCollection($v) : $v);
             }
             return $list;
         }
     }
 }