/** * 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; }
/** * Create a new record * * @return void */ public function saveTask() { // Check for request forgeries Request::checkToken(); // Incoming $fields = Request::getVar('fields', array(), 'post'); $no_html = Request::getInt('no_html', 0); $tmpl = Request::getVar('component', ''); $row = new Query($this->database); if (!$row->bind($fields)) { if (!$no_html && $tmpl != 'component') { $this->setError($row->getError()); $this->editTask($row); } else { echo $row->getError(); } return; } // Check content if (!$row->check()) { if (!$no_html && $tmpl != 'component') { $this->setError($row->getError()); $this->editTask($row); } else { echo $row->getError(); } return; } // Store new content if (!$row->store()) { if (!$no_html && $tmpl != 'component') { $this->setError($row->getError()); $this->editTask($row); } else { echo $row->getError(); } return; } $row->reorder('folder_id=' . $this->database->Quote($row->folder_id)); if (!$no_html && $tmpl != 'component') { // Output messsage and redirect App::redirect(Route::url('index.php?option=' . $this->_option . '&controller=' . $this->_controller, false), Lang::txt('COM_SUPPORT_QUERY_SUCCESSFULLY_SAVED')); } else { $this->listTask(); } }
/** * Create a new record * * @return void */ public function saveTask() { // Check for request forgeries Request::checkToken(); // Incoming $fields = Request::getVar('fields', array(), 'post'); $no_html = Request::getInt('no_html', 0); $tmpl = Request::getVar('component', ''); $row = new Query($this->database); if (!$row->bind($fields)) { if (!$no_html && $tmpl != 'component') { $this->setError($row->getError()); $this->editTask($row); } else { echo $row->getError(); } return; } // Check content if (!$row->check()) { if (!$no_html && $tmpl != 'component') { $this->setError($row->getError()); $this->editTask($row); } else { echo $row->getError(); } return; } // Store new content if (!$row->store()) { if (!$no_html && $tmpl != 'component') { $this->setError($row->getError()); $this->editTask($row); } else { echo $row->getError(); } return; } if (!$no_html && $tmpl != 'component') { // Output messsage and redirect App::redirect(Route::url('index.php?option=' . $this->_option . '&controller=tickets&task=display&show=' . $row->id, false)); } else { $this->listTask(); } }