예제 #1
0
 /**
  * Load items from the database table and return them in the same type class that getAll() returns
  * A selector string or Selectors may be provided so that this can be used as a find() by descending classes that don't load all items at once.  
  *
  * @param Selectors|string|null $selectors Selectors or a selector string to find, or NULL to load all. 
  * @return WireArray Returns the same type as specified in the getAll() method.
  *
  */
 protected function ___load(WireArray $items, $selectors = null)
 {
     $query = $this->getLoadQuery($selectors);
     $result = $this->fuel('db')->query($query);
     $lookupField = $this->getLookupField();
     while ($row = $result->fetch_assoc()) {
         $item = $this->makeBlankItem();
         $lookupValue = $row[$lookupField];
         unset($row[$lookupField]);
         $item->addLookupItem($lookupValue, $row);
         foreach ($row as $field => $value) {
             $item->{$field} = $value;
         }
         if ($items->has($item)) {
             // LEFT JOIN is adding more elements of the same item, i.e. from lookup table
             // if the item is already present in $items, then use the existing one rather
             // and throw out the one we just created
             $item = $items->get($item);
             $item->addLookupItem($lookupValue, $row);
         } else {
             // add a new item
             $items->add($item);
         }
     }
     if ($result) {
         $result->free();
     }
     $items->setTrackChanges(true);
     return $items;
 }
 /**
  * Load items from the database table and return them in the same type class that getAll() returns
  *
  * A selector string or Selectors may be provided so that this can be used as a find() by descending classes that don't load all items at once.
  *
  * @param WireArray $items
  * @param Selectors|string|null $selectors Selectors or a selector string to find, or NULL to load all.
  * @return WireArray Returns the same type as specified in the getAll() method.
  *
  */
 protected function ___load(WireArray $items, $selectors = null)
 {
     $query = $this->getLoadQuery($selectors);
     $database = $this->wire('database');
     $sql = $query->getQuery();
     $stmt = $database->prepare($sql);
     $stmt->execute();
     $lookupField = $this->getLookupField();
     while ($row = $stmt->fetch(PDO::FETCH_ASSOC)) {
         $item = $this->makeBlankItem();
         $lookupValue = $row[$lookupField];
         unset($row[$lookupField]);
         $item->addLookupItem($lookupValue, $row);
         foreach ($row as $field => $value) {
             $item->{$field} = $value;
         }
         if ($items->has($item)) {
             // LEFT JOIN is adding more elements of the same item, i.e. from lookup table
             // if the item is already present in $items, then use the existing one rather
             // and throw out the one we just created
             $item = $items->get($item);
             $item->addLookupItem($lookupValue, $row);
         } else {
             // add a new item
             $items->add($item);
         }
     }
     $stmt->closeCursor();
     $items->setTrackChanges(true);
     return $items;
 }
 /**
  * Load items from the database table and return them in the same type class that getAll() returns
  * A selector string or Selectors may be provided so that this can be used as a find() by descending classes that don't load all items at once.  
  *
  * @param Selectors|string|null $selectors Selectors or a selector string to find, or NULL to load all. 
  * @return WireArray Returns the same type as specified in the getAll() method.
  *
  */
 protected function ___load(WireArray $items, $selectors = null)
 {
     $query = $this->getLoadQuery($selectors);
     $result = $this->fuel('db')->query($query);
     $lookupField = $this->getLookupField();
     while ($row = $result->fetch_assoc()) {
         $item = $this->makeBlankItem();
         foreach ($row as $field => $value) {
             if ($field == $lookupField) {
                 $item->addLookupItem($value);
             } else {
                 $item->{$field} = $value;
             }
         }
         if ($items->has($item)) {
             // LEFT JOIN is adding more elements of the same item, i.e. from lookup table
             $items->get($item)->addLookupItem($row[$lookupField]);
             // $items->get($item)->setArray($row);
         } else {
             $items->add($item);
         }
     }
     if ($result) {
         $result->free();
     }
     $items->setTrackChanges(true);
     return $items;
 }
예제 #4
0
 /**
  * Does this PageArray contain the given index or Page? 
  *
  * @param Page|int $key Page Array index or Page object. 
  * @return bool True if the index or Page exists here, false if not. 
  */
 public function has($key)
 {
     if (is_int($key) || is_string($key)) {
         return parent::has($key);
     }
     $has = false;
     if (is_object($key) && $key instanceof Page) {
         foreach ($this as $k => $pg) {
             $has = $pg->id == $key->id;
             if ($has) {
                 break;
             }
         }
     }
     return $has;
 }