Added Download counter
This commit is contained in:
parent
10ac7f4ec1
commit
49b7368f44
@ -70,6 +70,7 @@ return ArrayX::merge(
|
|||||||
'programs/' => ['programs/index', 'defaultParams' => ['categoryfilter' => '']],
|
'programs/' => ['programs/index', 'defaultParams' => ['categoryfilter' => '']],
|
||||||
'programs/cat/<categoryfilter>' => ['programs/index', 'defaultParams' => ['categoryfilter' => '']],
|
'programs/cat/<categoryfilter>' => ['programs/index', 'defaultParams' => ['categoryfilter' => '']],
|
||||||
'programs/view/<id>' => 'programs/view',
|
'programs/view/<id>' => 'programs/view',
|
||||||
|
'programs/download/<id>' => 'programs/download',
|
||||||
|
|
||||||
'log/' => ['log/index', 'defaultParams' => ['logid' => '-1']],
|
'log/' => ['log/index', 'defaultParams' => ['logid' => '-1']],
|
||||||
'log/<logid:[0-9]+>' => ['log/index', 'defaultParams' => ['logid' => '-1']],
|
'log/<logid:[0-9]+>' => ['log/index', 'defaultParams' => ['logid' => '-1']],
|
||||||
|
@ -28,7 +28,7 @@ class ProgramsController extends MSController
|
|||||||
{
|
{
|
||||||
return array(
|
return array(
|
||||||
array('allow', // allow all users to perform 'index' and 'view' actions
|
array('allow', // allow all users to perform 'index' and 'view' actions
|
||||||
'actions'=>array('index','view'),
|
'actions'=>array('index','view', 'download'),
|
||||||
'users'=>array('*'),
|
'users'=>array('*'),
|
||||||
),
|
),
|
||||||
array('allow', // allow authenticated user to perform 'create' and 'update' actions
|
array('allow', // allow authenticated user to perform 'create' and 'update' actions
|
||||||
@ -72,6 +72,34 @@ class ProgramsController extends MSController
|
|||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Displays a particular model.
|
||||||
|
* @param integer $id the ID of the model to be displayed
|
||||||
|
* @throws CHttpException when $id is integer
|
||||||
|
*/
|
||||||
|
public function actionDownload($id)
|
||||||
|
{
|
||||||
|
$this->layout = '//layouts/main';
|
||||||
|
|
||||||
|
if (is_numeric($id))
|
||||||
|
{
|
||||||
|
if (Yii::app()->user->name == 'admin') {
|
||||||
|
$model = $this->loadModelByID($id);
|
||||||
|
} else {
|
||||||
|
throw new CHttpException(400, "You can't access a program by ID");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
$model = $this->loadModelByName($id);
|
||||||
|
}
|
||||||
|
|
||||||
|
$model->Downloads++;
|
||||||
|
$model->save();
|
||||||
|
|
||||||
|
$this->redirect($model->getDirectDownloadLink());
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a new model.
|
* Creates a new model.
|
||||||
* If creation is successful, the browser will be redirected to the 'view' page.
|
* If creation is successful, the browser will be redirected to the 'view' page.
|
||||||
|
@ -176,6 +176,20 @@ class Program extends CActiveRecord
|
|||||||
return '/programs/view/' . $this->Name;
|
return '/programs/view/' . $this->Name;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public function getDownloadLink() {
|
||||||
|
return '/programs/download/' . $this->Name;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public function getDirectDownloadLink() {
|
||||||
|
return '/data/programs/' . $this->Name . '.zip' ;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return string[]
|
* @return string[]
|
||||||
*/
|
*/
|
||||||
|
@ -93,7 +93,8 @@ if (!$model->visible && Yii::app()->user->name != 'admin') {
|
|||||||
'block' => true,
|
'block' => true,
|
||||||
'color' => TbHtml::BUTTON_COLOR_PRIMARY,
|
'color' => TbHtml::BUTTON_COLOR_PRIMARY,
|
||||||
'size' => TbHtml::BUTTON_SIZE_DEFAULT,
|
'size' => TbHtml::BUTTON_SIZE_DEFAULT,
|
||||||
'url' => '#', //TODO-MS Add Download link
|
'Content' => 'nofollow',
|
||||||
|
'url' => $model->getDownloadLink(), //TODO-MS Add Download link
|
||||||
]);
|
]);
|
||||||
?>
|
?>
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user