diff --git a/TandemPlugin.class.php b/TandemPlugin.class.php index dd8be9173b1b15b79352030c8858959bbf4a7313..a5155ec1c902bb7b527492971ad90f6a9c93c239 100644 --- a/TandemPlugin.class.php +++ b/TandemPlugin.class.php @@ -23,19 +23,19 @@ require_once(__DIR__ . '/classes/TandemMatching.class.php'); class TandemPlugin extends StudIPPlugin implements SystemPlugin, PortalPlugin { - public static function isGenderSearchEnabled() + public static function isGenderSearchEnabled() : bool { return (bool)Config::get()->TANDEMPLUGIN_GENDER_SEARCH_ENABLED; } - public function isOldStudip() + public function isOldStudip() : bool { return version_compare($GLOBALS['SOFTWARE_VERSION'], '5.0', '<'); } - public function getLevels() + public function getLevels() : array { return [ 'A1', @@ -48,7 +48,7 @@ class TandemPlugin extends StudIPPlugin implements SystemPlugin, PortalPlugin } - public function userHasAccess($user_id) + public function userHasAccess($user_id) : bool { return !\TandemPlugin\BlocklistEntry::userIsBlocked($user_id); } @@ -180,7 +180,7 @@ class TandemPlugin extends StudIPPlugin implements SystemPlugin, PortalPlugin } - public function cleanupTandemData($event, User $user) + public function cleanupTandemData($event, User $user) : void { TandemUserMotherLanguage::deleteByUser_id($user->id); @@ -264,12 +264,14 @@ class TandemPlugin extends StudIPPlugin implements SystemPlugin, PortalPlugin if(count($profiles) == 0) { $template->set_attribute('never_used', true); } else { - $pair_exist = []; - $match_count = []; + $match_count = []; + $pair_requests = []; + $pairs = []; $matches_exist = false; + foreach($profiles as $profile) { - $pairs[$profile->id] = TandemPair::findByProfileAndStatus($profile, 1)[0]; + $pairs[$profile->id] = TandemPair::findByProfileAndStatus($profile)[0]; $pair_requests[$profile->id] = TandemPair::countByProfileAndStatus($profile, 0); if(!$pairs[$profile->id]) { //We're only looking for matches if no pairs have been found. diff --git a/TandemPluginCronjob.class.php b/TandemPluginCronjob.class.php index 2860c879503642330d3d7e539b32aa7ac6507314..559c88a3f019879ca2d3f3cff3e093a71b945b5d 100644 --- a/TandemPluginCronjob.class.php +++ b/TandemPluginCronjob.class.php @@ -14,9 +14,6 @@ **/ -require_once('lib/classes/CronJob.class.php'); - - class TandemPluginCronjob extends CronJob { public static function getName() @@ -33,7 +30,7 @@ class TandemPluginCronjob extends CronJob public function setUp() { global $STUDIP_BASE_PATH; - require_once($STUDIP_BASE_PATH . '/lib/classes/Config.class.php'); + require_once($STUDIP_BASE_PATH . '/lib/classes/Config.php'); } diff --git a/classes/TandemManager.class.php b/classes/TandemManager.class.php index a69e4cf7842e5b00fc1f4a54ec6537e32d1e5d9c..af18db5db397ce374c5ba1485be5d74acf6e50c3 100644 --- a/classes/TandemManager.class.php +++ b/classes/TandemManager.class.php @@ -23,7 +23,7 @@ class TandemManager /** * Sends a match notification to the user who owns the tandem request. */ - public static function sendMatchNotification(TandemProfile $request, TandemProfile $match) + public static function sendMatchNotification(TandemProfile $request, TandemProfile $match) : void { $message_title = ''; $message_text = ''; @@ -92,16 +92,17 @@ class TandemManager * * @param TandemProfile $request The profile of the user who is applying for a tandem. * @param TandemProfile $offer The profile where the user applies for building a tandem. - * @param User $user The user who applies for a tandem. + * + * @returns bool True on success, false on failure. */ - public static function applyForPair(TandemProfile $request, TandemProfile $offer) + public static function applyForPair(TandemProfile $request, TandemProfile $offer) : bool { $pair = new TandemPair(); $pair->request_profile_id = $request->id; $pair->offer_profile_id = $offer->id; $pair->status = 0; - if($pair->store()) { + if ($pair->store()) { //Send system message to offerer: $message_title = ''; @@ -322,14 +323,14 @@ class TandemManager //Get the tandem admin role object first: $tandem_admin_role = null; - foreach(RolePersistence::getAllRoles() as $role) { + foreach (RolePersistence::getAllRoles() as $role) { if($role->rolename == 'TandemAdmin') { $tandem_admin_role = $role; break; } } - if($tandem_admin_role) { + if ($tandem_admin_role) { //We have the tandem admin role object and can proceed. $tandem_admins = User::findBySql( 'INNER JOIN roles_user ON auth_user_md5.user_id = roles_user.userid @@ -339,7 +340,7 @@ class TandemManager ] ); - foreach($tandem_admins as $tandem_admin) { + foreach ($tandem_admins as $tandem_admin) { $admin_message_title = ''; $admin_message_text = ''; @@ -448,9 +449,9 @@ class TandemManager * This method handles termination of a tandem pair. * - * @return True on success, false on failure. + * @return bool True on success, false on failure. */ - public static function terminatePair(TandemPair $pair, User $user, $delete_users_profile = false) + public static function terminatePair(TandemPair $pair, User $user, $delete_users_profile = false) : bool { $message_text = ''; $message_title = ''; @@ -474,11 +475,7 @@ class TandemManager $message_text = sprintf( '%s has terminated the tandem for the language %s!', - ( - $user - ? $user->getFullName() - : 'unknown' - ), + $user->getFullName(), ($target_language->name_eng ? $target_language->name_eng : $target_language->name) @@ -491,11 +488,7 @@ class TandemManager $message_text = sprintf( '%s hat das Tandem für die Sprache %s aufgelöst!', - ( - $user - ? $user->getFullName() - : 'unbekannt' - ), + $user->getFullName(), ($target_language->name_ger ? $target_language->name_ger : $target_language->name) diff --git a/controllers/admin.php b/controllers/admin.php index b1788924bb0f307450a7b6375663bb040ff90924..f47d9a5c216f72fc6b52f3c45c36bc5c63694f08 100644 --- a/controllers/admin.php +++ b/controllers/admin.php @@ -148,17 +148,26 @@ class AdminController extends PluginController } } + $requester_sex = '?'; + if ($pair->request->user->geschlecht == '1') { + $requester_sex = 'm'; + } elseif ($pair->request->user->geschlecht == '2') { + $requester_sex = 'w'; + } + $offerer_sex = '?'; + if ($pair->offer->user->geschlecht == '1') { + $offerer_sex = 'm'; + } elseif ($pair->offer->user->geschlecht == '2') { + $offerer_sex = 'w'; + } + if (Config::get()->TANDEMPLUGIN_PROOF_FIELDS_ENABLED) { $csv_data[] = [ $pair->request->user->nachname, $pair->request->user->vorname, $pair->request->user->email, implode(',', $user1_study_names), - (($pair->request->user->geschlecht == '1') - ? 'm' - : ($pair->request->user->geschlecht == '2') - ? 'w' - : '?'), + $requester_sex, $pair->offer->target_language_id, $pair->request->target_language_id, $user1_proofs, @@ -167,11 +176,7 @@ class AdminController extends PluginController $pair->offer->user->vorname, $pair->offer->user->email, implode(',', $user2_study_names), - (($pair->offer->user->geschlecht == '1') - ? 'm' - : ($pair->offer->user->geschlecht == '2') - ? 'w' - : '?'), + $offerer_sex, $pair->request->target_language_id, $pair->offer->target_language_id, $user2_proofs, @@ -184,11 +189,7 @@ class AdminController extends PluginController $pair->request->user->vorname, $pair->request->user->email, implode(',', $user1_study_names), - (($pair->request->user->geschlecht == '1') - ? 'm' - : ($pair->request->user->geschlecht == '2') - ? 'w' - : '?'), + $requester_sex, $pair->offer->target_language_id, $pair->request->target_language_id, @@ -196,11 +197,7 @@ class AdminController extends PluginController $pair->offer->user->vorname, $pair->offer->user->email, implode(',', $user2_study_names), - (($pair->offer->user->geschlecht == '1') - ? 'm' - : ($pair->offer->user->geschlecht == '2') - ? 'w' - : '?'), + $offerer_sex, $pair->request->target_language_id, $pair->offer->target_language_id, @@ -250,10 +247,7 @@ class AdminController extends PluginController $this->terminated_pairs = []; - $this->terminated_pairs = TerminatedTandemPair::findBySql( - 'TRUE ORDER BY mkdate DESC', - [] - ); + $this->terminated_pairs = TerminatedTandemPair::findBySql('TRUE ORDER BY `mkdate` DESC'); if(Request::get('csv_export')) { //A CSV file with all terminated pairs shall be created instead of @@ -283,28 +277,32 @@ class AdminController extends PluginController } } + $requester_sex = '?'; + if ($pair->requester->geschlecht == '1') { + $requester_sex = 'm'; + } elseif ($pair->requester->geschlecht == '2') { + $requester_sex = 'w'; + } + $offerer_sex = '?'; + if ($pair->offerer->geschlecht == '1') { + $offerer_sex = 'm'; + } elseif ($pair->offerer->geschlecht == '2') { + $offerer_sex = 'w'; + } + $csv_data[] = [ $pair->requester->nachname, $pair->requester->vorname, $pair->requester->email, implode(',', $user1_study_names), - (($pair->requester->geschlecht == '1') - ? 'm' - : ($pair->requester->geschlecht == '2') - ? 'w' - : '?'), + $requester_sex, $pair->offerer_language_id, $pair->requester_language_id, - $pair->offerer->nachname, $pair->offerer->vorname, $pair->offerer->email, implode(',', $user2_study_names), - (($pair->offerer->geschlecht == '1') - ? 'm' - : ($pair->offerer->geschlecht == '2') - ? 'w' - : '?'), + $offerer_sex, $pair->requester_language_id, $pair->offerer_language_id, @@ -621,7 +619,7 @@ class AdminController extends PluginController } - protected function validateFormFields() + protected function validateFormFields() :bool { $name = Request::get('name'); $name_ger = Request::get('name_ger'); @@ -824,7 +822,7 @@ class AdminController extends PluginController ); $this->response->add_header('X-Dialog-Close', '1'); } else { - PageLayout::postFailure( + PageLayout::postError( sprintf( dgettext('TandemPlugin', 'Beim Hinzufügen von %s zur Blockliste trat ein Fehler auf.'), $user->getFullName() diff --git a/controllers/my_tandems.php b/controllers/my_tandems.php index b082554a7e4424d2494532205e5ee1cad6a361c4..461d4d1e515fc61c04544ada517df0efcd0664bb 100644 --- a/controllers/my_tandems.php +++ b/controllers/my_tandems.php @@ -22,9 +22,7 @@ require_once(__DIR__ . '/../models/TandemUserMotherLanguage.class.php'); class MyTandemsController extends PluginController { - protected $utf8decode_xhr = true; - - private function buildSidebar() + protected function buildSidebar() : void { $sidebar = Sidebar::get(); @@ -82,6 +80,8 @@ class MyTandemsController extends PluginController Navigation::activateItem('/profile/my_tandems/index'); } + $this->first_run = false; + $this->mother_languages = TandemUserMotherLanguage::findByUser_id( $this->user->id ); @@ -171,15 +171,15 @@ class MyTandemsController extends PluginController $this->all_languages = TandemLanguage::findBySql('TRUE'); - if(Request::submitted('manage')) { + if (Request::submitted('manage')) { //check for added, edited and deleted entries: - $ids = Request::getArray('ids', []); - $language_ids = Request::getArray('language_ids', []); - $countries = Request::getArray('countries', []); - $regions = Request::getArray('regions', []); - $status = Request::getArray('status', []); - $levels = Request::getArray('level', []); + $ids = Request::getArray('ids'); + $language_ids = Request::getArray('language_ids'); + $countries = Request::getArray('countries'); + $regions = Request::getArray('regions'); + $status = Request::getArray('status'); + $levels = Request::getArray('level'); $processed_language_ids = []; //array of languages that were processed $duplicate_language = false; diff --git a/controllers/pair.php b/controllers/pair.php index 3599005985a0bc7caa05c93f413779004578aa1b..62669f20733868d8f18d0f91b6c4e30a77400d8f 100644 --- a/controllers/pair.php +++ b/controllers/pair.php @@ -276,7 +276,7 @@ class PairController extends PluginController return; } - //Check, if the "offerer" (the opposite person) has made an request + //Check, if the "offerer" (the opposite person) has made a request //for the current user's request. //This would mean the current user can simply accept or reject the offer //from the "offerer". @@ -589,7 +589,7 @@ class PairController extends PluginController $result = TandemManager::terminatePair( $pair, $user, - (($pair->request->user_id == $user->id) ? true : false) + ($pair->request->user_id === $user->id) ); if($result) { diff --git a/controllers/profile.php b/controllers/profile.php index 52daf69d7a865fd12141e49a5c110ebf4e2280a8..8703c8ded5eaa06f37a29cace3972d8a2178bc37 100644 --- a/controllers/profile.php +++ b/controllers/profile.php @@ -23,9 +23,6 @@ require_once(__DIR__ . '/../classes/TandemManager.class.php'); class ProfileController extends PluginController { - protected $utf8decode_xhr = true; - - public function before_filter(&$action, &$args) { parent::before_filter($action, $args); @@ -38,8 +35,11 @@ class ProfileController extends PluginController } - private function addEditHandler($edit_mode = false) + private function addEditHandler($edit_mode = false) : void { + $this->hide_form = false; + $this->pair_exists = false; + //load the list of languages: $this->language_list = TandemLanguage::findBySql('TRUE'); @@ -54,10 +54,10 @@ class ProfileController extends PluginController $this->tandem_profile = new TandemProfile($this->tandem_profile_id); - if($edit_mode) { + if ($edit_mode) { //In edit mode we have to check, if the tandem profile referenced by its //ID exists in the database: - if(!$this->tandem_profile) { + if ($this->tandem_profile->isNew()) { PageLayout::postError( dgettext('TandemPlugin', 'Das ausgewählte Profil wurde nicht in der Datenbank gefunden!') ); @@ -78,15 +78,15 @@ class ProfileController extends PluginController } if($edit_mode) { - $this->pair_exists = (TandemPair::countByProfileAndStatus($this->tandem_profile, 1) > 0); + $this->pair_exists = (TandemPair::countByProfileAndStatus($this->tandem_profile) > 0); } if(Request::submitted('save')) { //A tandem profile shall be saved. //Read all attributes: - $this->target_language_id = Request::get('target_language_id', null); - $this->level = Request::get('level', null); + $this->target_language_id = Request::get('target_language_id'); + $this->level = Request::get('level'); $this->requested_level = Config::get()->TANDEMPLUGIN_USE_LEVEL ? Request::get('requested_level', '') : ''; @@ -181,7 +181,7 @@ class ProfileController extends PluginController $result = $this->tandem_profile->store(); } - if($result == true) { + if ($result) { //Saving was successful. We can now look for matches. $matches = TandemMatching::findMatches( $this->tandem_profile @@ -206,7 +206,7 @@ class ProfileController extends PluginController } } - $pair_exists = (TandemPair::countByProfileAndStatus($this->tandem_profile, 1) > 0); + $pair_exists = (TandemPair::countByProfileAndStatus($this->tandem_profile) > 0); if($pair_exists) { PageLayout::postSuccess( @@ -300,7 +300,7 @@ class ProfileController extends PluginController PageLayout::setTitle( dgettext('TandemPlugin', 'Profil hinzufügen') ); - $this->addEditHandler(false); + $this->addEditHandler(); } diff --git a/migrations/01_initial.php b/migrations/01_initial.php index 09c845cc107653e3e1dae0dea3720a91e51341dd..994c7538dea130cbc6213a2d079fd931c5eb67da 100644 --- a/migrations/01_initial.php +++ b/migrations/01_initial.php @@ -17,12 +17,13 @@ class Initial extends Migration { - private static $cronjob = array( + protected string $cronjob_md5 = ''; + + private static array $cronjob = [ 'filename' => 'public/plugins_packages/data-quest/TandemPlugin/TandemPluginCronjob.class.php', 'class' => 'TandemPluginCronjob', - 'priority' => 'normal', 'execution_interval' => ['3', '0'] //at 3:00 every day - ); + ]; public function __construct() @@ -30,7 +31,6 @@ class Initial extends Migration $this->cronjob_md5 = md5( self::$cronjob['filename'] . self::$cronjob['class'] . - self::$cronjob['priority'] . self::$cronjob['execution_interval'] ); @@ -106,7 +106,7 @@ class Initial extends Migration //Create configuration fields, if they don't exist yet: $gender_search_enabled = ConfigEntry::findByField('TANDEMPLUGIN_GENDER_SEARCH_ENABLED'); - if(!$gender_search_enabled) { + if (!$gender_search_enabled) { $gender_search_enabled = new ConfigEntry(); $gender_search_enabled->field = 'TANDEMPLUGIN_GENDER_SEARCH_ENABLED'; $gender_search_enabled->type = 'boolean'; @@ -116,7 +116,7 @@ class Initial extends Migration } $delete_old_period = ConfigEntry::findByField('TANDEMPLUGIN_DELETE_OLD_PERIOD'); - if(!$delete_old_period) { + if (!$delete_old_period) { $delete_old_period = new ConfigEntry(); $delete_old_period->field = 'TANDEMPLUGIN_DELETE_OLD_PERIOD'; $delete_old_period->type = 'integer'; @@ -145,12 +145,12 @@ class Initial extends Migration $db->exec( "INSERT INTO `cronjobs_schedules` - (`schedule_id`, `task_id`, `active`, `parameters`, `priority`, - `type`, `hour`, `minute`, `mkdate`, `chdate`, `last_result`) + (`schedule_id`, `task_id`, `active`, `parameters`, + `hour`, `minute`, `mkdate`, `chdate`, `last_result`) VALUES ('".$schedule_id."', '" - .$this->cronjob_md5."', '1', '[]', '".self::$cronjob['priority'] - ."', 'periodic', '".self::$cronjob['execution_interval'][0] + .$this->cronjob_md5."', '1', '[]', " + ."'".self::$cronjob['execution_interval'][0] ."', '" . self::$cronjob['execution_interval'][1] ."', UNIX_TIMESTAMP(), UNIX_TIMESTAMP(), NULL)" ); diff --git a/migrations/02_add_data.php b/migrations/02_add_data.php index 367b99dcd078f05fbfc16dcc3181ffd760685953..f235f5bd8ee7a845195a96c51866f9f0089c01df 100644 --- a/migrations/02_add_data.php +++ b/migrations/02_add_data.php @@ -17,7 +17,7 @@ class AddData extends Migration { - private $languages = [ + private array $languages = [ ["ara", "Arabic", "Arabisch"], ["chi", "Chinese", "Chinesisch"], ["dan", "Danish", "Dänisch"], @@ -54,7 +54,7 @@ class AddData extends Migration $values = []; foreach($this->languages as $language) { - $values[] = '(' + $values[] = '(' . $db->quote($language[0]) . ',' . $db->quote($language[1]) . ',' . $db->quote($language[1]) . ',' diff --git a/models/BlocklistEntry.class.php b/models/BlocklistEntry.class.php index b32c66325c097629c21786c6295189c65c26fe70..0a7f2d6253761925def69aec53af4d35d150f3a8 100644 --- a/models/BlocklistEntry.class.php +++ b/models/BlocklistEntry.class.php @@ -53,7 +53,7 @@ class BlocklistEntry extends \SimpleORMap } - public static function userIsBlocked($user_id) + public static function userIsBlocked($user_id) : bool { return self::countByUser_id($user_id) > 0; } diff --git a/models/TandemOffer.class.php b/models/TandemOffer.class.php index b3041e3ee799f072f75b9ad42b82ab7e1967d740..d7bdc62176a480b22b564b06b817d2cbe6c9288f 100644 --- a/models/TandemOffer.class.php +++ b/models/TandemOffer.class.php @@ -14,12 +14,9 @@ **/ -require_once(__DIR__ . '/TandemData.class.php'); - - /** * A model class to store tandem offers for the TandemPlugin. - * + * * @property string id Generated MD5 hash * @property string user_id A reference to a Stud.IP user * @property string tandem_data_id A reference to a tandem_data entry. @@ -31,27 +28,27 @@ require_once(__DIR__ . '/TandemData.class.php'); */ class TandemOffer extends SimpleORMap { - + static protected function configure($config = []) { $config['db_table'] = 'tandem_offers'; - + $config['has_one']['data'] = [ 'class_name' => 'TandemData', 'foreign_key' => 'tandem_data_id', 'assoc_func' => 'find' ]; - + $config['belongs_to']['user'] = [ 'class_name' => 'User', 'foreign_key' => 'user_id', 'assoc_func' => 'find' ]; - + parent::configure($config); } - - + + static protected function sqlForTandemDataAndLevel(TandemData $tandem_data, Array $levels, $limit = 0) { $sql = "INNER JOIN tandem_data @@ -59,21 +56,21 @@ require_once(__DIR__ . '/TandemData.class.php'); WHERE tandem_data.language_id = :language_id "; $sql_params = ['language_id' => $tandem_data->language_id]; - + if($tandem_data->country_id) { $sql .= "AND tandem_data.country_id = :country_id "; $sql_params['country_id'] = $tandem_data->country_id; } - + if($tandem_data->region) { $sql .= "AND tandem_data.region = :region "; $sql_params['region'] = $tandem_data->region; } - + if($levels) { if(count($levels) > 1) { //More than one level in array: - + //check levels for correct values: $correct_levels = []; foreach($levels as $level) { @@ -81,12 +78,13 @@ require_once(__DIR__ . '/TandemData.class.php'); $correct_levels[] = $level; } } - + if(count($correct_levels)) { //at least one given level was correct: - $sql .= "AND tandem_offers.level IN ( '" . implode($correct_levels, "','") . "') + $sql .= "AND tandem_offers.level IN ( :correct_levels )' ORDER BY FIELD(tandem_offers.level, '" - . implode($correct_levels, "','") . "'), mkdate "; + . implode( "','", $correct_levels) . "'), mkdate "; + $sql_params['correct_levels'] = $correct_levels; } } else { //Only one level in array: @@ -96,22 +94,22 @@ require_once(__DIR__ . '/TandemData.class.php'); } } } - + if($limit > 0) { $sql .= "LIMIT :limit "; $sql_params['limit'] = $limit; } - - + + return [ 'sql' => $sql, 'params' => $sql_params ]; } - - - - + + + + /** * Finds tandem offers by the attributes of a given TandemData object. */ @@ -120,11 +118,11 @@ require_once(__DIR__ . '/TandemData.class.php'); $query = self::sqlForTandemDataAndLevel($tandem_data, $levels, $limit); return self::findBySql($query['sql'], $query['params']); } - - + + static public function countByTandemDataAndLevel(TandemData $tandem_data, Array $levels) { - $query = self::sqlForTandemDataAndLevel($tandem_data, $levels, $limit); + $query = self::sqlForTandemDataAndLevel($tandem_data, $levels); return self::countBySql($query['sql'], $query['params']); } } diff --git a/models/TandemPair.class.php b/models/TandemPair.class.php index f86bcb3d9bf27ffec13089490466766db1b03e8d..09d50da038930aac4c651b8cac9a047cfbd21e24 100644 --- a/models/TandemPair.class.php +++ b/models/TandemPair.class.php @@ -19,13 +19,13 @@ require_once(__DIR__ . '/TerminatedTandemPair.class.php'); /** * A model class to store tandem pairs for the TandemPlugin. - * + * * When a user with a tandem request wants to pair with a * user having a matching tandem offer he creates a TandemPair object * which status is undecided/unanswered. * The offerer may now either accept or reject the paring request. - * In case - * + * In case + * * @property string id Generated MD5 hash * @property string request_profile_id A reference to a TandemProfile object. * @property string offer_profile_id A reference to a TandemProfile object. @@ -33,72 +33,72 @@ require_once(__DIR__ . '/TerminatedTandemPair.class.php'); * 0: undecided/unanswered, 1: accepted, -1: rejected * @property string mkdate database column * @property string chdate database column - * @property TandemRequest request belongs to TandemRequest - * @property TandemOffer offer belongs to TandemOffer + * @property TandemProfile request belongs to TandemProfile + * @property TandemProfile offer belongs to TandemProfile */ class TandemPair extends SimpleORMap { - + static protected function configure($config = []) { $config['db_table'] = 'tandem_pairs'; - + $config['belongs_to']['request'] = [ 'class_name' => 'TandemProfile', 'foreign_key' => 'request_profile_id', 'assoc_func' => 'find' ]; - + $config['belongs_to']['offer'] = [ 'class_name' => 'TandemProfile', 'foreign_key' => 'offer_profile_id', 'assoc_func' => 'find' ]; - + parent::configure($config); } - - + + /** - * Finds tandem pairs by looking at the tandem requests and + * Finds tandem pairs by looking at the tandem requests and * tandem offers bound to tandem pairs. */ - static public function findByUserId($user_id = null, Array $status = []) + static public function findByUserId($user_id = null, Array $status = []) : array { if($user_id == null) { return []; } - + $sql = 'INNER JOIN tandem_profiles ON (tandem_pairs.request_profile_id = tandem_profiles.id OR tandem_pairs.offer_profile_id = tandem_profiles.id) AND tandem_profiles.user_id = :user_id'; - + $sql_params = ['user_id' => $user_id]; - + if($status) { $sql .= ' AND tandem_pairs.status IN ( :status )'; $sql_params['status'] = $status; } - + $sql .= ' ORDER BY tandem_pairs.status DESC'; - - + + $all_pairs = self::findBySql($sql, $sql_params); - + $result_set = []; foreach($all_pairs as $pair) { - if((($pair->request->user_id == $user_id) and $pair->request_visible) + if((($pair->request->user_id == $user_id) and $pair->request_visible) or (($pair->offer->user_id == $user_id) and $pair->offer_visible)) { $result_set[] = $pair; } } - + return $result_set; } - - + + /** * Returns true, if a pair with given status exists for a profile. */ @@ -113,12 +113,12 @@ require_once(__DIR__ . '/TerminatedTandemPair.class.php'); ] ); } - - + + /** * Returns the number of pairs for a given status and a given profile. */ - static public function countByProfileAndStatus(TandemProfile $profile, $status = 1) + static public function countByProfileAndStatus(TandemProfile $profile, $status = 1) : int { return self::countBySql( '(request_profile_id = :profile_id OR offer_profile_id = :profile_id) @@ -129,9 +129,9 @@ require_once(__DIR__ . '/TerminatedTandemPair.class.php'); ] ); } - - - public function getStatusNameForUser(User $user) + + + public function getStatusNameForUser(User $user) : string { if($this->status == 0) { if($this->request->user_id == $user->id) { @@ -152,14 +152,14 @@ require_once(__DIR__ . '/TerminatedTandemPair.class.php'); return dgettext('TandemPlugin', 'Unbekannter Status'); } } - - + + /** * Factory method that creates a TerminatedTandemPair out of this TandemPair. - * + * * @returns TerminatedTandemPair|null A TerminatedTandemPair object or null on failure. */ - public function createTerminatedTandemPair() + public function createTerminatedTandemPair() : ?TerminatedTandemPair { if (!$this->request->user_id || !$this->offer->user_id) { return null; diff --git a/models/TandemProfile.class.php b/models/TandemProfile.class.php index aaf392cc03b42eb3411aa8e036eb01a50a454c70..7de777e590a8b1bc5aa68abb7b3fd3aed8cafe95 100644 --- a/models/TandemProfile.class.php +++ b/models/TandemProfile.class.php @@ -56,7 +56,7 @@ require_once(__DIR__ . '/TandemUserMotherLanguage.class.php'); parent::configure($config); } - public function getTargetName() + public function getTargetName() : string { return $this->target_language->getLocalName() . ' (' @@ -67,7 +67,7 @@ require_once(__DIR__ . '/TandemUserMotherLanguage.class.php'); } - public function matchesSpokenLanguages(string $user_id) + public function matchesSpokenLanguages(string $user_id) : bool { return TandemUserMotherLanguage::countBySql( 'user_id = :user_id diff --git a/models/TandemUserMotherLanguage.class.php b/models/TandemUserMotherLanguage.class.php index 73ad1fb7b416c5ef7e0e77c5f7cefe50374a1624..2a3f061af2f7d5c3667ef85f2a2fd9a489aa190d 100644 --- a/models/TandemUserMotherLanguage.class.php +++ b/models/TandemUserMotherLanguage.class.php @@ -52,7 +52,7 @@ require_once(__DIR__ . '/TandemLanguage.class.php'); } - static public function findSortedByName($user_id = null) + static public function findSortedByName($user_id = null) : array { if(!$user_id) { return []; @@ -85,7 +85,7 @@ require_once(__DIR__ . '/TandemLanguage.class.php'); } elseif($this->country && $this->region) { $html .= sprintf('(%1$s, %2$s)', htmlReady($this->country), htmlReady($this->region)); } elseif($this->region) { - $html .= sprintf('(%s)', htmlReady($uml->region)); + $html .= sprintf('(%s)', htmlReady($this->region)); } } if (Config::get()->TANDEMPLUGIN_USE_LEVEL && $this->level) { diff --git a/plugin.manifest b/plugin.manifest index fc3b9f31148640894221a0a010c16a9123de61f1..fe72fd321d069e88b07bb54e6a3f267f9f03e576 100644 --- a/plugin.manifest +++ b/plugin.manifest @@ -1,7 +1,7 @@ pluginname=TandemPlugin pluginclassname=TandemPlugin origin=data-quest -version=1.5.5-rc1 +version=1.6 description=Dieses Plugin ermöglicht es, Sprachtandems innerhalb der Stud.IP Platform zu bilden. -studipMinVersion=5.0 -studipMaxVersion=5.9.99 +studipMinVersion=5.5 +studipMaxVersion=6.0.99 diff --git a/templates/start.php b/templates/start.php index 9bdec36a97990ce7d7e129e907dee161daa3c4f4..c099bab53b807d79d446baa3226d35ecf923b2aa 100644 --- a/templates/start.php +++ b/templates/start.php @@ -1,17 +1,27 @@ +<?php +/** + * @var bool $never_used + * @var TandemProfile[] $profiles + * @var TandemPair[] $pairs + * @var string $current_user_id + * @var array $pair_requests + * @var array $match_count + */ +?> <section class="contentbox"> <section> <a href="<?= PluginEngine::getLink('tandemplugin/my_tandems/index') ?>"> - <? if($never_used): ?> + <?php if ($never_used) : ?> <?= dgettext('TandemPlugin', 'Hier klicken, um ein Sprachtandem zu finden!') ?> - <? else: ?> + <?php else : ?> <table class="default"> - <? foreach($profiles as $profile): ?> + <?php foreach($profiles as $profile) : ?> <tr> <td> <strong style="display:block;"><?= htmlReady($profile->target_language->getLocalName()) ?></strong>(<?= htmlReady($profile->level) ?>) </td> <td> - <? if($pairs[$profile->id]): ?> + <?php if ($pairs[$profile->id]) : ?> <?= sprintf( dgettext('TandemPlugin', 'Bestehendes Tandem mit %s'), ($pairs[$profile->id]->request->user_id == $current_user_id) @@ -22,34 +32,34 @@ : dgettext('TandemPlugin', 'unbekannt') ) ) ?> - <? elseif($pair_requests[$profile->id] > 0): ?> - <? if($pair_requests[$profile->id] == 1): ?> + <?php elseif ($pair_requests[$profile->id] > 0) : ?> + <?php if($pair_requests[$profile->id] == 1) : ?> <?= dgettext('TandemPlugin', 'Es gibt eine Anfrage zur Tandem-Bildung!') ?> - <? else: ?> + <?php else : ?> <?= sprintf( dgettext('TandemPlugin', 'Es gibt %s Anfragen zur Tandem-Bildung!'), $pair_requests[$profile->id] ) ?> - <? endif ?> - <? else: ?> - <? if($match_count[$profile->id] > 0): ?> + <?php endif ?> + <?php else : ?> + <?php if ($match_count[$profile->id] > 0) : ?> <?= dgettext('TandemPlugin', 'Es wurden passende Sprachtandem-Angebote gefunden!') ?> - <? else: ?> + <?php else : ?> <?= dgettext('TandemPlugin', 'Die Tandemsuche läuft. Im Moment liegen keine Angebote vor.') ?> - <? endif ?> - <? endif ?> + <?php endif ?> + <?php endif ?> </td> </tr> - <? endforeach ?> + <?php endforeach ?> </table> - <? endif ?> + <?php endif ?> </a> </section> - <? if(!empty($profiles)): ?> + <?php if(!empty($profiles)) : ?> <section> <a href="<?= PluginEngine::getLink('tandemplugin/my_tandems/index') ?>"> <?= dgettext('TandemPlugin', 'Hier klicken, um weitere Sprachtandems anzulegen!') ?> </a> </section> - <? endif ?> + <?php endif ?> </section> diff --git a/views/_common/_profile.php b/views/_common/_profile.php index cfb35f398e7a9d9ee432da4df48031b9ac4f9b3f..31b3c070138aa99b231d995920df08f44c79ab1d 100644 --- a/views/_common/_profile.php +++ b/views/_common/_profile.php @@ -1,49 +1,59 @@ +<?php +/** + * @var TandemProfile $profile + * @var string[] $highlighted_languages + */ +?> <?= Avatar::getAvatar($profile->user_id)->getImageTag( Avatar::MEDIUM, ['style' => 'float:left; margin-right: 0.5em;'] ) ?> <div style="float:left;"> - <? if ($profile->user): ?> + <?php if ($profile->user) : ?> <a href="<?= URLHelper::getLink( 'dispatch.php/profile', ['username' => $profile->user->username] ) ?>"> <strong><?= htmlReady($profile->user->getFullName()) ?></strong> </a> - <? else: ?> + <?php else : ?> <strong><?= dgettext('TandemPlugin', 'unbekannt') ?></strong> - <? endif ?> - <? if($established_pair or $admin_view): ?> - <? if ($profile->user) : ?> + <?php endif ?> + <?php if (!empty($established_pair) || !empty($admin_view)) : ?> + <?php if ($profile->user) : ?> <a href="<?= URLHelper::getLink( 'dispatch.php/messages/write', ['rec_uname' => $profile->user->username] ) ?>" data-dialog> <?= Icon::create('mail', 'clickable')->asImg('20px', ['class' => 'text-bottom']) ?> </a> - <? endif ?> + <?php endif ?> - <? endif ?> + <?php endif ?> <div> - <? if ($profile->user): ?> + <?php if ($profile->user) : ?> <strong><?= dgettext('TandemPlugin', 'Geschlecht') ?>:</strong> <?= ($profile->user->geschlecht == '1') ? dgettext('TandemPlugin', 'männlich') : (($profile->user->geschlecht == '2') ? dgettext('TandemPlugin', 'weiblich') : dgettext('TandemPlugin', 'Keine Angabe')) ?> - <? endif ?> + <?php endif ?> </div> - <? $study_names = null; ?> - <? if ($profile->user): ?> - <? if($profile->user->studycourses): ?> - <? $study_names = []; - foreach($profile->user->studycourses as $studycourse) { + <?php + $study_names = null; + ?> + <?php if ($profile->user) : ?> + <?php if($profile->user->studycourses) : ?> + <?php + $study_names = []; + foreach ($profile->user->studycourses as $studycourse) { $study_names[] = $studycourse->studycourse->name; - } ?> - <? endif ?> - <? endif ?> + } + ?> + <?php endif ?> + <?php endif ?> <div> <strong><?= dgettext('TandemPlugin', 'Studiengänge') ?>:</strong> <?= ($study_names @@ -51,52 +61,52 @@ : dgettext('TandemPlugin', 'Keine Angabe')) ?> </div> - <? if($established_pair or $admin_view): ?> - <? if($highlighted_languages): ?> + <?php if (!empty($established_pair) || !empty($admin_view)) : ?> + <?php if (!empty($highlighted_languages)) : ?> <div> <strong><?= htmlReady($highlighted_languages[0]) ?></strong> <?= Icon::create('group', 'info')->asImg('16px', ['class' => 'text-bottom']) ?> <?= htmlReady($profile->getTargetName()) ?> </div> - <? endif ?> - <? else: ?> + <?php endif ?> + <?php else : ?> <div> <strong><?= dgettext('TandemPlugin', 'Sucht') ?>:</strong> <?= htmlReady($profile->getTargetName()) ?> </div> <div> <strong><?= dgettext('TandemPlugin', 'Spricht') ?>:</strong> - <? $user_mother_languages = TandemUserMotherLanguage::findSortedByName($profile->user_id) ?> - <? foreach($user_mother_languages as $uml): ?> + <?php $user_mother_languages = TandemUserMotherLanguage::findSortedByName($profile->user_id) ?> + <?php foreach($user_mother_languages as $uml) : ?> <span style="white-space: nowrap;"> <?= $uml->render( $highlighted_languages && in_array($uml->language->getLocalName(), $highlighted_languages), true ) ?> </span> - <? endforeach ?> + <?php endforeach ?> </div> - <? endif ?> - <? if($profile->comment): ?> + <?php endif ?> + <?php if ($profile->comment): ?> <div> <strong><?= dgettext('TandemPlugin', 'Bemerkung') ?>:</strong> <?= htmlReady($profile->comment) ?> </div> - <? endif ?> - <? if($admin_view and Config::get()->TANDEMPLUGIN_PROOF_FIELDS_ENABLED): ?> + <?php endif ?> + <?php if (!empty($admin_view) && Config::get()->TANDEMPLUGIN_PROOF_FIELDS_ENABLED) : ?> <div> - <? if($profile->proof_of_achievement): ?> + <?php if($profile->proof_of_achievement) : ?> <div> <strong><?= dgettext('TandemPlugin', 'Leistungsbescheinigung') ?>:</strong> <span><?= dgettext('TandemPlugin', 'gewünscht') ?></span> </div> - <? endif ?> - <? if($profile->proof_of_attendance): ?> + <?php endif ?> + <?php if($profile->proof_of_attendance) : ?> <div> <strong><?= dgettext('TandemPlugin', 'Teilnahmebestätigung') ?>:</strong> <span><?= dgettext('TandemPlugin', 'gewünscht') ?></span> </div> - <? endif ?> - <? endif ?> + <?php endif ?> + <?php endif ?> </div> </div> diff --git a/views/admin/_common_language_form.php b/views/admin/_common_language_form.php index 9782bcc2b2301b16c3a161ae2649f12bddee9176..aa86d0589fe76f69be2a8bdda69a78afe51f724f 100644 --- a/views/admin/_common_language_form.php +++ b/views/admin/_common_language_form.php @@ -1,3 +1,10 @@ +<?php +/** + * @var string $name + * @var string $name_ger + * @var string $name_eng + */ +?> <label> <?= dgettext('TandemPlugin', 'Name') ?> <input type="text" name="name" value="<?= htmlReady($name) ?>"> diff --git a/views/admin/add_language.php b/views/admin/add_language.php index fa29d79761734af4ac419bd0e4e7e3c56100915e..19e60ab05b370c30f0343b2d266f0daf13a51b23 100644 --- a/views/admin/add_language.php +++ b/views/admin/add_language.php @@ -1,3 +1,12 @@ +<?php +/** + * @var PluginController $controller + * @var string $lang_id + * @var string $name + * @var string $name_ger + * @var string $name_eng + */ +?> <form class="default" method="post" data-dialog="reload-on-close" action="<?= $controller->link_for('admin/add_language') ?>"> <?= CSRFProtection::tokenTag() ?> diff --git a/views/admin/add_to_blocklist.php b/views/admin/add_to_blocklist.php index e2477152ee1e6d48d5f7748d16e0b725c8789329..a687d7b7f82774f8d925e7b414b434fe629bc211 100644 --- a/views/admin/add_to_blocklist.php +++ b/views/admin/add_to_blocklist.php @@ -1,3 +1,10 @@ +<?php +/** + * @var PluginController $controller + * @var QuickSearch $user_search + * @var string $reason + */ +?> <form class="default" method="post" action="<?= $controller->link_for('admin/add_to_blocklist') ?>" data-dialog="reload-on-close"> <?= CSRFProtection::tokenTag() ?> diff --git a/views/admin/blocklist.php b/views/admin/blocklist.php index 2cf3f0c921b35c80be9b8ac2f489f5c75ded04b8..c0cb16eb136c90ab8880476a606b4c9eb85caba9 100644 --- a/views/admin/blocklist.php +++ b/views/admin/blocklist.php @@ -1,3 +1,9 @@ +<?php +/** + * @var PluginController $controller + * @var \TandemPlugin\BlocklistEntry[] $blocklist_entries + */ +?> <table class="default TandemPlugin"> <caption><?= dgettext('TandemPlugin', 'Einträge auf der Blockliste') ?></caption> <thead> @@ -8,8 +14,8 @@ </tr> </thead> <tbody> - <? foreach ($blocklist_entries as $entry) : ?> - <? + <?php foreach ($blocklist_entries as $entry) : ?> + <?php $user_name = !empty($entry->user) ? $entry->user->getFullName('full_rev') : ''; ?> <tr> @@ -25,6 +31,6 @@ </form> </td> </tr> - <? endforeach ?> + <?php endforeach ?> </tbody> </table> diff --git a/views/admin/config.php b/views/admin/config.php index 782c9a6d06de58e71ff1a5c3983b48b09dbedd1a..47acd3fbeeeb346f0a3b37db1bd7e45fc4958c88 100644 --- a/views/admin/config.php +++ b/views/admin/config.php @@ -1,3 +1,13 @@ +<?php +/** + * @var bool $gender_search_enabled + * @var bool $use_level + * @var string $delete_old_period + * @var bool $proof_fields_enabled + * @var bool $use_tools_navigation + * @var string $management_email_address + */ +?> <h1><?= dgettext('TandemPlugin', 'Konfiguration des Tandem-Plugins') ?></h1> <form class="default" method="post"> <?= CSRFProtection::tokenTag() ?> diff --git a/views/admin/delete_language.php b/views/admin/delete_language.php index 4d64e5415b0351c167ff5b2122f2e7018323f7be..647091d1a1cf6ac68e6627303d3111535d4df3e8 100644 --- a/views/admin/delete_language.php +++ b/views/admin/delete_language.php @@ -1,4 +1,10 @@ -<? if ($language) : ?> +<?php +/** + * @var TandemLanguage $language + * @var PluginController $controller + */ +?> +<?php if ($language) : ?> <?= MessageBox::warning( dgettext('TandemPlugin', 'Soll die folgende Sprache wirklich gelöscht werden?') ) ?> @@ -22,4 +28,4 @@ ) ?> </div> </form> -<? endif ?> +<?php endif ?> diff --git a/views/admin/edit_language.php b/views/admin/edit_language.php index 0de8d44f8f28e3cc7416e395b268869a8f20eba2..1f3ae3e3e77a072642a26c7e7c8aca0171797c48 100644 --- a/views/admin/edit_language.php +++ b/views/admin/edit_language.php @@ -1,3 +1,9 @@ +<?php +/** + * @var PluginController $controller + * @var TandemLanguage $language + */ +?> <form class="default" method="post" data-dialog="reload-on-close" action="<?= $controller->link_for('admin/edit_language/' . $language->id) ?>"> <?= CSRFProtection::tokenTag() ?> diff --git a/views/admin/languages.php b/views/admin/languages.php index 8e0111f2bfdaf907a45edb99c2c806924e3f77ce..a3d3c19b7f586cc215f13415a8f1b02832061bce 100644 --- a/views/admin/languages.php +++ b/views/admin/languages.php @@ -1,4 +1,10 @@ -<? if ($languages) : ?> +<?php +/** + * @var PluginController $controller + * @var TandemLanguage[] $languages + */ +?> +<?php if ($languages) : ?> <table class="default sortable-table" data-sortlist="[[0, 0]]"> <thead> <tr> @@ -10,14 +16,14 @@ </tr> </thead> <tbody> - <? foreach ($languages as $language) : ?> + <?php foreach ($languages as $language) : ?> <tr> <td><?= htmlReady($language->id) ?></td> <td><?= htmlReady($language->name) ?></td> <td><?= htmlReady($language->name_ger) ?></td> <td><?= htmlReady($language->name_eng) ?></td> <td class="actions"> - <? + <?php $action_menu = ActionMenu::get(); $action_menu->addLink( $controller->url_for('admin/edit_language/' . $language->id), @@ -35,9 +41,9 @@ <?= $action_menu->render() ?> </td> </tr> - <? endforeach ?> + <?php endforeach ?> </tbody> </table> -<? else : ?> +<?php else : ?> <?= MessageBox::info(dgettext('TandemPlugin', 'Es sind keine Sprachen verfügbar.')) ?> -<? endif ?> +<?php endif ?> diff --git a/views/admin/search.php b/views/admin/search.php index ec24e4639deb3dc9b08c30753acd4b6fea7ce486..acc7045a0ea93df833058b5ff25e06f5d85d8359 100644 --- a/views/admin/search.php +++ b/views/admin/search.php @@ -52,7 +52,7 @@ 'search' ) ?> </fieldset> - <? if ($search_results): ?> + <? if (!empty($search_results)): ?> <table class="default"> <thead> <tr> @@ -88,7 +88,7 @@ </tbody> </table> <? endif ?> - <? if ($search_requested and !$search_results): ?> + <? if (!empty($search_requested) && empty($search_results)): ?> <?= MessageBox::info( dgettext( 'TandemPlugin',