2015-11-21 14:27:53 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Gist\Model;
|
|
|
|
|
|
|
|
use Gist\Model\Base\User as BaseUser;
|
|
|
|
use Symfony\Component\Security\Core\User\UserInterface;
|
2015-11-23 21:09:32 +01:00
|
|
|
use Propel\Runtime\ActiveQuery\Criteria;
|
|
|
|
use Propel\Runtime\Connection\ConnectionInterface;
|
2016-12-21 22:52:23 +01:00
|
|
|
|
2016-11-13 00:44:23 +01:00
|
|
|
/**
|
|
|
|
* Class User.
|
|
|
|
*
|
|
|
|
* @author Simon Vieille <simon@deblan.fr>
|
|
|
|
*/
|
2015-11-21 14:27:53 +01:00
|
|
|
class User extends BaseUser implements UserInterface
|
|
|
|
{
|
2016-11-13 00:44:23 +01:00
|
|
|
/**
|
|
|
|
* Erases credentials.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2015-11-21 14:27:53 +01:00
|
|
|
public function eraseCredentials()
|
|
|
|
{
|
|
|
|
}
|
2015-11-21 18:28:48 +01:00
|
|
|
|
2016-11-13 00:44:23 +01:00
|
|
|
/**
|
|
|
|
* Returns roles.
|
|
|
|
*
|
|
|
|
* @return array
|
|
|
|
*/
|
2015-11-21 18:28:48 +01:00
|
|
|
public function getRoles()
|
|
|
|
{
|
|
|
|
return explode(',', parent::getRoles());
|
|
|
|
}
|
2015-11-23 21:09:32 +01:00
|
|
|
|
2016-11-13 00:44:23 +01:00
|
|
|
/**
|
|
|
|
* {@inheritdoc}
|
|
|
|
*/
|
2015-11-23 21:09:32 +01:00
|
|
|
public function getGists(Criteria $criteria = null, ConnectionInterface $con = null)
|
|
|
|
{
|
|
|
|
if ($criteria === null) {
|
|
|
|
$criteria = GistQuery::create()->orderById(Criteria::DESC);
|
|
|
|
}
|
|
|
|
|
|
|
|
return parent::getGists($criteria, $con);
|
|
|
|
}
|
2016-06-18 16:37:45 +02:00
|
|
|
|
2016-11-13 00:44:23 +01:00
|
|
|
/**
|
|
|
|
* Generates a pager of the user's gists.
|
|
|
|
*
|
|
|
|
* @param int $page
|
|
|
|
* @param array $options
|
|
|
|
* @param int $maxPerPage
|
|
|
|
*
|
|
|
|
* @return Propel\Runtime\Util\PropelModelPager
|
|
|
|
*/
|
2017-06-25 19:13:27 +02:00
|
|
|
public function getGistsPager($page, $options = array(), $maxPerPage = 10)
|
2016-06-18 16:37:45 +02:00
|
|
|
{
|
2016-06-18 17:44:07 +02:00
|
|
|
$query = GistQuery::create()
|
2016-06-18 16:37:45 +02:00
|
|
|
->filterByUser($this)
|
2016-06-18 17:44:07 +02:00
|
|
|
->orderByCreatedAt(Criteria::DESC);
|
|
|
|
|
|
|
|
if (!empty($options['type']) && $options['type'] !== 'all') {
|
|
|
|
$query->filterByType($options['type']);
|
|
|
|
}
|
2017-06-25 19:13:27 +02:00
|
|
|
|
2017-04-23 16:30:26 +02:00
|
|
|
if (!empty($options['title'])) {
|
|
|
|
$query->filterByTitle('%'.$options['title'].'%', Criteria::LIKE);
|
|
|
|
}
|
2017-06-25 19:13:27 +02:00
|
|
|
|
2016-06-18 17:44:07 +02:00
|
|
|
if (!empty($options['cipher']) && $options['cipher'] !== 'anyway') {
|
|
|
|
$bools = array(
|
|
|
|
'yes' => true,
|
|
|
|
'no' => false,
|
|
|
|
);
|
|
|
|
|
|
|
|
$query->filterByCipher($bools[$options['cipher']]);
|
|
|
|
}
|
|
|
|
|
|
|
|
return $query->paginate($page, $maxPerPage);
|
2016-06-18 16:37:45 +02:00
|
|
|
}
|
2015-11-21 14:27:53 +01:00
|
|
|
}
|