当前位置: 首页>>代码示例>>PHP>>正文


PHP ArrayList::first方法代码示例

本文整理汇总了PHP中ArrayList::first方法的典型用法代码示例。如果您正苦于以下问题:PHP ArrayList::first方法的具体用法?PHP ArrayList::first怎么用?PHP ArrayList::first使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ArrayList的用法示例。


在下文中一共展示了ArrayList::first方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: getEarliestElectionSince

 /**
  * @param int $years
  * @return IElection
  */
 public function getEarliestElectionSince($years)
 {
     $sql = 'select * from Election where ElectionsClose >= date_add(now(), interval -' . $years . ' year) ORDER BY ElectionsClose ASC LIMIT 0,1;';
     $result = DB::query($sql);
     // let Silverstripe work the magic
     $elections = new ArrayList();
     foreach ($result as $rowArray) {
         // concept: new Product($rowArray)
         $elections->push(new $rowArray['ClassName']($rowArray));
     }
     return $elections->first();
 }
开发者ID:OpenStackweb,项目名称:openstack-org,代码行数:16,代码来源:SapphireElectionRepository.php

示例2: getPrintURLForMany

 /**
  * Returns the print URL for the given DataObject
  * (silvercart-print/$DataObjectName/$DataObjectID)
  *
  * @param ArrayList $dataObjectList ArrayList to get print URL for
  * 
  * @return string 
  */
 public static function getPrintURLForMany($dataObjectList)
 {
     $printURL = '';
     if ($dataObjectList instanceof SS_List) {
         $dataObject = $dataObjectList->first();
         if ($dataObject instanceof DataObject) {
             $map = $dataObjectList->map('ID', 'ID');
             if ($map instanceof SS_Map) {
                 $map = $map->toArray();
             }
             $printURL = sprintf('silvercart-print-many/%s/%s', $dataObject->ClassName, implode('-', $map));
         }
     }
     return $printURL;
 }
开发者ID:silvercart,项目名称:silvercart,代码行数:23,代码来源:SilvercartPrint.php

示例3: testGetColumnAttributesBadResponseFromComponent

 public function testGetColumnAttributesBadResponseFromComponent()
 {
     $this->setExpectedException('LogicException');
     $list = new ArrayList(array(new Member(array("ID" => 1, "Email" => "test@example.org"))));
     $config = GridFieldConfig::create()->addComponent(new GridFieldTest_Component());
     $obj = new GridField('testfield', 'testfield', $list, $config);
     $obj->getColumnAttributes($list->first(), 'Surname');
 }
开发者ID:ivoba,项目名称:silverstripe-framework,代码行数:8,代码来源:GridFieldTest.php

示例4: translate

 public function translate(SS_HTTPRequest $request)
 {
     $locales = "";
     if (SiteTree::has_extension("Translatable")) {
         $locales = Translatable::get_allowed_locales();
     } else {
         $locales = array("it_IT");
     }
     $locales_list = new ArrayList();
     foreach ($locales as $key => $value) {
         $obj = new ViewableData();
         $obj->__set("Locale", $value);
         $obj->__set("LocaleName", i18n::get_locale_name($value));
         $obj->__set("Lang", i18n::get_lang_from_locale($value));
         $locales_list->push($obj);
     }
     if ($request->isAjax()) {
         if (isset($_POST["collect"])) {
             foreach ($locales as $value) {
                 $c = new TextCollector($value);
                 $c->run(LanguageAdmin::$modules, true);
             }
             die(_t("SUCCESSFULL_COLLECT", "The text was collected."));
         }
         if (isset($_POST["save"])) {
             $lang_array[$_POST["locale"]] = $_POST[$_POST["locale"]];
             $file = $_POST["file"];
             $yml_file = sfYaml::dump($lang_array);
             if ($fh = fopen($file, "w")) {
                 fwrite($fh, $yml_file);
                 fclose($fh);
                 file_get_contents("http://{$_SERVER['HTTP_HOST']}?flush");
             } else {
                 throw new LogicException("Cannot write language file! Please check permissions of {$langFile}");
             }
             die;
         }
         $files = $this->getFiles();
         if (isset($_POST["loadfiles"])) {
             //  die($this->getYaml($_POST["loadfiles"]));
             $this->customise(array("Translations" => $this->getYaml($_POST["loadfiles"]), "Modules" => $files, "Locales" => $locales_list));
             $content = $this->renderWith('LanguageAdmin_Content');
             return $content;
         } else {
             $this->customise(array("Modules" => $files, "Translations" => $this->getYaml($files->filter(array('Locale' => $locales_list->first()->Locale))->first()->Path), "Locales" => $locales_list, "CurrentLocale" => $locales_list->first()->LocaleName));
             $content = $this->renderWith('LanguageAdmin_Content');
             return $content;
         }
     } else {
         $files = $this->getFiles();
         $this->customise(array("Modules" => $files, "Translations" => $this->getYaml($files->filter(array('Locale' => $locales_list->first()->Locale))->first()->Path), "Locales" => $locales_list, "CurrentLocale" => $locales_list->first()->LocaleName));
         $content = $this->renderWith($this->getViewer('translate'));
         return $content;
     }
 }
开发者ID:helpfulrobot,项目名称:calinhoria-langedit,代码行数:55,代码来源:LanguageAdmin.php

示例5: testFirstLast

 public function testFirstLast()
 {
     $list = new ArrayList(array(array('Key' => 1), array('Key' => 2), array('Key' => 3)));
     $this->assertEquals($list->first(), array('Key' => 1));
     $this->assertEquals($list->last(), array('Key' => 3));
 }
开发者ID:maent45,项目名称:redefine_renos,代码行数:6,代码来源:ArrayListTest.php

示例6: testMultiSort

	public function testMultiSort() {
		$list = new ArrayList(array(
			(object) array('ID'=>3, 'Name'=>'Bert', 'Importance'=>1),
			(object) array('ID'=>1, 'Name'=>'Aron', 'Importance'=>2),
			(object) array('ID'=>2, 'Name'=>'Aron', 'Importance'=>1),
		));
		
		$list->sort(array('Name'=>'ASC', 'Importance'=>'ASC'));
		$this->assertEquals($list->first()->ID, 2, 'Aron.2 should be first in the list');
		$this->assertEquals($list->last()->ID, 3, 'Bert.3 should be last in the list');
		
		$list->sort(array('Name'=>'ASC', 'Importance'=>'DESC'));
		$this->assertEquals($list->first()->ID, 1, 'Aron.2 should be first in the list');
		$this->assertEquals($list->last()->ID, 3, 'Bert.3 should be last in the list');
	}
开发者ID:redema,项目名称:sapphire,代码行数:15,代码来源:ArrayListTest.php


注:本文中的ArrayList::first方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。