public function getOrder() { $id = $this->getIdentity(); $workId = $this->work_id; if (!empty($id) && !empty($workId)) { $chapterTbl = new Book_Model_DbTable_Chapters(); $chapterTblName = $chapterTbl->info('name'); $select = $chapterTbl->select()->setIntegrityCheck(false)->from($chapterTblName, new Zend_Db_Expr('COUNT(chapter_id) AS ordering'))->where("{$chapterTblName}.work_id = ?", $this->work_id)->where("{$chapterTblName}.chapter_id < ?", $this->getIdentity()); $data = $chapterTbl->fetchRow($select); if ($data) { return (int) $data->ordering + 1; } } }