Ejemplo n.º 1
0
 /**
  * Inserts a new row if id is zero or updates an existing row in the database table
  *
  * Can be overloaded/supplemented by the child class
  *
  * @access public
  * @param boolean If false, null object variables are not updated
  * @return null|string null if successful otherwise returns and error message
  */
 function store($updateNulls = false)
 {
     $k = $this->_tbl_key;
     if ($this->{$k}) {
         $ret = $this->_db->updateObject($this->_tbl, $this, $this->_tbl_key, $updateNulls);
     } else {
         //loading libraries
         $properties = $this->getProperties();
         //loading resources
         $user =& eFactory::getUser();
         //initializing object properties
         $this->_juser_id = $user->id;
         $this->{$k} = create_guid();
         if (array_key_exists('created_on', $properties)) {
             $this->created_on = date('Y-m-d H:i:s', time());
         }
         if ($ret = $this->_db->insertObject($this->_tbl, $this, $this->_tbl_key)) {
             $this->saveRelationship('juser');
         }
     }
     if (!$ret) {
         $this->setError(get_class($this) . '::store failed - ' . $this->_db->getErrorMsg());
         return false;
     } else {
         return true;
     }
 }
Ejemplo n.º 2
0
 /**
  * Default truncate method
  *
  * can be overloaded/supplemented by the child class
  *
  * @access public
  * @return true if successful otherwise returns and error message
  */
 function truncate()
 {
     $query = 'TRUNCATE ' . $this->_db->quoteName($this->_tbl);
     $this->_db->setQuery($query);
     if ($this->_db->query()) {
         return true;
     } else {
         $this->setError($this->_db->getErrorMsg());
         return false;
     }
 }
Ejemplo n.º 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;
 }
Ejemplo n.º 4
0
function jotcache_upgrade(JDatabase $db)
{
    $message = '';
    $query = $db->getQuery(true);
    $query->select('COUNT(*)')->from('#__jotcache_exclude')->where('type=1');
    $tplex_count = $db->setQuery($query)->loadResult();
    if ($tplex_count == 0) {
        return false;
    }
    $query->clear('where');
    $query->where('type=4');
    $count = $db->setQuery($query)->loadResult();
    if ($count == 0) {
        $query->clear('select')->clear('where');
        $query->select($db->quoteName('value'))->from($db->quoteName('#__template_styles', 's'))->where('name=s.id')->where('type=1')->order('s.home');
        $defs = $db->setQuery($query)->loadResultArray();
        $positions = array();
        foreach ($defs as $def) {
            $def_array = unserialize($def);
            $positions = array_merge($positions, $def_array);
        }
        $query->clear();
        $query->select('position')->from('#__modules')->where('client_id = 0')->where('published = 1')->where('position <>' . $db->quote(''))->group('position')->order('position');
        $db->setQuery($query);
        $items = $db->loadResultArray();
        $cleaned_positions = array();
        foreach ($items as $item) {
            if (array_key_exists($item, $positions)) {
                $cleaned_positions[$item] = $positions[$item];
            }
        }
        $defs = serialize($cleaned_positions);
        $query->clear();
        $query->insert('#__jotcache_exclude')->columns('name,value,type')->values('1,' . $db->quote($defs) . ',4');
        if ($db->setQuery($query)->query()) {
            $message = "TABLE #__jotcache_exclude has been upgraded. Check JotCache TPL exclude definitions for correct values.";
        } else {
            JError::raiseNotice(100, $db->getErrorMsg());
        }
        return $message;
    }
}
Ejemplo n.º 5
0
 /**
  * get exisiting records sets, optionally filtered by inn list
  *
  * @param string $table table suffix
  * @param array $filter array of inns or numbers
  * @return array of record objects
  */
 private function getExistingRecords($filter = array(), $table = "")
 {
     if ($table && $table == "_oldcert") {
         $fields = "id,number,adding_date";
         $wherefld = "number";
     } else {
         $fields = "id,inn,adding_date";
         $wherefld = "inn";
     }
     $sql = "SELECT {$fields} FROM #__sro{$table} ";
     if (!empty($filter)) {
         $numbers = implode(",", $filter);
         $sql .= " WHERE {$wherefld} IN ({$numbers})";
     }
     $this->_db->setQuery($sql);
     $result = $this->_db->loadObjectList($wherefld);
     if (is_null($result)) {
         $this->setError("Ошибка при загрузке существующих данных:" . $this->_db->getErrorMsg());
         return array();
     }
     return $result;
 }
Ejemplo n.º 6
0
	public function addItem(){
		
		$this->db->setQuery("
		
			Insert 
			Into 
				#__facileforms_integrator_items
			(
				rule_id,
				element_id,
				reference_column
			)
			Values
			(
				".$this->db->Quote(JRequest::getInt('id',-1)).",
				".$this->db->Quote(JRequest::getInt('element_id',-1)).",
				".$this->db->Quote(JRequest::getVar('reference_column',''))."
			)
		
		");
		$this->db->query();
		echo $this->db->getErrorMsg();
	}
Ejemplo n.º 7
0
 /**
  * Generic Publish/Unpublish function
  *
  * @access public
  * @param array An array of id numbers
  * @param integer 0 if unpublishing, 1 if publishing
  * @param integer The id of the user performnig the operation
  * @since 1.0.4
  */
 function publish($cid = null, $publish = 1, $user_id = 0)
 {
     JArrayHelper::toInteger($cid);
     $user_id = (int) $user_id;
     $publish = (int) $publish;
     $k = $this->_tbl_key;
     if (count($cid) < 1) {
         if ($this->{$k}) {
             $cid = array($this->{$k});
         } else {
             $this->setError("No items selected.");
             return false;
         }
     }
     $cids = $k . '=' . implode(' OR ' . $k . '=', $cid);
     $query = 'UPDATE ' . $this->_tbl . ' SET published = ' . (int) $publish . ' WHERE (' . $cids . ')';
     $checkin = in_array('checked_out', array_keys($this->getProperties()));
     if ($checkin) {
         $query .= ' AND (checked_out = 0 OR checked_out = ' . (int) $user_id . ')';
     }
     $this->_db->setQuery($query);
     if (!$this->_db->query()) {
         $this->setError($this->_db->getErrorMsg());
         return false;
     }
     if (count($cid) == 1 && $checkin) {
         if ($this->_db->getAffectedRows() == 1) {
             $this->checkin($cid[0]);
             if ($this->{$k} == $cid[0]) {
                 $this->published = $publish;
             }
         }
     }
     $this->setError('');
     return true;
 }
Ejemplo n.º 8
0
 /**
  * Restituisce l'ultimo messaggio di errore
  * @return string
  */
 public function getErrorMsg()
 {
     return $this->db->getErrorMsg();
 }
Ejemplo n.º 9
0
 public function addItem()
 {
     $this->db->setQuery("\n\t\t\n\t\t\tInsert \n\t\t\tInto \n\t\t\t\t#__facileforms_integrator_items\n\t\t\t(\n\t\t\t\trule_id,\n\t\t\t\telement_id,\n\t\t\t\treference_column\n\t\t\t)\n\t\t\tValues\n\t\t\t(\n\t\t\t\t" . $this->db->Quote(JRequest::getInt('id', -1)) . ",\n\t\t\t\t" . $this->db->Quote(JRequest::getInt('element_id', -1)) . ",\n\t\t\t\t" . $this->db->Quote(JRequest::getVar('reference_column', '')) . "\n\t\t\t)\n\t\t\n\t\t");
     $this->db->query();
     echo $this->db->getErrorMsg();
 }
Ejemplo n.º 10
0
 /**
  * Gets error message
  *
  * @deprecated 2.0 (use exceptions instead)
  *
  * @return string The error message for the most recent query
  */
 public function getErrorMsg()
 {
     return stripslashes($this->_db->getErrorMsg());
 }