You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
130 lines
2.5 KiB
130 lines
2.5 KiB
|
5 years ago
|
<?php
|
||
|
|
/* For licensing terms, see /license.txt */
|
||
|
|
|
||
|
|
namespace Chamilo\PluginBundle\UserRemoteService;
|
||
|
|
|
||
|
|
use Doctrine\ORM\Mapping as ORM;
|
||
|
|
use Exception;
|
||
|
|
|
||
|
|
/**
|
||
|
|
* UserRemoteService.
|
||
|
|
*
|
||
|
|
* @ORM\Table(name="user_remote_service")
|
||
|
|
* @ORM\Entity
|
||
|
|
*/
|
||
|
|
class UserRemoteService
|
||
|
|
{
|
||
|
|
/**
|
||
|
|
* @var int
|
||
|
|
*
|
||
|
|
* @ORM\Column(name="id", type="integer")
|
||
|
|
* @ORM\Id
|
||
|
|
* @ORM\GeneratedValue
|
||
|
|
*/
|
||
|
|
protected $id;
|
||
|
|
|
||
|
|
/**
|
||
|
|
* @var string
|
||
|
|
*
|
||
|
|
* @ORM\Column(name="title", type="string", length=255, nullable=false)
|
||
|
|
*/
|
||
|
|
protected $title;
|
||
|
|
|
||
|
|
/**
|
||
|
|
* @var string
|
||
|
|
*
|
||
|
|
* @ORM\Column(name="url", type="string", length=255, nullable=false)
|
||
|
|
*/
|
||
|
|
protected $url;
|
||
|
|
|
||
|
|
/**
|
||
|
|
* @return int
|
||
|
|
*/
|
||
|
|
public function getId()
|
||
|
|
{
|
||
|
|
return $this->id;
|
||
|
|
}
|
||
|
|
|
||
|
|
/**
|
||
|
|
* @param int $id
|
||
|
|
*
|
||
|
|
* @return $this
|
||
|
|
*/
|
||
|
|
public function setId($id)
|
||
|
|
{
|
||
|
|
$this->id = $id;
|
||
|
|
|
||
|
|
return $this;
|
||
|
|
}
|
||
|
|
|
||
|
|
/**
|
||
|
|
* @return string
|
||
|
|
*/
|
||
|
|
public function getTitle()
|
||
|
|
{
|
||
|
|
return $this->title;
|
||
|
|
}
|
||
|
|
|
||
|
|
/**
|
||
|
|
* @param string $title
|
||
|
|
*
|
||
|
|
* @return UserRemoteService
|
||
|
|
*/
|
||
|
|
public function setTitle($title)
|
||
|
|
{
|
||
|
|
$this->title = $title;
|
||
|
|
|
||
|
|
return $this;
|
||
|
|
}
|
||
|
|
|
||
|
|
/**
|
||
|
|
* @return string
|
||
|
|
*/
|
||
|
|
public function getURL()
|
||
|
|
{
|
||
|
|
return $this->url;
|
||
|
|
}
|
||
|
|
|
||
|
|
/**
|
||
|
|
* @param string $url
|
||
|
|
*
|
||
|
|
* @return UserRemoteService
|
||
|
|
*/
|
||
|
|
public function setURL($url)
|
||
|
|
{
|
||
|
|
$this->url = $url;
|
||
|
|
|
||
|
|
return $this;
|
||
|
|
}
|
||
|
|
|
||
|
|
/**
|
||
|
|
* Returns a user-specific URL, with two extra query string parameters : 'username' and 'hash'.
|
||
|
|
* 'hash' is the return value of function call crypt($username, $salt).
|
||
|
|
*
|
||
|
|
* @param string $username the URL query parameter 'username'
|
||
|
|
* @param string $salt the salt to be passed to crypt() in order to generate the 'hash' query parameter
|
||
|
|
*
|
||
|
|
* @throws Exception on crypt() failure
|
||
|
|
*
|
||
|
|
* @return string the custom user URL
|
||
|
|
*/
|
||
|
|
public function getCustomUserURL($username, $salt)
|
||
|
|
{
|
||
|
|
$hash = crypt($username, $salt);
|
||
|
|
if (is_null($hash)) {
|
||
|
|
throw new Exception('crypt() failed');
|
||
|
|
}
|
||
|
|
return sprintf(
|
||
|
|
'%s%s%s',
|
||
|
|
$this->url,
|
||
|
|
false === strpos($this->url, '?') ? '?' : '&',
|
||
|
|
http_build_query(
|
||
|
|
[
|
||
|
|
'username' => $username,
|
||
|
|
'hash' => $hash,
|
||
|
|
]
|
||
|
|
)
|
||
|
|
);
|
||
|
|
}
|
||
|
|
}
|