public function toString() { $queryString = "{$this->name}="; Assert::isNotEmptyArray($this->colors); foreach ($this->colors as $color) { $queryString .= $color->toString() . ','; } return rtrim($queryString, ','); }
public function toString() { $queryString = "{$this->name}="; Assert::isNotEmptyArray($this->styles); $i = 0; foreach ($this->styles as $style) { $queryString .= $style->toString() . '|'; } return rtrim($queryString, '|'); }
/** * @return ModelAndView **/ public function handleRequest(HttpRequest $request) { Assert::isNotEmptyArray($this->innerControllers, 'Add atleast one innerController first'); $activeController = $this->getActiveController($request); $model = $this->mav->getModel(); if ($activeController) { $controllerName = $activeController->getName(); $activeMav = $activeController->handleRequest($request); $model->set(TextUtils::downFirst($controllerName), $activeMav->getModel()); unset($this->innerControllers[$controllerName]); } foreach ($this->innerControllers as $controller) { $passedRequest = clone $request; $passedRequest->{'set' . $controller->getRequestGetter() . 'Var'}('action', null); $subMav = $controller->handleRequest($passedRequest); $model->set(TextUtils::downFirst($controller->getName()), $subMav->getModel()); } return isset($activeMav) && $activeMav->viewIsRedirect() ? $activeMav : $this->mav; }
public function sort() { Assert::isGreater(count($this->keys), 0); Assert::isNotEmptyArray($this->vector); usort($this->vector, array($this, "compare")); }
public function multiSend() { Assert::isNotEmptyArray($this->multiRequests); $handles = array(); $mh = curl_multi_init(); foreach ($this->multiRequests as $alias => $request) { $this->multiResponses[$alias] = new CurlHttpResponse(); $handles[$alias] = $this->makeHandle($request, $this->multiResponses[$alias]); if (isset($this->multiThreadOptions[$alias])) { foreach ($this->multiThreadOptions[$alias] as $key => $value) { curl_setopt($handles[$alias], $key, $value); } } curl_multi_add_handle($mh, $handles[$alias]); } $running = null; do { curl_multi_exec($mh, $running); } while ($running > 0); foreach ($this->multiResponses as $alias => $response) { $this->makeResponse($handles[$alias], $response); curl_multi_remove_handle($mh, $handles[$alias]); curl_close($handles[$alias]); } curl_multi_close($mh); return true; }
public function fetchCollections(array $collections, array $list) { Assert::isNotEmptyArray($list); $ids = ArrayUtils::getIdsArray($list); $mainId = DBField::create($this->getIdName(), $this->getTable()); foreach ($collections as $path => $info) { $lazy = $info['lazy']; $query = OSQL::select()->get($mainId)->from($this->getTable()); $proto = reset($list)->proto(); $this->processPath($proto, $path, $query, $this->getTable()); if ($criteria = $info['criteria']) { $query = $criteria->setDao($this)->fillSelectQuery($query); } $query->andWhere(Expression::in($mainId, $ids)); $propertyPath = $info['propertyPath']; $property = $propertyPath->getFinalProperty(); $proto = $propertyPath->getFinalProto(); $dao = $propertyPath->getFinalDao(); $selfName = $this->getObjectName(); $self = new $selfName(); $getter = 'get' . ucfirst($property->getName()); Assert::isTrue($property->getRelationId() == MetaRelation::ONE_TO_MANY || $property->getRelationId() == MetaRelation::MANY_TO_MANY); $table = $dao->getJoinName($property->getColumnName()); $id = $this->getIdName(); $collection = array(); if ($lazy) { if ($property->getRelationId() == MetaRelation::MANY_TO_MANY) { $childId = $self->{$getter}()->getChildIdField(); } else { $childId = $dao->getIdName(); } $alias = 'cid'; // childId, collectionId, whatever $field = DBField::create($childId, $self->{$getter}()->getHelperTable()); $query->get($field, $alias); if (!$property->isRequired()) { $query->andWhere(Expression::notNull($field)); } try { $rows = $dao->getCustomList($query); foreach ($rows as $row) { if (!empty($row[$alias])) { $collection[$row[$id]][] = $row[$alias]; } } } catch (ObjectNotFoundException $e) { /*_*/ } } else { $prefix = $table . '_'; foreach ($dao->getFields() as $field) { $query->get(DBField::create($field, $table), $prefix . $field); } if (!$property->isRequired()) { $query->andWhere(Expression::notNull(DBField::create($dao->getIdName(), $table))); } try { // otherwise we don't know which object // belongs to which collection $rows = $dao->getCustomList($query); foreach ($rows as $row) { $collection[$row[$id]][] = $dao->makeObject($row, $prefix); } } catch (ObjectNotFoundException $e) { /*_*/ } } $suffix = ucfirst($property->getName()); $fillMethod = 'fill' . $suffix; $getMethod = 'get' . $suffix; Assert::isTrue(method_exists(reset($list), $fillMethod), 'can not find filler'); Assert::isTrue(method_exists(reset($list), $getMethod), 'can not find getter'); foreach ($list as $object) { if (!empty($collection[$object->getId()])) { $object->{$fillMethod}($collection[$object->getId()], $lazy); } else { $object->{$getMethod}()->mergeList(array()); } } } return $list; }