/** * @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; }
/** * @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; }