_isAdmin = (bool) $value; } return $this->_isAdmin; } public function getSchools($schoolId = null) { $select = $this->_db->select(); $select->from($this->_getPair('School')); $select->order('School.sorter'); if ($schoolId) { $select->where('School.id = ?', $schoolId, Qs_Db::INT_TYPE); } else { if (!$this->isAdmin()) { $select->where('`School`.`enabled` = "y"'); } else { $select->where('`School`.`id` != ?', App_School_AbstractObj::ADMINISTRATION_ID, Zend_Db::INT_TYPE); } } return $this->_db->fetchAll($select); } public function getReportStatuses($schoolId = null) { $select = $this->_db->select(); $select->from($this->_getPair('Report'), array('reportId' => 'id')); if (!$this->isAdmin()) { $joinWhere = '`School`.`enabled` = "y"'; } else { $joinWhere = $this->_db->quoteInto('`School`.`id` != ?', App_School_AbstractObj::ADMINISTRATION_ID, Zend_Db::INT_TYPE); } $select->join( $this->_getPair('School'), $joinWhere, array( 'schoolId' => 'id', 'status' => $this->_getStatusExpr('School.id') ) ); if ($schoolId) { $select->where('School.id = ?', $schoolId, Qs_Db::INT_TYPE); } $list = $this->_db->fetchAll($select); $result = array(); foreach ((array) $list as $row) { $result[$row['reportId']][$row['schoolId']] = $row['status']; } return $result; } public function getStatusesStatistics() { $statuses = $this->_db->select(); $statuses->from($this->_getPair('Report'), array()); if (!$this->isAdmin()) { $joinWhere = '`School`.`enabled` = "y"'; } else { $joinWhere = $this->_db->quoteInto('`School`.`id` != ?', App_School_AbstractObj::ADMINISTRATION_ID, Zend_Db::INT_TYPE); } $statuses->join( $this->_getPair('School'), $joinWhere, array( 'status' => $this->_getStatusExpr('School.id') ) ); $sql = 'SELECT `Statuses`.`status`, COUNT(`Statuses`.`status`) AS `count` ' . 'FROM (' . $statuses . ') AS `Statuses` ' . 'GROUP BY `Statuses`.`status`'; $statuses = $this->_db->fetchPairs($sql); return $this->_prepareStatusStatistics($statuses); } public function getReportFileDates($schoolId = null) { $select = $this->_db->select(); $select->from($this->_getPair('Report'), array('reportId' => 'id')); if (!$this->isAdmin()) { $joinWhere = '`School`.`enabled` = "y"'; } else { $joinWhere = $this->_db->quoteInto('`School`.`id` != ?', App_School_AbstractObj::ADMINISTRATION_ID, Zend_Db::INT_TYPE); } $select->join( $this->_getPair('School'), $joinWhere, array( 'schoolId' => 'id', 'added' => $this->_getUserReportDateExpr(), ) ); if ($schoolId) { $select->where('School.id = ?', $schoolId, Qs_Db::INT_TYPE); } $list = $this->_db->fetchAll($select); $result = array(); foreach ((array) $list as $row) { $result[$row['reportId']][$row['schoolId']] = $row['added']; } return $result; } public function getUserReports() { $select = $this->_db->select(); $select->from( $this->_getPair('UserReport'), array('reportId', 'schoolId', 'file', 'comments', 'addedIdx', 'rejected', 'rejectComment', 'rejectDate', 'added') ); $select->order('added ASC'); $list = $this->_db->fetchAll($select); $result = array(); foreach ((array) $list as $row) { $result[$row['reportId']][$row['schoolId']][] = $row; } return $result; } public function getForcedStatuses($schoolId = null) { $select = $this->_db->select(); $select->from(Qs_Db::getPair('ReportForceStatus'), array('reportId', 'schoolId', 'status')); $select->join(Qs_Db::getPair('Report'), 'Report.id = ReportForceStatus.reportId AND Report.dueDateMonth IS NULL'); if ($schoolId) { $select->where('ReportForceStatus.schoolId = ?', $schoolId, Qs_Db::INT_TYPE); } $list = $this->_db->fetchAll($select); $result = array(); foreach ((array) $list as $row) { $result[$row['reportId']][$row['schoolId']] = $row['status']; } return $result; } }