_saveDependency(); return $this; } protected function _insertDependency() { $this-> _saveDependency(); return $this; } protected function _saveDependency() { $this->savePremiumData(); return $this; } public function savePremiumData() { $premiumData = $this->getData('premium'); if (is_array($premiumData) && count($premiumData) > 0) { $this->_deleteIds($this->_dataTableAlias, 'yearId'); $this->_insertLinks( $this->_dataTableAlias, $premiumData, ['yearId' => $this->getPrimaryKey()] ); } return $this; } public function getNextYear() { $select = $this->_db->select()->from($this->_getPair(), array('MAX(year)')); $lastYear = (int)$this->_db->fetchOne($select); return ($lastYear) ? $lastYear + 1 : date('Y'); } protected function _getFromDb($primaryKey, $field = null) { $data = parent::_getFromDb($primaryKey); if ($data) { $data['premium'] = $this->getPremiumData($primaryKey); } return $data; } public function getPremiumData($yearId) { $data = []; if ($yearId) { $select = $this->_db->select(); $select->from($this->_getPair($this->_dataTableAlias), ['fpg', 'monthlyPremium']); $select->where('yearId = ?', $yearId, Qs_Db::INT_TYPE); $select->order('fpg'); $data = $this->_db->fetchAll($select); } return $data; } }