function createGenre($id, $english) { $o1 = new sotf_NodeObject("sotf_genres"); $o1->set('genre_id', $id); $o1->set('language', 'en'); $o1->set('name', $english); $o1->create(); }
function createRole($id, $english, $creator = 'f') { $o1 = new sotf_NodeObject("sotf_roles"); $o1->set('role_id', $id); $o1->set('creator', $creator); $o1->create(); $o2 = new sotf_NodeObject("sotf_role_names"); $o2->set('role_id', $id); $o2->set('language', 'en'); $o2->set('name', $english); $o2->create(); }
/** Creates a deletion record: used when a replicated object is deleted. */ function createDeletionRecord() { global $db; $dr = new sotf_NodeObject('sotf_deletions'); $dr->set('del_id', $this->id); $dr->set('del_time', $db->getTimestampTz()); $dr->create(); }
// set caption $capid = sotf_Utils::getParameter('capid'); $capvalue = sotf_Utils::getParameter('capvalue'); $capurl = sotf_Utils::getParameter('capurl'); $capname = sotf_Utils::getParameter('capname'); if ($capname == "ofiles") { $x = new sotf_NodeObject("sotf_other_files", $capid); $x->set('caption', addslashes($capvalue)); $x->update(); if (!strstr($capurl, "#")) { $capurl .= "#ofiles"; } $page->redirect($capurl); } elseif ($capname == "mfiles") { $x = new sotf_NodeObject("sotf_media_files", $capid); $x->set('caption', addslashes($capvalue)); $x->update(); if (!strstr($capurl, "#")) { $capurl .= "#mfiles"; } $page->redirect($capurl); } $prg =& new sotf_Programme($id); if (!$prg->isLocal()) { raiseError("You can only edit programmes locally!"); } if ($prg->isVideoPrg()) { $video = true; } else { $video = false; }
function updatePrgStats() { global $db, $repository; $id = $db->getOne("SELECT id FROM sotf_prog_stats WHERE prog_id='" . $this->get('prog_id') . "'"); if (!$id) { $obj = new sotf_NodeObject("sotf_prog_stats"); $obj->set('prog_id', $this->get('prog_id')); } else { $obj = $repository->getObject($id); } $obj->set('station_id', $this->get('station_id')); $obj->set('unique_visits', $this->get('unique_visits')); $obj->set('unique_listens', $this->get('unique_listens')); $obj->set('unique_downloads', $this->get('unique_downloads')); $prgId = $this->get('prog_id'); $data = $db->getRow("SELECT SUM(visits) as visits, SUM(listens) as listens, SUM(downloads) as downloads FROM sotf_stats WHERE prog_id='{$prgId}'"); $obj->set('visits', $data['visits']); $obj->set('listens', $data['listens']); $obj->set('downloads', $data['downloads']); $obj->save(); }
$name = sotf_Utils::getParameter('name'); $topic_id = sotf_Utils::getParameter('topic_id'); $topic_name = sotf_Utils::getParameter('topic_name'); $topic_counter = sotf_Utils::getParameter('topic_counter'); $find = sotf_Utils::getParameter('find'); $add = sotf_Utils::getParameter('add'); if ($name != "") { $x = new sotf_NodeObject("sotf_topic_tree_defs"); $x->set('supertopic', $parent); $x->set('name', $name); $x->create(); $id = $x->getID(); } if ($topic_name != "") { $x = new sotf_NodeObject("sotf_topics"); $x->set('topic_id', $topic_id); $x->set('language', "en"); $x->set('topic_name', $topic_name); $x->create(); $id = $x->getID(); print $id; } if ($topic_counter != "") { $x = new sotf_Object("sotf_topics_counter"); $x->set('topic_id', $topic_id); $x->set('number', $topic_counter); $x->create(); $id = $x->getID(); print $id; } $query = "SELECT sotf_topic_tree_defs.*, sotf_topics.topic_name, sotf_topics_counter.number from sotf_topic_tree_defs" . " LEFT JOIN sotf_topics ON sotf_topics.topic_id = sotf_topic_tree_defs.id" . " LEFT JOIN sotf_topics_counter ON sotf_topics_counter.topic_id = sotf_topic_tree_defs.id";
/** Imports genre translations from a text files into database */ function importGenres($lines, $language) { if (empty($lines)) { logError("importGenres: file is empty"); return; } reset($lines); while (list(, $line) = each($lines)) { if (preg_match('/^\\s*$/', $line) || preg_match('/^#/', $line)) { continue; } if (!preg_match('/^\\s*(\\d+)\\s+(.*)/', $line, $items)) { logError("bad line syntax: {$line}"); continue; } debug("genre item", $items); $id = $items[1]; $name = trim($items[2]); $o1 = new sotf_NodeObject("sotf_genres"); $o1->setID($o1->makeId(0, $o1->tablename, $id . $language)); $o1->set('genre_id', $id); $o1->set('language', $language); $o1->set('name', $name); $o1->create(); } }
if (!$roleSelected) { raiseError("No role selected!"); } // save if (is_object($role)) { $role->set('contact_id', $contactId); $role->set('role_id', $roleSelected); $role->update(); } else { if (sotf_ComplexNodeObject::findRole($objectId, $contactId, $roleSelected)) { // this role already exists $page->addStatusMsg("role_exists"); $page->redirectSelf(); } $role = new sotf_NodeObject("sotf_object_roles"); $role->set('object_id', $objectId); $role->set('contact_id', $contactId); $role->set('role_id', $roleSelected); $role->create(); } $page->redirect("closeAndRefresh.php?anchor=roles"); } // general data $obj =& $repository->getObject($objectId); $smarty->assign("OBJECT_ID", $objectId); $smarty->assign("STATION_ID", $obj->getStationId()); $smarty->assign("ROLE_ID", $roleId); $smarty->assign('ROLE_LIST', $vocabularies->getRoles()); if (!$scope) { $scope = 1; }
/** static: create contact record from metadata */ function importContact($contactData, $contactRole, $prgId, $stationId, $admins) { global $db, $permissions, $repository, $vocabularies, $config; $db->begin(); // find out what should go into the 'name' field if ($contactData['type'] == 'organisation') { $name = $contactData['organizationname']; } elseif ($contactData['type'] == 'individual') { $name = $contactData['firstname'] . ' ' . $contactData['lastname']; } else { logError("unknown type of contact: " . $contactData['type']); return null; } // if not exists, create new contact $id = sotf_Contact::findByNameLocal($name); if (!$id) { $contact = new sotf_Contact(); $status = $contact->create($name, $stationId); if (!$status) { //$page->addStatusMsg('contact_create_failed'); return null; } // add permissions for all station admins (??) while (list(, $adminId) = each($admins)) { $permissions->addPermission($contact->id, $adminId, 'admin'); } } else { $contact = $repository->getObject($id); } //debug("contactData", $contactData); // set/update contact data $contact->set('acronym', $contactData['organizationacronym']); $contact->set('alias', $contactData['alias']); $contact->set('url', $contactData['uri']); $contact->set('email', $contactData['email']); $contact->set('address', $contactData['address']); $contact->update(); // determine role if ($contactData['role']) { $language = 'eng'; // for now $rid = $vocabularies->getRoleId($contactData['role'], $language); if ($rid) { $contactRole = $rid; } } // create role if (!sotf_ComplexNodeObject::findRole($prgId, $contact->id, $contactRole)) { $role = new sotf_NodeObject("sotf_object_roles"); $role->set('object_id', $prgId); $role->set('contact_id', $contact->id); $role->set('role_id', $contactRole); $role->create(); } $db->commit(); // fetch logo from url and store if (!empty($contactData['logo'])) { $url = $contactData['logo']; if ($handle = @fopen($url, 'rb')) { $contents = ""; while (!feof($handle)) { $contents .= fread($handle, 8192); } /* do { $data = fread ($handle, 100000); if (strlen($data) == 0) { break; } //debug("received", strlen($data)); $contents .= $data; } while(0); */ fclose($handle); $tmpFile = tempnam($config['tmpDir'], 'logo_u'); debug("received logo from", $url); sotf_Utils::save($tmpFile, $contents); chmod($tmpFile, 0660); $contact->setIcon($tmpFile); unlink($tmpFile); } else { logError("Could not fetch icon from {$url}"); } } return $contact->id; }
function addToTopic($progId, $topicId) { global $db; // TODO: ha mar van, akkor ne adja hozza $query = "SELECT id FROM sotf_prog_topics WHERE prog_id = '" . $progId . "' AND topic_id = '" . $topicId . "'"; $result = $db->getAll($query); if (count($result) == 0) { $x = new sotf_NodeObject("sotf_prog_topics"); $x->set('prog_id', $progId); $x->set('topic_id', $topicId); $x->create(); $query = "UPDATE sotf_topics_counter SET number = number+1 WHERE topic_id = '" . $topicId . "'"; $result = $db->query($query); $query = "SELECT supertopic FROM sotf_topic_tree_defs WHERE id = '" . $topicId . "'"; $supertopic = $db->getOne($query); if (!$supertopic) { $supertopic = $topicId; } $query = "UPDATE sotf_topics_counter SET total = total+1 WHERE topic_id = '" . $supertopic . "'"; $result = $db->query($query); } }
function processPortalEvent($event) { debug("processing event", $event); $progId = $event['prog_id']; if ($progId) { if ($this->looksLikeId($progId)) { $prg =& $this->getObject($progId); } if (!$prg) { debug("Invalid prog_id arrived in portal event", $progId); return -1; } } switch ($event['name']) { case 'programme_added': $obj = new sotf_NodeObject('sotf_prog_refs'); $obj->set('prog_id', $event['value']); $obj->set('url', $event['url']); $obj->find(); $obj->set('station_id', $prg->get('station_id')); $obj->set('start_date', $event['timestamp']); $obj->set('portal_name', $event['portal_name']); $obj->save(); break; case 'programme_deleted': $obj = new sotf_NodeObject('sotf_prog_refs'); $obj->set('prog_id', $event['value']); $obj->set('url', $event['url']); $obj->find(); if (!$obj->exists()) { debug("unknown prog ref arrives: " . $event['value'] . ' - ' . $event['url']); $obj->set('portal_name', $event['portal_name']); } $obj->set('station_id', $prg->get('station_id')); $obj->set('end_date', $event['timestamp']); //$obj->set('portal_name', $event['portal_name']); $obj->save(); break; case 'visit': $obj = new sotf_NodeObject('sotf_prog_refs'); $obj->set('prog_id', $event['value']['prog_id']); $obj->set('url', $event['url']); $obj->find(); if (!$obj->exists()) { // TODO: how can this happen? It happens too many times! debug("unknown prog ref arrives: " . $event['value']['prog_id'] . ' - ' . $event['url']); $obj->set('start_date', $event['timestamp']); $obj->set('portal_name', $event['portal_name']); } $obj->set('station_id', $prg->get('station_id')); $obj->set('visits', (int) $obj->get('visits') + 1); // TODO: count unique accesses $obj->save(); break; case 'page_impression': $obj = new sotf_NodeObject('sotf_portals'); $obj->set('url', $event['url']); $obj->find(); $obj->set('name', $event['portal_name']); $obj->set('page_impression', $event['value']); $obj->set('last_access', $event['timestamp']); $obj->save(); break; case 'portal_updated': $obj = new sotf_NodeObject('sotf_portals'); $obj->set('url', $event['url']); $obj->find(); $obj->set('name', $event['portal_name']); $obj->set('last_update', $event['timestamp']); $obj->save(); break; case 'users': $obj = new sotf_NodeObject('sotf_portals'); $obj->set('url', $event['url']); $obj->find(); if (!$obj->exists()) { $obj->set('name', $event['portal_name']); } $obj->set('last_update', $event['timestamp']); $obj->set('reg_users', $event['value']); if (!$obj->get('name') || !$obj->get('url')) { logError("Bad portal even teceived", implode(" | ", $event)); } else { $obj->save(); } break; case 'rating': // first save in prog_refs $obj = new sotf_NodeObject('sotf_prog_refs'); $obj->set('prog_id', $event['value']['prog_id']); $obj->set('url', $event['url']); $obj->find(); if (!$obj->exists()) { debug("unknown prog ref arrives: " . $event['url']); $obj->set('start_date', $event['timestamp']); $obj->set('portal_name', $event['portal_name']); } $obj->set('station_id', $prg->get('station_id')); $obj->set('rating', $event['value']['RATING_VALUE']); $obj->set('raters', $event['value']['RATING_COUNT']); $obj->save(); // TODO second, put into global rating database /* $rating = new sotf_Rating(); $id = $event['value']['prog_id']; $obj = & $this->getObject($id); if($obj->isLocal()) { $data = $event['value']; $rating->setRemoteRating($data); } else { logError("received rating for non-local object!"); } */ break; case 'comment': // first save in prog_refs $obj = new sotf_NodeObject('sotf_prog_refs'); $obj->set('prog_id', $event['value']['prog_id']); $obj->set('url', $event['url']); $obj->find(); if (!$obj->exists()) { logError("unknown prog ref arrives: " . $event['value']['prog_id'] . ' - ' . $event['url']); $obj->set('start_date', $event['timestamp']); $obj->set('portal_name', $event['portal_name']); } $obj->set('station_id', $prg->get('station_id')); $obj->set('comments', (int) $obj->get('comments') + 1); $obj->save(); // save comment $obj = new sotf_Object('sotf_comments'); $obj->set('prog_id', $event['value']['prog_id']); $obj->set('portal', $event['url']); $obj->set('entered', $event['timestamp']); $obj->set('comment_title', $event['value']['title']); $obj->set('comment_text', $event['value']['comment']); $obj->set('from_name', $event['value']['user_name']); $obj->set('from_email', $event['value']['email']); $obj->create(); // TODO forward to authors break; case 'query_added': //debug("query from portal", $event); //debug("query from portal", $event); case 'query_deleted': case 'file_uploaded': // silently ignored break; default: logError("unknown portal event: " . $event['name']); } }
$smarty->assign("RIGHTS_TEXT", $rights->get('rights_text')); } else { $newRight = 1; $smarty->assign('NEW', 1); } if ($save) { $startTime = sotf_Utils::getParameter('start_time'); $stopTime = sotf_Utils::getParameter('stop_time'); $rightsText = sotf_Utils::getParameter('rights_text'); $fullProg = sotf_Utils::getParameter('fullprog'); // save if ($newRight) { $rights = new sotf_NodeObject("sotf_rights"); } if ($fullProg) { $rights->set('start_time', null); $rights->set('stop_time', null); } else { // check input params if (!is_int($startTime) || !is_int($stopTime)) { raiseError("not_integer"); } $rights->set('start_time', $startTime); $rights->set('stop_time', $stopTime); } $rights->set('rights_text', $rightsText); if ($newRight) { $rights->set('prog_id', $objectId); $rights->create(); } else { $rights->update();
function addChild($parent, $name, $topic_name = "", $lang = "en", $treeId = 2) { $x = new sotf_NodeObject("sotf_topic_tree_defs"); $x->set('supertopic', $parent); $x->set('name', $name); $x->set('tree_id', $treeId); $x->create(); $id = $x->getID(); if ($topic_name != "") { $y = new sotf_NodeObject("sotf_topics"); $y->set('topic_id', $id); $y->set('language', $lang); $y->set('topic_name', $topic_name); $y->create(); //print($id); } return $x->getID(); }
/** Creates a deletion record: used when a replicated object is deleted. */ function createDeletionRecord() { $dr = new sotf_NodeObject('sotf_deletions'); $dr->set('del_id', $this->id); $dr->create(); }