Проектирование системы дистанционного обучения

Листинг программ

SQL запросы для создания таблиц к модулям системы.
 
БД: `sevntu_do`

Структура таблицы `lection_lecture`

CREATE TABLE `lection_lecture` (
`lection_lecture_id` int(10) unsigned NOT NULL auto_increment,
`lection_subject_id` int(10) unsigned NOT NULL,
`lection_lecture` text NOT NULL,
PRIMARY KEY  (`lection_lecture_id`)
) ;

Структура таблицы `lection_lecture_addition`

CREATE TABLE `lection_lecture_addition` (
`lection_lecture_id` int(10) unsigned NOT NULL,
`lection_lecture_addition_id` int(10) unsigned NOT NULL auto_increment,
`type` text NOT NULL,
`author` text NOT NULL,
`rating` int(10) unsigned NOT NULL default '0',
PRIMARY KEY  (`lection_lecture_addition_id`)
);

Структура таблицы `lection_lecture_audio`

CREATE TABLE `lection_lecture_audio` (
`lection_lecture_id` int(10) unsigned NOT NULL,
`lection_lecture_audio_id` int(10) unsigned NOT NULL auto_increment,
`type` text NOT NULL,
`author` text NOT NULL,
`rating` int(10) unsigned NOT NULL default '0',
PRIMARY KEY  (`lection_lecture_audio_id`)
);

Структура таблицы `lection_lecture_print`

CREATE TABLE `lection_lecture_print` (
`lection_lecture_id` int(10) unsigned NOT NULL,
`lection_lecture_print_id` int(10) unsigned NOT NULL auto_increment,
`type` text NOT NULL,
`author` text NOT NULL,
`rating` int(10) unsigned NOT NULL default '0',
PRIMARY KEY  (`lection_lecture_print_id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=29 ;

Структура таблицы `lection_lecture_video`

CREATE TABLE `lection_lecture_video` (
`lection_lecture_id` int(10) unsigned NOT NULL,
`lection_lecture_video_id` int(10) unsigned NOT NULL auto_increment,
`type` text NOT NULL,
`author` text NOT NULL,
`rating` int(10) unsigned NOT NULL default '0',
PRIMARY KEY  (`lection_lecture_video_id`)
);

Структура таблицы `lection_subject`

CREATE TABLE `lection_subject` (
`lection_subject_id` int(10) unsigned NOT NULL auto_increment,
`subject` text NOT NULL,
PRIMARY KEY  (`lection_subject_id`)
);

Структура таблицы `test_list`

CREATE TABLE `test_list` (
`test_id` int(11) NOT NULL,
`lection_lecture_id` int(11) NOT NULL,
PRIMARY KEY  (`test_id`,`lection_lecture_id`)
);

Структура таблицы `test_name`

CREATE TABLE `test_name` (
`test_id` int(10) unsigned NOT NULL auto_increment,
`test_description` text NOT NULL,
PRIMARY KEY  (`test_id`)
) ;

Структура таблицы `test_question`

CREATE TABLE `test_question` (
`test_question_id` int(10) unsigned NOT NULL auto_increment,
`lection_lecture_id` int(10) unsigned NOT NULL,
`question` text NOT NULL,
`answer` int(11) NOT NULL,
`index` int(10) unsigned NOT NULL,
PRIMARY KEY  (`test_question_id`)
);

Структура таблицы `test_question_variants`

CREATE TABLE `test_question_variants` (
`test_question_id` int(11) NOT NULL,
`variants` text NOT NULL,
`variants_id` int(10) unsigned NOT NULL auto_increment,
PRIMARY KEY  (`variants_id`)
);

-- Структура таблицы `user`

CREATE TABLE `user` (
`user_id` int(10) unsigned NOT NULL,
`user_login` text NOT NULL,
`user_pass` text NOT NULL,
`user_group` int(11) NOT NULL,
`mane_full` text NOT NULL,
);

 


Приложение Б

Листинг файла модель (subject.php) в паттерне MVC
<?
require_once 'Zend/Db/Table/Abstract.php';

/* Класс поддерживаемых форматов*/
class supportFilePrint
{
public $print = array(
array( 'description' => 'Microsoft office',
'type' => 'application/msword',
'ext' => 'doc'),
array( 'description' => 'Adobe Acrobat',
'type' => 'application/pdf',
'ext' => 'pdf')
);
public $video = array(
array( 'description' => 'Flash Vidoe',
'type' => 'content="text/html',
'ext' => 'flv')
);

            public $audio = array(
array( 'description' => 'mp3 Layer',
'type' => 'audio/mpeg',
'ext' => 'mp3')
);

            public $addition = array(
array( 'description' => 'Ana oi?iaou',
'type' => '*',
'ext' => '*')
);

}
/* Класс модели БД*/
class Subject extends Zend_Db_Table_Abstract
{
protected $_name = 'lection_subject';
protected $_primary = 'lection_subject_id';
protected $_dependentTables = array('Lection');

            public function subjectList()
{
$result = $this->fetchAll();
return $result;
}

            public function subjectId($id)
{
$result = $this->fetchRow('lection_subject_id = '.$id);
return $result;
}

            public function subjectAllLection($id)
{
$row = $this->fetchRow('lection_subject_id = '.$id);
return  $row->findDependentRowset('lection');
}

            public function getAllQuestionBySubjectId($id)
{
$select = $this->_db->select()
->from('test_question')
->where('test_question.lection_lecture_id = ?', $id);
return $select->query()->fetchAll();
}

            public function getAllQuestionVariantBySubjectId($id)
{
$select = $this->_db->select()
->from('test_question_variants')
->join('test_question', 'test_question.test_question_id = test_question_variants.test_question_id')
->where('test_question.lection_lecture_id = ?', $id);
return $select->query()->fetchAll();
}

            public function getAllLectionPrintBySubjectId($id)
{
$select = $this->_db->select()
->from('lection_lecture')
->where('lection_lecture.lection_subject_id = ?', $id);
return $select->query()->fetchAll();
}

            public function getLectNameByLectId($id)
{
$select = $this->_db->select()
->from('lection_lecture')
->where('lection_lecture.lection_lecture_id = ?', $id)
->limit(0,1);
$result = $select->query()->fetchAll();
return $result[0]['lection_lecture'];
}

            public function getLectIdByPrintId($id)
{
$select = $this->_db->select()
->from('lection_lecture_print')
->where('lection_lecture_print_id = ?', $id)
->limit(0,1);
$result = $select->query()->fetchAll();
return $result[0]['lection_lecture_id'];
}

            public function getLectIdByVId($id)
{
$select = $this->_db->select()
->from('lection_lecture_video')
->where('lection_lecture_video_id = ?', $id)
->limit(0,1);
$result = $select->query()->fetchAll();
return $result[0]['lection_lecture_id'];
}

            public function getLectIdByVideoId($id)
{
$select = $this->_db->select()
->from('lection_lecture_video')
->where('lection_lecture_video_id = ?', $id)
->limit(0,1);
$result = $select->query()->fetchAll();
return $result[0]['lection_lecture_id'];
}

            public function getLectIdByAudioId($id)
{
$select = $this->_db->select()
->from('lection_lecture_audio')
->where('lection_lecture_audio_id = ?', $id)
->limit(0,1);
$result = $select->query()->fetchAll();
return $result[0]['lection_lecture_id'];
}

            public function getLectIdByAdditionId($id)
{
$select = $this->_db->select()
->from('lection_lecture_addition')
->where('lection_lecture_addition_id = ?', $id)
->limit(0,1);
$result = $select->query()->fetchAll();
return $result[0]['lection_lecture_id'];
}

            public function getNameAdditionByAdditionId($id)
{
$select = $this->_db->select()
->from('lection_lecture_addition')
->where('lection_lecture_addition_id = ?', $id)
->limit(0,1);
$result = $select->query()->fetchAll();
return $result[0]['author'];
}

            public function getSubjNameByLecId($id)
{
$select = $this->_db->select()
->from('lection_lecture')
->join('lection_subject',
'lection_lecture.lection_subject_id = lection_subject.lection_subject_id')
->where('lection_lecture.lection_lecture_id = ?', $id)
->limit(0,1);
$result = $select->query()->fetchAll();;
return $result[0]['subject'];
}

            public function getSubjIdByLectPrintId($id)
{
$select = $this->_db->select()
->from('lection_lecture')
->join('lection_lecture_print',
'lection_lecture.lection_lecture_id  = lection_lecture_print.lection_lecture_id ')
->where('lection_lecture_print.lection_lecture_print_id = ?', $id)
->limit(0,1);
$result = $select->query()->fetchAll();;
return $result[0]['lection_subject_id'];
}

            public function getSubjIdByLectVideoId($id)
{
$select = $this->_db->select()
->from('lection_lecture')
->join('lection_lecture_video', 'lection_lecture.lection_lecture_id  =
lection_lecture_video.lection_lecture_id ')
->where('lection_lecture_video.lection_lecture_video_id = ?', $id)
->limit(0,1);
$result = $select->query()->fetchAll();;
return $result[0]['lection_subject_id'];
}

            public function getSubjIdByLectAudioId($id)
{
$select = $this->_db->select()
->from('lection_lecture')
->join('lection_lecture_audio', 'lection_lecture.lection_lecture_id  =
lection_lecture_audio.lection_lecture_id ')
->where('lection_lecture_audio.lection_lecture_audio_id = ?', $id)
->limit(0,1);
$result = $select->query()->fetchAll();;
return $result[0]['lection_subject_id'];
}

            public function getSubjIdByLectAdditionId($id)
{
$select = $this->_db->select()
->from('lection_lecture')
->join('lection_lecture_addition', 'lection_lecture.lection_lecture_id  =
lection_lecture_addition.lection_lecture_id ')
->where('lection_lecture_addition.lection_lecture_addition_id = ?', $id)
->limit(0,1);
$result = $select->query()->fetchAll();;
return $result[0]['lection_subject_id'];
}

            public function getSubjIdByLectId($id)
{
$select = $this->_db->select()
->from('lection_lecture')
->join('lection_subject', 'lection_lecture.lection_subject_id =
lection_subject.lection_subject_id')
->where('lection_lecture.lection_lecture_id = ?', $id)
->limit(0,1);
$result = $select->query()->fetchAll();;
return $result[0]['lection_subject_id'];
}

            public function getAuthorByLectId($id)
{
$select = $this->_db->select()
->from('lection_lecture_print')
->where('lection_lecture_print_id = ?', $id)
->limit(0,1);
$result = $select->query()->fetchAll();
return $result[0]['author'];
}

            public function getAuthorByVideoId($id)
{
$select = $this->_db->select()
->from('lection_lecture_video')
->where('lection_lecture_video_id = ?', $id)
->limit(0,1);
$result = $select->query()->fetchAll();
return $result[0]['author'];
}

            public function getAuthorByAudioId($id)
{
$select = $this->_db->select()
->from('lection_lecture_audio')
->where('lection_lecture_audio_id = ?', $id)
->limit(0,1);
$result = $select->query()->fetchAll();
return $result[0]['author'];
}

            public function getAuthorByAdditionId($id)
{
$select = $this->_db->select()
->from('lection_lecture_addition')
->where('lection_lecture_addition_id = ?', $id)
->limit(0,1);
$result = $select->query()->fetchAll();
return $result[0]['author'];
}

            public function getRatingByPrintId($id)
{
$select = $this->_db->select()
->from('lection_lecture_print')
->where('lection_lecture_print_id = ?', $id)
->limit(0,1);
$result = $select->query()->fetchAll();
return $result[0]['rating'];
}

            public function getRatingByVideoId($id)
{
$select = $this->_db->select()
->from('lection_lecture_video')
->where('lection_lecture_video_id = ?', $id)
->limit(0,1);
$result = $select->query()->fetchAll();
return $result[0]['rating'];
}

            public function getRatingByAudioId($id)
{
$select = $this->_db->select()
->from('lection_lecture_audio')
->where('lection_lecture_audio_id = ?', $id)
->limit(0,1);
$result = $select->query()->fetchAll();
return $result[0]['rating'];
}

            public function getTypeByLectId($id)
{
$select = $this->_db->select()
->from('lection_lecture_print')
->where('lection_lecture_print_id = ?', $id)
->limit(0,1);
$result = $select->query()->fetchAll();
return $result[0]['type'];
}

            public function getTypeByVideoId($id)
{
$select = $this->_db->select()
->from('lection_lecture_video')
->where('lection_lecture_video_id = ?', $id)
->limit(0,1);
$result = $select->query()->fetchAll();
return $result[0]['type'];
}

            public function getTypeByAudioId($id)
{
$select = $this->_db->select()
->from('lection_lecture_audio')
->where('lection_lecture_audio_id = ?', $id)
->limit(0,1);
$result = $select->query()->fetchAll();
return $result[0]['type'];
}

            public function getTypeByAdditionId($id)

            {
                        $select = $this->_db->select()
                                   ->from('lection_lecture_addition')
                                   ->where('lection_lecture_addition_id = ?', $id)
                                   ->limit(0,1);
                        $result = $select->query()->fetchAll();
                        return $result[0]['type'];
            }

            public function getAuthorListByPrintId($id)
{
$select = $this->_db->select()
->from('lection_lecture_print')
->where('lection_lecture_print.lection_lecture_id = ?', $id)
->order(array('rating DESC', 'author'));

                        $result = $select->query()->fetchAll();
$i = 0;
foreach ($result as $val)
{
$authors[$i]['author'] = $val['author'];
$authors[$i]['id'] = $val['lection_lecture_print_id'];
$authors[$i]['rating'] = $val['rating'];
$i++;
}
return $authors;
}

            public function getAuthorListByVideoId($id)
{
$select = $this->_db->select()
->from('lection_lecture_video')
->where('lection_lecture_video.lection_lecture_id = ?', $id)
->order(array('rating DESC', 'author'));

                        $result = $select->query()->fetchAll();
$i = 0;
foreach ($result as $val)
{
$authors[$i]['author'] = $val['author'];
$authors[$i]['id'] = $val['lection_lecture_video_id'];
$authors[$i]['rating'] = $val['rating'];
$i++;
}
return $authors;
}

            public function getAuthorListByAudioId($id)
{
$select = $this->_db->select()
->from('lection_lecture_audio')
->where('lection_lecture_audio.lection_lecture_id = ?', $id)
->order(array('rating DESC', 'author'));

                        $result = $select->query()->fetchAll();
$i = 0;
foreach ($result as $val)
{
$authors[$i]['author'] = $val['author'];
$authors[$i]['id'] = $val['lection_lecture_audio_id'];
$authors[$i]['rating'] = $val['rating'];
$i++;
}
return $authors;
}

            public function getAuthorListByAdditionId($id)
{
$select = $this->_db->select()
->from('lection_lecture_addition')
->where('lection_lecture_addition.lection_lecture_id = ?', $id)
->order(array('rating DESC', 'author'));

                        $result = $select->query()->fetchAll();
$i = 0;
foreach ($result as $val)
{
$authors[$i]['author'] = $val['author'];
$authors[$i]['id'] = $val['lection_lecture_addition_id'];
$authors[$i]['rating'] = $val['rating'];
$i++;
}
return $authors;
}

            public function getCountQesttBySubject($id)
{
$select = $this->_db->select()
->from('test_list')
->where('test_list.lection_lecture_id = ?', $id);
->count('lection_lecture_id');
$result = $select->query()->fetchAll();
}

            public function saveLectionPrint($author, $lectionId, $type)
{
if ($author == '')
{
$author = "Гость";
}
$data = array (
'lection_lecture_id' => $lectionId,
'type' => $type,
'author' => $author
);
$select = $this->_db->insert('lection_lecture_print', $data);
return $this->_db->lastInsertId();
}

            public function saveLectionVideo($author, $lectionId, $type)
{
if ($author == '')
{
$author = "Ainou";
}
$data = array (
'lection_lecture_id' => $lectionId,
'type' => $type,
'author' => $author
);
$select = $this->_db->insert('lection_lecture_video', $data);
return $this->_db->lastInsertId();
}

            public function saveLectionAudio($author, $lectionId, $type)
{
if ($author == '')
{
$author = "Ainou";
}
$data = array (
'lection_lecture_id' => $lectionId,
'type' => $type,
'author' => $author
);
$select = $this->_db->insert('lection_lecture_audio', $data);
return $this->_db->lastInsertId();
}

            public function saveLectionAddition($author, $lectionId, $type)
{
if ($author == '')
{
$author = "Ainou";
}
$data = array (
'lection_lecture_id' => $lectionId,
'type' => $type,
'author' => $author
);
$select = $this->_db->insert('lection_lecture_addition', $data);
return $this->_db->lastInsertId();
}

            public function saveVariant($s, $i)
{
$data = array (
'test_question_id' => $i,
'variants' => $s
);
$this->_db->insert('test_question_variants', $data);
}

            public function saveQuestion($s, $i)
{
$data = array (
'lection_lecture_id' => $i,
'question' => $s
);
$this->_db->insert('test_question', $data);
}

            public function updateAuthorPrint($id, $author)
{
$data = array('author' => $author);
$this->_db->update('lection_lecture_print', $data, 'lection_lecture_print_id = '.$id);
}

            public function updateAuthorVideo($id, $author)
{
$data = array('author' => $author);
$this->_db->update('lection_lecture_video', $data, 'lection_lecture_video_id = '.$id);
}

            public function updateAuthorAudio($id, $author)
{
$data = array('author' => $author);
$this->_db->update('lection_lecture_audio', $data, 'lection_lecture_audio_id = '.$id);
}

            public function updateAuthorAddition($id, $author)
{
$data = array('author' => $author);
$this->_db->update('lection_lecture_addition', $data, 'lection_lecture_addition_id = '.$id);
}

            public function updateTypePrint($id, $ext)
{
$data = array('type' => $ext);
$this->_db->update('lection_lecture_print', $data, 'lection_lecture_print_id = '.$id);
}

            public function deleteLectionPrint($id)
{
$this->_db->delete('lection_lecture_print', 'lection_lecture_print_id = '.$id);
}

            public function deleteLectionVideo($id)
{
$this->_db->delete('lection_lecture_video', 'lection_lecture_video_id = '.$id);
}

            public function deleteLectionAudio($id)
{
$this->_db->delete('lection_lecture_audio', 'lection_lecture_audio_id = '.$id);
}

            public function deleteLectionAddition($id)
{
$this->_db->delete('lection_lecture_addition', 'lection_lecture_addition_id = '.$id);
}

            public function deleteVariantById($id)
{
$this->_db->delete('test_question_variants', 'variants_id = '.$id);
}

            public function deleteQustionById($id)
{
$this->_db->delete('test_question_variants', 'test_question_id = '.$id);
$this->_db->delete('test_question', 'test_question_id = '.$id);
}

            public function insertLection($id, $lection)
{
$data = array (
'lection_subject_id' => $id,
'lection_lecture' => $lection
);
$select = $this->_db->insert('lection_lecture', $data);
}

            public function insertSubject($subject)
{
$data = array (
'subject' => $subject
);
$select = $this->_db->insert('lection_subject', $data);
return $this->_db->lastInsertId();
}

            public function updateRaytingPrint($id)
{
$select = $this->_db->select()
->from('lection_lecture_print')
->where('lection_lecture_print.lection_lecture_print_id = ?', $id);
$result = $select->query()->fetchAll();

                        $rating = $result[0]['rating'];
$rating++;
$data = array('rating' => $rating);
$n = $this->_db->update('lection_lecture_print', $data, 'lection_lecture_print_id = '.$id);
return $rating;
}

            public function updateQustionVariantById($id, $s)
{
$data = array('variants' => $s);
$this->_db->update('test_question_variants', $data, 'variants_id = '.$id);
}

            public function updateQustionById($id, $s)
{
$data = array('question' => $s);
$this->_db->update('test_question', $data, 'test_question_id  = '.$id);
}
}

 

class Lection extends Zend_Db_Table_Abstract
{
protected $_name = 'lection_lecture';
protected $_primary = 'lection_lecture_id';

            protected $_dependentTables = array(
'LectionPrint',
'LectionVideo',
'LectionAudio',
'LectionAddition');
protected $_referenceMap    = array(
'Subject' => array(
'columns'           => array('lection_subject_id'),
'refTableClass'     => 'Subject',
'refColumns'        => array('lection_subject_id')
)
);
public function LectionUpdate($str, $id)
{
$data = array( 'lection_lecture' => $str);
$where = $this->getAdapter()->quoteInto('lection_lecture_id = ?', $id);
$this->update($data, $where);
}

    public function printAllLection($id)
{
$select = $this->_db->select()
->from('lection_lecture')
->join('lection_lecture_print','lection_lecture_print.lection_lecture_id =
lection_lecture.lection_lecture_id')
->where('lection_lecture.lection_subject_id = ?', $id);
return $select->query()->fetchAll();
}

            public function printAllVideo($id)
{

                        $select = $this->_db->select()
->from('lection_lecture')
->join('lection_lecture_video','lection_lecture_video.lection_lecture_id =
lection_lecture.lection_lecture_id')
->where('lection_lecture.lection_subject_id = ?', $id);
return $select->query()->fetchAll();
}

            public function printAllAudio($id)
{

                        $select = $this->_db->select()
->from('lection_lecture')
->join('lection_lecture_audio','lection_lecture_audio.lection_lecture_id =
lection_lecture.lection_lecture_id')
->where('lection_lecture.lection_subject_id = ?', $id);
return $select->query()->fetchAll();
}

            public function printAllAddition($id)
{

                        $select = $this->_db->select()
->from('lection_lecture')
->join('lection_lecture_addition','lection_lecture_addition.lection_lecture_id =
lection_lecture.lection_lecture_id')
->where('lection_lecture.lection_subject_id = ?', $id);
return $select->query()->fetchAll();
}
}

class LectionPrint extends Zend_Db_Table_Abstract
{
protected $_name = 'lection_lecture_print';
protected $_primary = 'lection_lecture_print_id';

            protected $_referenceMap    = array(
'Lection' => array(
'columns'           => array('lection_lecture_id'),
'refTableClass'     => 'Lection',
'refColumns'        => array('lection_lecture_id')
)
);
}

class LectionVideo extends Zend_Db_Table_Abstract
{
protected $_name = 'lection_lecture_video';
protected $_primary = 'lection_lecture_video_id';

            protected $_referenceMap    = array(
'Lection' => array(
'columns'           => array('lection_lecture_id'),
'refTableClass'     => 'Lection',
'refColumns'        => array('lection_lecture_id')
)
);
}

class LectionAudio extends Zend_Db_Table_Abstract
{
protected $_name = 'lection_lecture_audio';
protected $_primary = 'lection_lecture_audio_id';

            protected $_referenceMap    = array(
'Lection' => array(
'columns'           => array('lection_lecture_id'),
'refTableClass'     => 'Lection',
'refColumns'        => array('lection_lecture_id')
)
);
}
class LectionAddition extends Zend_Db_Table_Abstract
{
protected $_name = 'lection_lecture_addition';
protected $_primary = 'lection_lecture_addition_id';

            protected $_referenceMap    = array(
'Lection' => array(
'columns'           => array('lection_lecture_id'),
'refTableClass'     => 'Lection',
'refColumns'        => array('lection_lecture_id')
)
);
}

Листинг контроллера обзора лекционных материалов(«SubjectController»).
<?
/* подключения библиотеки Json для  работы с xmlHttpRequest запросами*/
require_once('Zend/Json.php');class subjectController extends Zend_Controller_Action
{
            function indexAction()
            {
                        $subject = new Subject();
                        $this->view->subjectList = $subject->subjectList();
$this->view->title = “Web – ориентированная система дистанционного обучения СевНТУ”;
            }

 

            function viewsubjectAction()
{
$subject = new Subject();
$id = (int)$this->_request->getParam('subject');
$author = (int)$this->_request->getParam('author');
$this->view->lectionList = $subject->getAllLectionPrintBySubjectId($id);
$this->view->subject = $subject->getSubjNameByLecId($id);
$this->view->subjectId = $subject->getSubjIdByLectId($id);
}

            function viewprintAction()
{
$subject = new Subject();
$id = (int)$this->_request->getParam('id');
$author = (int)$this->_request->getParam('author');

                        $this->view->lectionList = $subject->getAllLectionPrintBySubjectId($id);
$this->view->author = $subject->getAuthorByLectId($author);
$this->view->subject = $subject->getSubjNameByLecId($id);
$this->view->subjectId = $subject->getSubjIdByLectId($id);
$this->view->lectionId = $id;
$this->view->lection = $subject->getLectNameByLectId($id);
$this->view->printId = $author;
$this->view->rating = $subject->getRatingByPrintId($author);

                        $this->view->authorListPrint = $subject->getAuthorListByPrintId($id);
$this->view->authorListVideo = $subject->getAuthorListByVideoId($id);
$this->view->authorListAudio = $subject->getAuthorListByAudioId($id);
$this->view->authorListAddition = $subject->getAuthorListByAdditionId($id);

            }

            function viewvideoAction()
{
$subject = new Subject();
$id = (int)$this->_request->getParam('id');
$author = (int)$this->_request->getParam('author');

                        $this->view->lectionList = $subject->getAllLectionPrintBySubjectId($id);

                        $this->view->author = $subject->getAuthorByVideoId($author);
$this->view->subject = $subject->getSubjNameByLecId($id);
$this->view->subjectId = $subject->getSubjIdByLectId($id);
$this->view->lectionId = $id;
$this->view->lection = $subject->getLectNameByLectId($id);
$this->view->printId = $author;
$this->view->rating = $subject->getRatingByVideoId($author);

                        $this->view->authorListPrint = $subject->getAuthorListByPrintId($id);
$this->view->authorListVideo = $subject->getAuthorListByVideoId($id);
$this->view->authorListAudio = $subject->getAuthorListByAudioId($id);
$this->view->authorListAddition = $subject->getAuthorListByAdditionId($id);
}

            function viewaudioAction()
{
$subject = new Subject();
$id = (int)$this->_request->getParam('id');
$author = (int)$this->_request->getParam('author');

                        $this->view->lectionList = $subject->getAllLectionPrintBySubjectId($id);

                        $this->view->author = $subject->getAuthorByAudioId($author);
$this->view->subject = $subject->getSubjNameByLecId($id);
$this->view->subjectId = $subject->getSubjIdByLectId($id);
$this->view->lectionId = $id;
$this->view->lection = $subject->getLectNameByLectId($id);
$this->view->printId = $author;
$this->view->rating = $subject->getRatingByVideoId($author);

                        $this->view->authorListPrint = $subject->getAuthorListByPrintId($id);
$this->view->authorListVideo = $subject->getAuthorListByVideoId($id);
$this->view->authorListAudio = $subject->getAuthorListByAudioId($id);
$this->view->authorListAddition = $subject->getAuthorListByAdditionId($id);
}

function downloadAction()
{
$subject = new Subject();
/* установка директории дампа памяти */
$patchToDump = "D:\\DUMP\\";

if ($this->_request->getParam('download'))
{
$exp = "";
switch($this->_request->getParam('type'))
{
case 'video' :
/*  загрузка идентификатора файла видео формата /*
$type = 'video';
$id = (int) $this->_request->getParam('download');
$lectionId = $subject->getLectIdByVideoId($id);                                                                             break;
/*  загрузка идентификатора файла аудио формата */
case 'audio' :
$type = 'audio';
$result = strpos($this->_request->getParam('download'), ".");
$id =(int)substr($this->_request->getParam('download'),0, $result);
$lectionId = $subject->getLectIdByAudioId($id);
/* извлечение разрешения файла(необходимо только для аудио форматов) */
$exp = $subject->getExpByAudioId($id);;
break;
case 'addition' :

                                   $type = 'addition';
$id = (int) $this->_request->getParam('download');
$lectionId = $subject->getLectIdByAdditionId($id);                                                                         break;
default: exit;
}
$subjectId = $subject->getSubjIdByLectId($lectionId);

$filename = $patchToDump.$subjectId."_".$lectionId."_".$type."_".$id;
$contents = "";
/* открытие файла из дампа памяти */
$f = fopen($filename, "r");

             while (!feof($f))
{
$contents .= fread($f, 2048);
}
fclose ($f);
if ($type = 'addition')
{
/* присваивание переменной $id имени файла */
$id = $subject->getNameAdditionByAdditionId($id);                      
}
/* изменение заголовка пакета HTTP протокола */
header("Content-Type: ".$type."; charset=\"windows-1251\";\r\n");
header("Content-Disposition: attachment; filename=".$id.".".$exp.";\r\n");
/* вывод содержимого файла */
echo $contents;
}                 
exit;
}

            function ratingAction()
{
$subject = new Subject();
$id = (int) $_REQUEST['id'][1];
$resp = false;
/* работа с COOKIE, проверка о существовании в кэше браузера информации об уже проголосованной лекции*/
if (!isset($_COOKIE["ratingPrint"][$id]))
{          
$resp = $subject->updateRaytingPrint($id);
setcookie("ratingPrint[".$id."]", 1);
}
break;
}
echo $resp;
}

            function init()
{
$this->view->baseUrl = $this->_request->getBaseUrl();
Zend_Loader::loadClass('Subject');
}
}

Листинг контроллера adminController. В этом классе описаны функции, которые позволяют выводить контент страницы на шаблон согласно входным переменным, а также вносить изменения в БД.
<?
class adminController extends Zend_Controller_Action
{
function indexAction()
{
$this->view->title = "Администрирование";
}

            function subjectAction()
{
$subject = new Subject();
$lection = new Lection();
// rename
if ($this->_request->getPost('subject'))
{
if ($this->_request->getPost('lection'))
{
$lection->LectionUpdate($this->_request->getPost(
'lection'.$this->_request->getPost('lection')),
$this->_request->getPost('lection'));
}
else
{
$data = array( 'subject' => $this->_request->getPost('subject'));
$where = $subject->getAdapter()->quoteInto('lection_subject_id = ?',
$this->_request->getPost('id'));
$subject->update($data, $where);
}
}
/ * добавление лекции*/
if ($this->_request->getPost('addLection'))
{
$subject->insertLection($this->_request->getPost('id'),
$this->_request->getPost('addLection'));
}
/ * добавление курса */
if ($this->_request->getPost('addSubject'))
{
$id = $subject->insertSubject($this->_request->getPost('addSubject'));
header('location: /admin/subject/id/'.$id);
}
$this->view->subjectList = $subject->subjectList();

                        $id = (int)$this->_request->getParam('id');
if ($id != 0)
{
$sub = $subject->subjectId($id);
$this->view->title = "Администрирование > Курсы > " . $sub->subject;
$this->view->subject = $sub->subject;
$this->view->subjectId = $id;

                                   $this->view->lections = $subject->subjectAllLection($id);

/ * печать текстовой лекции */
$this->view->prints = $lection->printAllLection($id);
$this->view->video = $lection->printAllVideo($id);
$this->view->audio = $lection->printAllAudio($id);
$this->view->addition = $lection->printAllAddition($id);
}
else
{
$this->view->title = "Администрирование > Курсы";
}
}

            function addlectAction()
{
$subject = new Subject();
if($this->_request->isGet())
{
$id = (int) $this->_request->getParam('id');
$sub = $subject->getSubjNameByLecId($id);
$this->view->title = $sub." :: Добавление новой лекции";
$this->view->subject = $sub;
$this->view->subjectId = $subject->getSubjIdByLectId($id);

                                   $this->view->lection =  $subject->getLectNameByLectId($id);
$this->view->lectionId = $this->_request->getParam('id');
$this->view->type = $this->_request->getParam('type');

                                   $supportFile = new supportFilePrint();
$this->view->supportFilePrint = $supportFile->print;
$this->view->typeView = "Печатный";
}

                        if($this->_request->isPost())
{
$supportFile = new supportFilePrint();

                                   $patchToConverter = "D:\\SERVER\\converter\\";
$patchToDump = "D:\\DUMP\\";
$patchToDumpUpl = "D:/DUMP/";
print_r($supportFile);

                                   $i = false;
foreach ($supportFile->print as $key => $val)
{
if (in_array($_FILES['file']['type'], $val))
{
$i = $key;
}
}

                                   if ($i !== false)
{

$uploadfile = $patchToDumpUpl.$this->_request->getParam('subjectId').'_'.$this->_request->getParam('lectionId').'_print_'.$id.'.'.$ext;
if (move_uploaded_file($_FILES['file']['tmp_name'], $uploadfile))
{
$in = " ".$uploadfile;
$out = ' '.$patchToDumpUpl.$this->_request->getParam('subjectId').'_'.$this->_request->getParam('lectionId').'_print_'.$id.'.txt';

                                                           exec($patchToConverter."minetext.exe".$in.$out, $error);
print_r($error);
}
header('location: /admin/viewlect/id/'.$id.'/type/print');
}
}
}

            function viewlectAction()
{
/*  установка директории к используемому
дампу памяти и к конвертору текстовых файлов */
$patchToConverter = "D:\\SERVER\\converter\\";
$patchToDump = "D:\\DUMP\\";
$patchToDumpUpl = "D:/DUMP/";

            $subject = new Subject();
if($this->_request->isPost())
{
/*  форма отображения экзмемпляра лекции  отправляет
запрос на viewlectAction, в форме action – интерфейсный
элемент  типа hidden, указывающий на тип действий     */              
switch ($this->_request->getPost('action'))
{
/*  переименование автора лекции */
case 'rename':
if ($this->_request->getPost('author') == '')
{
$author = "Гость";
}
else
{
$author = $this->_request->getPost('author');
}
$subject->updateAuthorPrint($this->_request->getPost('printId'),
$this->_request->getPost('author'));
break;

/*  удаление экземпляра лекции */
case 'delete':
$id=$subject->getSubjIdByLectPrintId(
$this->_request->getPost('printId'));
$subject->deleteLectionPrint($this->_request->getPost('printId'));                                                 exit;                                                   
break;

/*  замена файла с последующим конвертированием*/
case 'replace':
/*  создание объекта класса  supportFile */
$supportFile = new supportFile();
$i = false;
foreach ($supportFile->print as $key => $val)
{
/*  проверка условия: входит ли разрешение загруженного
файла   в список поддерживаемых файлов                 */
if (in_array($_FILES['file']['type'], $val))
{
$i = $key;                  
}
}
/*  если загруженный файл входит в поддерживаемый тип    выполняется
процесса конвертирования и  записи изменений в БД                       */
if ($i !== false)
{
$id = $this->_request->getPost('printId');
$ext = $supportFile->print[$i]['ext'];
$subjectId = $subject->getSubjIdByLectId(
$this->_request->getParam('lectionId'));
/*  установка директории и названия файла */
$uploadfile = $patchToDumpUpl.$subjectId.'_'.$this->
_request->getParam('lectionId').'_print_'.$id.'.'.$ext;
/*  перемещение загруженного файла из директории временного
хранения   файлов(указанного в настройках PHP) в директорию
значение которой проинициализировано переменной $uploadfile */
if (move_uploaded_file($_FILES['file']['tmp_name'], $uploadfile))
{
/* инициализация двух выходных параметров
программы «Minetext»                            */
$in = " ".$uploadfile;
$out = ' '.$patchToDumpUpl.$subjectId.'_'.$this->
_request->getParam('lectionId').'_print_'.$id.'.txt';
/* запуск приложения «minetext» */
exec($patchToConverter."minetext.exe".$in.$out, $error);
$subject->updateTypePrint($id, $_FILES['file']['type']);
}
}
break;
}
}

            function subjectaddAction()
{
$subject = new Subject();
if ($this->_request->getPost('subject'))
{
$this->view->title = "Администрирование :: Добавление нового курса :: ". $this->_request->getPost('subject');

                                   $data = array( 'subject' => $this->_request->getPost('subject'));
$subject->insert($data);
}
}

            function testAction()
{

                        $subject = new Subject();

                        $this->view->subjectList = $subject->subjectList();
$id = (int)$this->_request->getParam('subject');
if ($id != 0)
{
$sub = $subject->subjectId($id);
$this->view->title = "Администрирование > Тесты > " . $sub->subject;
$this->view->subject = $sub->subject;
$this->view->subjectId = $id;

                                   $this->view->lections = $subject->subjectAllLection($id);
$this->view->countquest = $subject->getCountQesttBySubject($id);

                        }
else
{
$this->view->title = "Администрирование > Тесты";
}
}

            function testresultAction()
{
$subject = new Subject();
$this->view->subjectList = $subject->subjectList();
$id = (int)$this->_request->getParam('testId');
if ($id != 0)
{
$test = $subject->test($id);
$sub = $subject->subjectId($id);
$this->view->title = "Администрирование >  " . $sub->subject . " > " . $sub->test;
$this->view->subject = $sub->subject;
$this->view->subjectId = $id;
$this->view->resultTest = $subject->getTestResult($id);
}
}

            function testlistAction()
{
$subject = new Subject();
$this->view->subjectList = $subject->subjectList();

                        $id = (int)$this->_request->getParam('subject');
if ($id != 0)
{
$sub = $subject->subjectId($id);
$this->view->title = "Администрирование > Создание тестов > " . $sub->subject;
$this->view->subject = $sub->subject;
$this->view->subjectId = $id;
//                                $this->view->testlist = $subject->getTestListBySubjectId($id);
}
else
{
$this->view->title = "Администрирование > Создание тестов";
$this->view->noSubject = "Выберите курс";
}
}

            function edittestAction()
{
$subject = new Subject();
if($this->_request->isPost())
{
$id = $this->_request->getPost('testId');
if ($this->_request->getPost('deleteTest') == true)
{
$subject->deleteTestById($id);
header("location: /admin/testlist/");
exit;
}
$subject->updateTestById($id, $this->_request->getPost('value'));
$subject->removeAllLection($id);
$i = false;
foreach ($supportFile->print as $key => $val)
{
if (($this->_request->getPost('lection')+$i) == true)
{
$subject->addTestLection($id, ($this->_request->getPost('lection')+$i));
}
}
header('location: /admin/testlist/subject/'.$id);
}
}

            function adminAction()
{
$subject = new Subject();
if($this->_request->isPost())
{
$id = $this->_request->getPost('userId');
if ($this->_request->getPost('deleteUser') == true)
{
$subject->deleteTestById($id);
header("location: /admin/");
exit;
}
if ($this->_request->getPost('changeGruopUser') == true)
{
$subject->addUserToPrepod($id);
}
header('location: /admin/');
}
else
{
$this->view->title = "Список пользователей";
$this->view->userlistPrepod = $subject->getUserListPrepod();
$this->view->userlistStud = $subject->getUserListStud();
}
}

            function viewtestAction()
{
$subject = new Subject();
$this->view->subjectList = $subject->subjectList();
$id = (int)$this->_request->getParam('id');
if ($id != 0)
{
$sub = $subject->subjectId($id);
$this->view->title = "Администрирование > Тесты > " . $sub->subject;
$this->view->subject = $sub->subject;
$this->view->subjectId = $id;

                                   $this->view->questions = $subject->getAllQuestionBySubjectId($id);
$this->view->questions_variants = $subject->getAllQuestionVariantBySubjectId($id);
}
else
{
$this->view->title = "Администрирование > Тесты";
}
}
function updatequstionAction()
{
$subject = new Subject();
/*  инициализация входных переменных */
$id = (int) $_REQUEST['i'];
$s = $_REQUEST['s'];
$t = $_REQUEST['t'];
if ($t == 'aq')
{
if ($s != "")
{
/* добавление  вопроса  */
$subject->insertQuestion($s,$id);
/* возврат true обозначает, что страницу необходимо
перегрузить  после отправленного запроса            */
echo 'true';
}
}                     

}

            function init()
{
$this->view->baseUrl = $this->_request->getBaseUrl();
Zend_Loader::loadClass('Subject');
}
}

СевНТУ 2008г. автор работы Прищак Сергей
Hosted by uCoz