Файловый менеджер - Редактировать - /var/www/vhosts/studiocol.dev1.mndrn.cloud/libs/collectionsObject.lib.php
Назад
<?php ### GYURAL ### /* ------------ Gyural 1.9.1 ------------ Filename: /libs/collectionsObject.lib.php Version: 1.9.1 Author: federicoq <f.quagliotto@mandarinoadv.com> Date: 04/11/2014 */ class collectionsObject { var $results; ///////////////////////// // Infos about Results // ///////////////////////// // Tot Length public function length() { return count($this->results); } // Max public function max($key, $onlyVar = false) { $max = 0; if($this->length() > 1) { foreach($this->results as $k => $r) { if(!isset($r->$key)) continue; if($r->$key > $max) { $max = $r->$key; $obj = $r; } } } if($onlyVar) return $max; else return $obj; } // Min public function min($key, $onlyVar = false) { if($this->length() > 1) { foreach($this->results as $k => $r) { if(!isset($r->$key)) continue; if($r->$key < $min || !isset($min)) { $min = $r->$key; $obj = $r; } } } if($onlyVar) return $min; else return $obj; } // Average public function average($key, $onlyVar = false) { $info = $this->filterBy($key); $average = ceil($info->length()/2); if(!$onlyVar) return $info->results[$average]; else return $info->results[$average]->$key; } ///////////////////////// ///////////////////////// ///////////////////////// // Popolate public function popolate($results) { if(is_array($results)) $this->results = $results; else $this->results[] = $results; return $this; } // Filter by a field public function filterBy($field, $ord = ASC) { $key = array(); $output = array(); if($this->length() == 1) return $this; foreach($this->results as $index => $row) { if(!isset($row->$field)) continue; $key[$index] = $row->$field; } if($ord == ASC) asort($key); else if($ord == DESC) arsort($key); foreach($key as $index => $useless) $output[] = $this->results[$index]; $this->results = $output; return $this; } // Change key of Results public function changeKey($what) { $output = array(); foreach($this->results as $index => $obj) { if(!isset($obj->$what)) continue; if(!isset($output[$obj->$what])) $output[$obj->$what] = $obj; else { if(is_array($output[$obj->$what])) { $output[$obj->$what][] = $obj; } else { $tmp = $output[$obj->$what]; $output[$obj->$what] = array($tmp, $obj); } } } $this->results = $output; return $this; } // Link the field to another class public function link($key, $class) { foreach($this->results as $index => $obj) { if(isset($obj->$key)) { $obj->{ 'gyu_' . $key } = LoadClass($class, 1)->get($obj->$key); } } return $this; } // Find public function find($what) { if(is_string($what)) { preg_match_all('/(\w+)(!=|=|<=|<|>|>=|~=)(\w+)/i', $what, $matches); foreach($matches[1] as $k=>$v) { $conditions[] = array($v, $matches[2][$k], $matches[3][$k]); } } else { $conditions = $what; } $output = array(); foreach($this->results as $k => $value) { $canCheck = true; foreach($conditions as $checker) { if(!$canCheck) continue; $canCheck = false; $value_condition = $checker[2]; $value_operator = $checker[1]; $value_toCheck = $value->$checker[0]; if($value_operator == '=') { if(strtolower($value_condition) == strtolower($value_toCheck)) { $canCheck = true; } } else if($value_operator == '!=') { if($value_condition != $value_toCheck) { $canCheck = true; } } else if($value_operator == '>') { if($value_toCheck > $value_condition) { $canCheck = true; } } else if($value_operator == '<') { if($value_toCheck < $value_condition) { $canCheck = true; } } else if($value_operator == '>=') { if($value_toCheck >= $value_condition) { $canCheck = true; } } else if($value_operator == '<=') { if($value_toCheck <= $value_condition) { $canCheck = true; } } else if($value_operator == '~=') { if(stristr($value_toCheck, $value_condition)) { $canCheck = true; } } } if($canCheck) { $output[$k] = $value; } } if(count($output) > 0) $this->results = $output; return $this; } // Map function map($methodName) { foreach($this->results as $obj) { if(method_exists($obj, $methodName)) { $obj->$methodName(); } } return $this; } } ?>
| ver. 1.4 |
Github
|
.
| PHP 8.2.5 | Генерация страницы: 0 |
proxy
|
phpinfo
|
Настройка