2010-12-07 20:19:27 +01:00
|
|
|
<?php
|
|
|
|
|
2012-07-16 03:17:13 +02:00
|
|
|
class Application_Model_User
|
|
|
|
{
|
2011-05-06 05:41:48 +02:00
|
|
|
private $_userInstance;
|
2010-12-10 23:59:57 +01:00
|
|
|
|
2011-05-06 05:41:48 +02:00
|
|
|
public function __construct($userId)
|
2010-12-10 23:59:57 +01:00
|
|
|
{
|
2012-07-11 00:51:32 +02:00
|
|
|
if (empty($userId)) {
|
2011-02-09 20:09:42 +01:00
|
|
|
$this->_userInstance = $this->createUser();
|
2012-07-11 00:51:32 +02:00
|
|
|
} else {
|
2011-02-09 20:09:42 +01:00
|
|
|
$this->_userInstance = CcSubjsQuery::create()->findPK($userId);
|
2012-01-16 09:56:57 +01:00
|
|
|
|
2012-07-11 00:51:32 +02:00
|
|
|
if (is_null($this->_userInstance)) {
|
2012-01-16 09:56:57 +01:00
|
|
|
throw new Exception();
|
|
|
|
}
|
|
|
|
}
|
2010-12-10 23:59:57 +01:00
|
|
|
}
|
|
|
|
|
2012-07-11 00:51:32 +02:00
|
|
|
public function getId()
|
|
|
|
{
|
2011-02-09 19:03:46 +01:00
|
|
|
return $this->_userInstance->getDbId();
|
2011-05-06 05:41:48 +02:00
|
|
|
}
|
2012-04-01 21:51:03 +02:00
|
|
|
|
2012-07-11 00:51:32 +02:00
|
|
|
public function isGuest()
|
2012-07-16 03:17:13 +02:00
|
|
|
{
|
|
|
|
return $this->getType() == UTYPE_GUEST;
|
2012-03-28 18:43:44 +02:00
|
|
|
}
|
2010-12-13 17:49:45 +01:00
|
|
|
|
2012-08-22 19:59:37 +02:00
|
|
|
public function isHostOfShow($showId)
|
|
|
|
{
|
|
|
|
$userId = $this->_userInstance->getDbId();
|
2021-10-11 16:10:47 +02:00
|
|
|
|
2012-08-22 19:59:37 +02:00
|
|
|
return CcShowHostsQuery::create()
|
|
|
|
->filterByDbShow($showId)
|
|
|
|
->filterByDbHost($userId)->count() > 0;
|
|
|
|
}
|
|
|
|
|
2012-08-28 18:30:33 +02:00
|
|
|
public function isHost()
|
2012-07-11 00:51:32 +02:00
|
|
|
{
|
2012-08-22 19:59:37 +02:00
|
|
|
return $this->isUserType(UTYPE_HOST);
|
2011-05-06 05:41:48 +02:00
|
|
|
}
|
2012-04-01 21:51:03 +02:00
|
|
|
|
2012-07-11 00:51:32 +02:00
|
|
|
public function isPM()
|
|
|
|
{
|
2012-03-15 19:29:31 +01:00
|
|
|
return $this->isUserType(UTYPE_PROGRAM_MANAGER);
|
|
|
|
}
|
2010-12-13 17:49:45 +01:00
|
|
|
|
2012-07-11 00:51:32 +02:00
|
|
|
public function isAdmin()
|
|
|
|
{
|
2011-06-07 20:31:39 +02:00
|
|
|
return $this->isUserType(UTYPE_ADMIN);
|
|
|
|
}
|
2021-10-11 16:10:47 +02:00
|
|
|
|
2014-06-20 19:36:06 +02:00
|
|
|
public function isSuperAdmin()
|
|
|
|
{
|
|
|
|
return $this->isUserType(UTYPE_SUPERADMIN);
|
|
|
|
}
|
2021-10-11 16:10:47 +02:00
|
|
|
|
2012-07-11 00:51:32 +02:00
|
|
|
public function canSchedule($p_showId)
|
|
|
|
{
|
|
|
|
$type = $this->getType();
|
|
|
|
$result = false;
|
2012-01-31 18:59:27 +01:00
|
|
|
|
2022-07-07 20:01:15 +02:00
|
|
|
if (
|
|
|
|
$this->isAdmin()
|
2021-10-11 16:10:47 +02:00
|
|
|
|| $this->isSuperAdmin()
|
|
|
|
|| $this->isPM()
|
2022-07-07 20:01:15 +02:00
|
|
|
|| self::isHostOfShow($p_showId)
|
|
|
|
) {
|
2012-07-11 00:51:32 +02:00
|
|
|
$result = true;
|
|
|
|
}
|
2021-10-11 16:10:47 +02:00
|
|
|
|
2012-07-11 00:51:32 +02:00
|
|
|
return $result;
|
|
|
|
}
|
|
|
|
|
2015-03-24 16:18:03 +01:00
|
|
|
public function isSourcefabricAdmin()
|
|
|
|
{
|
|
|
|
$username = $this->getLogin();
|
2021-10-11 16:10:47 +02:00
|
|
|
if ($username == 'sourcefabric_admin') {
|
2015-03-24 16:18:03 +01:00
|
|
|
return true;
|
|
|
|
}
|
2021-10-11 16:10:47 +02:00
|
|
|
|
2015-03-24 16:18:03 +01:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2012-09-14 22:50:28 +02:00
|
|
|
// TODO : refactor code to only accept arrays for isUserType and
|
|
|
|
// simplify code even further
|
2012-08-22 19:59:37 +02:00
|
|
|
public function isUserType($type)
|
2012-07-11 00:51:32 +02:00
|
|
|
{
|
2012-09-14 22:47:55 +02:00
|
|
|
if (!is_array($type)) {
|
2021-10-11 16:10:47 +02:00
|
|
|
$type = [$type];
|
2012-07-11 00:51:32 +02:00
|
|
|
}
|
2012-09-14 22:47:55 +02:00
|
|
|
$real_type = $this->_userInstance->getDbType();
|
2021-10-11 16:10:47 +02:00
|
|
|
|
2012-09-14 22:47:55 +02:00
|
|
|
return in_array($real_type, $type);
|
2012-07-11 00:51:32 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public function setLogin($login)
|
|
|
|
{
|
2011-05-06 05:41:48 +02:00
|
|
|
$user = $this->_userInstance;
|
2012-01-16 09:56:57 +01:00
|
|
|
$user->setDbLogin($login);
|
2011-02-09 19:03:46 +01:00
|
|
|
}
|
2012-01-16 09:56:57 +01:00
|
|
|
|
2012-07-11 00:51:32 +02:00
|
|
|
public function setPassword($password)
|
|
|
|
{
|
2011-05-06 05:41:48 +02:00
|
|
|
$user = $this->_userInstance;
|
2012-01-16 09:56:57 +01:00
|
|
|
$user->setDbPass(md5($password));
|
2011-02-09 19:03:46 +01:00
|
|
|
}
|
2012-01-16 09:56:57 +01:00
|
|
|
|
2012-07-11 00:51:32 +02:00
|
|
|
public function setFirstName($firstName)
|
|
|
|
{
|
2011-05-06 05:41:48 +02:00
|
|
|
$user = $this->_userInstance;
|
2012-01-16 09:56:57 +01:00
|
|
|
$user->setDbFirstName($firstName);
|
2011-02-09 19:03:46 +01:00
|
|
|
}
|
2012-01-16 09:56:57 +01:00
|
|
|
|
2012-07-11 00:51:32 +02:00
|
|
|
public function setLastName($lastName)
|
|
|
|
{
|
2011-05-06 05:41:48 +02:00
|
|
|
$user = $this->_userInstance;
|
2012-01-16 09:56:57 +01:00
|
|
|
$user->setDbLastName($lastName);
|
2011-02-09 19:03:46 +01:00
|
|
|
}
|
2012-01-16 09:56:57 +01:00
|
|
|
|
2012-07-11 00:51:32 +02:00
|
|
|
public function setType($type)
|
|
|
|
{
|
2011-05-06 05:41:48 +02:00
|
|
|
$user = $this->_userInstance;
|
2012-01-16 09:56:57 +01:00
|
|
|
$user->setDbType($type);
|
2011-02-09 19:03:46 +01:00
|
|
|
}
|
2011-02-12 00:13:26 +01:00
|
|
|
|
2012-07-11 00:51:32 +02:00
|
|
|
public function setEmail($email)
|
|
|
|
{
|
2011-05-06 05:41:48 +02:00
|
|
|
$user = $this->_userInstance;
|
2012-06-15 21:03:48 +02:00
|
|
|
$user->setDbEmail(strtolower($email));
|
2011-02-12 00:13:26 +01:00
|
|
|
}
|
2012-07-11 00:51:32 +02:00
|
|
|
|
|
|
|
public function setCellPhone($cellPhone)
|
|
|
|
{
|
2012-06-13 19:39:54 +02:00
|
|
|
$user = $this->_userInstance;
|
|
|
|
$user->setDbCellPhone($cellPhone);
|
|
|
|
}
|
2011-02-12 00:13:26 +01:00
|
|
|
|
2012-07-11 00:51:32 +02:00
|
|
|
public function setSkype($skype)
|
|
|
|
{
|
2011-05-06 05:41:48 +02:00
|
|
|
$user = $this->_userInstance;
|
2012-01-16 09:56:57 +01:00
|
|
|
$user->setDbSkypeContact($skype);
|
2011-02-12 00:13:26 +01:00
|
|
|
}
|
|
|
|
|
2012-07-11 00:51:32 +02:00
|
|
|
public function setJabber($jabber)
|
|
|
|
{
|
2011-05-06 05:41:48 +02:00
|
|
|
$user = $this->_userInstance;
|
2012-01-16 09:56:57 +01:00
|
|
|
$user->setDbJabberContact($jabber);
|
2011-02-12 00:13:26 +01:00
|
|
|
}
|
2012-01-16 09:56:57 +01:00
|
|
|
|
2012-07-11 00:51:32 +02:00
|
|
|
public function getLogin()
|
|
|
|
{
|
2011-05-06 05:41:48 +02:00
|
|
|
$user = $this->_userInstance;
|
2012-07-16 03:17:13 +02:00
|
|
|
|
2012-01-16 09:56:57 +01:00
|
|
|
return $user->getDbLogin();
|
|
|
|
}
|
|
|
|
|
2012-07-11 00:51:32 +02:00
|
|
|
public function getPassword()
|
|
|
|
{
|
2011-05-06 05:41:48 +02:00
|
|
|
$user = $this->_userInstance;
|
2012-07-16 03:17:13 +02:00
|
|
|
|
2012-01-16 09:56:57 +01:00
|
|
|
return $user->getDbPass();
|
2011-02-09 19:03:46 +01:00
|
|
|
}
|
2012-01-16 09:56:57 +01:00
|
|
|
|
2012-07-11 00:51:32 +02:00
|
|
|
public function getFirstName()
|
|
|
|
{
|
2011-05-06 05:41:48 +02:00
|
|
|
$user = $this->_userInstance;
|
2012-07-16 03:17:13 +02:00
|
|
|
|
2012-01-16 09:56:57 +01:00
|
|
|
return $user->getDbFirstName();
|
2011-02-09 19:03:46 +01:00
|
|
|
}
|
2012-01-16 09:56:57 +01:00
|
|
|
|
2012-07-11 00:51:32 +02:00
|
|
|
public function getLastName()
|
|
|
|
{
|
2011-05-06 05:41:48 +02:00
|
|
|
$user = $this->_userInstance;
|
2012-07-16 03:17:13 +02:00
|
|
|
|
2012-01-16 09:56:57 +01:00
|
|
|
return $user->getDbLastName();
|
2011-02-09 19:03:46 +01:00
|
|
|
}
|
2012-01-16 09:56:57 +01:00
|
|
|
|
2012-07-11 00:51:32 +02:00
|
|
|
public function getType()
|
|
|
|
{
|
2011-05-06 05:41:48 +02:00
|
|
|
$user = $this->_userInstance;
|
2012-07-16 03:17:13 +02:00
|
|
|
|
2012-01-16 09:56:57 +01:00
|
|
|
return $user->getDbType();
|
2011-02-09 19:03:46 +01:00
|
|
|
}
|
2011-02-12 00:13:26 +01:00
|
|
|
|
2012-07-11 00:51:32 +02:00
|
|
|
public function getEmail()
|
|
|
|
{
|
2011-05-06 05:41:48 +02:00
|
|
|
$user = $this->_userInstance;
|
2012-07-16 03:17:13 +02:00
|
|
|
|
2012-01-16 09:56:57 +01:00
|
|
|
return $user->getDbEmail();
|
2011-02-12 00:13:26 +01:00
|
|
|
}
|
2012-07-11 00:51:32 +02:00
|
|
|
|
|
|
|
public function getCellPhone()
|
|
|
|
{
|
2012-06-13 19:39:54 +02:00
|
|
|
$user = $this->_userInstance;
|
2012-07-16 03:17:13 +02:00
|
|
|
|
2012-06-13 19:39:54 +02:00
|
|
|
return $user->getDbCellPhone();
|
|
|
|
}
|
2011-02-12 00:13:26 +01:00
|
|
|
|
2012-07-11 00:51:32 +02:00
|
|
|
public function getSkype()
|
|
|
|
{
|
2011-05-06 05:41:48 +02:00
|
|
|
$user = $this->_userInstance;
|
2012-07-16 03:17:13 +02:00
|
|
|
|
2012-01-16 09:56:57 +01:00
|
|
|
return $user->getDbSkypeContact();
|
2011-02-12 00:13:26 +01:00
|
|
|
}
|
|
|
|
|
2012-07-11 00:51:32 +02:00
|
|
|
public function getJabber()
|
|
|
|
{
|
2011-05-06 05:41:48 +02:00
|
|
|
$user = $this->_userInstance;
|
2012-07-16 03:17:13 +02:00
|
|
|
|
2012-01-16 09:56:57 +01:00
|
|
|
return $user->getDbJabberContact();
|
2011-02-12 00:13:26 +01:00
|
|
|
}
|
2012-01-16 09:56:57 +01:00
|
|
|
|
2012-07-11 00:51:32 +02:00
|
|
|
public function save()
|
|
|
|
{
|
2011-02-09 20:09:42 +01:00
|
|
|
$this->_userInstance->save();
|
2011-02-09 19:03:46 +01:00
|
|
|
}
|
2012-01-16 09:56:57 +01:00
|
|
|
|
2012-07-11 00:51:32 +02:00
|
|
|
public function delete()
|
|
|
|
{
|
|
|
|
if (!$this->_userInstance->isDeleted()) {
|
2011-02-09 20:09:42 +01:00
|
|
|
$this->_userInstance->delete();
|
2012-07-11 00:51:32 +02:00
|
|
|
}
|
2011-02-09 19:03:46 +01:00
|
|
|
}
|
2021-10-11 16:10:47 +02:00
|
|
|
|
2012-09-17 21:41:27 +02:00
|
|
|
public function getOwnedFiles()
|
2012-08-28 22:22:35 +02:00
|
|
|
{
|
|
|
|
$user = $this->_userInstance;
|
2023-08-15 18:28:18 +02:00
|
|
|
|
2012-08-28 23:24:55 +02:00
|
|
|
// do we need a find call at the end here?
|
2012-08-28 22:22:35 +02:00
|
|
|
return $user->getCcFilessRelatedByDbOwnerId();
|
|
|
|
}
|
|
|
|
|
2012-09-18 21:26:43 +02:00
|
|
|
public function donateFilesTo($user) // $user is object not user id
|
2012-08-28 22:22:35 +02:00
|
|
|
{
|
|
|
|
$my_files = $this->getOwnedFiles();
|
|
|
|
foreach ($my_files as $file) {
|
|
|
|
$file->reassignTo($user);
|
|
|
|
}
|
|
|
|
}
|
2010-12-13 17:49:45 +01:00
|
|
|
|
2012-08-28 23:24:55 +02:00
|
|
|
public function deleteAllFiles()
|
|
|
|
{
|
|
|
|
$my_files = $this->getOwnedFiles();
|
2013-05-28 23:30:48 +02:00
|
|
|
foreach ($my_files as $file) {
|
2012-08-30 21:23:12 +02:00
|
|
|
$file->delete();
|
|
|
|
}
|
2012-08-28 23:24:55 +02:00
|
|
|
}
|
2010-12-13 17:49:45 +01:00
|
|
|
|
2012-07-11 00:51:32 +02:00
|
|
|
private function createUser()
|
|
|
|
{
|
2021-10-11 16:10:47 +02:00
|
|
|
return new CcSubjs();
|
2011-05-06 05:41:48 +02:00
|
|
|
}
|
|
|
|
|
2012-08-29 16:58:03 +02:00
|
|
|
public static function getUsersOfType($type)
|
|
|
|
{
|
2012-08-24 18:36:20 +02:00
|
|
|
return CcSubjsQuery::create()->filterByDbType($type)->find();
|
|
|
|
}
|
2012-09-18 21:26:43 +02:00
|
|
|
|
2017-05-22 00:11:27 +02:00
|
|
|
/**
|
2021-10-11 16:10:47 +02:00
|
|
|
* Get the first admin user from the database.
|
2017-05-22 00:11:27 +02:00
|
|
|
*
|
|
|
|
* This function gets used in UserController in the delete action. The controller
|
|
|
|
* uses it to figure out who to reassign the deleted users files to.
|
|
|
|
*
|
|
|
|
* @param $ignoreUser String optional userid of a user that shall be ignored when
|
2023-12-29 15:28:57 +01:00
|
|
|
* when looking for the "first" admin
|
2017-05-22 00:11:27 +02:00
|
|
|
*
|
2021-10-11 16:10:47 +02:00
|
|
|
* @return null|CcSubj
|
2017-05-22 00:11:27 +02:00
|
|
|
*/
|
2021-10-11 16:10:47 +02:00
|
|
|
public static function getFirstAdmin($ignoreUser = null)
|
|
|
|
{
|
2014-07-08 23:45:22 +02:00
|
|
|
$superAdmins = Application_Model_User::getUsersOfType('S');
|
|
|
|
if (count($superAdmins) > 0) { // found superadmin => pick first one
|
|
|
|
return $superAdmins[0];
|
2012-09-18 21:26:43 +02:00
|
|
|
}
|
2021-10-11 16:10:47 +02:00
|
|
|
// get all admin users
|
|
|
|
$query = CcSubjsQuery::create()->filterByDbType('A');
|
|
|
|
// ignore current user if one was specified
|
|
|
|
if ($ignoreUser !== null) {
|
|
|
|
$query->filterByDbId($ignoreUser, Criteria::NOT_EQUAL);
|
|
|
|
}
|
|
|
|
$admins = $query->find();
|
|
|
|
if (count($admins) > 0) { // found admin => pick first one
|
|
|
|
return $admins[0];
|
|
|
|
}
|
|
|
|
Logging::warn('Warning. no admins found in database');
|
|
|
|
|
|
|
|
return null;
|
2012-09-18 21:26:43 +02:00
|
|
|
}
|
2012-08-29 16:58:03 +02:00
|
|
|
|
2021-10-11 16:10:47 +02:00
|
|
|
public static function getUsers(array $type, $search = null)
|
2012-04-01 21:51:03 +02:00
|
|
|
{
|
2021-10-11 16:10:47 +02:00
|
|
|
$con = Propel::getConnection();
|
2011-05-06 05:41:48 +02:00
|
|
|
|
2021-10-11 16:10:47 +02:00
|
|
|
$sql_gen = 'SELECT login AS value, login AS label, id as index FROM cc_subjs ';
|
2012-01-16 09:56:57 +01:00
|
|
|
|
2021-10-11 16:10:47 +02:00
|
|
|
$types = [];
|
|
|
|
$params = [];
|
|
|
|
for ($i = 0; $i < count($type); ++$i) {
|
2012-09-05 23:43:45 +02:00
|
|
|
$p = ":type{$i}";
|
2021-10-11 16:10:47 +02:00
|
|
|
$types[] = "type = {$p}";
|
2012-09-05 23:43:45 +02:00
|
|
|
$params[$p] = $type[$i];
|
|
|
|
}
|
2012-08-23 20:44:14 +02:00
|
|
|
|
Feature: Support php7.4 (#1354)
* Run CI tests against php 7.4
* Sort composer dependencies
* Remove unused Aws S3 php library
* Pin simplepie dependency to ^1.5
* Pin getid3 dependency to ^1.9
* Pin composer semver to ^3.2
* Pin php-amqplib to ^2.12
* Drop sentry logging support
* Update composer dependencies
* Move propel regenerate to Makefile
* Regenerate propel files with v1.7.0
* Pin propel orm to ^1.7
* Regenerate propel files with v1.7.2
* fix: generator_version in airtime-conf-production.php
* Replace propel/propel1 with jooola/propel1
* Regenerate propel files with v1.7.3-dev
* Fix php7.4 compatibility
Using php-cs-fixer:
'@PhpCsFixer' => true,
'concat_space' => ['spacing' => 'one'],
'ordered_class_elements' => false,
'yoda_style' => false,
'@PHP74Migration' => true,
'assign_null_coalescing_to_coalesce_equal' => false,
'ternary_to_null_coalescing' => false,
'heredoc_indentation' => false,
'@PHP74Migration:risky' => true,
'declare_strict_types' => false,
'void_return' => false,
'use_arrow_functions' => false,
* Fix pre-commit
2021-10-17 17:19:53 +02:00
|
|
|
$sql_type = implode(' OR ', $types);
|
2012-01-16 09:56:57 +01:00
|
|
|
|
2021-10-11 16:10:47 +02:00
|
|
|
$sql = $sql_gen . ' WHERE (' . $sql_type . ') ';
|
2012-01-16 09:56:57 +01:00
|
|
|
|
2021-10-11 16:10:47 +02:00
|
|
|
$sql .= ' AND login ILIKE :search';
|
|
|
|
$params[':search'] = "%{$search}%";
|
2011-02-13 05:07:28 +01:00
|
|
|
|
2023-09-17 17:14:59 +02:00
|
|
|
$sql .= ' ORDER BY login';
|
2012-01-16 09:56:57 +01:00
|
|
|
|
2021-10-11 16:10:47 +02:00
|
|
|
return Application_Common_Database::prepareAndExecute($sql, $params, 'all');
|
2011-05-06 05:41:48 +02:00
|
|
|
}
|
2012-01-16 09:56:57 +01:00
|
|
|
|
2012-09-06 18:23:53 +02:00
|
|
|
public static function getUserCount()
|
2012-07-11 00:51:32 +02:00
|
|
|
{
|
2021-10-11 16:10:47 +02:00
|
|
|
$sql_gen = 'SELECT count(*) AS cnt FROM cc_subjs';
|
2012-01-16 09:56:57 +01:00
|
|
|
|
2021-10-11 16:10:47 +02:00
|
|
|
$query = Application_Common_Database::prepareAndExecute(
|
|
|
|
$sql_gen,
|
|
|
|
[],
|
|
|
|
Application_Common_Database::COLUMN
|
|
|
|
);
|
2012-07-16 03:17:13 +02:00
|
|
|
|
2012-07-11 00:51:32 +02:00
|
|
|
return ($query !== false) ? $query : null;
|
2011-06-15 18:06:50 +02:00
|
|
|
}
|
2010-12-07 20:19:27 +01:00
|
|
|
|
2021-10-11 16:10:47 +02:00
|
|
|
public static function getHosts($search = null)
|
2012-07-11 00:51:32 +02:00
|
|
|
{
|
2021-10-11 16:10:47 +02:00
|
|
|
return Application_Model_User::getUsers(['H'], $search);
|
2011-05-06 05:41:48 +02:00
|
|
|
}
|
2012-01-16 09:56:57 +01:00
|
|
|
|
2021-10-11 16:10:47 +02:00
|
|
|
public static function getNonGuestUsers($search = null)
|
2019-03-05 16:00:54 +01:00
|
|
|
{
|
2021-10-11 16:10:47 +02:00
|
|
|
return Application_Model_User::getUsers(['H', 'A', 'S', 'P'], $search);
|
2019-03-05 16:00:54 +01:00
|
|
|
}
|
|
|
|
|
2012-07-11 00:51:32 +02:00
|
|
|
public static function getUsersDataTablesInfo($datatables)
|
|
|
|
{
|
|
|
|
$con = Propel::getConnection(CcSubjsPeer::DATABASE_NAME);
|
2011-02-08 01:03:14 +01:00
|
|
|
|
2021-10-11 16:10:47 +02:00
|
|
|
$displayColumns = ['id', 'login', 'first_name', 'last_name', 'type'];
|
|
|
|
$fromTable = 'cc_subjs';
|
2012-01-16 09:56:57 +01:00
|
|
|
|
2011-05-06 05:41:48 +02:00
|
|
|
// get current user
|
2021-10-11 16:10:47 +02:00
|
|
|
$username = '';
|
2011-05-06 00:38:33 +02:00
|
|
|
$auth = Zend_Auth::getInstance();
|
|
|
|
|
|
|
|
if ($auth->hasIdentity()) {
|
|
|
|
$username = $auth->getIdentity()->login;
|
|
|
|
}
|
2012-01-16 09:56:57 +01:00
|
|
|
|
2012-03-12 15:32:24 +01:00
|
|
|
$res = Application_Model_Datatables::findEntries($con, $displayColumns, $fromTable, $datatables);
|
2012-04-01 21:51:03 +02:00
|
|
|
|
2011-05-06 05:41:48 +02:00
|
|
|
// mark record which is for the current user
|
2021-10-11 16:10:47 +02:00
|
|
|
foreach ($res['aaData'] as $key => &$record) {
|
2012-07-11 00:51:32 +02:00
|
|
|
if ($record['login'] == $username) {
|
2021-10-11 16:10:47 +02:00
|
|
|
$record['delete'] = 'self';
|
2012-01-13 20:17:39 +01:00
|
|
|
} else {
|
2021-10-11 16:10:47 +02:00
|
|
|
$record['delete'] = '';
|
2011-05-06 05:41:48 +02:00
|
|
|
}
|
2021-10-11 16:10:47 +02:00
|
|
|
|
|
|
|
if ($record['login'] == 'sourcefabric_admin') {
|
2022-03-14 11:15:04 +01:00
|
|
|
// arrays in PHP are basically associative arrays that can be iterated in order.
|
|
|
|
// Deleting an earlier element does not change the keys of elements that come after it. --MK
|
2012-10-24 00:47:15 +02:00
|
|
|
unset($res['aaData'][$key]);
|
2021-10-11 16:10:47 +02:00
|
|
|
--$res['iTotalDisplayRecords'];
|
|
|
|
--$res['iTotalRecords'];
|
2012-10-24 00:47:15 +02:00
|
|
|
}
|
2013-01-29 21:17:29 +01:00
|
|
|
|
|
|
|
$record = array_map('htmlspecialchars', $record);
|
2011-05-06 05:41:48 +02:00
|
|
|
}
|
2012-01-16 09:56:57 +01:00
|
|
|
|
2012-10-24 00:47:15 +02:00
|
|
|
$res['aaData'] = array_values($res['aaData']);
|
2021-10-11 16:10:47 +02:00
|
|
|
|
2011-05-06 05:41:48 +02:00
|
|
|
return $res;
|
|
|
|
}
|
2012-01-16 09:56:57 +01:00
|
|
|
|
2012-07-11 00:51:32 +02:00
|
|
|
public static function getUserData($id)
|
|
|
|
{
|
2021-10-11 16:10:47 +02:00
|
|
|
$sql = <<<'SQL'
|
2012-09-14 23:09:05 +02:00
|
|
|
SELECT login, first_name, last_name, type, id, email, cell_phone, skype_contact,
|
|
|
|
jabber_contact
|
|
|
|
FROM cc_subjs
|
|
|
|
WHERE id = :id
|
|
|
|
SQL;
|
2021-10-11 16:10:47 +02:00
|
|
|
|
|
|
|
return Application_Common_Database::prepareAndExecute($sql, [
|
2022-07-07 20:01:15 +02:00
|
|
|
':id' => $id,
|
|
|
|
], 'single');
|
2011-02-09 19:03:46 +01:00
|
|
|
}
|
2012-01-16 09:56:57 +01:00
|
|
|
|
2012-07-11 00:51:32 +02:00
|
|
|
public static function getCurrentUser()
|
|
|
|
{
|
2012-01-31 18:59:27 +01:00
|
|
|
$userinfo = Zend_Auth::getInstance()->getStorage()->read();
|
2012-07-11 00:51:32 +02:00
|
|
|
if (is_null($userinfo)) {
|
2012-04-20 17:31:24 +02:00
|
|
|
return null;
|
2012-08-23 20:41:54 +02:00
|
|
|
}
|
2021-10-11 16:10:47 +02:00
|
|
|
|
2012-08-23 20:41:54 +02:00
|
|
|
try {
|
|
|
|
return new self($userinfo->id);
|
|
|
|
} catch (Exception $e) {
|
2022-03-14 11:15:04 +01:00
|
|
|
// we get here if $userinfo->id is defined, but doesn't exist
|
|
|
|
// in the database anymore.
|
2012-08-23 20:41:54 +02:00
|
|
|
Zend_Auth::getInstance()->clearIdentity();
|
2012-08-29 16:58:03 +02:00
|
|
|
|
2012-08-23 20:41:54 +02:00
|
|
|
return null;
|
2012-04-20 17:31:24 +02:00
|
|
|
}
|
2012-01-31 18:59:27 +01:00
|
|
|
}
|
2010-12-07 20:19:27 +01:00
|
|
|
}
|