/** * 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 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; }
public function add($item) { if ($item->flags & Notice::debug) { if (!$this->fuel('config')->debug) { return $this; } } return parent::add($item); }
public function add($item) { if ($item instanceof Page) { $page = $item; $item = new Breadcrumb(); $item->title = $page->get("title|name"); $item->url = $page->url; } return parent::add($item); }
/** * Add a field to this Fieldgroup * * @param Field|string * */ public function add($field) { if (!is_object($field)) { $field = $this->getFuel('fields')->get($field); } if ($field && $field instanceof Field) { if (!$field->id) { throw new WireException("You must save field '{$field}' before adding to Fieldgroup '{$this->name}'"); } parent::add($field); } else { throw new WireException("Unable to add field '{$field}' to Fieldgroup '{$this->name}'"); } return $this; }
/** * 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->getFuel('db')->query($query); while ($row = $result->fetch_assoc()) { $item = $this->makeBlankItem(); foreach ($row as $field => $value) { if ($field == 'data') { if ($value) { $value = $this->decodeData($value); } else { continue; } } $item->{$field} = $value; } $item->setTrackChanges(true); $items->add($item); } $result->free(); $items->setTrackChanges(true); return $items; }
public function add($item) { if ($item->flags & Notice::debug) { if (!$this->wire('config')->debug) { return $this; } } // check for duplicates $dup = false; foreach ($this as $notice) { if ($notice->text == $item->text && $notice->flags == $item->flags) { $dup = true; } } if ($dup) { return $this; } if ($item->flags & Notice::log || $item->flags & Notice::logOnly) { $this->addLog($item); if ($item->flags & Notice::logOnly) { return $this; } } return parent::add($item); }
/** * Add a Permission to this Role * * Permission may be specified by name, id or Permission instance * * @param string|id|Permission $item * @return this * */ public function add($item) { if (!is_object($item)) { $item = $this->getFuel('permissions')->get($item); } return parent::add($item); }
/** * 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) { $database = $this->wire('database'); $sql = $this->getLoadQuery($selectors)->getQuery(); $query = $database->prepare($sql); $query->execute(); while ($row = $query->fetch(PDO::FETCH_ASSOC)) { $item = $this->makeBlankItem(); foreach ($row as $field => $value) { if ($field == 'data') { if ($value) { $value = $this->decodeData($value); } else { continue; } } $item->{$field} = $value; } $item->setTrackChanges(true); $items->add($item); } $query->closeCursor(); $items->setTrackChanges(true); return $items; }
public function add($item) { if ($item->flags & Notice::debug) { if (!$this->wire('config')->debug) { return $this; } } if (is_array($item->text)) { $item->text = "<pre>" . trim(print_r($this->sanitizeArray($item->text), true)) . "</pre>"; $item->flags = $item->flags | Notice::allowMarkup; } else { if (is_object($item->text) && $item->text instanceof Wire) { $item->text = "<pre>" . $this->wire('sanitizer')->entities(print_r($item->text, true)) . "</pre>"; $item->flags = $item->flag | Notice::allowMarkup; } else { if (is_object($item->text)) { $item->text = (string) $item->text; } } } // check for duplicates $dup = false; foreach ($this as $notice) { if ($notice->text == $item->text && $notice->flags == $item->flags) { $dup = true; } } if ($dup) { return $this; } if ($item->flags & Notice::warning && !$item instanceof NoticeWarning) { // if given a warning of either NoticeMessage or NoticeError, convert it to a NoticeWarning // this is in support of legacy code, as NoticeWarning didn't used to exist $warning = new NoticeWarning($item->text, $item->flags); $warning->class = $item->class; $warning->timestamp = $item->timestamp; $item = $warning; } if (self::logAllNotices || $item->flags & Notice::log || $item->flags & Notice::logOnly) { $this->addLog($item); $item->flags = $item->flags & ~Notice::log; // remove log flag, to prevent it from being logged again if ($item->flags & Notice::logOnly) { return $this; } } return parent::add($item); }
public function add($item) { $item->page = $this->page; return parent::add($item); }
/** * Get a new Notification * * @param string $flag Specify any flag, flag name or space-separated combination of flag names * @param bool $addNow Add it to this NotificationArray now? * @return Notification * */ public function getNew($flag = 'message', $addNow = true) { $notification = new Notification(); $notification->setFlags($flag, true); $notification->created = time(); $notification->modified = time(); $notification->title = 'Untitled'; $notification->page = $this->page; $notification->src_id = $this->wire('page')->id; if ($addNow) { parent::add($notification); } return $notification; }
/** * Add a Page to this PageArray. * * @param Page|int $page Page object or Page ID. If Page ID, it will be loaded and added. * @return PageArray reference to current instance. */ public function add($page) { if ($this->isValidItem($page)) { parent::add($page); $this->numTotal++; } else { if (ctype_digit("{$page}")) { if ($page = $this->getFuel('pages')->findOne("id={$page}")) { parent::add($page); $this->numTotal++; } } } return $this; }
public function add($item) { if ($item->flags & Notice::debug) { if (!$this->wire('config')->debug) { return $this; } } if ($item->flags & Notice::log || $item->flags & Notice::logOnly) { $this->addLog($item); if ($item->flags & Notice::logOnly) { return $this; } } return parent::add($item); }
/** * 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; }
/** * Add a Page to this PageArray. * * @param Page|PageArray|int $page Page object, PageArray object, or Page ID. * If Page, the Page will be added. * If PageArray, it will do the same thing as the import() function: import all the pages. * If Page ID, it will be loaded and added. * @return PageArray reference to current instance. */ public function add($page) { if ($this->isValidItem($page)) { parent::add($page); $this->numTotal++; } else { if ($page instanceof PageArray || is_array($page)) { return $this->import($page); } else { if (ctype_digit("{$page}")) { if ($page = $this->getFuel('pages')->findOne("id={$page}")) { parent::add($page); $this->numTotal++; } } } } return $this; }
/** * Add a new Pagefile item, or create one from it's filename and add it. * * @param Pagefile|string $item If item is a string (filename) then the Pagefile instance will be created automatically. * @return this * */ public function add($item) { if (is_string($item)) { $item = new Pagefile($this, $item); } return parent::add($item); }