private function loadJsonString($policyName, $data) { $rawRules = json_decode($data); if ($rawRules === NULL) { $jsonErrorCode = json_last_error(); $jsonErrorMessage = $this->getJsonErrorReason($jsonErrorCode); throw new \UnexpectedValueException(sprintf("%s: error while reading policy file `%s`. Reason: %s (%d)", __CLASS__, $policyName, $jsonErrorMessage, $jsonErrorCode), 1327572840); } if (!is_array($rawRules)) { throw new \UnexpectedValueException(sprintf("%s: invalid policy file `%s`.", __CLASS__, $policyName), 1327572841); } foreach ($rawRules as $rawRule) { $ruleObject = PolicyRule::createFromObject($rawRule); // skip existing "final" rule: if (isset($this->rules[$ruleObject->getIdentifier()])) { if ($this->rules[$ruleObject->getIdentifier()]->isFinal()) { continue; } else { $this->getLog()->notice(sprintf('%s: rule#%d is overridden in policy `%s`', __CLASS__, $ruleObject->getIdentifier(), $policyName)); } } $this->rules[$ruleObject->getIdentifier()] = $ruleObject; } // reverse sorting: $this->rules->uasort(function (PolicyRule $a, PolicyRule $b) { return -$a->compare($b); }); return $this; }
/** * Sort gears by parameter * * @param string $param */ private function sortGears($param = 'order') { $method = 'sortBy' . ucfirst($param); if (method_exists('Core_ArrayObject', $method)) { $this->gears->uasort('Core_ArrayObject::' . $method); } }
/** * Retrieve messages * @param integer $limit * @return ArrayAccess */ public function get($limit = 10) { foreach ($this->sources as $source) { $this->messages = $source->retrieve($this->searchfor, $limit); } $messages = new ArrayObject(); $order = new AI(); foreach ($this->messages as $message) { $message = new Message($message[2], $message[0], $message[6], $message[3], $message[4], $message[5], $message[1], $message[7]); $message = $order->rank($message); $messages->append($message); } $messages->uasort(array($this, 'sortByRank')); return $messages; }
/** * Constructor. * * @param \Iterator $iterator The Iterator to filter * @param integer|\Closure $sort The sort type (SORT_BY_NAME, SORT_BY_TYPE, or a \Closure instance) */ public function __construct(\Iterator $iterator, $sort) { if (self::SORT_BY_NAME === $sort) { $sort = function ($a, $b) { return strcmp($a->getRealpath(), $b->getRealpath()); }; } elseif (self::SORT_BY_TYPE === $sort) { $sort = function ($a, $b) { if ($a->isDir() && $b->isFile()) { return -1; } elseif ($a->isFile() && $b->isDir()) { return 1; } return strcmp($a->getRealpath(), $b->getRealpath()); }; } elseif (!$sort instanceof \Closure) { throw new \InvalidArgumentException(sprintf('The SortableIterator takes a \\Closure or a valid built-in sort algorithm as an argument (%s given).', $sort)); } $array = new \ArrayObject(iterator_to_array($iterator)); $array->uasort($sort); parent::__construct($array); }
/** * Return the list of available modules, including uninstalled modules. */ static function available() { if (empty(self::$available)) { $modules = new ArrayObject(array(), ArrayObject::ARRAY_AS_PROPS); foreach (glob(MODPATH . "*/module.info") as $file) { $module_name = basename(dirname($file)); $modules->{$module_name} = new ArrayObject(parse_ini_file($file), ArrayObject::ARRAY_AS_PROPS); foreach ($modules->{$module_name} as &$value) { $value = html::purify($value); } $m =& $modules->{$module_name}; $m->installed = module::is_installed($module_name); $m->active = module::is_active($module_name); $m->code_version = $m->version; $m->version = module::get_version($module_name); $m->locked = false; if ($m->active && $m->version != $m->code_version) { site_status::warning(t("Some of your modules are out of date. <a href=\"%upgrader_url\">Upgrade now!</a>", array("upgrader_url" => url::abs_site("upgrader"))), "upgrade_now"); } } // Lock certain modules $modules->gallery->locked = true; $identity_module = module::get_var("gallery", "identity_provider", "user"); $modules->{$identity_module}->locked = true; $modules->uasort(array("module", "module_comparator")); self::$available = $modules; } return self::$available; }
$error="Something weird happened: ".$e->getMessage()." (errcode=".$e->getCode().")\n"; print $error; exit; } $object->fields->$_POST['fields']->$_POST['attrname']->type=$_POST['type']; $object->fields->$_POST['fields']->$_POST['attrname']->length=$_POST['size']; $object->fields->$_POST['fields']->$_POST['attrname']->enable=$_POST['enable']; if (isset($_POST['label'])) { $object->fields->$_POST['fields']->$_POST['attrname']->label=$_POST['label']; } foreach ($object->fields as $key => $value) { $array = new ArrayObject($object->fields->$key); $array->uasort(array("ExtraFields","compare")); //trie suivant la position $value=$array; } //print_r ($object->fields);exit; try { $couchdb->storeDoc($object); } catch (Exception $e) { $error="Something weird happened: ".$e->getMessage()." (errcode=".$e->getCode().")\n"; print $error; exit; } Header("Location: ".$_SERVER["PHP_SELF"]);
public function rsort() { parent::uasort('Arr::sort_alg'); return $this; }
<?php /* Prototype : int ArrayObject::uasort(callback cmp_function) * Description: proto int ArrayIterator::uasort(callback cmp_function) Sort the entries by values user defined function. * Source code: ext/spl/spl_array.c * Alias to functions: */ echo "*** Testing ArrayObject::uasort() : basic functionality ***\n"; // Reverse sorter function cmp($value1, $value2) { if ($value1 == $value2) { return 0; } else { if ($value1 < $value2) { return 1; } else { return -1; } } } $ao = new ArrayObject(array(2, 3, 1)); $ao->uasort('cmp'); var_dump($ao); ?> ===DONE===
private function PlayListFromDir($Dir, &$Key, &$Playlist, &$Info) { global $NL; global $DIR_DELIM; $Arr = new ArrayObject(); try { $cnt = 0; $MTimeDPL = -1; $MaxMTimeMusic = -1; $it = new directoryIterator($Dir); while ($it->valid()) { if ($it->isFile()) { $ext = pathinfo($it->current(), PATHINFO_EXTENSION); if ($ext == "dpl") { $MTimeDPL = $it->getMTime(); } elseif ($ext == "flac" || $ext == "mp3" || $ext == "wma" || $ext == "m4a") { if ($MaxMTimeMusic == -1 || $MaxMTimeMusic < $it->getMTime()) { $MaxMTimeMusic = $it->getMTime(); } $cnt++; } } $it->next(); } if ($cnt == 0 || $MTimeDPL > 0 && $MTimeDPL > $MaxMTimeMusic) { return false; } $it->rewind(); while ($it->valid()) { if ($it->isFile()) { $ext = pathinfo($it->current(), PATHINFO_EXTENSION); if ($ext == "dpl") { unlink($it->getPathName()); } elseif ($ext == "flac" || $ext == "mp3" || $ext == "wma" || $ext == "m4a") { //echo $it->getPathName() . $NL; $Arr->append(new MusicTags($it->getPathName())); } } $it->next(); } } catch (Exception $e) { echo $e->getMessage(); } $Tracks = ""; $cnt = $Arr->count(); if ($cnt > 1) { $Arr->uasort(array('Playlist', 'TrackNoOrder')); } $it = $Arr->getIterator(); while ($it->valid()) { if (0 && isset($Artist) && $Artist != $it->current()->Artist()) { $Artist = "Various Artists"; $ARTIST = $Artist; } else { $Artist = str_replace("/", ",", $it->current()->Artist()); $ARTIST = $it->current()->Artist(); } $AlbumArtist = str_replace("/", ",", $it->current()->AlbumArtist()); $ALBUMARTIST = $it->current()->AlbumArtist(); $Album = str_replace("/", ",", $it->current()->Album()); $ALBUM = $it->current()->Album(); $Date = $it->current()->Date(); $DATE = $Date; $Genre = str_replace("/", ",", $it->current()->Genre()); $GENRE = $it->current()->Genre(); $Tracks .= $NL . Linn_Track($it->current()->getDIDL()); $it->next(); } if ($cnt > 0) { $PLAYLIST = RelativeBuildPath($Dir . $DIR_DELIM . "playlist.dpl"); $PLAYLIST = str_replace("&", "&", $PLAYLIST); $img = $Dir . $DIR_DELIM . "folder.png"; if (!file_exists($img)) { $img = $Dir . $DIR_DELIM . "folder.jpg"; } $ART = RelativeBuildPath($img); $img80 = dirname($img) . $DIR_DELIM . "80x80.jpg"; $img160 = dirname($img) . $DIR_DELIM . "160x160.jpg"; if (file_exists($img)) { if (!file_exists($img80)) { $cmd = 'convert "' . $img . '" -thumbnail 80x80 +profile "*" "' . $img80 . '"'; echo $NL . $cmd . $NL; shell_exec($cmd); } if (!file_exists($img160)) { $cmd = 'convert "' . $img . '" -thumbnail 160x160 +profile "*" "' . $img160 . '"'; echo $NL . $cmd . $NL; shell_exec($cmd); } } $ART80 = RelativeBuildPath($img80); $ART160 = RelativeBuildPath($img160); $ART = str_replace("&", "&", $ART); $ART80 = str_replace("&", "&", $ART80); $ART160 = str_replace("&", "&", $ART160); $ALBUM = str_replace("&", "&", $ALBUM); $GENRE = str_replace("&", "&", $GENRE); $ARTIST = str_replace("&", "&", $ARTIST); $ALBUMARTIST = str_replace("&", "&", $ALBUMARTIST); $ART = str_replace('"', """, $ART); $ART80 = str_replace('"', """, $ART80); $ART160 = str_replace('"', """, $ART160); $ALBUM = str_replace('"', """, $ALBUM); $GENRE = str_replace('"', """, $GENRE); $ARTIST = str_replace('"', """, $ARTIST); $Artist = str_replace('"', """, $Artist); $ALBUMARTIST = str_replace('"', """, $ALBUMARTIST); $AlbumArtist = str_replace('"', """, $AlbumArtist); $Key = $AlbumArtist . "+" . $Album . "+" . $Date . "+" . $Genre . "+" . $MaxMTimeMusic; //$KEY = $ALBUMARTIST . "+" . $ALBUM . "+" . $DATE . "+" . $GENRE . "+" . $MaxMTimeMusic; $Info = <<<EOT <?xml version="1.0" encoding="UTF-8"?> <Info> <Artist>{$ARTIST}</Artist> <AlbumArtist>{$ALBUMARTIST}</AlbumArtist> <Album>{$ALBUM}</Album> <Date>{$DATE}</Date> <Genre>{$GENRE}</Genre> <MusicTime>{$MaxMTimeMusic}</MusicTime> <Playlist>{$PLAYLIST}</Playlist> <NoTracks>{$cnt}</NoTracks> <Art>{$ART}</Art> <Art80>{$ART80}</Art80> <Art160>{$ART160}</Art160> </Info> EOT; $Playlist = Linn_Playlist($Tracks); } else { $Key = ""; $Info = ""; $Playlist = ""; } return $cnt > 0; }
static function get_next_courses($user_id) { /* $items = array(); $db = \DBManager::get(); $semester = \SemesterData::getCurrentSemesterData(); $semester_begin = $semester["beginn"]; $semester_ende = $semester["ende"]; $today =date("N"); // !!! bisher ohne cycling, kein Dozent // !! bisher die ersten 5 in der woche // was ist cycle bzw weekoffset inseminar seminar_cycle_dates $fields= "seminar_user.Seminar_id AS Seminar_id, seminar_user.user_id, seminar_user.visible, seminare.Seminar_id, seminare.start_time, seminare.Name AS name, seminar_cycle_dates.start_time AS beginn, seminar_cycle_dates.end_time AS ende, seminar_cycle_dates.start_time, seminar_cycle_dates.weekday AS weekday, seminar_cycle_dates.seminar_id, seminar_cycle_dates.description AS description "; $query = "SELECT $fields FROM seminar_user JOIN seminare ON seminar_user.Seminar_id = seminare.Seminar_id JOIN seminar_cycle_dates ON seminar_user.Seminar_id = seminar_cycle_dates.seminar_id WHERE seminar_user.user_id = '$user_id' AND seminar_user.visible = 'yes' AND seminare.start_time >= '$semester_begin' ORDER BY seminar_cycle_dates.weekday, seminar_cycle_dates.start_time "; $result = $db->query($query); $i = 0; foreach($result as $row) { $i++; $items[$i] = array( 'id' => $row['Seminar_id'], 'title' => $row['name'], 'beginn' => substr($row['beginn'], 0, 5), 'ende' => substr($row['ende'], 0, 5), 'weekday' => $row['weekday'], 'description' => $row['description'] ); } */ //get current semester $semdata = new \SemesterData(); $current_semester = $semdata->getCurrentSemesterData(); $current_semester_id = $current_semester['semester_id']; $entries = \CalendarScheduleModel::getEntries($user_id, $current_semester, 00, 2000, array(0, 1, 2, 3, 4, 5, 6), false); $output = array(); $counter = 0; $currentWeekDay = date("N") - 1; $currentTime = date("Gi"); if (!empty($entries)) { for ($i = 0; $i <= 6; $i++) { $currentWeekDay += $i; if ($currentWeekDay > 6) { $currentWeekDay = 0; } $currentDayObject = $entries[$currentWeekDay]; if (!empty($currentDayObject)) { //sortieren der einträge des tages $arrayObject = new \ArrayObject($currentDayObject->getEntries()); $arrayObject->uasort('Helper::cmpEarlier'); foreach ($arrayObject->getArrayCopy() as $entry) { if ($counter >= 3) { break; $i = 7; } if ($entry["start"] > $currentTime || $i != 0) { $output[$counter] = array("title" => $entry["title"], "description" => $entry["content"], "beginn" => $entry["start_formatted"], "ende" => $entry["end_formatted"], "weekday" => $currentWeekDay + 1, "id" => substr($entry["id"], 0, 32)); $counter++; } } } } } else { return null; } return $output; /* //var_dump($output); //nur die nächsten 3 sollen auftauchen $currentWeekDay =date("N"); $i = 0; if (!empty($items)) { $ausgabe = array(); //suchen des nächsten Cycles for ($i = 0; $i <= 6; $i++) { $currentWeekDay +=$i; if($currentWeekDay > 7) $currentWeekDay = 1; foreach($items AS $item) { //an dem gesuchten wochentag event .... if ($item['weekday'] == $currentWeekDay) { //nächstes event gefunden //Auffinden der nächsten beiden $ausgabe[1] = $item; $nextitemID = $item['weekday']; if (isset($items[ $nextitemID ])) { //zweites gefunden $ausgabe[2] = $items[ 1 ]; $nextitemID++; } else { $ausgabe[2] = $items[ 1 ]; $nextitemID = 2; } if (isset($items[ $nextitemID ])) { //zweites gefunden $ausgabe[3] = $items[ 1 ]; } else { $ausgabe[3] = $items[ 1 ]; } //fertig $i=8; break; } } } } else { return null; } return $ausgabe; */ }
/** * Сортируем студентов по имени. * * @param array студенты. */ protected static function doSortArrObj(\ArrayObject $arrObj) { $arrObj->uasort(create_function('$ctL,$ctR', 'return strcmp(mb_strtoupper($ctL->getName()), mb_strtoupper($ctR->getName()));')); }
<?php /* Prototype : int ArrayObject::uasort(callback cmp_function) * Description: proto int ArrayIterator::uasort(callback cmp_function) Sort the entries by values user defined function. * Source code: ext/spl/spl_array.c * Alias to functions: */ $ao = new ArrayObject(); try { $ao->uasort(); } catch (BadMethodCallException $e) { echo $e->getMessage() . "\n"; } try { $ao->uasort(1, 2); } catch (BadMethodCallException $e) { echo $e->getMessage() . "\n"; } ?> ===DONE===
public function uasort($cmp_function) { $this->lazyLoadArray(); parent::uasort($cmp_function); }
/** * Implementation of ArrayObject::uasort(). * * This function sorts the entries such that keys maintain their correlation * with the entry that they are associated with, using a user-defined * comparison function. * * This is used mainly when sorting associative arrays where the actual * element order is significant. * * No value is returned. * * @param callable $cmpFunction The callback comparison function. */ public function uasort($cmpFunction) { $this->arrayObject->uasort($cmpFunction); }