public function map($format, $value)
 {
     switch ($format) {
         case "username":
             $user = User::findOneByUsername($value);
             if ($user) {
                 return $user->getId();
             }
             break;
         case "email":
             $user = User::findOneByEmail($value);
             if ($user) {
                 return $user->getId();
             }
             break;
         default:
             //Datenfeld:
             $datafield = DataField::find($format);
             if ($datafield && $datafield['object_type'] === "user") {
                 $entry = DatafieldEntryModel::findOneBySQL("datafield_id = ? AND content = ?", array($datafield->getId(), $value));
                 if ($entry) {
                     return $entry['range_id'];
                 }
             }
     }
 }
 public function afterStoreCallback()
 {
     if ($this->isDirty()) {
         //add notification to writer of review
         if (!$this->review['host_id'] && $this->review['user_id'] !== $this['user_id']) {
             PersonalNotifications::add($this->review['user_id'], URLHelper::getURL("plugins.php/lernmarktplatz/market/discussion/" . $this['review_id'] . "#comment_" . $this->getId()), sprintf(_("%s hat einen Kommentar zu Ihrem Review geschrieben."), $this['host_id'] ? LernmarktplatzUser::find($this['user_id'])->name : get_fullname($this['user_id'])), "comment_" . $this->getId(), Icon::create("support", "clickable"));
         }
         //add notification to all users of this servers who discussed this review but are neither the new
         //commentor nor the writer of the review
         $statement = DBManager::get()->prepare("\n                SELECT user_id\n                FROM lernmarktplatz_comments\n                WHERE review_id = :review_id\n                    AND host_id IS NULL\n                GROUP BY user_id\n            ");
         $statement->execute(array('review_id' => $this->review->getId()));
         foreach ($statement->fetchAll(PDO::FETCH_COLUMN, 0) as $user_id) {
             if (!in_array($user_id, array($this->review['user_id'], $this['user_id']))) {
                 PersonalNotifications::add($user_id, URLHelper::getURL("plugins.php/lernmarktplatz/market/discussion/" . $this['review_id'] . "#comment_" . $this->getId()), sprintf(_("%s hat auch einen Kommentar geschrieben."), $this['host_id'] ? LernmarktplatzUser::find($this['user_id'])->name : get_fullname($this['user_id'])), "comment_" . $this->getId(), Icon::create("support", "clickable"));
             }
         }
         //only push if the comment is from this server and the material-server is different
         if (!$this['host_id']) {
             $myHost = LernmarktplatzHost::thisOne();
             $data = array();
             $data['host'] = array('name' => $myHost['name'], 'url' => $myHost['url'], 'public_key' => $myHost['public_key']);
             $data['data'] = $this->toArray();
             $data['data']['foreign_comment_id'] = $data['data']['comment_id'];
             unset($data['data']['comment_id']);
             unset($data['data']['id']);
             unset($data['data']['user_id']);
             unset($data['data']['host_id']);
             $user_description_datafield = DataField::find(get_config("LERNMARKTPLATZ_USER_DESCRIPTION_DATAFIELD")) ?: DataField::findOneBySQL("name = ?", array(get_config("LERNMARKTPLATZ_USER_DESCRIPTION_DATAFIELD")));
             if ($user_description_datafield) {
                 $datafield_entry = DatafieldEntryModel::findOneBySQL("range_id = ? AND datafield_id = ?", array($this['user_id'], $user_description_datafield->getId()));
             }
             $data['user'] = array('user_id' => $this['user_id'], 'name' => get_fullname($this['user_id']), 'avatar' => Avatar::getAvatar($this['user_id'])->getURL(Avatar::NORMAL), 'description' => $datafield_entry ? $datafield_entry['content'] : null);
             $statement = DBManager::get()->prepare("\n                    SELECT host_id\n                    FROM lernmarktplatz_comments\n                    WHERE review_id = :review_id\n                        AND host_id IS NOT NULL\n                    GROUP BY host_id\n                ");
             $statement->execute(array('review_id' => $this->review->getId()));
             $hosts = $statement->fetchAll(PDO::FETCH_COLUMN, 0);
             if ($this->review['host_id'] && !in_array($this->review['host_id'], $hosts)) {
                 $hosts[] = $this->review['host_id'];
             }
             if ($this->review->material['host_id'] && !in_array($this->review->material['host_id'], $hosts)) {
                 $hosts[] = $this->review->material['host_id'];
             }
             foreach ($hosts as $host_id) {
                 $remote = new LernmarktplatzHost($host_id);
                 if (!$remote->isMe()) {
                     $review_id = $this->review['foreign_review_id'] ?: $this->review->getId();
                     if ($this->review['foreign_review_id']) {
                         if ($this->review->host_id === $remote->getId()) {
                             $host_hash = null;
                         } else {
                             $host_hash = md5($this->review->host['public_key']);
                         }
                     } else {
                         $host_hash = md5($myHost['public_key']);
                     }
                     $remote->pushDataToEndpoint("add_comment/" . $review_id . "/" . $host_hash, $data);
                 }
             }
         }
     }
 }
 public function afterStoreCallback()
 {
     if (!$this->material['host_id'] && $this->material['user_id'] !== $GLOBALS['user']->id) {
         PersonalNotifications::add($this->material['user_id'], URLHelper::getURL("plugins.php/lernmarktplatz/market/details/" . $this->material->getId() . "#review_" . $this->getId()), $this->isNew() ? sprintf(_("%s hat ein Review zu '%s' geschrieben."), $this['host_id'] ? LernmarktplatzUser::find($this['user_id'])->name : get_fullname($this['user_id']), $this->material['name']) : sprintf(_("%s hat ein Review zu '%s' verändert."), $this['host_id'] ? LernmarktplatzUser::find($this['user_id'])->name : get_fullname($this['user_id']), $this->material['name']), "review_" . $this->getId(), Icon::create("support", "clickable"));
     }
     //only push if the comment is from this server and the material-server is different
     if ($this->material['host_id'] && !$this['host_id'] && $this->isDirty()) {
         $remote = new LernmarktplatzHost($this->material['host_id']);
         $myHost = LernmarktplatzHost::thisOne();
         $data = array();
         $data['host'] = array('name' => $myHost['name'], 'url' => $myHost['url'], 'public_key' => $myHost['public_key']);
         $data['data'] = $this->toArray();
         $data['data']['foreign_review_id'] = $data['data']['review_id'];
         unset($data['data']['review_id']);
         unset($data['data']['id']);
         unset($data['data']['user_id']);
         unset($data['data']['host_id']);
         $user_description_datafield = DataField::find(get_config("LERNMARKTPLATZ_USER_DESCRIPTION_DATAFIELD")) ?: DataField::findOneBySQL("name = ?", array(get_config("LERNMARKTPLATZ_USER_DESCRIPTION_DATAFIELD")));
         if ($user_description_datafield) {
             $datafield_entry = DatafieldEntryModel::findOneBySQL("range_id = ? AND datafield_id = ?", array($this['user_id'], $user_description_datafield->getId()));
         }
         $data['user'] = array('user_id' => $this['user_id'], 'name' => get_fullname($this['user_id']), 'avatar' => Avatar::getAvatar($this['user_id'])->getURL(Avatar::NORMAL), 'description' => $datafield_entry ? $datafield_entry['content'] : null);
         if (!$remote->isMe()) {
             $remote->pushDataToEndpoint("add_review/" . $this->material['foreign_material_id'], $data);
         }
     }
 }
 public function map($format, $value)
 {
     switch ($format) {
         case "number":
             $course = Course::findOneBySQL("VeranstaltungsNummer = ?", array($value));
             if ($course) {
                 return $course->getId();
             }
             break;
         case "name":
             $course = Course::findOneBySQL("name = ?", array($value));
             if ($course) {
                 return $course->getId();
             }
             break;
         default:
             //Datenfeld:
             $datafield = DataField::find($format);
             if ($datafield && $datafield['object_type'] === "sem") {
                 $entry = DatafieldEntryModel::findOneBySQL("datafield_id = ? AND content = ?", array($datafield->getId(), $value));
                 if ($entry) {
                     return $entry['range_id'];
                 }
             }
     }
 }
 public function map($format, $value)
 {
     switch ($format) {
         case "name":
             $inst = Institute::findOneBySQL("Name = ?", array($value));
             if ($inst) {
                 return $inst->getId();
             }
             break;
         default:
             //Datenfeld:
             $datafield = DataField::find($format);
             if ($datafield && $datafield['object_type'] === "inst") {
                 $entry = DatafieldEntryModel::findOneBySQL("datafield_id = ? AND content = ?", array($datafield->getId(), $value));
                 if ($entry) {
                     return $entry['range_id'];
                 }
             }
     }
 }
 /**
  * @see UserFilterField::__construct
  */
 public function __construct($typeparam, $fieldId = '')
 {
     $this->validCompareOperators = array('>=' => _('mindestens'), '<=' => _('höchstens'), '=' => _('gleich'), '!=' => _('ungleich'));
     if ($fieldId) {
         $this->id = $fieldId;
         $this->load();
     } else {
         $this->id = $this->generateId();
         $this->datafield_id = $typeparam;
     }
     $df = DataField::find($this->datafield_id);
     if ($df) {
         $this->datafield_name = $df->name;
     } else {
         throw new UnexpectedValueException('datafield not found, id: ' . $typeparam);
     }
     $typed_df = DataFieldEntry::createDataFieldEntry($df);
     if ($typed_df instanceof DataFieldBoolEntry) {
         $this->validValues = array(1 => _('Ja'), 0 => _('Nein'));
         unset($this->validCompareOperators['>=']);
         unset($this->validCompareOperators['<=']);
         unset($this->validCompareOperators['!=']);
         $this->null_yields = 0;
     } else {
         if ($typed_df instanceof DataFieldSelectboxEntry) {
             list($valid_values, $is_assoc) = $typed_df->getParams();
             if (!$is_assoc) {
                 $valid_values = array_combine($valid_values, $valid_values);
             }
             $this->validValues = $valid_values;
             $this->null_yields = $typed_df instanceof DataFieldSelectboxMultipleEntry ? '' : key($valid_values);
         } else {
             $this->null_yields = '';
         }
     }
 }
Exemple #7
0
            <div class="author_name">
                <a href="<?php 
echo URLHelper::getLink("dispatch.php/profile", array('username' => $user['username']));
?>
">
                    <?php 
echo htmlReady($user->getFullName());
?>
                </a>
            </div>
            <div class="author_host">(<?php 
echo htmlReady($GLOBALS['UNI_NAME_CLEAN']);
?>
)</div>
            <div class="description"><?
                $user_description_datafield = DataField::find(get_config("LERNMARKTPLATZ_USER_DESCRIPTION_DATAFIELD")) ?: DataField::findOneBySQL("name = ?", array(get_config("LERNMARKTPLATZ_USER_DESCRIPTION_DATAFIELD")));
                if ($user_description_datafield) {
                    $datafield_entry = DatafieldEntryModel::findOneBySQL("range_id = ? AND datafield_id = ?", array($user['user_id'], $user_description_datafield->getId()));
                    echo $datafield_entry && $datafield_entry['content'] ? formatReady($datafield_entry['content']) : "";

                    if ($material['user_id'] === $GLOBALS['user']->id) : ?>
                        <a href="<?php 
echo URLHelper::getLink("dispatch.php/settings/details#datafields_" . $user_description_datafield->getId());
?>
" title="<?php 
echo _("Text bearbeiten");
?>
">
                            <?php 
echo Icon::create("edit", "clickable")->asImg(20, array('class' => "text-bottom"));
?>
Exemple #8
0
 /**
  * Caching for the datafields
  * @param type $member
  * @param type $fieldID
  * @return null
  */
 private function getDatafield($member, $fieldID)
 {
     if (strlen($fieldID) == 32) {
         if (!array_key_exists($fieldID, $this->datafieldCache)) {
             $this->datafieldCache[$fieldID] = DataField::find($fieldID);
         }
         if (isset($this->datafieldCache[$fieldID])) {
             if ($this->datafieldCache[$fieldID]->object_type == 'usersemdata') {
                 $field = current(DatafieldEntryModel::findByModel($member, $fieldID));
             }
             if ($this->datafieldCache[$fieldID]->object_type == 'user') {
                 $field = current(DatafieldEntryModel::findByModel(User::find($member->user_id), $fieldID));
             }
             if ($field) {
                 $range_id = $field->sec_range_id ? array($field->range_id, $field->sec_range_id) : $field->range_id;
                 $typed_df = DataFieldEntry::createDataFieldEntry($field->datafield, $range_id, $field->getValue('content'));
                 return array($field->name => $typed_df);
             }
         }
     }
 }
 public function pushDataToIndexServers($delete = false)
 {
     $myHost = LernmarktplatzHost::thisOne();
     $data = array();
     $data['host'] = array('name' => $myHost['name'], 'url' => $myHost['url'], 'public_key' => $myHost['public_key']);
     $data['data'] = $this->toArray();
     $data['data']['foreign_material_id'] = $data['data']['material_id'];
     unset($data['data']['material_id']);
     unset($data['data']['id']);
     unset($data['data']['user_id']);
     unset($data['data']['host_id']);
     $user_description_datafield = DataField::find(get_config("LERNMARKTPLATZ_USER_DESCRIPTION_DATAFIELD")) ?: DataField::findOneBySQL("name = ?", array(get_config("LERNMARKTPLATZ_USER_DESCRIPTION_DATAFIELD")));
     if ($user_description_datafield) {
         $datafield_entry = DatafieldEntryModel::findOneBySQL("range_id = ? AND datafield_id = ?", array($this['user_id'], $user_description_datafield->getId()));
     }
     $data['user'] = array('user_id' => $this['user_id'], 'name' => get_fullname($this['user_id']), 'avatar' => Avatar::getAvatar($this['user_id'])->getURL(Avatar::NORMAL), 'description' => $datafield_entry ? $datafield_entry['content'] : null);
     $data['topics'] = array();
     foreach ($this->getTopics() as $tag) {
         if ($tag['name']) {
             $data['topics'][] = $tag['name'];
         }
     }
     if ($delete) {
         $data['delete_material'] = 1;
     }
     foreach (LernmarktplatzHost::findBySQL("index_server = '1' AND allowed_as_index_server = '1' ") as $index_server) {
         if (!$index_server->isMe()) {
             echo " push ";
             $index_server->pushDataToEndpoint("push_data", $data);
         }
     }
 }
Exemple #10
0
 /**
  * Returns data of a given item including where to download it and the structure, decription, etc.
  * If item is not hosted on this server, just relocate the request to the real server.
  *
  * This endpoint should be called by a remote whenever a client wants to view the details of an item.
  *
  * @param $item_id : ID of the item on this server.
  */
 public function get_item_data_action($item_id)
 {
     $material = new LernmarktplatzMaterial($item_id);
     if ($material->isNew()) {
         $this->render_json(array('deleted' => 1));
     } elseif (!$material['foreign_material_id']) {
         $me = LernmarktplatzHost::thisOne();
         $topics = array();
         foreach ($material->getTopics() as $topic) {
             $topics[] = $topic['name'];
         }
         $user_description_datafield = DataField::find(get_config("LERNMARKTPLATZ_USER_DESCRIPTION_DATAFIELD")) ?: DataField::findOneBySQL("name = ?", array(get_config("LERNMARKTPLATZ_USER_DESCRIPTION_DATAFIELD")));
         if ($user_description_datafield) {
             $datafield_entry = DatafieldEntryModel::findOneBySQL("range_id = ? AND datafield_id = ?", array($material['user_id'], $user_description_datafield->getId()));
         }
         $reviews = array();
         foreach ($material->reviews as $review) {
             if ($review['host_id']) {
                 $user = LernmarktplatzUser::findOneBySQL("user_id = ?", array($review['user_id']));
                 $user = array('user_id' => $review['user_id'], 'name' => $user['name'], 'avatar' => $user['avatar'], 'description' => $user['description']);
             } else {
                 if ($user_description_datafield) {
                     $user_description = DatafieldEntryModel::findOneBySQL("range_id = ? AND datafield_id = ?", array($review['user_id'], $user_description_datafield->getId()));
                 }
                 $user = array('user_id' => $review['user_id'], 'name' => get_fullname($review['user_id']), 'avatar' => Avatar::getAvatar($review['user_id'])->getURL(Avatar::NORMAL), 'description' => $user_description['content'] ?: null);
             }
             $reviews[] = array('foreign_review_id' => $review['foreign_review_id'] ?: $review->getId(), 'review' => $review['review'], 'rating' => $review['rating'], 'user' => $user, 'host' => array('name' => $review['host_id'] ? $review->host['name'] : $me['name'], 'url' => $review['host_id'] ? $review->host['url'] : $me['url'], 'public_key' => $review['host_id'] ? $review->host['public_key'] : $me['public_key']), 'mkdate' => $review['mkdate'], 'chkdate' => $review['chdate']);
         }
         $this->render_json(array('data' => array('name' => $material['name'], 'short_description' => $material['short_description'], 'description' => $material['description'], 'content_type' => $material['content_type'], 'front_image_content_type' => $material['front_image_content_type'], 'url' => ($GLOBALS['LERNMARKTPLATZ_PREFERRED_URI'] ?: $GLOBALS['ABSOLUTE_URI_STUDIP']) . "/plugins.php/lernmarktplatz/market/download/" . $item_id, 'structure' => $material['structure'], 'license' => $material['license']), 'user' => array('user_id' => $material['user_id'], 'name' => User::find($material['user_id'])->getFullName(), 'avatar' => Avatar::getAvatar($material['user_id'])->getURL(Avatar::NORMAL), 'description' => $datafield_entry ? $datafield_entry['content'] : null), 'topics' => $topics, 'reviews' => $reviews));
     } else {
         $host = new LernmarktplatzHost($material['host_id']);
         header("Location: " . $host['url'] . "get_item_data/" . $item_id);
         return;
     }
 }
Exemple #11
0
 function checkData()
 {
     global $invalidEntries;
     // check the standard role data
     if (!Request::get('new_name') && Request::get('presetName') != 'none') {
         $this->name = remove_magic_quotes(Request::get('presetName'));
     } else {
         $this->name = remove_magic_quotes(Request::get('new_name'));
     }
     $this->size = (int) Request::int('new_size');
     // check if we have to remove the self_assign_exclusive-flag
     $this->selfassign = SetSelfAssign($this->statusgruppe_id, Request::quoted('new_selfassign') ? 1 : 0);
     /*if (Request::quoted('new_selfassign')) {
           if ($this->selfassign == 0) {
               $this->selfassign = 1;
           }
       } else {
           if ($this->selfassign == 2) {
               if ($GLOBALS['SessSemName']) {
                   SetSelfAssignExclusive($GLOBALS['SessSemName'][1], false);
               }
           }
           $this->selfassign = 0;
       }*/
     if (Request::get('groupfolder')) {
         // check if there already exists a folder
         $stmt = DBManager::get()->prepare("SELECT COUNT(*) as c FROM folder WHERE range_id = ?");
         $stmt->execute(array($this->statusgruppe_id));
         if ($folder = $stmt->fetch(PDO::FETCH_ASSOC)) {
             if ($folder['c'] == 0) {
                 // if no folder exists, we create one
                 $title = _("Dateiordner der Gruppe:") . ' ' . $this->name;
                 $description = _("Ablage für Ordner und Dokumente dieser Gruppe");
                 $permission = 15;
                 create_folder(addslashes($title), $description, $this->statusgruppe_id, $permission);
                 $this->messages['msg'][] = _("Es wurde ein Gruppenordner angelegt.");
             }
         }
     }
     if (!$this->isSeminar()) {
         // check the datafields
         foreach (Request::quotedArray('datafields') as $id => $data) {
             $struct = DataField::find($id);
             $entry = DataFieldEntry::createDataFieldEntry($struct, array($this->range_id, $this->statusgruppe_id));
             $entry->setValueFromSubmit($data);
             if ($entry->isValid()) {
                 $entry->store();
             } else {
                 $invalidEntries[$struct->id] = $entry;
             }
         }
         // a group cannot be its own vather!
         if (Request::get('vather') == $this->statusgruppe_id) {
             $this->messages['error'][] = _("Sie könne diese Gruppe nicht sich selbst unterordnen!");
         } else {
             // check if the group shall be moved
             if (Request::get('vather') != 'nochange') {
                 if (Request::option('vather') == 'root') {
                     $vather_id = $GLOBALS['range_id'];
                 } else {
                     $vather_id = Request::option('vather');
                 }
                 if (!isVatherDaughterRelation($this->statusgruppe_id, $vather_id)) {
                     $this->range_id = $vather_id;
                     //$db->query("UPDATE statusgruppen SET range_id = '$vather_id' WHERE statusgruppe_id = '{$this->statusgruppe_id}'");
                 } else {
                     $this->messages['error'][] = _("Sie können diese Gruppe nicht einer ihr untergeordneten Gruppe zuweisen!");
                 }
             }
         }
     }
     if (!$this->isSeminar() && is_array($invalidEntries)) {
         $this->messages['error'][] = _("Korrigieren Sie die fehlerhaften Eingaben!");
         return false;
     }
     return true;
 }
Exemple #12
0
 /**
  * Configures a datafield
  *
  * @param String $datafield_id Datafield id
  */
 public function config_action($datafield_id)
 {
     $datafield = DataField::find($datafield_id);
     if (Request::get('typeparam')) {
         $datafield->typeparam = Request::get('typeparam');
     }
     if (Request::isPost() && Request::submitted('store')) {
         $datafield->store();
         PageLayout::postSuccess(_('Die Parameter wurden übernommen.'));
         $this->redirect('admin/datafields/index/' . $datafield_id->object_type . '#item_' . $datafield_id);
     }
     $this->struct = $datafield;
     if (Request::submitted('preview')) {
         $this->preview = DataFieldEntry::createDataFieldEntry($datafield);
         $this->render_action('preview');
     }
 }