Add delete button on docs
This commit is contained in:
11
inc/catc.php
11
inc/catc.php
@@ -150,12 +150,19 @@ class CATC extends Main
|
||||
return self::getJsonResult(!empty($asDocList), '', $asDocList);
|
||||
}
|
||||
|
||||
public function uploadDoc($iCourseId)
|
||||
{
|
||||
public function uploadDoc($iCourseId) {
|
||||
$this->oClassManagement->incClass('uploader', true);
|
||||
$oDoc = new Doc($this->oDb, $this->oAuth->getUserId(), $iCourseId);
|
||||
$oUploader = new Uploader($oDoc);
|
||||
|
||||
return $oUploader->sBody;
|
||||
}
|
||||
|
||||
public function deleteDoc($iDocId) {
|
||||
$oDoc = new Doc($this->oDb);
|
||||
$oDoc->setDocId($iDocId);
|
||||
$bResult = $oDoc->delete();
|
||||
|
||||
return self::getJsonResult($bResult, '');
|
||||
}
|
||||
}
|
||||
21
inc/doc.php
21
inc/doc.php
@@ -14,7 +14,7 @@ class Doc extends PhpObject {
|
||||
private $iUserId;
|
||||
private $iCourseId;
|
||||
|
||||
public function __construct(Db &$oDb, $iUserId, $iCourseId)
|
||||
public function __construct(Db &$oDb, $iUserId=0, $iCourseId=0)
|
||||
{
|
||||
parent::__construct(__CLASS__, Settings::DEBUG);
|
||||
$this->oDb = &$oDb;
|
||||
@@ -53,13 +53,24 @@ class Doc extends PhpObject {
|
||||
return $bResult?'':'error_db';
|
||||
}
|
||||
|
||||
public function delete($sFileName) {
|
||||
public function delete() {
|
||||
if($this->iDocId > 0) {
|
||||
$asDoc = $this->getDoc();
|
||||
$bResult = $this->oDb->deleteRow(self::DOC_TABLE, $this->iDocId);
|
||||
if($bResult) $bResult = unlink($asDoc['filepath']);
|
||||
}
|
||||
|
||||
return $bResult;
|
||||
}
|
||||
|
||||
public function getList() {
|
||||
$this->oDb->setTrace(true);
|
||||
$asDocs = $this->oDb->selectRows(array('select'=>array(Db::getId(self::DOC_TABLE), 'type', 'filename'), 'from'=>self::DOC_TABLE, 'constraint'=>$this->getDocKeys()));
|
||||
public function getDoc() {
|
||||
$asDocList = $this->getList(array(Db::getId(self::DOC_TABLE) => $this->iDocId));
|
||||
return array_shift($asDocList);
|
||||
}
|
||||
|
||||
public function getList($asConstraint=array()) {
|
||||
$asKeys = empty($asConstraint)?$this->getDocKeys():$asConstraint;
|
||||
$asDocs = $this->oDb->selectRows(array('select'=>array(Db::getId(self::DOC_TABLE), 'type', 'filename'), 'from'=>self::DOC_TABLE, 'constraint'=>$asKeys));
|
||||
foreach($asDocs as &$asDoc) $asDoc['filepath'] = self::getFilePath($asDoc['filename']);
|
||||
|
||||
return $asDocs;
|
||||
|
||||
Reference in New Issue
Block a user