2014-05-19 10:16:43 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/**
|
2014-05-28 11:02:52 +02:00
|
|
|
* This is the model class for table "program".
|
2014-05-19 10:16:43 +02:00
|
|
|
*
|
2014-05-28 11:02:52 +02:00
|
|
|
* The followings are the available columns in table 'program':
|
2014-05-19 10:16:43 +02:00
|
|
|
* @property integer $ID
|
|
|
|
* @property string $Name
|
2014-05-28 17:19:57 +02:00
|
|
|
* @property string Thumbnailname
|
2014-05-19 10:16:43 +02:00
|
|
|
* @property double $Downloads
|
|
|
|
* @property string $Kategorie
|
|
|
|
* @property double $Sterne
|
|
|
|
* @property integer $enabled
|
|
|
|
* @property integer $visible
|
|
|
|
* @property string $Language
|
2014-06-03 14:24:37 +02:00
|
|
|
* @property string $programming_lang
|
2014-05-19 10:16:43 +02:00
|
|
|
* @property string $Description
|
|
|
|
* @property string $add_date
|
|
|
|
* @property string $download_url
|
|
|
|
* @property string $sourceforge_url
|
|
|
|
* @property string $homepage_url
|
|
|
|
* @property string $github_url
|
|
|
|
* @property integer $uses_absCanv
|
|
|
|
* @property string $update_identifier
|
|
|
|
* @property integer $highscore_gid
|
2014-06-12 15:37:03 +02:00
|
|
|
*
|
|
|
|
* @property ProgramUpdates $version
|
2014-05-19 10:16:43 +02:00
|
|
|
*/
|
2014-05-28 11:02:52 +02:00
|
|
|
class Program extends CActiveRecord
|
2014-05-19 10:16:43 +02:00
|
|
|
{
|
|
|
|
/**
|
|
|
|
* @return string the associated database table name
|
|
|
|
*/
|
|
|
|
public function tableName()
|
|
|
|
{
|
2014-06-04 09:33:24 +02:00
|
|
|
return '{{programs}}';
|
2014-05-19 10:16:43 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return array validation rules for model attributes.
|
|
|
|
*/
|
|
|
|
public function rules()
|
|
|
|
{
|
|
|
|
// NOTE: you should only define rules for those attributes that
|
|
|
|
// will receive user inputs.
|
|
|
|
return array(
|
2014-06-30 22:51:59 +02:00
|
|
|
array('Name, Thumbnailname, Downloads, Kategorie, Sterne, enabled, visible, Language, programming_lang, Description, add_date, uses_absCanv', 'required'),
|
2014-06-12 14:36:34 +02:00
|
|
|
array('enabled, visible, uses_absCanv, highscore_gid', 'numerical', 'integerOnly'=>true),
|
2014-05-19 10:16:43 +02:00
|
|
|
array('Downloads, Sterne', 'numerical'),
|
2014-06-12 14:36:34 +02:00
|
|
|
array('update_identifier', 'length', 'max'=>64),
|
2014-06-03 14:24:37 +02:00
|
|
|
array('programming_lang', 'length', 'max'=>16),
|
2014-05-19 10:16:43 +02:00
|
|
|
// The following rule is used by search().
|
2014-06-12 14:36:34 +02:00
|
|
|
array('ID, Name, Thumbnailname, Downloads, Kategorie, Sterne, enabled, visible, Language, programming_lang, Description, add_date, download_url, sourceforge_url, homepage_url, github_url, uses_absCanv, update_identifier, highscore_gid', 'safe', 'on'=>'search'),
|
2014-05-19 10:16:43 +02:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return array relational rules.
|
|
|
|
*/
|
|
|
|
public function relations()
|
|
|
|
{
|
|
|
|
return array(
|
2014-06-12 15:37:03 +02:00
|
|
|
'version' =>
|
|
|
|
[
|
|
|
|
self::HAS_ONE,
|
|
|
|
'ProgramUpdates',
|
|
|
|
[
|
|
|
|
'Name' => 'update_identifier'
|
|
|
|
]],
|
2014-05-19 10:16:43 +02:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return array customized attribute labels (name=>label)
|
|
|
|
*/
|
|
|
|
public function attributeLabels()
|
|
|
|
{
|
|
|
|
return array(
|
|
|
|
'ID' => 'ID',
|
|
|
|
'Name' => 'Name',
|
2014-05-28 17:19:57 +02:00
|
|
|
'Thumbnailname' => 'Thumbnail name',
|
2014-05-19 10:16:43 +02:00
|
|
|
'Downloads' => 'Downloads',
|
|
|
|
'Kategorie' => 'Kategorie',
|
|
|
|
'Sterne' => 'Sterne',
|
|
|
|
'enabled' => 'Enabled',
|
|
|
|
'visible' => 'Visible',
|
|
|
|
'Language' => 'Language',
|
2014-06-30 22:51:59 +02:00
|
|
|
'programming_lang' => 'programming Language',
|
2014-05-19 10:16:43 +02:00
|
|
|
'Description' => 'Description',
|
|
|
|
'add_date' => 'Add Date',
|
|
|
|
'download_url' => 'Download Url',
|
|
|
|
'sourceforge_url' => 'Sourceforge Url',
|
|
|
|
'homepage_url' => 'Homepage Url',
|
|
|
|
'github_url' => 'Github Url',
|
|
|
|
'uses_absCanv' => 'Uses Abs Canv',
|
|
|
|
'update_identifier' => 'Update Identifier',
|
|
|
|
'highscore_gid' => 'Highscore Gid',
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Retrieves a list of models based on the current search/filter conditions.
|
|
|
|
*
|
|
|
|
* Typical usecase:
|
|
|
|
* - Initialize the model fields with values from filter form.
|
|
|
|
* - Execute this method to get CActiveDataProvider instance which will filter
|
|
|
|
* models according to data in model fields.
|
|
|
|
* - Pass data provider to CGridView, CListView or any similar widget.
|
|
|
|
*
|
|
|
|
* @return CActiveDataProvider the data provider that can return the models
|
|
|
|
* based on the search/filter conditions.
|
|
|
|
*/
|
|
|
|
public function search()
|
|
|
|
{
|
|
|
|
$criteria=new CDbCriteria;
|
|
|
|
|
|
|
|
$criteria->compare('ID',$this->ID);
|
|
|
|
$criteria->compare('Name',$this->Name,true);
|
2014-05-28 17:19:57 +02:00
|
|
|
$criteria->compare('Thumbnailname',$this->Thumbnailname,true);
|
2014-05-19 10:16:43 +02:00
|
|
|
$criteria->compare('Downloads',$this->Downloads);
|
|
|
|
$criteria->compare('Kategorie',$this->Kategorie,true);
|
|
|
|
$criteria->compare('Sterne',$this->Sterne);
|
|
|
|
$criteria->compare('enabled',$this->enabled);
|
|
|
|
$criteria->compare('visible',$this->visible);
|
|
|
|
$criteria->compare('Language',$this->Language,true);
|
2014-06-03 14:24:37 +02:00
|
|
|
$criteria->compare('programming_lang',$this->programming_lang,true);
|
2014-05-19 10:16:43 +02:00
|
|
|
$criteria->compare('Description',$this->Description,true);
|
|
|
|
$criteria->compare('add_date',$this->add_date,true);
|
|
|
|
$criteria->compare('download_url',$this->download_url,true);
|
|
|
|
$criteria->compare('sourceforge_url',$this->sourceforge_url,true);
|
|
|
|
$criteria->compare('homepage_url',$this->homepage_url,true);
|
|
|
|
$criteria->compare('github_url',$this->github_url,true);
|
|
|
|
$criteria->compare('uses_absCanv',$this->uses_absCanv);
|
|
|
|
$criteria->compare('update_identifier',$this->update_identifier,true);
|
|
|
|
$criteria->compare('highscore_gid',$this->highscore_gid);
|
|
|
|
|
|
|
|
return new CActiveDataProvider($this, array(
|
|
|
|
'criteria'=>$criteria,
|
2014-05-19 10:35:32 +02:00
|
|
|
'Pagination' => array (
|
|
|
|
'PageSize' => 50 //edit your number items per page here
|
|
|
|
),
|
2014-05-19 10:16:43 +02:00
|
|
|
));
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the static model of the specified AR class.
|
|
|
|
* Please note that you should have this exact method in all your CActiveRecord descendants!
|
|
|
|
* @param string $className active record class name.
|
2014-05-28 11:02:52 +02:00
|
|
|
* @return Program the static model class
|
2014-05-19 10:16:43 +02:00
|
|
|
*/
|
|
|
|
public static function model($className=__CLASS__)
|
|
|
|
{
|
|
|
|
return parent::model($className);
|
|
|
|
}
|
2014-06-03 14:24:37 +02:00
|
|
|
|
|
|
|
//####################################
|
|
|
|
//########### MY FUNCTIONS ###########
|
|
|
|
//####################################
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return string
|
2014-06-04 09:33:24 +02:00
|
|
|
* @throws CHttpException
|
2014-06-03 14:24:37 +02:00
|
|
|
*/
|
|
|
|
public function getImagePath() {
|
|
|
|
if (file_exists('images/programs/thumbnails/' . $this->Name . '.png'))
|
2014-08-04 20:10:58 +02:00
|
|
|
return '/images/programs/thumbnails/' . rawurlencode($this->Name) . '.png';
|
2014-06-04 18:06:38 +02:00
|
|
|
// else if (file_exists('images/programs/thumbnails/' . $this->Name . '.jpg'))
|
|
|
|
// return '/images/programs/thumbnails/' . $this->Name . '.jpg';
|
2014-06-03 14:24:37 +02:00
|
|
|
else throw new CHttpException(500, "Could not find Program Thumbnail '" . $this->Name . "'");
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
public function getLink() {
|
2014-08-04 20:10:58 +02:00
|
|
|
return '/programs/view/' . rawurlencode($this->Name);
|
2014-06-03 14:24:37 +02:00
|
|
|
}
|
|
|
|
|
2014-07-19 19:35:53 +02:00
|
|
|
/**
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
public function getDownloadLink() {
|
2014-08-04 20:10:58 +02:00
|
|
|
return '/programs/download/' . rawurlencode($this->Name);
|
2014-07-19 19:35:53 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
public function getDirectDownloadLink() {
|
2014-07-20 21:29:07 +02:00
|
|
|
if ($this->download_url == 'direkt' || is_null($this->download_url) || empty($this->download_url))
|
2014-08-04 20:10:58 +02:00
|
|
|
return '/data/programs/' . rawurlencode($this->Name) . '.zip';
|
2014-07-20 21:29:07 +02:00
|
|
|
else
|
|
|
|
return $this->download_url;
|
2014-07-19 19:35:53 +02:00
|
|
|
}
|
|
|
|
|
2014-06-03 14:24:37 +02:00
|
|
|
/**
|
|
|
|
* @return string[]
|
|
|
|
*/
|
|
|
|
public function getLanguageList() {
|
|
|
|
return explode("|", $this->Language);
|
|
|
|
}
|
2014-06-06 12:02:56 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @return DateTime
|
|
|
|
*/
|
|
|
|
public function getDateTime() {
|
|
|
|
return new DateTime($this->add_date);
|
|
|
|
}
|
2014-06-12 14:36:34 +02:00
|
|
|
|
2014-07-20 16:37:49 +02:00
|
|
|
/**
|
|
|
|
* @return string
|
|
|
|
*/
|
2014-06-12 14:36:34 +02:00
|
|
|
public function getStarHTML()
|
|
|
|
{
|
|
|
|
$out = '';
|
|
|
|
|
|
|
|
for ($i = 0; $i < 4; $i++) {
|
|
|
|
if ($i < $this->Sterne)
|
|
|
|
$out .= MsHtml::icon(MsHtml::ICON_STAR);
|
|
|
|
else
|
|
|
|
$out .= MsHtml::icon(MsHtml::ICON_STAR_EMPTY);
|
|
|
|
}
|
|
|
|
|
|
|
|
return $out;
|
|
|
|
}
|
2014-07-05 21:15:24 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @return array()
|
|
|
|
*/
|
|
|
|
public function getDescriptions()
|
|
|
|
{
|
|
|
|
$result = array();
|
|
|
|
|
|
|
|
$path = "data/programs/desc/" . $this->Name . "/*";
|
|
|
|
|
|
|
|
$tl_paths = glob($path, GLOB_MARK);
|
|
|
|
|
|
|
|
foreach ($tl_paths as $fn)
|
|
|
|
{
|
2014-08-04 21:46:15 +02:00
|
|
|
if (MsHelper::endsWith($fn, DIRECTORY_SEPARATOR))
|
2014-07-05 21:15:24 +02:00
|
|
|
{
|
|
|
|
$bl_paths = glob($fn . '*.markdown');
|
|
|
|
|
|
|
|
$bl_arr = array();
|
|
|
|
foreach ($bl_paths as $bl_fn)
|
|
|
|
{
|
|
|
|
$bl_arr[] = ['type' => 1, 'name' => ProgramHelper::getIndexedFilename($bl_fn, $num), 'path' => $bl_fn];
|
|
|
|
}
|
|
|
|
|
|
|
|
$result[] = ['type' => 0,'name' => ProgramHelper::getIndexedFilename($fn, $num), 'items' => $bl_arr];
|
|
|
|
}
|
|
|
|
else if (MsHelper::endsWith($fn, ".markdown"))
|
|
|
|
{
|
|
|
|
$ifn = ProgramHelper::getIndexedFilename($fn, $num);
|
|
|
|
|
|
|
|
if (strcasecmp($ifn, "index") == 0) // == 0 : true
|
|
|
|
{
|
|
|
|
array_unshift($result, ['type' => 1,'name' => $ifn, 'path' => $fn]);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
$result[] = ['type' => 1,'name' => $ifn, 'path' => $fn];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return $result;
|
|
|
|
}
|
2014-07-06 15:45:52 +02:00
|
|
|
|
2014-07-20 16:37:49 +02:00
|
|
|
public function deleteDescriptions()
|
|
|
|
{
|
2014-07-06 15:45:52 +02:00
|
|
|
MsHelper::deleteDir("data/programs/desc/" . $this->Name . "/");
|
|
|
|
}
|
2014-07-20 16:37:49 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @return HighscoreGames
|
|
|
|
*/
|
|
|
|
public function getHighscoreGame()
|
|
|
|
{
|
|
|
|
return HighscoreGames::model()->findByPk($this->highscore_gid);
|
|
|
|
}
|
2014-08-04 14:57:13 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @param $search string[]
|
|
|
|
* @return array()
|
|
|
|
*/
|
|
|
|
public static function getSearchResults($search)
|
|
|
|
{
|
|
|
|
/* @var $all Program[] */
|
|
|
|
/* @var $resultarr Program[] */
|
|
|
|
$all = Program::model()->findAll();
|
|
|
|
|
|
|
|
$resultarr = array();
|
|
|
|
|
|
|
|
foreach($search as $searchpart)
|
|
|
|
{
|
|
|
|
foreach($all as $prog)
|
|
|
|
{
|
|
|
|
if (! $prog->enabled || ! $prog->visible)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (stripos($prog->Name, $searchpart) !== false && ! in_array($prog, $resultarr))
|
|
|
|
$resultarr []= $prog;
|
|
|
|
|
|
|
|
if (stripos($prog->Description, $searchpart) !== false && ! in_array($prog, $resultarr))
|
|
|
|
$resultarr []= $prog;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
$result = array();
|
|
|
|
|
|
|
|
foreach($resultarr as $prog)
|
|
|
|
{
|
|
|
|
$result []=
|
|
|
|
[
|
|
|
|
'Name' => $prog->Name,
|
|
|
|
'Description' => $prog->Description,
|
|
|
|
'Link' => $prog->GetLink(),
|
|
|
|
'Image' => $prog->GetImagePath(),
|
|
|
|
];
|
|
|
|
}
|
|
|
|
|
|
|
|
return $result;
|
|
|
|
}
|
2014-05-19 10:16:43 +02:00
|
|
|
}
|