public function addBeneficiary(BeneficiaryUser $beneficiary) { if (!$this->beneficiaries->contains($beneficiary)) { $this->beneficiaries->add($beneficiary); } return $this; }
public function getIncompleteProductLoads($user_id) { //get user and in progress product requests / ideas $user = $this->eloquent->with(['ideas' => function ($query) { $query->where('is_fulfilled', '=', 0); }])->with(['productRequests' => function ($query) { $query->whereNull('product_id'); }])->find($user_id); if (empty($user)) { return []; } $user = $user->toArray(); $product_requests = $user['product_requests']; $ideas = $user['ideas']; //compile inprogress items $inprogress_items = new \Collection(); foreach ($product_requests as $product_request) { $inprogress_items->add(['type' => 'id load', 'human_time_diff' => \Carbon::createFromFormat('Y-m-d H:i:s', $product_request['created_at'])->diffForHumans(), 'created_at' => $product_request['created_at'], 'updated_at' => $product_request['updated_at'], 'id' => $product_request['id'], 'description' => $product_request['vendor'] . ' ' . $product_request['vendor_id'], 'query' => ['vendor' => $product_request['vendor'], 'vendor_id' => $product_request['vendor_id']]]); } foreach ($ideas as $idea) { $inprogress_items->add(['type' => 'idea load', 'human_time_diff' => \Carbon::createFromFormat('Y-m-d H:i:s', $idea['created_at'])->diffForHumans(), 'created_at' => $idea['created_at'], 'updated_at' => $idea['updated_at'], 'id' => $idea['id'], 'description' => $idea['description'], 'query' => ['idea_description' => $idea['description']]]); } $inprogress_items->sortBy('created_at'); return $inprogress_items->toArray(); }
/** * {@inheritdoc} */ public function addActivityPrototype(ActivityPrototypeInterface $activityPrototype) { if (!$this->hasActivityPrototype($activityPrototype)) { $this->activityPrototypes->add($activityPrototype); } return $this; }
/** * Find element from collection by key and value * * @param string $key - search index * @param string $value - search value * @param [boolean $onlyIndex] - this flag can return only indixes of records found * @return NULL|Collection <NULL, \VCAPI\Common\Collection> */ public function find($key, $value, $onlyIndex = false) { if (empty($this->collection)) { return null; } $return = new Collection(); foreach ($this->collection as $index => $item) { if (is_array($item)) { if (!isset($item[$key])) { continue; } if ($item[$key] == $value) { if ($onlyIndex) { $return->add($index); } else { $return->add($item); } } } elseif (is_object($item)) { if (!property_exists($item, $key)) { continue; } if ($item->{$key} == $value) { if ($onlyIndex) { $return->add($index); } else { $return->add($item); } } } } return $return->count() ? $return : null; }
/** * @test Collection::add() */ public function testAdd() { $this->buildEnvironment(); $this->source['a3'] = $this->source['a1']; $this->source['a3']->id = 'a3'; $this->collection->add($this->source['a1']); $this->assertEquals($this->collection->fetch(), $this->source); }
/** * Enter description here... * * @param Node $node * @param Node $parent * @return Node */ public function addNode($node, $parent = null) { $this->_nodes->add($node); $node->setParent($parent); if (!is_null($parent) && $parent instanceof Node) { $parent->addChild($node); } return $node; }
public static function generateClasificacion($liga) { $jornadasAll = $liga->getJornadas(); $jornadas = new Collection(); $jornadaActual = $jornadasAll->iterate(); while ($jornadaActual) { if ($jornadaActual->getEstado() === "true") { $jornadas->add($jornadaActual); } $jornadaActual = $jornadasAll->iterate(); } $equipos = new Collection(); $jornadaActual = $jornadas->iterate(); while ($jornadaActual) { $partidos = $jornadaActual->getPartidos(); $partidoActual = $partidos->iterate(); if ($equipos->isEmpty()) { $partidos->resetIterator(); $partidoActual = $partidos->iterate(); while ($partidoActual) { $equipoLocal = new Equipo($partidoActual->getEqLocal()->getNombre(), $partidoActual->getEqLocal()->getId_equipo(), 0, 0, 0, 0); $equipoVisitante = new Equipo($partidoActual->getEqVisitante()->getNombre(), $partidoActual->getEqVisitante()->getId_equipo(), 0, 0, 0, 0); $equipos->add($equipoLocal); $equipos->add($equipoVisitante); $partidoActual = $partidos->iterate(); } $partidos->resetIterator(); $partidoActual = $partidos->iterate(); } while ($partidoActual) { $equipoLocal = $equipos->getByProperty("id_equipo", $partidoActual->getEqLocal()->getId_equipo()); $equipoVisitante = $equipos->getByProperty("id_equipo", $partidoActual->getEqVisitante()->getId_equipo()); $golesL = $partidoActual->getGolesLocal(); $golesV = $partidoActual->getGolesVisitante(); if ($golesL > $golesV) { $equipoLocal->setPuntos($equipoLocal->getPuntos() + 3); } else { if ($golesL < $golesV) { $equipoVisitante->setPuntos($equipoVisitante->getPuntos() + 3); } else { $equipoLocal->setPuntos($equipoLocal->getPuntos() + 1); $equipoVisitante->setPuntos($equipoVisitante->getPuntos() + 1); } } $equipoLocal->setGolesF($equipoLocal->getGolesF() + $golesL); $equipoLocal->setGolesC($equipoLocal->getGolesC() + $golesV); $equipoVisitante->setGolesF($equipoVisitante->getGolesF() + $golesV); $equipoVisitante->setGolesC($equipoVisitante->getGolesC() + $golesL); $equipoLocal->setDifG(); $equipoVisitante->setDifG(); $partidoActual = $partidos->iterate(); } $jornadaActual = $jornadas->iterate(); } return $equipos; }
/** * Insert into an object * * @param mixed $value * @param int $afterKey * * @return Collection */ public function insertAfter($value, $afterKey) { $new_object = new Collection(); foreach ((array) $this->items as $k => $v) { if ($afterKey == $k) { $new_object->add($value); } $new_object->add($v); } $this->items = $new_object->items; return $this; }
/** * @param array $ids * @param Collection $collection */ public function reverseTransform($ids, $collection) { if (count($ids) == 0) { // don't check for collection count, a straight clear doesnt initialize the collection $collection->clear(); return $collection; } $em = $this->getOption('em'); $metadata = $em->getClassMetadata($this->getOption('className')); $reflField = $metadata->getReflectionProperty($metadata->identifier[0]); foreach ($collection as $object) { $key = array_search($reflField->getValue($object), $ids); if (false === $key) { $collection->removeElement($object); } else { unset($ids[$key]); } } // @todo: This can be greatly optimized into a single SELECT .. WHERE id IN () query. foreach ($ids as $id) { $entity = $em->find($this->getOption('className'), $id); if (!$entity) { throw new TransformationFailedException("Selected entity of type '" . $this->getOption('className') . "' by id '" . $id . "' which is not present in the database."); } $collection->add($entity); } return $collection; }
public function addRole(Role $role) { if (!$this->roles->contains($role)) { $this->roles->add($role); } return $this; }
/** * {@inheritdoc} */ public function addPromotion(PromotionInterface $promotion) { if (!$this->hasPromotion($promotion)) { $this->promotions->add($promotion); } return $this; }
/** * * @param Subject $child * @return Subject */ function addChild($child) { if (!$this->hasChild($child)) { $this->children->add($child); } return $this; }
private function addCollectableToCollection($task, Collection $collection, $taskName = Collection::UNNAMEDTASK, TaskInterface $rollbackTask = null) { $collection->add($taskName, $task); if ($rollbackTask) { $collection->rollback($rollbackTask); } return $this; }
public function addOrganization(OrganizationUser $organization) { $organization->addBeneficiary($this); if (!$this->organizations->contains($organization)) { $this->organizations->add($organization); } return $this; }
/** * {@inheritdoc} */ public function addActivity(ActivityInterface $activity) { if (!$this->hasActivity($activity)) { $activity->setRegimen($this); $this->activities->add($activity); } return $this; }
/** * Add an instance, identified by a unique identifier, to the list and to the corresponding group * * @param string $identifier * @param AssetInterface $asset * @param array $properties * @return void */ public function add($identifier, AssetInterface $asset, array $properties = array()) { parent::add($identifier, $asset); $properties = array_filter($properties); $properties[self::PROPERTY_CONTENT_TYPE] = $asset->getContentType(); $properties[self::PROPERTY_CAN_MERGE] = $asset instanceof MergeableInterface; $this->getGroupFor($properties)->add($identifier, $asset); }
/** * Addings element to Set unless it already exists within the set * * @param scalar $element * @throws \InvalidArgumentException * @return boolean */ public function add($element) { if ($this->contains($element)) { $message = 'Duplicate element added'; throw new \InvalidArgumentException($message); } return parent::add($element); }
/** * {@inheritdoc} */ public function addChild(PermissionInterface $permission) { if (!$this->hasChild($permission)) { $permission->setParent($this); $this->children->add($permission); } return $this; }
/** * Adds a model to the Collection * * Before adding the model to the Collection, sets model's relation_type to a * valid type. * * @see ModelCollection::relation_type() * @param Model $item * @return void */ public function add($item) { if (is_a($item, 'ModelBase') === false) { throw new Exception('ModelCollection accepts only instances of ModelBase - given: ' . gettype($item)); } $item->relation_type($this->relation_type); parent::add($item); }
function after() { $after = new Collection(); $last = $this->paginator->getLastPage(); if ($this->paginator->getCurrentPage() < $last) { for ($a = 1; $a <= $this->size; $a++) { $after->add($a, $this->paginator->getNextPage($a)); if ($this->paginator->getNextPage($a) == $last) { break; } } } if ($this->paginator->getCurrentPage() + 5 < $this->paginator->getLastPage()) { $after->add($this->size + 1, $this->paginator->getNextPage(5)); } return $after; }
/** * @param SubscriberInterface $subscriber * @return Newsletter */ public function addSubscriber(SubscriberInterface $subscriber) { if ($this->subscribers->contains($subscriber)) { return $this; } $subscriber->addNewsletter($this); $this->subscribers->add($subscriber); return $this; }
/** * Add a new response to that item * * @param \Amisure\P4SApiBundle\Entity\EvaluationItemResponse|string $response * Item response, or value of the item response * @see \Amisure\P4SApiBundle\Entity\EvaluationItemResponse * @return \Amisure\P4SApiBundle\Entity\EvaluationItem */ public function addResponse($response) { $element = $response; if (is_string($response)) { $element = new EvaluationItemResponse($response); } $element->setItem($this); $this->responses->add($element); return $this; }
public function add($product, $qty) { //if it's already in the collection, don't add it again, just update quantity if (!array_key_exists($product->id, $this->quantity_product_map)) { parent::add($product); } if (isset($this->quantity_product_map[$product->id])) { $qty = $this->quantity_product_map[$product->id] + $qty; } $this->quantity_product_map[$product->id] = $qty; }
public function add($word) { if (!$this->has($word)) { parent::add($word); } $word = $this->get($word); if ($word->index == 0) { $word->index = $this->size(); } $word->count++; return $word; }
public function testGetsElementByIndex() { $list = new Collection(\Cassandra::TYPE_VARINT); $list->add(new Varint('1'), new Varint('2'), new Varint('3'), new Varint('4'), new Varint('5'), new Varint('6'), new Varint('7'), new Varint('8')); $this->assertEquals(new Varint('1'), $list->get(0)); $this->assertEquals(new Varint('2'), $list->get(1)); $this->assertEquals(new Varint('3'), $list->get(2)); $this->assertEquals(new Varint('4'), $list->get(3)); $this->assertEquals(new Varint('5'), $list->get(4)); $this->assertEquals(new Varint('6'), $list->get(5)); $this->assertEquals(new Varint('7'), $list->get(6)); $this->assertEquals(new Varint('8'), $list->get(7)); }
/** * Add a new item * * @param \Amisure\P4SApiBundle\Entity\EvaluationModelItem|string $item * Evaluation item, or description of the evaluation item * @param string $value * Value of the evaluation item if the evaluation item itself is not previsously provided * @see \Amisure\P4SApiBundle\Entity\EvaluationModelItem * @return \Amisure\P4SApiBundle\Entity\EvaluationModelCategory */ public function addItem($item, $responseType = '') { $evaluationItem = $item; if (is_string($item)) { $evaluationItem = new EvaluationModelItem($item, $responseType); } $evaluationItem->setCategory($this); if (-1 == $evaluationItem->getItemId()) { $evaluationItem->setItemId($this->items->count()); } $this->items->add($evaluationItem); return $this; }
/** * Add a new category that list items * * @param \Amisure\P4SApiBundle\Entity\EvaluationItemCategory|string $category * Evaluation item category, or name of the evaluation item category * @see \Amisure\P4SApiBundle\Entity\EvaluationItemCategory * @return \Amisure\P4SApiBundle\Entity\Evaluation */ public function addCategory($category) { $evaluationCategory = $category; if (is_string($category)) { $evaluationCategory = new EvaluationModelCategory($category); } $evaluationCategory->setEvaluation($this); if (-1 == $evaluationCategory->getCategoryId()) { $evaluationCategory->setCategoryId($this->categories->count()); } $this->categories->add($evaluationCategory); return $this; }
/** * Add a new item response * * @param \Amisure\P4SApiBundle\Entity\EvaluationModelItemResponse|string $item * Evaluation item, or description of the evaluation item * @param string $label * Label of the evaluation item response if the evaluation item response itself is not previsously provided * @param string $type * Type of the evaluation item response if the evaluation item response itself is not previsously provided * @see \Amisure\P4SApiBundle\Entity\EvaluationModelItem * @return \Amisure\P4SApiBundle\Entity\EvaluationModelItem */ public function addResponse($response, $label = '', $type = EvaluationModelItemResponse::TypeString) { $evaluationResponse = $response; if (is_string($response)) { $evaluationResponse = new EvaluationModelItem($response, $label, $type); } $evaluationResponse->setItem($this); if (-1 == $evaluationResponse->getResponseId()) { $evaluationResponse->setResponseId($this->responses->count()); } $this->responses->add($evaluationResponse); return $this; }
public static function getPartidos($id_jornada) { $bd = BD::getConexion(); $sql = "select * from partido where id_jornada = :id_jornada "; $stmt = $bd->prepare($sql); $stmt->execute([":id_jornada" => $id_jornada]); $stmt->setFetchMode(PDO::FETCH_CLASS | PDO::FETCH_PROPS_LATE, "Partidos"); $partido = $stmt->fetchAll(); $partidos = new Collection(); foreach ($partido as $partida) { $partidos->add($partida); } return $partidos; }
public static function getDetalle($id, $tipo, $fecha1, $fecha2) { $bd = BD::getConexion(); $sql = "SELECT * FROM apuntes where id_usuario = :id_usuario and tipo = :tipo and fecha BETWEEN :fecha1 AND :fecha2 "; $stmt = $bd->prepare($sql); $stmt->execute([":id_usuario" => $id, ":tipo" => $tipo, ":fecha1" => $fecha1, ":fecha2" => $fecha2]); $stmt->setFetchMode(PDO::FETCH_CLASS | PDO::FETCH_PROPS_LATE, "Apuntes"); $apuntes = $stmt->fetchAll(); $listado = new Collection(); foreach ($apuntes as $apunte) { $listado->add($apunte); } return $listado; }