joinLeft( $this->pairUser, "`User`.`id` = `{$this->_tableAlias}`.`idUser`", array('sourceContact' => new Zend_Db_Expr("IF (`User`.`name` IS NULL, 'N/A', `User`.`name`)")) ); $select->joinLeft( $this->pairDLessonType, "`DLessonType`.`id` = `{$this->_tableAlias}`.`idLessonType`", array('lessonType' => 'title') ); $select->joinLeft( $this->pairSchool, "`School`.`id` = `{$this->_tableAlias}`.`idSchool`", array('fileSource' => 'name') ); $select->joinLeft( $this->pairSubject, "`Subject`.`id` = `{$this->_tableAlias}`.`idSubject`", array('subject' => 'title') ); $select->joinLeft( $this->_getPair('File', true), "`File`.`nameFs` = `{$this->_tableAlias}`.`file`", array('size', 'fileTitle' => 'name') ); return $select; } protected function _prepareList(&$list) { if (!is_array($list) || empty($list)) { return false; } foreach (array_keys($list) as $k) { if (empty($this->_urlParseFields)) { $this->_arrayParseTag2Url($list[$k]); } $list[$k]['size'] = Qs_Math::sizeToByteString($list[$k]['size']); } return true; } protected function _addDependenciesFromDb(&$data) { $data['sourceContact'] = $this->_getSourceContactName($data['idUser']); return $this; } protected function _getSourceContactName($idUser) { $sql = "SELECT `name` FROM `{$this->_getTableName('User')}` WHERE `id` = " . (int) $idUser; return $this->db->fetchOne($sql); } protected function _filterWhere(Zend_Db_Select $select) { $select = parent::_filterWhere($select); foreach ($this->_filter as $k => $v) { $v = trim($v); if (!empty($v)) { switch ($k) { case 'grade': $select->where("`{$this->_tableAlias}`.`grade` = " . $this->db->quote($v)); break; case 'idSubject': $select->where("`{$this->_tableAlias}`.`idSubject` = " . (int) $v); break; case 'idLessonType': $select->where("`{$this->_tableAlias}`.`idLessonType` = " . (int) $v); break; case 'assessmentNumber': if ($this->_filter['idLessonType'] == 2) { $select->where("`{$this->_tableAlias}`.`summativeAssessmentNumber` = " . (int) $v); } break; case 'idSchool': $select->where("`{$this->_tableAlias}`.`idSchool` = " . (int) $v); break; case 'enabledSubject': $select->where("`Subject`.`enabled` = " . $this->db->quote($v)); break; } } } return $select; } public function getSchool4Select($enabledOnly = true) { $where = array($this->_db->quoteInto('`id` != ?', App_School_AbstractObj::ADMINISTRATION_ID, Zend_Db::INT_TYPE)); if ($enabledOnly) { $where[] = '`enabled` = "y"'; } return $this->_get4Select('School', array('id', 'name'), null, $where, 'name'); } }