/** * Load all items. * * @return \self */ public static function loadList($groupBy = 'itemType') { $sql = ' SELECT `itemId` FROM items WHERE !deleted ORDER BY `name` '; $itemIds = query($sql, true); $obj = new self(); if (empty($itemIds)) { return $obj; } $list = array(); foreach ($itemIds as $item) { $itemObject = \Model\Item::loadById($item['itemId']); if (!is_array($list[$itemObject->getItemType()])) { $list[$itemObject->getItemType()] = array(); } $list[$itemObject->getItemType()][$item['itemId']] = $itemObject; } $obj->setList($list); return $obj; }
/** * Create or edit an item type. * * @param integer|string $id The id of the item type entry. May be a string * if a new item type is created. Otherwise it's * an integer. * @param array $data The data for the item type. * * @return void */ protected function editItem($id, $data) { if ($id == 'new') { $response = array('ok' => \Model\Item::create($data)); } else { $item = \Model\Item::loadById($id); $response = array('ok' => $item->update($data), 'data' => $item->getAsArray()); } $this->echoAjaxResponse($response); }
/** * Fill the data from the array into the object and cast them to the nearest possible type. * * @param array $data * * @return void */ public function fill($data) { foreach ($data as $key => $value) { if ($key === 'itemId') { $this->item = \Model\Item::loadById($value); } elseif ($key === 'itemTypeId') { $this->itemType = \Model\ItemType::loadById($value); } elseif (property_exists($this, $key)) { $this->{$key} = $this->castToType($value); } } }