本文整理汇总了PHP中ArrayList::add方法的典型用法代码示例。如果您正苦于以下问题:PHP ArrayList::add方法的具体用法?PHP ArrayList::add怎么用?PHP ArrayList::add使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ArrayList
的用法示例。
在下文中一共展示了ArrayList::add方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testAddSameElementTwice
function testAddSameElementTwice()
{
$list = new ArrayList("string");
$list->add("Hello there");
$list->add("Hello there");
$this->assertEqual(2, $list->size());
}
示例2: testNormalList
function testNormalList()
{
$list = new ArrayList("string");
$list->add("a");
$list->add("b");
$this->assertEqual("[a,b]", $list->__toString());
}
示例3: testUpdateElementCheckChanged
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: testSortObjectsComparator
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());
}
示例5: getMenu
/**
* 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");
}
示例6: ViewableDiscussions
/**
* 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);
}
开发者ID:helpfulrobot,项目名称:i-lateral-silverstripe-discussions,代码行数:35,代码来源:DiscussionHolder_Controller.php
示例7: add
/**
* 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();
}
}
}
示例8: getCMSFields
/**
* @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: getPossibleCombinations
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: initItems
/**
* Initializes the items to use in template
*
* @return ArrayList
*
* @author Sebastian Diel <sdiel@pixeltricks.de>
* @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;
}
示例11: testAddRemove
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: testLastIndexOf
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);
}
示例13: getTag
/**
* 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: __toString
public function __toString()
{
$pairs = new ArrayList("string");
foreach ($this as $key => $value) {
$pairs->add("{$key}:{$value}");
}
return "{" . $pairs->join(",") . "}";
}
示例15: Transactions
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;
}