Beispiel #1
0
 public function getNewItemid($id)
 {
     $query = 'SELECT k2_item_id,new_item_id,item_type from #__k2_recipe_map where k2_item_id =  ' . $id . ';';
     $query_set = $this->dbo->setQuery($query);
     $newitem = $this->dbo->loadObject();
     return $newitem;
 }
Beispiel #2
0
 /**
  * Method to load an object by primary id.
  *
  * @return  void
  *
  * @since   12.1
  * @throws  RuntimeException
  */
 protected function doLoad()
 {
     // Get the primary key.
     $primaryKey = $this->getTableKey('primary', 'primary');
     $primaryTable = $this->getTableExpression('primary');
     // Build the query object.
     $query = $this->db->getQuery(true);
     $query->select($this->getTableKeyExpression('primary', '*'));
     $query->from($primaryTable);
     $query->where($this->getTableKeyExpression('primary', 'primary') . ' = ' . (int) $this->{$primaryKey});
     // Get the subtables.
     $tables = $this->tables;
     unset($tables['primary']);
     // Add additional tables to the query.
     foreach ($tables as $alias => $table) {
         // Add the table select and join clauses.
         $query->select($this->getTableKeyExpression($alias, '*'));
         $query->join('INNER', $this->getTableExpression($alias));
     }
     // Get the content data.
     $this->db->setQuery($query);
     $data = $this->db->loadObject();
     // Check the type data.
     if (empty($data)) {
         throw new RuntimeException(JText::sprintf('JDATABASEOBJECT_NOT_FOUND', $this->{$primaryKey}, $primaryTable));
     }
     // Bind the data.
     $this->bind($data);
 }
Beispiel #3
0
 /**
  * Generic check for whether dependencies exist for this object in the database schema
  *
  * Can be overloaded/supplemented by the child class
  *
  * @param   mixed  $pk     An optional primary key value check the row for.  If not
  * set the instance property value is used.
  * @param   array  $joins  An optional array to compiles standard joins formatted like:
  * [label => 'Label', name => 'table name' , idfield => 'field', joinfield => 'field']
  *
  * @return  boolean  True on success.
  *
  * @deprecated    12.1
  * @link    http://docs.joomla.org/JTable/canDelete
  * @since   11.1
  */
 public function canDelete($pk = null, $joins = null)
 {
     // Deprecation warning.
     JLog::add('JTable::canDelete() is deprecated.', JLog::WARNING, 'deprecated');
     // Initialise variables.
     $k = $this->_tbl_key;
     $pk = is_null($pk) ? $this->{$k} : $pk;
     // If no primary key is given, return false.
     if ($pk === null) {
         return false;
     }
     if (is_array($joins)) {
         // Get a query object.
         $query = $this->_db->getQuery(true);
         // Setup the basic query.
         $query->select($this->_db->quoteName($this->_tbl_key));
         $query->from($this->_db->quoteName($this->_tbl));
         $query->where($this->_db->quoteName($this->_tbl_key) . ' = ' . $this->_db->quote($this->{$k}));
         $query->group($this->_db->quoteName($this->_tbl_key));
         // For each join add the select and join clauses to the query object.
         foreach ($joins as $table) {
             $query->select('COUNT(DISTINCT ' . $table['idfield'] . ') AS ' . $table['idfield']);
             $query->join('LEFT', $table['name'] . ' ON ' . $table['joinfield'] . ' = ' . $k);
         }
         // Get the row object from the query.
         $this->_db->setQuery((string) $query, 0, 1);
         $row = $this->_db->loadObject();
         // Check for a database error.
         if ($this->_db->getErrorNum()) {
             $this->setError($this->_db->getErrorMsg());
             return false;
         }
         $msg = array();
         $i = 0;
         foreach ($joins as $table) {
             $k = $table['idfield'] . $i;
             if ($row->{$k}) {
                 $msg[] = JText::_($table['label']);
             }
             $i++;
         }
         if (count($msg)) {
             $this->setError("noDeleteRecord" . ": " . implode(', ', $msg));
             return false;
         } else {
             return true;
         }
     }
     return true;
 }
Beispiel #4
0
 /**
  * Description
  *
  * @access public
  * @param $dirn
  * @param $where
  */
 function move($dirn, $where = '')
 {
     if (!in_array('ordering', array_keys($this->getProperties()))) {
         $this->setError(get_class($this) . ' does not support ordering');
         return false;
     }
     $k = $this->_tbl_key;
     $sql = "SELECT {$this->_tbl_key}, ordering FROM {$this->_tbl}";
     if ($dirn < 0) {
         $sql .= ' WHERE ordering < ' . (int) $this->ordering;
         $sql .= $where ? ' AND ' . $where : '';
         $sql .= ' ORDER BY ordering DESC';
     } else {
         if ($dirn > 0) {
             $sql .= ' WHERE ordering > ' . (int) $this->ordering;
             $sql .= $where ? ' AND ' . $where : '';
             $sql .= ' ORDER BY ordering';
         } else {
             $sql .= ' WHERE ordering = ' . (int) $this->ordering;
             $sql .= $where ? ' AND ' . $where : '';
             $sql .= ' ORDER BY ordering';
         }
     }
     $this->_db->setQuery($sql, 0, 1);
     $row = null;
     $row = $this->_db->loadObject();
     if (isset($row)) {
         $query = 'UPDATE ' . $this->_tbl . ' SET ordering = ' . (int) $row->ordering . ' WHERE ' . $this->_tbl_key . ' = ' . $this->_db->Quote($this->{$k});
         $this->_db->setQuery($query);
         if (!$this->_db->query()) {
             $err = $this->_db->getErrorMsg();
             JError::raiseError(500, $err);
         }
         $query = 'UPDATE ' . $this->_tbl . ' SET ordering = ' . (int) $this->ordering . ' WHERE ' . $this->_tbl_key . ' = ' . $this->_db->Quote($row->{$k});
         $this->_db->setQuery($query);
         if (!$this->_db->query()) {
             $err = $this->_db->getErrorMsg();
             JError::raiseError(500, $err);
         }
         $this->ordering = $row->ordering;
     } else {
         $query = 'UPDATE ' . $this->_tbl . ' SET ordering = ' . (int) $this->ordering . ' WHERE ' . $this->_tbl_key . ' = ' . $this->_db->Quote($this->{$k});
         $this->_db->setQuery($query);
         if (!$this->_db->query()) {
             $err = $this->_db->getErrorMsg();
             JError::raiseError(500, $err);
         }
     }
     return true;
 }
 protected function _removeAttachment($data)
 {
     $result = array();
     // only registered users when the board is online will endup here
     // $data has already been escaped as part of this class
     // TODO: Get attachment details
     $query = "SELECT a.*, m.*\n\t\t\tFROM #__kunena_attachments AS a\n\t\t\tJOIN #__kunena_messages AS m ON a.mesid = m.id\n\t\t\tWHERE a.id = '" . $data . "'";
     $this->_db->setQuery($query);
     $attachment = $this->_db->loadObject();
     if ($this->_db->getErrorNum()) {
         $result = array('status' => '-1', 'error' => KunenaError::getDatabaseError());
         return $result;
     }
     // Verify permissions, user must be author of the message this
     // attachment is attached to or be a moderator or admin of the site
     if ($attachment->userid != $this->_my->id && !CKunenaTools::isModerator($this->_my->id, $attachment->catid) && !CKunenaTools::isAdmin()) {
         // not the author, not a moderator, not an admin
         // nothing todo here - end with permission error
         $result = array('status' => '-1', 'error' => JText::_('COM_KUNENA_AJAX_PERMISSION_DENIED'));
         return $result;
     }
     // Request coming form valid user, moderator or admin...
     // First remove files from filsystem - check for thumbs and raw in case this is an image
     if (file_exists(JPATH_ROOT . $attachment->folder . $attachment->filename)) {
         JFile::delete(JPATH_ROOT . $attachment->folder . $attachment->filename);
     }
     if (file_exists(JPATH_ROOT . $attachment->folder . '/raw/' . $attachment->filename)) {
         JFile::delete(JPATH_ROOT . $attachment->folder . '/raw/' . $attachment->filename);
     }
     if (file_exists(JPATH_ROOT . $attachment->folder . '/thumb/' . $attachment->filename)) {
         JFile::delete(JPATH_ROOT . $attachment->folder . '/thumb/' . $attachment->filename);
     }
     // Finally delete attachment record from db
     $query = "DELETE FROM #__kunena_attachments AS a\n\t\t\t\t\tWHERE a.id = {$this->_db->Quote($data)}";
     $this->_db->setQuery($query);
     $this->_db->query();
     if ($this->_db->getErrorNum()) {
         $result = array('status' => '-1', 'error' => KunenaError::getDatabaseError());
     } else {
         $result = array('status' => '1', 'error' => JText::_('COM_KUNENA_AJAX_ATTACHMENT_DELETED'));
     }
     return $result;
 }
 /**
  * This global function loads the first row of a query into an object
  *
  * If an object is passed to this function, the returned row is bound to the existing elements of <var>object</var>.
  * If <var>object</var> has a value of null, then all of the returned query fields returned in the object.
  * @param  object|\stdClass  $object
  * @return boolean          Success
  *
  * @throws  \RuntimeException
  */
 public function loadObject(&$object)
 {
     if ($object === null) {
         $object = $this->_db->loadObject();
         return is_object($object);
     }
     $array = $this->_db->loadAssoc();
     if (!is_array($array)) {
         return false;
     }
     foreach (get_object_vars($object) as $k => $v) {
         if (substr($k, 0, 1) != '_') {
             if (array_key_exists($k, $array)) {
                 $object->{$k} = $array[$k];
             }
         }
     }
     return true;
 }
Beispiel #7
0
 /**
  * Generic check for whether dependancies exist for this object in the db schema
  *
  * can be overloaded/supplemented by the child class
  *
  * @access public
  * @param string $msg Error message returned
  * @param int Optional key index
  * @param array Optional array to compiles standard joins: format [label=>'Label',name=>'table name',idfield=>'field',joinfield=>'field']
  * @return true|false
  */
 function canDelete($oid = null, $joins = null)
 {
     $k = $this->_tbl_key;
     if ($oid) {
         $this->{$k} = intval($oid);
     }
     if (is_array($joins)) {
         $select = "{$k}";
         $join = "";
         foreach ($joins as $table) {
             $select .= ', COUNT(DISTINCT ' . $table['idfield'] . ') AS ' . $table['idfield'];
             $join .= ' LEFT JOIN ' . $table['name'] . ' ON ' . $table['joinfield'] . ' = ' . $k;
         }
         $query = 'SELECT ' . $select . ' FROM ' . $this->_tbl . $join . ' WHERE ' . $k . ' = ' . $this->_db->Quote($this->{$k}) . ' GROUP BY ' . $k;
         $this->_db->setQuery($query);
         if (!($obj = $this->_db->loadObject())) {
             $this->setError($this->_db->getErrorMsg());
             return false;
         }
         $msg = array();
         $i = 0;
         foreach ($joins as $table) {
             $k = $table['idfield'] . $i;
             if ($obj->{$k}) {
                 $msg[] = JText::_($table['label']);
             }
             $i++;
         }
         if (count($msg)) {
             $this->setError("noDeleteRecord" . ": " . implode(', ', $msg));
             return false;
         } else {
             return true;
         }
     }
     return true;
 }
Beispiel #8
0
 /**
  * Execute a query to the database and load the result returned as an object
  *
  * The result returned by this method is the same as the one returned by JDatabase::loadObject()
  * Basically, it returns the first result of a database operation as an object
  * Generally used for SELECT fields operations
  *
  * @param string $query The query to be executed
  *
  * @return object The result of the query
  *
  * @throws RuntimeException
  *
  * @since 1.0.0
  */
 public function queryObject($query)
 {
     // query database table
     $this->_database->setQuery($query);
     return $this->_database->loadObject();
 }