Beispiel #1
0
     foreach ($EpTagIDs as $tid) {
         $AppearanceIDs = $CGDb->where('tid', $tid)->get('tagged', null, 'ponyid');
         foreach ($AppearanceIDs as $id) {
             $TaggedAppearanceIDs[$id['ponyid']] = true;
         }
     }
     $Appearances = $CGDb->where('ishuman', $Episode->isMovie)->where('"id" != 0')->orderBy('label', 'ASC')->get('appearances', null, 'id,label');
     $Sorted = array('unlinked' => array(), 'linked' => array());
     foreach ($Appearances as $a) {
         $Sorted[isset($TaggedAppearanceIDs[$a['id']]) ? 'linked' : 'unlinked'][] = $a;
     }
     Response::done($Sorted);
     break;
 case "setcgrelations":
     $AppearanceIDs = (new Input('ids', 'int[]', array(Input::IS_OPTIONAL => true, Input::CUSTOM_ERROR_MESSAGES => array(Input::ERROR_MISSING => 'Missing appearance ID list', Input::ERROR_INVALID => 'Appearance ID list is invalid'))))->out();
     $EpTagIDs = Episodes::getTagIDs($Episode);
     if (empty($EpTagIDs)) {
         Response::fail('The episode has no associated tag(s)!');
     }
     $EpTagIDs = implode(',', $EpTagIDs);
     $Tags = $CGDb->where("tid IN ({$EpTagIDs})")->orderByLiteral('char_length(name)', 'DESC')->getOne('tags', 'tid');
     $UseID = $Tags['tid'];
     if (!empty($AppearanceIDs)) {
         foreach ($AppearanceIDs as $id) {
             if (!$CGDb->where("tid IN ({$EpTagIDs})")->where('ponyid', $id)->has('tagged')) {
                 @$CGDb->insert('tagged', array('tid' => $UseID, 'ponyid' => $id));
             }
         }
         $CGDb->where('ponyid NOT IN (' . implode(',', $AppearanceIDs) . ')');
     }
     $CGDb->where("tid IN ({$EpTagIDs})")->delete('tagged');
Beispiel #2
0
 static function getAppearancesSectionHTML(Episode $Episode) : string
 {
     global $CGDb, $Color;
     $HTML = '';
     $EpTagIDs = Episodes::getTagIDs($Episode);
     if (!empty($EpTagIDs)) {
         $TaggedAppearances = $CGDb->rawQuery("SELECT p.id, p.label, p.private\n\t\t\t\tFROM tagged t\n\t\t\t\tLEFT JOIN appearances p ON t.ponyid = p.id\n\t\t\t\tWHERE t.tid IN (" . implode(',', $EpTagIDs) . ") && p.ishuman = ?\n\t\t\t\tORDER BY p.label", array($Episode->isMovie));
         if (!empty($TaggedAppearances)) {
             $hidePreviews = UserPrefs::get('ep_noappprev');
             $pages = CoreUtils::makePlural('page', count($TaggedAppearances));
             $HTML .= "<section class='appearances'><h2>Related <a href='/cg'>{$Color} Guide</a> {$pages}</h2>";
             $LINKS = '<ul>';
             $isStaff = Permission::sufficient('staff');
             foreach ($TaggedAppearances as $p) {
                 $safeLabel = Appearances::getSafeLabel($p);
                 if (Appearances::isPrivate($p, true)) {
                     $preview = "<span class='typcn typcn-" . ($isStaff ? 'lock-closed' : 'time') . " color-" . ($isStaff ? 'orange' : 'darkblue') . "'></span> ";
                 } else {
                     if ($hidePreviews) {
                         $preview = '';
                     } else {
                         $preview = Appearances::getPreviewURL($p);
                         $preview = "<img src='{$preview}' class='preview'>";
                     }
                 }
                 $LINKS .= "<li><a href='/cg/v/{$p['id']}-{$safeLabel}'>{$preview}{$p['label']}</a></li>";
             }
             $HTML .= "{$LINKS}</ul></section>";
         }
     }
     return $HTML;
 }