2015-05-06 14:11:00 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Gist\Model;
|
|
|
|
|
|
|
|
use Gist\Model\Base\Gist as BaseGist;
|
2017-06-25 19:13:27 +02:00
|
|
|
use Propel\Runtime\Map\TableMap;
|
2015-05-06 14:11:00 +02:00
|
|
|
|
2016-11-13 00:44:23 +01:00
|
|
|
/**
|
|
|
|
* Class Gist.
|
|
|
|
*
|
|
|
|
* @author Simon Vieille <simon@deblan.fr>
|
|
|
|
*/
|
2015-05-06 14:11:00 +02:00
|
|
|
class Gist extends BaseGist
|
|
|
|
{
|
2016-11-13 00:44:23 +01:00
|
|
|
/**
|
|
|
|
* Hydrates the gist with array data.
|
|
|
|
*
|
|
|
|
* @param array $data
|
|
|
|
*
|
|
|
|
* @return Gist
|
|
|
|
*/
|
2015-05-06 14:11:00 +02:00
|
|
|
public function hydrateWith(array $data)
|
|
|
|
{
|
|
|
|
if (isset($data['title'])) {
|
|
|
|
$this->setTitle(trim($data['title']));
|
|
|
|
}
|
|
|
|
|
|
|
|
if (isset($data['type'])) {
|
|
|
|
$this->setType($data['type']);
|
|
|
|
}
|
|
|
|
|
2015-05-06 20:35:30 +02:00
|
|
|
$this->setCipher(isset($data['cipher']) && $data['cipher'] === 'yes');
|
2015-05-06 14:11:00 +02:00
|
|
|
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
2016-11-13 00:44:23 +01:00
|
|
|
/**
|
|
|
|
* Generates a unique filename.
|
|
|
|
*
|
|
|
|
* @return string
|
|
|
|
*/
|
2015-05-06 14:11:00 +02:00
|
|
|
public function generateFilename()
|
|
|
|
{
|
|
|
|
$this->setFile(uniqid());
|
|
|
|
}
|
2015-05-07 13:38:24 +02:00
|
|
|
|
2016-11-13 00:44:23 +01:00
|
|
|
/**
|
2017-10-15 12:40:52 +02:00
|
|
|
* Returns the type for highlighting.
|
2016-11-13 00:44:23 +01:00
|
|
|
*
|
|
|
|
* @return string
|
|
|
|
*/
|
2017-10-15 12:40:52 +02:00
|
|
|
public function getHighlightType()
|
2015-05-09 12:30:33 +02:00
|
|
|
{
|
|
|
|
$data = array(
|
|
|
|
'html' => 'xml',
|
2017-10-15 12:40:52 +02:00
|
|
|
'asp' => 'aspnet',
|
|
|
|
'actionscript3' => 'actionscript',
|
2015-05-09 12:30:33 +02:00
|
|
|
);
|
|
|
|
|
|
|
|
return str_replace(array_keys($data), array_values($data), $this->getType());
|
|
|
|
}
|
|
|
|
|
2016-11-13 00:44:23 +01:00
|
|
|
/**
|
|
|
|
* Returns the extension depending of the type.
|
|
|
|
*
|
|
|
|
* @return string
|
|
|
|
*/
|
2015-05-07 13:38:24 +02:00
|
|
|
public function getTypeAsExtension()
|
|
|
|
{
|
|
|
|
$data = array(
|
|
|
|
'javascript' => 'js',
|
2016-09-24 16:07:35 +02:00
|
|
|
'yaml' => 'yml',
|
2015-05-07 13:38:24 +02:00
|
|
|
'perl' => 'pl',
|
|
|
|
'python' => 'py',
|
|
|
|
'bash' => 'sh',
|
|
|
|
'actionscript3' => 'as',
|
|
|
|
'text' => 'txt',
|
|
|
|
);
|
|
|
|
|
|
|
|
return str_replace(array_keys($data), array_values($data), $this->getType());
|
|
|
|
}
|
2016-12-23 11:17:56 +01:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Increments the number of commits.
|
|
|
|
*/
|
|
|
|
public function commit()
|
|
|
|
{
|
|
|
|
$this->setCommits($this->getCommits() + 1);
|
|
|
|
|
|
|
|
return $this;
|
|
|
|
}
|
2017-06-25 19:13:27 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* {@inheritdoc}
|
|
|
|
*/
|
|
|
|
public function toArray($keyType = TableMap::TYPE_PHPNAME, $includeLazyLoadColumns = true, $alreadyDumpedObjects = array(), $includeForeignObjects = false)
|
|
|
|
{
|
|
|
|
$data = parent::toArray(
|
|
|
|
$keyType,
|
|
|
|
$includeLazyLoadColumns,
|
|
|
|
$alreadyDumpedObjects,
|
|
|
|
$includeForeignObjects
|
|
|
|
);
|
|
|
|
|
|
|
|
foreach ($data as $key => $value) {
|
|
|
|
$newKey = lcfirst($key);
|
|
|
|
unset($data[$key]);
|
|
|
|
$data[$newKey] = $value;
|
|
|
|
}
|
|
|
|
|
|
|
|
return $data;
|
|
|
|
}
|
2015-05-06 14:11:00 +02:00
|
|
|
}
|