public function getWebItemCategory($con = null) { include_once 'lib/model/om/BaseWebItemCategoryPeer.php'; if ($this->aWebItemCategory === null && $this->item_category_id !== null) { $this->aWebItemCategory = WebItemCategoryPeer::retrieveByPK($this->item_category_id, $con); } return $this->aWebItemCategory; }
public function save($param) { $department_id = $param['department_id']; $departmentAvailable = $this->tools->departmentAvailable($department_id); $item = new WebItem(); if (empty($param['section'])) { $this->jsonwrapper->show_json_error('section', 'Kolom section harap diisi.'); } $itemSection = DepartmentPeer::retrieveByPK($param['section']); if (!$itemSection) { $this->jsonwrapper->show_json_error('type', 'Section yang anda masukkan tidak ditemukan.'); } if (!in_array($param['section'], $departmentAvailable)) { $this->jsonwrapper->show_json_error('forbidden', 'Maaf, anda tidak dapat membuat news dalam section ini.'); } if (empty($param['category_id'])) { $this->jsonwrapper->show_json_error('category', 'Kolom category harap diisi.'); } $itemCategory = WebItemCategoryPeer::retrieveByPK($param['category_id']); if (!$itemCategory) { $this->jsonwrapper->show_json_error('category', 'News Category yang anda masukkan tidak ditemukan.'); } if (empty($param['date'])) { $this->jsonwrapper->show_json_error('date', 'Kolom created harap diisi.'); } if (empty($param['hour'])) { $param['hour'] = 0; } if (empty($param['minute'])) { $param['minute'] = 0; } $newDate = $param['date'] . ' ' . $param['hour'] . ':' . $param['minute'] . ':00'; $newDate = date('Y-m-d H:i:s', strtotime($newDate)); if (empty($param['title'])) { $this->jsonwrapper->show_json_error('title', 'Kolom title harap diisi.'); } if (empty($param['initial'])) { $this->jsonwrapper->show_json_error('initial', 'Kolom initial harap diisi.'); } if (empty($param['image'])) { /* $this->jsonwrapper->show_json_error('image', 'Kolom image harap diisi.'); */ $param['image'] = ''; } if (empty($param['description'])) { $this->jsonwrapper->show_json_error('description', 'Kolom description harap diisi.'); } if (!empty($param['id'])) { $item = WebItemPeer::retrieveByPK($param['id']); if (!$item) { $this->jsonwrapper->show_json_error('id', 'News tidak ditemukan.'); } if (!in_array($item->getDepartmentId(), $departmentAvailable)) { $this->jsonwrapper->show_json_error('forbidden', 'Maaf, anda tidak dapat mengedit news ini.'); } } else { $item->setPublished(0); $item->setCreated(date('Y-m-d H:i:s')); } /* Add */ $item->setTitle($param['title']); $item->setInitial($param['initial']); $item->setImage($param['image']); $item->setDepartmentId($param['section']); $item->setItemCategoryId($param['category_id']); $item->setDescription($param['description']); $item->setCreated($newDate); if (!$item->validate()) { var_dump($item->validate()); } $item->save(); $output = array('success' => 1, 'data' => $param); $this->jsonwrapper->print_json($output); }
public function publish($param) { $category = WebItemCategoryPeer::retrieveByPK($param['id']); if (!$category) { $this->showJsonError('category', 'Category tidak ditemukan.'); } if ($category->getPublished() == 1) { $category->setPublished(0); } else { $category->setPublished(1); } $category->save(); $output = array('success' => 1, 'message' => 'Success', 'data' => $category->toArray()); $this->jsonwrapper->print_json($output); }