當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。