if (!$category->validate()) { var_dump($category->validate()); } $category->save(); $output = array('success' => 1, 'data' => $param); $this->jsonwrapper->print_json($output); } public function itemsave($param) { if (empty($param['category'])) { $this->jsonwrapper->show_json_error('Param', 'Kolom category harap diisi.'); } $imageCategory = WebImageCategoryPeer::retrieveByPK($param['category']); if (!$imageCategory) { $this->jsonwrapper->show_json_error('Param', 'Category tidak ditemukan.'); } $department_id = $param['department_id']; $departmentAvailable = $this->tools->departmentAvailable($department_id); if (!in_array($imageCategory->getDepartmentId(), $departmentAvailable)) { $this->jsonwrapper->show_json_error('forbidden', 'Maaf, anda tidak dapat membuat item dalam category ini.'); } if (empty($param['name'])) { $this->jsonwrapper->show_json_error('param', 'Kolom nama harap diisi.'); } if (empty($param['source'])) { $param['source'] = ''; } if (empty($param['link'])) { $param['link'] = ''; } if (empty($param['decrption'])) { $param['decrption'] = ''; } $imageItem = new WebImage(); if (!empty($param['id'])) { $imageItIem = WebImagePeer::retrieveByPK($param['id']); if (!$imageItem) { $this->jsonwrapper->show_json_error('id', 'Image category tidak ditemukan.'); } if (!in_array($imageItem->getWebImageCategory()->getDepartmentId(), $departmentAvailable)) { $this->jsonwrapper->show_json_error('forbidden', 'Maaf, anda tidak dapat mengedit category ini.'); } } else { $imageItem->setPublished(0); $imageItem->setCreated(date('Y-m-d H:i:s')); } $imageItem->setName($param['name']); $imageItem->setSource($param['source']); $imageItem->setDescription($param['description']); $imageItem->setLink($param['link']); $imageItem->setImageCategoryId($param['category']);
public function itempublish($param) { $department_id = $param['department_id']; $departmentAvailable = $this->tools->departmentAvailable($department_id); if (empty($param['id'])) { $this->jsonwrapper->show_json_error('param', 'Parameter id tidak ditemukan.'); } $item = WebImagePeer::retrieveByPK($param['id']); if (!$item) { $this->jsonwrapper->show_json_error('item', 'Item dengan id ' . $param['id'] . ' tidak ditemukan.'); } if (!in_array($item->getWebImageCategory()->getDepartmentId(), $departmentAvailable)) { $this->jsonwrapper->show_json_error('forbidden', 'Maaf, anda tidak dapat mengedit item ini.'); } if ($item->getPublished() == 1) { $item->setPublished(0); } else { $item->setPublished(1); } $item->save(); $output = array('success' => 1, 'message' => 'Success', 'data' => $item->toArray()); $this->jsonwrapper->print_json($output); }