Example #1
0
 public function saveAction()
 {
     $userid = $this->getUserId();
     $datestr = gmdate("Y-m-d\\TH:i:s\\Z");
     $this->disableLayout();
     $mashupData = $this->getRequest()->getParam(MashupController::MASHUP_DATA, false);
     $mashupMeta = $this->getRequest()->getParam(MashupController::MASHUP_META, false);
     if (!$mashupData || !$mashupMeta) {
         $this->sendError("Usage: POST me some data in " . MashupController::MASHUP_META . " and " . MashupController::MASHUP_DATA);
     }
     $mashupUri = $mashupMeta['uri'];
     $updateMode = false;
     if (!empty($mashupUri)) {
         // existing mashup
         // load it
         $m = $this->getLA()->loadMashup($mashupUri);
         if ($m == null) {
             $this->sendError("Failed to load mashup " . $mashupUri);
         }
         $m->setTitle($mashupMeta['title']);
         // change title
         $m->setModifyDate($datestr);
         $updateMode = true;
     } else {
         // new mashup
         $m = new Mashup($this->getLA()->getURIForTitle($mashupMeta['title'], LOOMP::MASHUP()), $userid, $datestr, $datestr, $mashupMeta['title'], array());
     }
     // rights check
     if ($updateMode && $m->getCreatorId() != $this->getUserId() && $this->view->user['type'] != "admin") {
         $this->sendError("You have no rights to edit " . $m->getUri());
     }
     $fragments = array();
     // add fragments
     foreach ($mashupData as $fragment) {
         $fragmentUri = @$fragment['uri'];
         if (!empty($fragmentUri)) {
             // existing fragment
             $f = $this->getLA()->loadFragment($fragmentUri);
             if ($f == null) {
                 $this->sendError("Failed to find fragment " . $fragmentUri . " in mashup " . $mashupUri);
             }
             $f->setTitle($fragment['title']);
             $f->setContent($fragment['content']);
             $f->setModifyDate($datestr);
             //2002-05-30T09:30:10Z
         } else {
             // new fragment
             $class = "Fragment_" . $fragment['type'];
             $f = new $class($this->getLA()->getURIForTitle($fragment['title'], LOOMP::FRAGMENT()), $userid, $datestr, $datestr, $fragment['title'], $fragment['content'], $fragment['type']);
         }
         $fragments[$fragment['order']] = $f;
     }
     $deletedFragments = array();
     if ($updateMode) {
         $oldFragments = $m->getFragments();
         foreach ($oldFragments as $fragment) {
             if (!in_array($fragment, $fragments)) {
                 $deletedFragments[] = $fragment;
             }
         }
     }
     $m->setFragments($fragments);
     //print_r($m);
     $this->getLA()->saveMashup($m, $deletedFragments) or $this->sendError("Failed to save Mashup " . $mashupUri);
     foreach ($m->getFragments() as $fragment) {
         searchUpdateFragment($fragment);
     }
     // print preview link for usage in frontend
     if ($updateMode) {
         $this->getLog()->info("Mashup " . $m->getUri() . " updated");
     } else {
         $this->getLog()->info("Mashup " . $m->getUri() . " created");
     }
     print $m->getUri();
 }
Example #2
0
 /**
  * Count all associations of the given fragment uri with mashups from the RDF Store
  *
  * @param string	$uri	Fragment URI
  * @return integer
  */
 private function _fragmentCount($uri)
 {
     $queryString = "SELECT ?mashup " . "WHERE " . "(?mashup ?p <" . $uri . ">) " . "(?mashup rdf:type <" . LOOMP::MASHUP()->getURI() . ">) ";
     $r = $this->rdfModel->rdqlQuery($queryString);
     // this workaround was needed due to a strange behavior of the rdqlDBengine.
     // this solution is stable even if there is no bug in the engine.
     if (count($r) == 1 && $r[0]['?mashup'] == NULL) {
         return 0;
     }
     return count($r);
 }