Ejemplo n.º 1
0
 /**
  * Method to check a row in if the necessary properties/fields exist.  Checking
  * a row in will allow other users the ability to edit the row.
  *
  * @param   mixed  $pk  An optional primary key value to check out.  If not set the instance property value is used.
  *
  * @return  boolean  True on success.
  *
  * @link    http://docs.joomla.org/JTable/checkIn
  * @since   11.1
  */
 public function checkIn($pk = null)
 {
     // If there is no checked_out or checked_out_time field, just return true.
     if (!property_exists($this, 'checked_out') || !property_exists($this, 'checked_out_time')) {
         return true;
     }
     // 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 JException(JText::_('JLIB_DATABASE_ERROR_NULL_PRIMARY_KEY'));
         $this->setError($e);
         return false;
     }
     // Check the row in by primary key.
     $query = $this->_db->getQuery(true);
     $query->update($this->_tbl);
     $query->set($this->_db->quoteName('checked_out') . ' = 0');
     $query->set($this->_db->quoteName('checked_out_time') . ' = ' . $this->_db->quote($this->_db->getNullDate()));
     $query->where($this->_tbl_key . ' = ' . $this->_db->quote($pk));
     $this->_db->setQuery($query);
     // Check for a database error.
     if (!$this->_db->execute()) {
         $e = new JException(JText::sprintf('JLIB_DATABASE_ERROR_CHECKIN_FAILED', get_class($this), $this->_db->getErrorMsg()));
         $this->setError($e);
         return false;
     }
     // Set table values in the object.
     $this->checked_out = 0;
     $this->checked_out_time = '';
     return true;
 }
Ejemplo n.º 2
0
	/**
	 * Tests the JDatabase::getNullDate method.
	 *
	 * @return  void
	 *
	 * @since   11.4
	 */
	public function testGetNullDate()
	{
		$this->assertThat(
			$this->db->getNullDate(),
			$this->equalTo('1BC')
		);
	}
Ejemplo n.º 3
0
 /**
  * Get the null or zero representation of a timestamp for the database driver.
  * @param   boolean $quoted Optionally wraps the null date in database quotes (true by default).
  * @return  string  Null or zero representation of a timestamp.
  */
 public function nullDate($quoted = true)
 {
     $result = $this->db->getNullDate($quoted);
     if ($quoted) {
         return $this->db->quote($result);
     }
     return $result;
 }
Ejemplo n.º 4
0
 /**
  * Checks in a row
  *
  * @access	public
  * @param	mixed	The primary key value for the row
  * @return	boolean	True if successful, or if checkout is not supported
  */
 function checkin($oid = null)
 {
     if (!(in_array('checked_out', array_keys($this->getProperties())) || in_array('checked_out_time', array_keys($this->getProperties())))) {
         return true;
     }
     $k = $this->_tbl_key;
     if ($oid !== null) {
         $this->{$k} = $oid;
     }
     if ($this->{$k} == NULL) {
         return false;
     }
     $query = 'UPDATE ' . $this->_db->nameQuote($this->_tbl) . ' SET checked_out = 0, checked_out_time = ' . $this->_db->Quote($this->_db->getNullDate()) . ' WHERE ' . $this->_tbl_key . ' = ' . $this->_db->Quote($this->{$k});
     $this->_db->setQuery($query);
     $this->checked_out = 0;
     $this->checked_out_time = '';
     return $this->_db->query();
 }
Ejemplo n.º 5
0
 /**
  * Returns the zero date/time
  *
  * @param  string  $dateTime  'datetime', 'date', 'time'
  * @return string             Unquoted null/zero date string
  */
 public function getNullDate($dateTime = 'datetime')
 {
     return $this->formatDateOrTime($this->_db->getNullDate(), $dateTime);
 }
Ejemplo n.º 6
0
Archivo: user.php Proyecto: laiello/yrm
    function save_resources()
    {
        $db =& JFactory::getDBO();
        $cid = JRequest::getVar('cid');
        $times_access = JRequest::getInt('times_access', -1);
        $nowdate = JFactory::getDate();
        $str_now = JHTML::_('date', $nowdate->toMySQL(), '%Y-%m-%d %H:%M:%S');
        $str_nulldate = JDatabase::getNullDate();
        $start_date = JRequest::getVar('start_date', $str_now);
        $end_date = JRequest::getVar('end_date', $str_nulldate);
        $keep_original = JRequest::getInt('keep_original', 1);
        /*if (!is_array($cid)) {
        			return 0;
        		}*/
        //overwrite original
        if ($keep_original == 0) {
            //remove all current user's resources
            $query = "DELETE FROM `#__yos_resources_manager_user_resource_xref` \n\t\t\t\tWHERE `user_id` = " . $this->user->id;
            $db->setQuery($query);
            if (!$db->query()) {
                JError::raiseError(500, $db->getErrorMsg());
            }
            foreach ($cid as $res_id) {
                $query = "INSERT INTO `#__yos_resources_manager_user_resource_xref` SET \n\t\t\t\t\t`user_id` = " . $this->user->id . ', 
					`resource_id` = ' . intval($res_id) . ", \n\t\t\t\t\t`times_access` = {$times_access},\n\t\t\t\t\t`start` = '{$start_date}', \n\t\t\t\t\t`end` = '{$end_date}'";
                $db->setQuery($query);
                if (!$db->query()) {
                    JError::raiseError(500, $db->getErrorMsg());
                }
            }
            return 1;
        }
        //keep original
        //select all resource
        $query = "SELECT `id` FROM `#__yos_resources_manager_resource`";
        $db->setQuery($query);
        $arr_res = $db->loadResultArray();
        if (!count($arr_res)) {
            return 0;
        }
        foreach ($arr_res as $res_id) {
            if (!in_array($res_id, $cid)) {
                //remove this resource from user
                $query = "DELETE FROM `#__yos_resources_manager_user_resource_xref` \n\t\t\t\t\tWHERE `user_id` = " . $this->user->id . " AND `resource_id` = {$res_id}";
                $db->setQuery($query);
                if (!$db->query()) {
                    JError::raiseError(500, $db->getErrorMsg());
                }
            } else {
                //check is existing in database
                $query = "SELECT COUNT(id) FROM `#__yos_resources_manager_user_resource_xref`\n\t\t\t\t\tWHERE `user_id` = " . $this->user->id . " AND resource_id = {$res_id}";
                $db->setQuery($query);
                if (!$db->loadResult()) {
                    $query = "INSERT INTO `#__yos_resources_manager_user_resource_xref` SET \n\t\t\t\t\t\t`user_id` = " . $this->user->id . ', 
						`resource_id` = ' . intval($res_id) . ", \n\t\t\t\t\t\t`times_access` = {$times_access},\n\t\t\t\t\t\t`start` = '{$start_date}', \n\t\t\t\t\t\t`end` = '{$end_date}'";
                    $db->setQuery($query);
                    if (!$db->query()) {
                        JError::raiseError(500, $db->getErrorMsg());
                    }
                }
            }
        }
        return 1;
    }