/** * Load all item types. * * @return \self */ public static function loadList() { $sql = ' SELECT `itemTypeId` FROM itemTypes WHERE !deleted ORDER BY `type`, `name` '; $itemTypeIds = query($sql, true); $obj = new self(); if (empty($itemTypeIds)) { return $obj; } $list = array(); foreach ($itemTypeIds as $itemType) { $list[$itemType['itemTypeId']] = \Model\ItemType::loadById($itemType['itemTypeId']); } $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 editItemType($id, $data) { if ($id == 'new') { $response = array('ok' => \Model\ItemType::create($data)); } else { $itemType = \Model\ItemType::loadById($id); $response = array('ok' => $itemType->update($data), 'data' => $itemType->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); } } }