/** * @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(); }
/** * 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; }
public function testGetColumnAttributesBadResponseFromComponent() { $this->setExpectedException('LogicException'); $list = new ArrayList(array(new Member(array("ID" => 1, "Email" => "*****@*****.**")))); $config = GridFieldConfig::create()->addComponent(new GridFieldTest_Component()); $obj = new GridField('testfield', 'testfield', $list, $config); $obj->getColumnAttributes($list->first(), 'Surname'); }
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; } }
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)); }
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'); }
public function testMultiSort() { $list = new ArrayList(array((object) array('Name' => 'Object1', 'F1' => 1, 'F2' => 2, 'F3' => 3), (object) array('Name' => 'Object2', 'F1' => 2, 'F2' => 1, 'F3' => 4), (object) array('Name' => 'Object3', 'F1' => 5, 'F2' => 2, 'F3' => 2))); $list->sort('F3', 'ASC'); $this->assertEquals($list->first()->Name, 'Object3', 'Object3 should be first in the list'); $list->sort('F3', 'DESC'); $this->assertEquals($list->first()->Name, 'Object2', 'Object2 should be first in the list'); $list->sort(array('F2' => 'ASC', 'F1' => 'ASC')); $this->assertEquals($list->last()->Name, 'Object3', 'Object3 should be last in the list'); $list->sort(array('F2' => 'ASC', 'F1' => 'DESC')); $this->assertEquals($list->last()->Name, 'Object1', 'Object1 should be last in the list'); }