예제 #1
0
파일: queries.php 프로젝트: vanie3/appland
 public function remove()
 {
     // Check for request forgeries
     MRequest::checkToken() or jexit('Invalid Token');
     $cid = MRequest::getVar('cid', array(), '', 'array');
     MArrayHelper::toInteger($cid);
     $msg = '';
     for ($i = 0, $n = count($cid); $i < $n; $i++) {
         $query = MTable::getInstance('Query', 'Table');
         if (!$query->delete($cid[$i])) {
             $msg .= $query->getError();
             $tom = "error";
         } else {
             $msg = MTEXT::_('COM_MIWOSQL_QUERY_DELETED');
             $tom = "";
         }
     }
     $this->setRedirect('index.php?option=com_miwosql&controller=queries', $msg, $tom);
 }
예제 #2
0
파일: model.php 프로젝트: vanie3/appland
 protected function _createTable($name, $prefix = 'Table', $config = array())
 {
     // Clean the model name
     $name = preg_replace('/[^A-Z0-9_]/i', '', $name);
     $prefix = preg_replace('/[^A-Z0-9_]/i', '', $prefix);
     // Make sure we are returning a DBO object
     if (!array_key_exists('dbo', $config)) {
         $config['dbo'] = $this->getDbo();
     }
     return MTable::getInstance($name, $prefix, $config);
 }
예제 #3
0
파일: queries.php 프로젝트: vanie3/appland
 function saveQuery($post)
 {
     $row = MTable::getInstance('Query', 'Table');
     // Bind the form fields to the web link table
     if (!$row->bind($post)) {
         $this->setError($this->_db->getErrorMsg());
         return false;
     }
     // Make sure the web link table is valid
     if (!$row->check()) {
         $this->setError($this->_db->getErrorMsg());
         return false;
     }
     // Store the web link table to the database
     if (!$row->store()) {
         $this->setError($this->_db->getErrorMsg());
         return false;
     }
     return true;
     return;
 }
예제 #4
0
 public function delete($pk = null, $children = true)
 {
     $k = $this->_tbl_key;
     $pk = is_null($pk) ? $this->{$k} : $pk;
     if (!$this->_lock()) {
         return false;
     }
     if ($this->_trackAssets) {
         $name = $this->_getAssetName();
         $asset = MTable::getInstance('Asset');
         if (!$asset->_lock()) {
             return false;
         }
         if ($asset->loadByName($name)) {
             if (!$asset->delete(null, $children)) {
                 $this->setError($asset->getError());
                 $asset->_unlock();
                 return false;
             }
             $asset->_unlock();
         } else {
             $this->setError($asset->getError());
             $asset->_unlock();
             return false;
         }
     }
     if (!($node = $this->_getNode($pk))) {
         $this->_unlock();
         return false;
     }
     if ($children) {
         $query = $this->_db->getQuery(true);
         $query->delete();
         $query->from($this->_tbl);
         $query->where('lft BETWEEN ' . (int) $node->lft . ' AND ' . (int) $node->rgt);
         $this->_runQuery($query, 'MLIB_DATABASE_ERROR_DELETE_FAILED');
         $query = $this->_db->getQuery(true);
         $query->update($this->_tbl);
         $query->set('lft = lft - ' . (int) $node->width);
         $query->where('lft > ' . (int) $node->rgt);
         $this->_runQuery($query, 'MLIB_DATABASE_ERROR_DELETE_FAILED');
         $query = $this->_db->getQuery(true);
         $query->update($this->_tbl);
         $query->set('rgt = rgt - ' . (int) $node->width);
         $query->where('rgt > ' . (int) $node->rgt);
         $this->_runQuery($query, 'MLIB_DATABASE_ERROR_DELETE_FAILED');
     } else {
         $query = $this->_db->getQuery(true);
         $query->delete();
         $query->from($this->_tbl);
         $query->where('lft = ' . (int) $node->lft);
         $this->_runQuery($query, 'MLIB_DATABASE_ERROR_DELETE_FAILED');
         $query = $this->_db->getQuery(true);
         $query->update($this->_tbl);
         $query->set('lft = lft - 1');
         $query->set('rgt = rgt - 1');
         $query->set('level = level - 1');
         $query->where('lft BETWEEN ' . (int) $node->lft . ' AND ' . (int) $node->rgt);
         $this->_runQuery($query, 'MLIB_DATABASE_ERROR_DELETE_FAILED');
         $query = $this->_db->getQuery(true);
         $query->update($this->_tbl);
         $query->set('parent_id = ' . (int) $node->parent_id);
         $query->where('parent_id = ' . (int) $node->{$k});
         $this->_runQuery($query, 'MLIB_DATABASE_ERROR_DELETE_FAILED');
         $query = $this->_db->getQuery(true);
         $query->update($this->_tbl);
         $query->set('lft = lft - 2');
         $query->where('lft > ' . (int) $node->rgt);
         $this->_runQuery($query, 'MLIB_DATABASE_ERROR_DELETE_FAILED');
         $query = $this->_db->getQuery(true);
         $query->update($this->_tbl);
         $query->set('rgt = rgt - 2');
         $query->where('rgt > ' . (int) $node->rgt);
         $this->_runQuery($query, 'MLIB_DATABASE_ERROR_DELETE_FAILED');
     }
     $this->_unlock();
     return true;
 }
예제 #5
0
파일: admin.php 프로젝트: vanie3/appland
 protected function batchMove($value, $pks, $contexts)
 {
     $categoryId = (int) $value;
     $table = $this->getTable();
     // Check that the category exists
     if ($categoryId) {
         $categoryTable = MTable::getInstance('Category');
         if (!$categoryTable->load($categoryId)) {
             if ($error = $categoryTable->getError()) {
                 // Fatal error
                 $this->setError($error);
                 return false;
             } else {
                 $this->setError(MText::_('MLIB_APPLICATION_ERROR_BATCH_MOVE_CATEGORY_NOT_FOUND'));
                 return false;
             }
         }
     }
     if (empty($categoryId)) {
         $this->setError(MText::_('MLIB_APPLICATION_ERROR_BATCH_MOVE_CATEGORY_NOT_FOUND'));
         return false;
     }
     // Check that user has create and edit permission for the component
     $extension = MFactory::getApplication()->input->get('option', '');
     $user = MFactory::getUser();
     if (!$user->authorise('core.create', $extension . '.category.' . $categoryId)) {
         $this->setError(MText::_('MLIB_APPLICATION_ERROR_BATCH_CANNOT_CREATE'));
         return false;
     }
     // Parent exists so we let's proceed
     foreach ($pks as $pk) {
         if (!$user->authorise('core.edit', $contexts[$pk])) {
             $this->setError(MText::_('MLIB_APPLICATION_ERROR_BATCH_CANNOT_EDIT'));
             return false;
         }
         // Check that the row actually exists
         if (!$table->load($pk)) {
             if ($error = $table->getError()) {
                 // Fatal error
                 $this->setError($error);
                 return false;
             } else {
                 // Not fatal error
                 $this->setError(MText::sprintf('MLIB_APPLICATION_ERROR_BATCH_MOVE_ROW_NOT_FOUND', $pk));
                 continue;
             }
         }
         // Set the new category ID
         $table->catid = $categoryId;
         // Check the row.
         if (!$table->check()) {
             $this->setError($table->getError());
             return false;
         }
         // Store the row.
         if (!$table->store()) {
             $this->setError($table->getError());
             return false;
         }
     }
     // Clean the cache
     $this->cleanCache();
     return true;
 }
예제 #6
0
파일: table.php 프로젝트: vanie3/appland
 public function delete($pk = null)
 {
     // Initialise variables.
     $k = $this->_tbl_key;
     $pk = is_null($pk) ? $this->{$k} : $pk;
     // If no primary key is given, return false.
     if ($pk === null) {
         $e = new MException(MText::_('MLIB_DATABASE_ERROR_NULL_PRIMARY_KEY'));
         $this->setError($e);
         return false;
     }
     // If tracking assets, remove the asset first.
     if ($this->_trackAssets) {
         // Get and the asset name.
         $this->{$k} = $pk;
         $name = $this->_getAssetName();
         $asset = MTable::getInstance('Asset');
         if ($asset->loadByName($name)) {
             if (!$asset->delete()) {
                 $this->setError($asset->getError());
                 return false;
             }
         } else {
             $this->setError($asset->getError());
             return false;
         }
     }
     // Delete the row by primary key.
     $query = $this->_db->getQuery(true);
     $query->delete();
     $query->from($this->_tbl);
     $query->where($this->_tbl_key . ' = ' . $this->_db->quote($pk));
     $this->_db->setQuery($query);
     // Check for a database error.
     if (!$this->_db->execute()) {
         $e = new MException(MText::sprintf('MLIB_DATABASE_ERROR_DELETE_FAILED', get_class($this), $this->_db->getErrorMsg()));
         $this->setError($e);
         return false;
     }
     return true;
 }