示例#1
0
 /**
  * If table key (id) is NULL : inserts a new row
  * otherwise updates existing row in the database table
  *
  * Can be overridden or overloaded by the child class
  *
  * @param  boolean  $updateNulls  TRUE: null object variables are also updated, FALSE: not.
  * @return boolean                TRUE if successful otherwise FALSE
  *
  * @throws \RuntimeException
  */
 public function store($updateNulls = false)
 {
     $k = $this->_tbl_key;
     if ($this->default == 1) {
         // Ensures maximum 1 default entry: If this field is the new default field, set default to 0 to any other row which was default:
         $sql = 'UPDATE ' . $this->_db->NameQuote($this->_tbl) . ' SET ' . $this->_db->NameQuote('default') . ' = 0' . "\n WHERE " . $this->_db->NameQuote('default') . ' <> 0';
         if ($this->{$k} !== null) {
             // existing record, avoid changing it:
             $sql .= ' AND ' . $this->_db->NameQuote($this->_tbl_key) . ' <> ' . (int) $this->{$k};
         }
         $this->_db->query($sql);
     }
     // Fix HTML-editor messy addition of <p> or <div> in description which messes with translation keys:
     $this->description = $this->cleanEditorsTranslationJunk($this->description);
     // Parent handles ordering of new record without any ordering by giving it highest ordering (below 10000 which is our ordering limit):
     return parent::store($updateNulls);
 }
示例#2
0
 /**
  * If table key (id) is NULL : inserts a new row
  * otherwise updates existing row in the database table
  *
  * Can be overridden or overloaded by the child class
  *
  * @param  boolean  $updateNulls  TRUE: null object variables are also updated, FALSE: not.
  * @return boolean                TRUE if successful otherwise FALSE
  *
  * @throws \RuntimeException
  */
 public function store($updateNulls = false)
 {
     // Fix HTML-editor messy addition of <p> or <div> in description which messes with translation keys:
     $this->description = $this->cleanEditorsTranslationJunk($this->description);
     return parent::store($updateNulls);
 }
示例#3
0
	/**
	 * If table key (id) is NULL : inserts a new row
	 * otherwise updates existing row in the database table
	 *
	 * This override handles assigning orderings of new records if unset.
	 * Can be overridden or overloaded by the child class
	 *
	 * @param  boolean  $updateNulls  TRUE: null object variables are also updated, FALSE: not.
	 * @return boolean                TRUE if successful otherwise FALSE
	 *
	 * @throws \RuntimeException
	 */
	public function store( $updateNulls = false ) {
		global $_PLUGINS;

		$k						=	$this->_tbl_key;

		$_PLUGINS->loadPluginGroup( 'user' );

		$fieldHandler			=	new cbFieldHandler();

		// Reset the plugin id so it can be updated by _loadFieldXML
		$this->pluginid			=	null;

		$fieldXML				=	$fieldHandler->_loadFieldXML( $this );

		// Rename non-system, non-calcualted, non-unique fields to ensure proper DB name structure:
		if ( ( ! $this->sys ) && ( ! $this->calculated ) && ( ! ( $fieldXML && ( $fieldXML->attributes( 'unique' ) == 'true' ) ) ) ) {
			// Always use lowercase names:
			$name				=	strtolower( $this->name );
			// Replace cb prefix to be added later:
			$name				=	preg_replace( '/^cb_/', '', $name );
			// Replace all invalid characters:
			$name				=	preg_replace( '/[^a-zA-Z0-9_]+/', '', $name );
			// Replace duplicate underscores:
			$name				=	preg_replace( '/(_{2,})+/', '', $name );
			// Replace leading underscores:
			$name				=	preg_replace( '/^_/', '', $name );
			// Set the new name for this field; always:
			$this->name			=	'cb_' . $name;

			if ( $this->fieldid ) {
				$field			=	new FieldTable( $this->_db );

				$field->load( $this->fieldid  );

				// Check if existing fields name has changed:
				if ( $this->name != $field->name ) {
					$columns				=	$this->getTableColumns();

					// Rename the database columns for this field as the name changed (we need to loop them encase it has more than 1 column like image fields):
					foreach ( $columns as $column ) {
						$this->_db->renameColumn( $this->table, $column, str_replace( $field->name, $this->name, $column ) );
					}

					// Rebuild the tablecolumns so the field row knows about its new column names:
					$this->tablecolumns		=	implode( ',', $fieldHandler->getMainTableColumns( $this ) );
				}
			}
		}

		// Fix HTML-editor messy addition of <p> or <div> in description which messes with translation keys:
		$this->description		=	$this->cleanEditorsTranslationJunk( $this->description );

		if ( $this->$k ) {
			// Existing Field: Store and adapt comprofiler table using Xml description of field:
			$return				=	parent::store( $updateNulls );

			if ( $return ) {
				$return			=	$fieldHandler->adaptSQL( $this, true, false, true );
			}
		} else {
		 	// New Field: Check that there is no clash on the unique name:
			$query				=	'SELECT COUNT(*)'
								.	"\n FROM " . $this->_db->NameQuote( $this->_tbl )
								.	"\n WHERE " . $this->_db->NameQuote( 'name' ) . " = " . $this->_db->Quote( $this->name );
			$this->_db->setQuery( $query );
			if ( $this->_db->LoadResult() > 0 ) {
				$this->_error	=	CBTxt::T( 'THIS_FIELD_NAME_NAME_IS_ALREADY_IN_USE', 'The field name [name] is already in use!', array( '[name]' => $this->name ) );

				return false;
			}

			$this->table		=	$fieldHandler->getMainTable( $this );
			$this->tablecolumns	=	implode( ',', $fieldHandler->getMainTableColumns( $this ) );

			if ( ( $this->tablecolumns == '' ) && ( $this->searchable == 1 ) ) {
				// Fields with no columns can't be searched; lets make sure it's not toggled to be searchable:
				$this->searchable	=	0;
			}

			// This handles ordering field setting too:
			$return				=	parent::store( $updateNulls );

			if ( $return ) {
				$return			=	$fieldHandler->adaptSQL( $this );
			}
		}

		if ( $return && $this->$k && ( $this->_fieldvalues !== null ) ) {
			$fieldValues		=	( is_string( $this->_fieldvalues ) ? json_decode( $this->_fieldvalues, true ) : $this->_fieldvalues );

			// Delete all current field values and Insert new field values:
			$fieldValuesTable	=	new FieldValueTable( $this->_db );
			$fieldValuesTable->updateFieldValues( $this->$k, $fieldValues );
		}

		if ( ! $return ) {
			$this->_error		=	CBTxt::T( 'CLASS_STORE_FAILED_ERROR', '[class]::store failed: [error]', array( '[class]' => get_class( $this ), '[error]' => addslashes( str_replace( "\n", '\n', $this->_error . ' ' . $this->_db->getErrorMsg() ) ) ) );

			return false;
		} else {
			return true;
		}
	}
示例#4
0
	public function store( $updateNulls = false )
	{
		global $_CB_framework, $_PLUGINS;

		$new	=	( $this->get( 'id' ) ? false : true );

		if ( ! $new ) {
			$this->set( 'modified', $_CB_framework->getUTCDate() );

			$_PLUGINS->trigger( 'cbconsultations_onBeforeUpdateconsultation', array( &$this, &$this ) );
		} else {
			$this->set( 'created', $_CB_framework->getUTCDate() );

			$_PLUGINS->trigger( 'cbconsultations_onBeforeCreateconsultation', array( &$this, &$this ) );
		}

		if ( ! parent::store( $updateNulls ) ) {
			return false;
		}

		$this->updateOrder();

		if ( ! $new ) {
			$_PLUGINS->trigger( 'cbconsultations_onAfterUpdateconsultation', array( $this, $this ) );
		} else {
			$_PLUGINS->trigger( 'cbconsultations_onAfterCreateconsultation', array( $this, $this ) );
		}

		return true;
	}
示例#5
0
	/**
	 * @param bool $updateNulls
	 * @return bool
	 */
	public function store( $updateNulls = false )
	{
		global $_PLUGINS;

		$new	=	( $this->get( 'id' ) ? false : true );
		$old	=	new self();

		$this->set( 'value', cbutf8_strtolower( preg_replace( '/[^-a-zA-Z0-9_.]/', '', $this->get( 'value' ) ) ) );

		if ( ! $new ) {
			$old->load( (int) $this->get( 'id' ) );

			$_PLUGINS->trigger( 'activity_onBeforeUpdateEmote', array( &$this, $old ) );
		} else {
			$_PLUGINS->trigger( 'activity_onBeforeCreateEmote', array( &$this ) );
		}

		if ( ! parent::store( $updateNulls ) ) {
			return false;
		}

		if ( ! $new ) {
			$_PLUGINS->trigger( 'activity_onAfterUpdateEmote', array( $this, $old ) );
		} else {
			$_PLUGINS->trigger( 'activity_onAfterCreateEmote', array( $this ) );
		}

		return true;
	}
示例#6
0
	/**
	 * @param bool $updateNulls
	 * @return bool
	 */
	public function store( $updateNulls = false )
	{
		global $_PLUGINS;

		$new	=	( $this->get( 'id' ) ? false : true );
		$old	=	new self();

		if ( ! $new ) {
			$old->load( (int) $this->get( 'id' ) );

			$_PLUGINS->trigger( 'activity_onBeforeUpdateAction', array( &$this, $old ) );
		} else {
			$_PLUGINS->trigger( 'activity_onBeforeCreateAction', array( &$this ) );
		}

		if ( ! parent::store( $updateNulls ) ) {
			return false;
		}

		if ( ! $new ) {
			$_PLUGINS->trigger( 'activity_onAfterUpdateAction', array( $this, $old ) );
		} else {
			$_PLUGINS->trigger( 'activity_onAfterCreateAction', array( $this ) );
		}

		return true;
	}
示例#7
0
	/**
	 * @param bool $updateNulls
	 * @return bool
	 */
	public function store( $updateNulls = false )
	{
		global $_PLUGINS;

		$new	=	( $this->get( 'id' ) ? false : true );
		$old	=	new self();

		if ( ! $new ) {
			$old->load( (int) $this->get( 'id' ) );

			$_PLUGINS->trigger( 'gj_onBeforeUpdateCategory', array( &$this, $old ) );
		} else {
			$_PLUGINS->trigger( 'gj_onBeforeCreateCategory', array( &$this ) );
		}

		if ( ! parent::store( $updateNulls ) ) {
			return false;
		}

		if ( ! CBGroupJive::uploadImage( 'canvas', $this ) ) {
			return false;
		}

		if ( ! CBGroupJive::uploadImage( 'logo', $this ) ) {
			return false;
		}

		if ( ! parent::store( $updateNulls ) ) {
			return false;
		}

		if ( ! $new ) {
			$_PLUGINS->trigger( 'gj_onAfterUpdateCategory', array( $this, $old ) );
		} else {
			$_PLUGINS->trigger( 'gj_onAfterCreateCategory', array( $this ) );
		}

		return true;
	}
示例#8
0
	/**
	 * @param bool $updateNulls
	 * @return bool
	 */
	public function store( $updateNulls = false )
	{
		global $_CB_framework, $_PLUGINS;

		$new				=	( $this->get( 'id' ) ? false : true );
		$old				=	new self();

		$this->set( 'date', $this->get( 'date', Application::Database()->getUtcDateTime() ) );

		if ( ! $new ) {
			$old->load( (int) $this->get( 'id' ) );

			$_PLUGINS->trigger( 'gj_onBeforeUpdateGroup', array( &$this, $old ) );
		} else {
			$_PLUGINS->trigger( 'gj_onBeforeCreateGroup', array( &$this ) );
		}

		if ( ! parent::store( $updateNulls ) ) {
			return false;
		}

		if ( ! CBGroupJive::uploadImage( 'canvas', $this ) ) {
			return false;
		}

		if ( ! CBGroupJive::uploadImage( 'logo', $this ) ) {
			return false;
		}

		if ( ! parent::store( $updateNulls ) ) {
			return false;
		}

		// If the new owner doesn't match the previous then demote (frontend) or delete (backend) the previous:
		if ( $old->get( 'id' ) ) {
			if ( $old->get( 'user_id' ) != $this->get( 'user_id' ) ) {
				$previousUser	=	new UserTable();

				$previousUser->load( array( 'user_id' => (int) $old->get( 'user_id' ), 'group' => (int) $this->get( 'id' ) ) );

				if ( $previousUser->get( 'id' ) ) {
					if ( Application::Cms()->getClientId() ) {
						if ( ! $previousUser->delete() ) {
							$this->setError( $previousUser->getError() );

							return false;
						}
					} else {
						$previousUser->set( 'status', 1 );

						if ( ! $previousUser->store() ) {
							$this->setError( $previousUser->getError() );

							return false;
						}
					}
				}
			}
		}

		$user				=	new UserTable();

		$user->load( array( 'user_id' => (int) $this->get( 'user_id' ), 'group' => (int) $this->get( 'id' ) ) );

		// If the owner doesn't exist or isn't marked owner then create them or promote them to owner:
		if ( ( ! $user->get( 'id' ) ) || ( $user->get( 'status' ) != 4 ) ) {
			$user->set( 'user_id', (int) $this->get( 'user_id' ) );
			$user->set( 'group', (int) $this->get( 'id' ) );
			$user->set( 'status', 4 );

			if ( $user->getError() || ( ! $user->store() ) ) {
				$this->setError( $user->getError() );

				return false;
			}
		}

		// If the category is changed be sure to move the canvas and logo as needed:
		if ( $old->get( 'id' ) && ( $this->get( 'canvas' ) || $this->get( 'logo' ) ) && ( $old->get( 'category' ) != $this->get( 'category' ) ) ) {
			$basePath		=	$_CB_framework->getCfg( 'absolute_path' ) . '/images/comprofiler/plug_cbgroupjive';
			$oldPath		=	$basePath . '/' . (int) $old->get( 'category' ) . '/' . (int) $this->get( 'id' );
			$newPath		=	$basePath . '/' . (int) $this->get( 'category' ) . '/' . (int) $this->get( 'id' );

			if ( is_dir( $oldPath ) ) {
				CBGroupJive::createDirectory( $basePath, $this->get( 'category' ), $this->get( 'id' ) );
				CBGroupJive::copyDirectory( $oldPath, $newPath, true );
			}
		}

		if ( ! $new ) {
			$_PLUGINS->trigger( 'gj_onAfterUpdateGroup', array( $this, $old ) );
		} else {
			$_PLUGINS->trigger( 'gj_onAfterCreateGroup', array( $this ) );
		}

		return true;
	}