Upload docs draft
This commit is contained in:
71
inc/doc.php
Normal file
71
inc/doc.php
Normal file
@@ -0,0 +1,71 @@
|
||||
<?php
|
||||
|
||||
class Doc extends PhpObject {
|
||||
|
||||
const DOC_FOLDER = 'files/';
|
||||
const DOC_TABLE = 'docs';
|
||||
/**
|
||||
* DB
|
||||
* @var Db
|
||||
*/
|
||||
private $oDb;
|
||||
|
||||
private $iDocId;
|
||||
private $iUserId;
|
||||
private $iCourseId;
|
||||
|
||||
public function __construct(Db &$oDb, $iUserId, $iCourseId)
|
||||
{
|
||||
parent::__construct(__CLASS__, Settings::DEBUG);
|
||||
$this->oDb = &$oDb;
|
||||
$this->setDocId(0);
|
||||
$this->setUserCourseId($iUserId, $iCourseId);
|
||||
}
|
||||
|
||||
public function setDocId($iDocId) {
|
||||
$this->iDocId = $iDocId;
|
||||
}
|
||||
|
||||
public function setUserCourseId($iUserId, $iCourseId) {
|
||||
$this->iUserId = $iUserId;
|
||||
$this->iCourseId = $iCourseId;
|
||||
}
|
||||
|
||||
public function exists($sFileName) {
|
||||
return file_exists(self::DOC_FOLDER.$sFileName);
|
||||
}
|
||||
|
||||
public function add($sFileName, $sMimeType) {
|
||||
$sType = '';
|
||||
switch(mime_content_type(self::getFilePath($sFileName))) {
|
||||
case 'application/msword':
|
||||
case 'application/vnd.openxmlformats-officedocument.wordprocessingml.document': $sType = 'word'; break;
|
||||
case 'application/pdf': $sType = 'pdf'; break;
|
||||
case 'audio/mpeg': $sType = 'audio'; break;
|
||||
case 'image/gif': $sType = 'image'; break;
|
||||
case 'image/jpeg': $sType = 'image'; break;
|
||||
case 'image/png': $sType = 'image'; break;
|
||||
}
|
||||
|
||||
$asData = array_merge($this->getDocKeys(), array('filename'=>$sFileName, 'type'=>$sType));
|
||||
|
||||
$bResult = $this->oDb->insertRow(self::DOC_TABLE, $asData);
|
||||
return $bResult?'':'error_db';
|
||||
}
|
||||
|
||||
public function delete($sFileName) {
|
||||
|
||||
}
|
||||
|
||||
public function getList() {
|
||||
return $this->oDb->selectRows(array('select'=>array(Db::getId(self::DOC_TABLE), 'type', 'filename'), 'from'=>self::DOC_TABLE, 'constraints'=>$this->getDocKeys()));
|
||||
}
|
||||
|
||||
private function getDocKeys() {
|
||||
return array(Db::getId(Auth::USER_TABLE) => $this->iUserId, Db::getId(Course::COURSE_TABLE) => $this->iCourseId);
|
||||
}
|
||||
|
||||
private static function getFilePath($sFileName) {
|
||||
return self::DOC_FOLDER.$sFileName;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user