예제 #1
0
	public function check()
	{
		if ( $this->get( 'title' ) == '' ) {
			$this->setError( CBTxt::T( 'Title not specified!' ) );

			return false;
		} elseif ( ! $this->get( 'user' ) ) {
			$this->setError( CBTxt::T( 'User not specified!' ) );

			return false;
		} elseif ( $this->get( 'user' ) && ( ! CBuser::getUserDataInstance( (int) $this->get( 'user' ) )->id ) ) {
			$this->setError( CBTxt::T( 'User specified does not exist!' ) );

			return false;
		} elseif ( $this->get( 'access' ) === '' ) {
			$this->setError( CBTxt::T( 'Access not specified!' ) );

			return false;
		} elseif ( $this->get( 'category' ) === '' ) {
			$this->setError( CBTxt::T( 'Category not specified!' ) );

			return false;
		} elseif ( ! in_array( $this->get( 'category' ), cbconsultationsModel::getCategoriesList( true ) ) ) {
			$this->setError( CBTxt::T( 'Category not allowed!' ) );

			return false;
		}

		return true;
	}
예제 #2
0
	/**
	 * @param  int[]             $paging
	 * @param  string            $where
	 * @param  UserTable         $viewer
	 * @param  UserTable         $user
	 * @param  PluginTable       $plugin
	 * @return cbconsultationsconsultationTable[]
	 */
	static public function getconsultations( $paging, $where, $viewer, $user, /** @noinspection PhpUnusedParameterInspection */ $plugin )
	{
		global $_CB_database;

		$categories		=	cbconsultationsModel::getCategoriesList( true );

		$consultations			=	array();

		if ( $categories ) {
			$query		=	'SELECT a.*'
						.	', a.' . $_CB_database->NameQuote( 'created_by' ) . ' AS user'
						.	', a.' . $_CB_database->NameQuote( 'introtext' ) . ' AS consultation_intro'
						.	', a.' . $_CB_database->NameQuote( 'fulltext' ) . ' AS consultation_full'
						.	', b.' . $_CB_database->NameQuote( 'name' ) . ' AS category'
						.	', b.' . $_CB_database->NameQuote( 'published' ) . ' AS category_published'
						.	', b.' . $_CB_database->NameQuote( 'alias' ) . ' AS category_alias'
						.	"\n FROM " . $_CB_database->NameQuote( '#__k2_items' ) . " AS a"
						.	"\n LEFT JOIN " . $_CB_database->NameQuote( '#__k2_categories' ) . " AS b"
						.	' ON b.' . $_CB_database->NameQuote( 'id' ) . ' = a.' . $_CB_database->NameQuote( 'catid' )
						.	"\n LEFT JOIN " . $_CB_database->NameQuote( '#__users' ) . " AS c"
						.	' ON c.' . $_CB_database->NameQuote( 'id' ) . ' = a.' . $_CB_database->NameQuote( 'created_by' )
						.	"\n WHERE a." . $_CB_database->NameQuote( 'catid' ) . " IN ( " . implode( ',', $categories ) . " )"
						.	"\n AND a." . $_CB_database->NameQuote( 'created_by' ) . " = " . (int) $user->get( 'id' )
						.	( ( $viewer->get( 'id' ) != $user->get( 'id' ) ) && ( ! Application::User( (int) $viewer->get( 'id' ) )->isGlobalModerator() ) ? "\n AND a." . $_CB_database->NameQuote( 'published' ) . " = 1" : null )
						.	"\n AND a." . $_CB_database->NameQuote( 'access' ) . " IN " . $_CB_database->safeArrayOfIntegers( Application::MyUser()->getAuthorisedViewLevels() )
						.	$where
						.	"\n ORDER BY a." . $_CB_database->NameQuote( 'created' ) . " DESC";

			if ( $paging ) {
				$_CB_database->setQuery( $query, $paging[0], $paging[1] );
			} else {
				$_CB_database->setQuery( $query );
			}

			$consultations		=	$_CB_database->loadObjectList( null, 'cbconsultationsconsultationTable', array( $_CB_database ) );
		}

		return $consultations;
	}
	/**
	 * @param  null|int     $id
	 * @param  UserTable    $user
	 * @param  stdClass     $model
	 * @param  PluginTable  $plugin
	 * @param  null|string  $message
	 * @param  null|string  $messageType
	 */
	public function showconsultationEdit( $id, $user, $model, $plugin, $message = null, $messageType = 'error' )
	{
		global $_CB_framework;

		$consultationLimit						=	(int) $plugin->params->get( 'consultation_limit', null );
		$consultationMode						=	$plugin->params->get( 'consultation_mode', 1 );
		$cbModerator					=	Application::User( (int) $user->get( 'id' ) )->isGlobalModerator();

		$row							=	new cbconsultationsconsultationTable();

		$canAccess						=	false;

		if ( $row->load( (int) $id ) ) {
			if ( ! $row->get( 'id' ) ) {
				if ( $cbModerator ) {
					$canAccess			=	true;
				} elseif ( $user->get( 'id' ) && Application::MyUser()->canViewAccessLevel( $plugin->params->get( 'consultation_create_access', 2 ) ) ) {
					if ( ( ! $consultationLimit ) || ( $consultationLimit && ( cbconsultationsModel::getconsultationsTotal( null, $user, $user, $plugin ) < $consultationLimit ) ) ) {
						$canAccess		=	true;
					}
				}
			} elseif ( $cbModerator || ( $row->get( 'user' ) == $user->get( 'id' ) ) ) {
				$canAccess				=	true;
			}
		}

		$profileUrl						=	$_CB_framework->userProfileUrl( $row->get( 'user', $user->get( 'id' ) ), false, 'cbconsultationsTab' );

		if ( $canAccess ) {
			cbconsultationsClass::getTemplate( 'consultation_edit' );

			$input						=	array();

			$publishedTooltip			=	cbTooltip( $_CB_framework->getUi(), CBTxt::T( 'Select publish status of the consultation. Unpublished consultations will not be visible to the public.' ), null, null, null, null, null, 'data-hascbtooltip="true"' );

			$input['published']			=	moscomprofilerHTML::yesnoSelectList( 'published', 'class="form-control"' . ( $publishedTooltip ? ' ' . $publishedTooltip : null ), (int) $this->input( 'post/published', $row->get( 'published', ( $cbModerator || ( ! $plugin->params->get( 'consultation_approval', 0 ) ) ? 1 : 0 ) ), GetterInterface::INT ) );

			$categoryTooltip			=	cbTooltip( $_CB_framework->getUi(), CBTxt::T( 'Select consultation category. Select the category that best describes your consultation.' ), null, null, null, null, null, 'data-hascbtooltip="true"' );

			$listCategory				=	cbconsultationsModel::getCategoriesList();
			$input['category']			=	moscomprofilerHTML::selectList( $listCategory, 'category', 'class="form-control"' . ( $categoryTooltip ? ' ' . $categoryTooltip : null ), 'value', 'text', $this->input( 'post/category', $row->get( 'category' ), GetterInterface::STRING ), 1, false, false );

			$accessTooltip				=	cbTooltip( $_CB_framework->getUi(), CBTxt::T( 'Select access to consultation; all groups above that level will also have access to the consultation.' ), null, null, null, null, null, 'data-hascbtooltip="true"' );

			$listAccess					=	Application::CmsPermissions()->getAllViewAccessLevels( true, Application::MyUser() );
			$input['access']			=	moscomprofilerHTML::selectList( $listAccess, 'access', 'class="form-control"' . ( $accessTooltip ? ' ' . $accessTooltip : null ), 'value', 'text', (int) $this->input( 'post/access', $row->get( 'access', $plugin->params->get( 'consultation_access_default', 1 ) ), GetterInterface::INT ), 1, false, false );

			$titleTooltip				=	cbTooltip( $_CB_framework->getUi(), CBTxt::T( 'Input consultation title. This is the title that will distinguish this consultation from others. Suggested to input something unique and intuitive.' ), null, null, null, null, null, 'data-hascbtooltip="true"' );

			$input['title']				=	'<input type="text" id="title" name="title" value="' . htmlspecialchars( $this->input( 'post/title', $row->get( 'title' ), GetterInterface::STRING ) ) . '" class="required form-control" size="30"' . ( $titleTooltip ? ' ' . $titleTooltip : null ) . ' />';

			if ( in_array( $consultationMode, array( 1, 2 ) ) ) {
				$consultationIntro				=	$_CB_framework->displayCmsEditor( 'consultation_intro', $this->input( 'post/consultation_intro', $row->get( 'consultation_intro' ), GetterInterface::HTML ), 400, 200, 40, 7 );

				$input['consultation_intro']	=	cbTooltip( $_CB_framework->getUi(), CBTxt::T( 'Input HTML supported consultation intro contents. Suggested to use minimal but well formatting for easy readability.' ), null, null, null, $consultationIntro, null, 'style="display:block;"' );
			}

			if ( in_array( $consultationMode, array( 1, 3 ) ) ) {
				$consultationFull				=	$_CB_framework->displayCmsEditor( 'consultation_full', $this->input( 'post/consultation_full', $row->get( 'consultation_full' ), GetterInterface::HTML ), 400, 200, 40, 7 );

				$input['consultation_full']		=	cbTooltip( $_CB_framework->getUi(), CBTxt::T( 'Input HTML supported consultation contents. Suggested to use minimal but well formatting for easy readability.' ), null, null, null, $consultationFull, null, 'style="display:block;"' );
			}

			$userTooltip				=	cbTooltip( $_CB_framework->getUi(), CBTxt::T( 'Input owner of consultation as single integer user_id.' ), null, null, null, null, null, 'data-hascbtooltip="true"' );

			$input['user']				=	'******' . (int) ( $cbModerator ? $this->input( 'post/user', $row->get( 'user', $user->get( 'id' ) ), GetterInterface::INT ) : $user->get( 'id' ) ) . '" class="digits required form-control" size="4"' . ( $userTooltip ? ' ' . $userTooltip : null ) . ' />';

			if ( $message ) {
				$_CB_framework->enqueueMessage( $message, $messageType );
			}

			HTML_cbconsultationsconsultationEdit::showconsultationEdit( $row, $input, $user, $model, $plugin );
		} else {
			cbRedirect( $profileUrl, CBTxt::T( 'Not authorized.' ), 'error' );
		}
	}