当前位置: 首页>>代码示例>>PHP>>正文


PHP Collection::add方法代码示例

本文整理汇总了PHP中Collection::add方法的典型用法代码示例。如果您正苦于以下问题:PHP Collection::add方法的具体用法?PHP Collection::add怎么用?PHP Collection::add使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Collection的用法示例。


在下文中一共展示了Collection::add方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: addBeneficiary

 public function addBeneficiary(BeneficiaryUser $beneficiary)
 {
     if (!$this->beneficiaries->contains($beneficiary)) {
         $this->beneficiaries->add($beneficiary);
     }
     return $this;
 }
开发者ID:trialog,项目名称:p4s-api-bundle,代码行数:7,代码来源:OrganizationUser.php

示例2: getIncompleteProductLoads

 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();
 }
开发者ID:ryanrobertsname,项目名称:giftertipster.com,代码行数:25,代码来源:EloquentUserRepository.php

示例3: addActivityPrototype

 /**
  * {@inheritdoc}
  */
 public function addActivityPrototype(ActivityPrototypeInterface $activityPrototype)
 {
     if (!$this->hasActivityPrototype($activityPrototype)) {
         $this->activityPrototypes->add($activityPrototype);
     }
     return $this;
 }
开发者ID:upenn-dag,项目名称:patient-repository,代码行数:10,代码来源:Prototype.php

示例4: find

 /**
  * 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;
 }
开发者ID:pshon,项目名称:vcapi,代码行数:41,代码来源:Collection.php

示例5: testAdd

 /**
  * @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);
 }
开发者ID:timoxeen,项目名称:php-commerceml,代码行数:11,代码来源:CollectionTest.php

示例6: addNode

 /**
  * 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;
 }
开发者ID:schpill,项目名称:standalone,代码行数:16,代码来源:Tree.php

示例7: generateClasificacion

 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;
 }
开发者ID:villapilla,项目名称:PHP,代码行数:56,代码来源:Clasificacion.php

示例8: insertAfter

 /**
  * 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;
 }
开发者ID:adamdburton,项目名称:Steam,代码行数:20,代码来源:Collection.php

示例9: reverseTransform

 /**
  * @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;
 }
开发者ID:notbrain,项目名称:symfony,代码行数:32,代码来源:CollectionToChoiceTransformer.php

示例10: addRole

 public function addRole(Role $role)
 {
     if (!$this->roles->contains($role)) {
         $this->roles->add($role);
     }
     return $this;
 }
开发者ID:trialog,项目名称:p4s-api-bundle,代码行数:7,代码来源:SessionUser.php

示例11: addPromotion

 /**
  * {@inheritdoc}
  */
 public function addPromotion(PromotionInterface $promotion)
 {
     if (!$this->hasPromotion($promotion)) {
         $this->promotions->add($promotion);
     }
     return $this;
 }
开发者ID:bcremer,项目名称:Sylius,代码行数:10,代码来源:OrderItem.php

示例12: addChild

 /**
  *
  * @param Subject $child
  * @return Subject
  */
 function addChild($child)
 {
     if (!$this->hasChild($child)) {
         $this->children->add($child);
     }
     return $this;
 }
开发者ID:CATSInformatica,项目名称:CatsSys,代码行数:12,代码来源:Subject.php

示例13: addCollectableToCollection

 private function addCollectableToCollection($task, Collection $collection, $taskName = Collection::UNNAMEDTASK, TaskInterface $rollbackTask = null)
 {
     $collection->add($taskName, $task);
     if ($rollbackTask) {
         $collection->rollback($rollbackTask);
     }
     return $this;
 }
开发者ID:surjit,项目名称:PHP-Robo-Task-Runner,代码行数:8,代码来源:Collectable.php

示例14: addOrganization

 public function addOrganization(OrganizationUser $organization)
 {
     $organization->addBeneficiary($this);
     if (!$this->organizations->contains($organization)) {
         $this->organizations->add($organization);
     }
     return $this;
 }
开发者ID:trialog,项目名称:p4s-api-bundle,代码行数:8,代码来源:BeneficiaryUser.php

示例15: addActivity

 /**
  * {@inheritdoc}
  */
 public function addActivity(ActivityInterface $activity)
 {
     if (!$this->hasActivity($activity)) {
         $activity->setRegimen($this);
         $this->activities->add($activity);
     }
     return $this;
 }
开发者ID:upenn-dag,项目名称:patient-repository,代码行数:11,代码来源:Regimen.php


注:本文中的Collection::add方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。