Example #1
0
 /**
  * Remove a folder
  *
  * @return  void
  */
 public function saveorderingTask()
 {
     // Check for request forgeries
     Request::checkToken(['get', 'post']);
     // Incoming
     $folders = Request::getVar('folder', array());
     $queries = Request::getVar('queries', array());
     if (is_array($folders)) {
         foreach ($folders as $key => $folder) {
             $row = new QueryFolder($this->database);
             $row->load(intval($folder));
             $row->ordering = $key + 1;
             $row->store();
         }
     }
     if (is_array($queries)) {
         $folder = null;
         $i = 0;
         foreach ($queries as $query) {
             $bits = explode('_', $query);
             $fd = intval($bits[0]);
             $id = intval($bits[1]);
             if ($fd != $folder) {
                 $folder = $fd;
                 $i = 0;
             }
             $row = new Query($this->database);
             $row->load($id);
             $row->folder_id = $fd;
             $row->ordering = $i + 1;
             $row->store();
             $i++;
         }
     }
     if (!$no_html) {
         // Output messsage and redirect
         App::redirect(Route::url('index.php?option=' . $this->_option . '&controller=' . $this->_controller, false), Lang::txt('COM_SUPPORT_QUERY_FOLDER_SUCCESSFULLY_REMOVED'));
     }
     $response = new stdClass();
     $response->success = 1;
     $response->message = Lang::txt('COM_SUPPORT_QUERY_FOLDER_ORDERING_UPDATED');
     echo json_encode($response);
 }
Example #2
0
 /**
  * Clone core folders and queries and assign
  * them to a given user ID
  *
  * @param   integer  $user_id  User ID
  * @return  array
  */
 public function cloneCore($user_id = 0)
 {
     // Get all the default folders
     $folders = $this->find('list', array('user_id' => 0, 'sort' => 'ordering', 'sort_Dir' => 'asc', 'iscore' => 1));
     $sq = new Query($this->_db);
     if (count($folders) <= 0) {
         $defaults = array(1 => array('Common', 'Mine', 'Custom'), 2 => array('Common', 'Mine'));
         foreach ($defaults as $iscore => $fldrs) {
             $i = 1;
             foreach ($fldrs as $fldr) {
                 $f = new self($this->_db);
                 $f->iscore = $iscore;
                 $f->title = $fldr;
                 $f->check();
                 $f->ordering = $i;
                 $f->user_id = 0;
                 $f->store();
                 switch ($f->alias) {
                     case 'common':
                         $j = $iscore == 1 ? $sq->populateDefaults('common', $f->id) : $sq->populateDefaults('commonnotacl', $f->id);
                         break;
                     case 'mine':
                         $sq->populateDefaults('mine', $f->id);
                         break;
                     default:
                         // Nothing for custom folder
                         break;
                 }
                 $i++;
                 if ($iscore == 1) {
                     $folders[] = $f;
                 }
             }
         }
     }
     $user_id = $user_id ?: User::get('id');
     $fid = 0;
     // Loop through each folder
     foreach ($folders as $k => $folder) {
         // Copy the folder for the user
         $stqf = new self($this->_db);
         $stqf->bind($folder);
         $stqf->created_by = $user_id;
         $stqf->created = Date::toSql();
         $stqf->id = null;
         $stqf->user_id = $user_id;
         $stqf->iscore = 0;
         $stqf->store();
         $queries = $sq->find('list', array('folder_id' => $folder->id));
         // Copy all the queries from the folder to the user
         foreach ($queries as $query) {
             $stq = new Query($this->_db);
             $stq->bind($query);
             $stq->created_by = $user_id;
             $stq->created = Date::toSql();
             $stq->id = null;
             $stq->user_id = $user_id;
             $stq->folder_id = $stqf->get('id');
             $stq->iscore = 0;
             $stq->store();
         }
         // If the folder is "custom", get its ID
         if ($folder->alias == 'custom') {
             $fid = $stqf->get('id');
         }
         $folders[$k] = $stqf;
     }
     if ($fid) {
         $this->_db->setQuery("UPDATE `#__support_queries` SET `folder_id`=" . $this->_db->quote($fid) . " WHERE `user_id`=" . $this->_db->quote($user_id) . " AND `iscore`=0 AND `folder_id`=0");
         $this->_db->query();
     }
     return $folders;
 }