from('Category c') ->orderBy('c.name') ->where('c.type=?', $type) ; $this->assign('type', $type) ; $this->assign('allCategories', $q->execute()) ; } /** * Edit Category * @param mixed $id */ public function edit($id) { $category = Category::getById($id) ; $this->assign('category', parent::edit($category)) ; } /** * Add new Category */ public function add($type) { $this->assign('type', $type) ; $category = new Category(); $category->type = $type ; $this->assign('category', parent::add($category)) ; } /** * Delete document and refresh page * @param mixed $id */ public function delete($id) { $category = Category::getById($id) ; $this->assign('category', parent::delete($category) ) ; } /** * Upload file and attach it to new Image() object. * If valid, move file from tmp directory to fixed place */ public function upload($categoryId=null) { $image = Image::createFromTmp() ; if (!$image->isValid()) { echo 'error' ; $this->isDisplayed = true ; } else { $this->assign('image', $image) ; $image->category_id = $categoryId ; $image->save() ; $category = $categoryId==null ? new Category() : Category::getById($categoryId) ; $this->assign('category', $category) ; } } /** * Delete Image * @param mixed $id */ public function deleteImage($id) { $image = Image::getById($id) ; $categoryId = $image->category_id ; $image->delete() ; $category = $categoryId==null ? new Category() : Category::getById($categoryId) ; $this->assign('category', $category) ; $this->display('_allImages.tpl') ; } /** * This method is called via ajax when user selects date picker in document editor */ public function getFriendlyDate() { $this->assign('date', Worker::getFriendlyDate($_POST['date'])) ; } }