コード例 #1
0
ファイル: model.php プロジェクト: nexgenta/weaver
 public function storedTransaction($db, $args)
 {
     $uuid = $args['uuid'];
     $json = $args['json'];
     $lazy = $args['lazy'];
     $data = $args['data'];
     $this->db->exec('DELETE FROM {weaver_core} WHERE "uuid" = ?', $uuid);
     $this->db->exec('DELETE FROM {weaver_storyref} WHERE "story" = ?', $uuid);
     if (isset($data['slug'])) {
         $data['tag'] = $data['slug'];
     }
     if (!isset($data['tags'])) {
         $data['tags'] = array();
     }
     $coreinfo = array('parent' => null);
     $storyrefs = array();
     if (isset($data['title'])) {
         $title = preg_replace('![^a-z0-9]!i', '-', strtolower(trim($data['title'])));
         while (substr($title, 0, 1) == '-') {
             $title = substr($title, 1);
         }
         while (substr($title, -1) == '-') {
             $title = substr($title, 0, -1);
         }
         while (strstr($title, '--') !== false) {
             $title = str_replace('--', '-', $title);
         }
         if (strlen($title)) {
             $coreinfo['title'] = $title;
             if (ctype_alpha($title[0])) {
                 $coreinfo['title_firstchar'] = $title[0];
             } else {
                 $coreinfo['title_firstchar'] = '*';
             }
         }
     }
     if (isset($data['universe'])) {
         $coreinfo['universe'] = $data['universe'];
     }
     if ($data['kind'] == 'story' && isset($data['events'])) {
         foreach ($data['events'] as $ev) {
             if (null !== ($edata = $this->dataForUUID($ev))) {
                 if (isset($edata['places'])) {
                     foreach ($edata['places'] as $thing) {
                         $storyrefs[] = array('uuid' => $ev, 'thing' => $thing, 'story' => $uuid);
                     }
                 }
                 if (isset($edata['agents'])) {
                     foreach ($edata['agents'] as $thing) {
                         $storyrefs[] = array('uuid' => $ev, 'thing' => $thing, 'story' => $uuid);
                     }
                 }
                 if (isset($edata['factors'])) {
                     foreach ($edata['factors'] as $thing) {
                         $storyrefs[] = array('uuid' => $ev, 'thing' => $thing, 'story' => $uuid);
                     }
                 }
                 $data['tags'][] = $ev;
             }
         }
     }
     if (isset($data['factors'])) {
         foreach ($data['factors'] as $factor) {
             $data['tags'][] = $factor;
         }
     }
     if (isset($data['agents'])) {
         foreach ($data['agents'] as $agent) {
             $data['tags'][] = $agent;
         }
     }
     if (isset($data['places'])) {
         foreach ($data['places'] as $place) {
             $data['tags'][] = $place;
         }
     }
     if (isset($data['notionalDate'])) {
         $coreinfo['notional_date'] = $data['notionalDate'];
     }
     if (count($coreinfo)) {
         $coreinfo['uuid'] = $uuid;
         $this->db->insert('weaver_core', $coreinfo);
     }
     if (count($storyrefs)) {
         foreach ($storyrefs as $ref) {
             $this->db->insert('weaver_storyref', $ref);
         }
     }
     $args['data'] = $data;
     return parent::storedTransaction($db, $args);
 }
コード例 #2
0
ファイル: model.php プロジェクト: nexgenta/media
 public function storedTransaction($db, $args)
 {
     $uuid = $args['uuid'];
     $json = $args['json'];
     $lazy = $args['lazy'];
     $data = $args['data'];
     $this->db->exec('DELETE FROM {media_core} WHERE "uuid" = ?', $uuid);
     if (!isset($data['iri'])) {
         $data['iri'] = array();
     }
     if (!isset($data['tags'])) {
         $data['tags'] = array();
     }
     if (isset($data['formats'])) {
         $this->addClassificationsTagList($data['tags'], $data['formats']);
     }
     if (isset($data['genres'])) {
         $this->addClassificationsTagList($data['tags'], $data['genres']);
     }
     if (isset($data['people'])) {
         $this->addClassificationsTagList($data['tags'], $data['people']);
     }
     if (isset($data['topics'])) {
         $this->addClassificationsTagList($data['tags'], $data['topics']);
     }
     if (isset($data['places'])) {
         $this->addClassificationsTagList($data['tags'], $data['places']);
     }
     if (isset($data['licenses'])) {
         $this->addClassificationsTagList($data['tags'], $data['licenses']);
     }
     if (isset($data['collections'])) {
         $this->addClassificationsTagList($data['tags'], $data['collections']);
     }
     if (isset($data['slug'])) {
         $data['tag'] = $data['slug'];
     }
     if (isset($data['curie'])) {
         if (is_array($data['curie'])) {
             foreach ($data['curie'] as $curie) {
                 $data['iri'][] = '[' . $curie . ']';
             }
         } else {
             $data['iri'][] = '[' . $data['curie'] . ']';
         }
     }
     if (isset($data['sameAs'])) {
         if (is_array($data['sameAs'])) {
             foreach ($data['sameAs'] as $iri) {
                 $data['iri'][] = $iri;
             }
         } else {
             $data['iri'][] = $iri;
         }
     }
     $coreinfo = array();
     if (isset($data['title'])) {
         $title = preg_replace('![^a-z0-9]!i', '-', strtolower(trim($data['title'])));
         while (substr($title, 0, 1) == '-') {
             $title = substr($title, 1);
         }
         while (substr($title, -1) == '-') {
             $title = substr($title, 0, -1);
         }
         while (strstr($title, '--') !== false) {
             $title = str_replace('--', '-', $title);
         }
         if (strlen($title)) {
             $coreinfo['title'] = $title;
             if (ctype_alpha($title[0])) {
                 $coreinfo['title_firstchar'] = $title[0];
             } else {
                 $coreinfo['title_firstchar'] = '*';
             }
         }
     }
     switch ($data['kind']) {
         case 'scheme':
             $data['iri'][] = '[scheme:' . $data['singular'] . ']';
             $data['iri'][] = '[scheme:' . $data['plural'] . ']';
             break;
         case 'resource':
             if (isset($data['version'])) {
                 $coreinfo['parent'] = $data['version'];
             }
             break;
         case 'version':
             if (isset($data['episode'])) {
                 $coreinfo['parent'] = $data['episode'];
             }
             break;
         case 'episode':
             if (isset($data['series'])) {
                 $coreinfo['parent'] = $data['series'];
             } else {
                 if (isset($data['show'])) {
                     $coreinfo['parent'] = $data['show'];
                 }
             }
             break;
         case 'series':
             if (isset($data['show'])) {
                 $coreinfo['parent'] = $data['show'];
             }
             break;
     }
     if (!isset($coreinfo['parent']) && array_key_exists('parent', $data) && isset($data['_refs']) && in_array('parent', $data['_refs'])) {
         $coreinfo['parent'] = $data['parent'];
     }
     if (!isset($coreinfo['parent'])) {
         /* Always set create a media_core row, so that parent IS NULL queries work */
         $coreinfo['parent'] = null;
     }
     if (count($coreinfo)) {
         $coreinfo['uuid'] = $uuid;
         $this->db->insert('media_core', $coreinfo);
     }
     $args['data'] = $data;
     return parent::storedTransaction($db, $args);
 }