Ejemplo n.º 1
0
 /**
  * List all tags and allow searching
  *
  * @param SettingsController $Sender
  */
 public function settingsController_tagging_create($Sender, $Search = null, $Type = null, $Page = null)
 {
     $Sender->title('Tagging');
     $Sender->addSideMenu('settings/tagging');
     $Sender->addJSFile('tagadmin.js', 'plugins/Tagging');
     $SQL = Gdn::sql();
     // Get all tag types
     $TagModel = TagModel::instance();
     $TagTypes = $TagModel->getTagTypes();
     $Sender->Form->Method = 'get';
     $Sender->Form->InputPrefix = '';
     list($Offset, $Limit) = offsetLimit($Page, 100);
     $Sender->setData('_Limit', $Limit);
     if ($Search) {
         $SQL->like('FullName', $Search, 'right');
     }
     // This type doesn't actually exist, but it will represent the
     // blank types in the column.
     if (strtolower($Type) == 'tags') {
         $Type = '';
     }
     if (!$Search) {
         if ($Type !== null) {
             if ($Type === 'null') {
                 $Type = null;
             }
             $SQL->where('Type', $Type);
         } elseif ($Type == '') {
             $SQL->where('Type', '');
         }
     } else {
         $Type = 'Search Results';
         // This is made up, and exists so search results can be placed in
         // their own tab.
         $TagTypes[$Type] = array('key' => $Type);
     }
     $TagTypes = array_change_key_case($TagTypes, CASE_LOWER);
     // Store type for view
     $TagType = !empty($Type) ? $Type : 'Tags';
     $Sender->setData('_TagType', $TagType);
     // Store tag types
     $Sender->setData('_TagTypes', $TagTypes);
     // Determine if new tags can be added for the current type.
     $CanAddTags = !empty($TagTypes[$Type]['addtag']) && $TagTypes[$Type]['addtag'] ? 1 : 0;
     $CanAddTags &= CheckPermission('Plugins.Tagging.Add');
     $Sender->setData('_CanAddTags', $CanAddTags);
     $Data = $SQL->select('t.*')->from('Tag t')->orderBy('t.FullName', 'asc')->orderBy('t.CountDiscussions', 'desc')->limit($Limit, $Offset)->get()->resultArray();
     $Sender->setData('Tags', $Data);
     if ($Search) {
         $SQL->like('Name', $Search, 'right');
     }
     // Make sure search uses its own search type, so results appear
     // in their own tab.
     $Sender->Form->Action = url('/settings/tagging/?type=' . $TagType);
     // Search results pagination will mess up a bit, so don't provide a type
     // in the count.
     $RecordCountWhere = array('Type' => $Type);
     if ($Type == '') {
         $RecordCountWhere = array('Type' => '');
     }
     if ($Search) {
         $RecordCountWhere = array();
     }
     $Sender->setData('RecordCount', $SQL->getCount('Tag', $RecordCountWhere));
     $Sender->render('tagging', '', 'plugins/Tagging');
 }