Find published news categories by parent ID.

@param int $pid

@return Collection|null
1796
public static function findPublishedByPid($pid)
    {
        $t = static::getTableAlias();
        $columns = ["$t.pid=?"];
        $values = [$pid];

        if (!BE_USER_LOGGED_IN) {
            $columns[] = "$t.published=?";
            $values[] = 1;
        }

        return static::findBy($columns, $values, ['order' => "$t.sorting"]);
    }
609981
public function getRoot($categoryId)
    {
        $category = CategoryQuery::create()->findPk($categoryId);

        if (0 !== $category->getParent()) {
            $parentCategory = CategoryQuery::create()->findPk($category->getParent());

            if (null !== $parentCategory) {
                $categoryId = $this->getRoot($parentCategory->getId());
            }
        }

        return $categoryId;
    }
91750
public function run( $pid ) {

		// Views
        $this->controller->setViewPath( '@cmsgears/module-core/admin/views/address' );

		$parentService = $this->controller->modelService;

		$parent = $this->controller->modelService->getById( $pid );

		if( isset( $parent ) ) {

			$model = $this->addressService->getModelObject();

			// Need the overriden model address, hence discarded $parent->address to get the address model.
			if( isset( $parent->addressId ) ) {

				$model = $this->addressService->getById( $parent->addressId );
			}

			if( isset( $this->scenario ) ) {

				$model->setScenario( $this->scenario );

				if( $this->scenario == 'location' && $model->hasAttribute( 'geoPoint' ) && empty( $model->geoPoint ) ) {

					$model->geoPoint = new Expression( "ST_GeometryFromText( CONCAT( 'POINT(', 0, ' ', 0, ')' ) )" );
				}
			}

			if( $model->load( Yii::$app->request->post(), $model->getClassName() ) && $model->validate() ) {

				if( empty( $parent->address ) ) {

					$address = $this->addressService->create( $model );

					$parent->addressId = $address->id;

					$parentService->update( $parent );
				}
				else {

					$this->addressService->update( $model );
				}

				return $this->controller->redirect( "all?pid=$parent->id" );
			}

			$countriesMap	= $this->countryService->getIdNameMap( [ 'default' => true ] );
			$countryId		= !empty( $model->countryId ) ? $model->countryId : key( $countriesMap );
			$provincesMap	= $this->provinceService->getMapByCountryId( $countryId, [ 'default' => true, 'defaultValue' => Yii::$app->core->provinceLabel ] );
			$provinceId		= !empty( $model->provinceId ) ? $model->provinceId : key( $provincesMap );
			$regionsMap		= $this->regionService->getMapByProvinceId( $provinceId, [ 'default' => true, 'defaultValue' => Yii::$app->core->regionLabel ] );

			return $this->controller->render( 'single', [
				'model' => $model,
				'parent' => $parent,
				'countriesMap' => $countriesMap,
				'provincesMap' => $provincesMap,
				'regionsMap' => $regionsMap
			]);
		}

		// Model not found
		throw new NotFoundHttpException( Yii::$app->coreMessage->getMessage( CoreGlobal::ERROR_NOT_FOUND ) );
	}
578589
public function getActiveCategoryIdList( $categoryId, $parentType ) {

		$modelClass	= static::$modelClass;

		$models = $modelClass::findActiveByCategoryIdParentType( $categoryId, $parentType );
		$ids	= [];

		foreach ( $models as $model ) {

			$category = $model->category;

			$ids[] = $category->id;
		}

		return $ids;
	}
674966
public function actionAll( $pid ) {

		Url::remember( Yii::$app->request->getUrl(), 'chat-members' );

		$modelClass = $this->modelService->getModelClass();

		$parent = $this->parentService->getById( $pid );

		if( isset( $parent ) ) {

			$dataProvider = $this->modelService->getPageByChatId( $parent->id );

			return $this->render( 'all', [
				'dataProvider' => $dataProvider,
				'parent' => $parent,
				'statusMap' => $modelClass::$baseStatusMap
			]);
		}

		// Model not found
		throw new NotFoundHttpException( Yii::$app->coreMessage->getMessage( CoreGlobal::ERROR_NOT_FOUND ) );
	}
952578
public function actionAll( $pid ) {

		$parent = $this->parentService->getById( $pid );

		if( isset( $parent ) ) {

			$modelClass = $this->modelService->getModelClass();

			$dataProvider = $this->modelService->getPage( [ 'conditions' => [ 'modelId' => $parent->id ] ] );

			return $this->render( 'all', [
				'dataProvider' => $dataProvider,
				'typeMap' => $modelClass::$typeMap,
				'parent' => $parent
			]);
		}

		// Model not found
		throw new NotFoundHttpException( Yii::$app->coreMessage->getMessage( CoreGlobal::ERROR_NOT_FOUND ) );
	}
1337960
public function findChildrenByParentId($parent_id)
    {
        $qb = $this->createQueryBuilder();
        $qb->andWhere($qb->getRootAliases()[0] . '.parent = ' . $this->addNamedParameter('parent', $parent_id, $qb))
            ->orderBy($qb->getRootAliases()[0] . '.position', 'ASC');
        return $qb->getQuery()->getResult();
    }
768689
public static function findChild( $parentId, $parentType, $childId ) {

		return self::find()->where( 'parentId=:pid AND parentType=:type AND childId=:cid', [ ':pid' => $parentId, ':type' => $parentType, ':cid' => $childId ] )->one();
	}
263895
public function parentGuid($guid)
    {
        $model = $this->noInitModel;
        if (!is_string($model->parentAttribute)) {
            return $this;
        }
        if ($guid instanceof $model) {
            $guid = $guid->getGUID();
        }
        return $this->andWhere([$model->parentAttribute => $guid]);
    }
911749
public function getProcessByPid($pid)
    {
        foreach ($this->processes as $process) {
            if ($process->getPid() == $pid) {
                return $process;
            }
        }

        return null;
    }
1260526
protected function get_info( $pid ) {
		$post = $this->prepare_post_info($pid);
		if ( !isset($post->post_status) ) {
			return null;
		}

		do_action_ref_array('the_post', array(&$post, &$GLOBALS['wp_query']));

		$post->status = $post->post_status;
		$post->id = $post->ID;
		$post->slug = $post->post_name;
		$customs = $this->get_post_custom($post->ID);
		if ( $this->is_previewing() ) {
			global $wp_query;
			$rev_id = $this->get_post_preview_id($wp_query);
			$customs = $this->get_post_custom($rev_id);
		}
		$post->custom = $customs;
		$post = (object) array_merge((array) $customs, (array) $post);
		return $post;
	}
1302070
public function findContentByUid($uid)
    {
        $results = $this->findContentsByUids(array($uid));
        if (0 < count($results)) {
            return reset($results);
        }

        return;
    }
336076
public function actionIndexPost($id=NULL)
	{
		if ($id === NULL)
		{
			$category = new Categories;
			$category->parent_id = 1;
		}
		else
		{
			$category = Categories::model()->findByPk($id);
			if ($category == NULL)
				throw new CHttpException(404, Yii::t('Api.category', 'A category with the id of {{id}} was not found.', array('{{id}}' => $id)));
		}

		$category->attributes = $_POST;

		if ($category->save())
			return $category->getAPIAttributes(array('parent_id'), array('parent', 'metadata'));

		return $this->returnError(400, NULL, $category->getErrors());
	}
1202551
public function getChildOrganizations($parentId = null)
    {
        static $children;

        if (is_null($parentId)) {
            return array();
        }

        if (! isset($children[$parentId])) {
            $organizations = $this->db->fetchPairs(
                    'SELECT gor_id_organization, gor_name
                        FROM gems__organizations
                        WHERE gor_active=1 AND gor_has_login=1 AND
                            (gor_accessible_by LIKE ' . $this->db->quote('%:' . $parentId . ':%') . ' OR
                                gor_id_organization = ' . $this->db->quote($parentId) .  ')
                            ORDER BY gor_name');

            natsort($organizations);

            $children[$parentId] = $organizations;
        }

        return $children[$parentId];
    }
654512
public function getPidLoadInfo($pid)
    {
        $commandsDto = new CommandsExecutionDto();
        $commandsDto->setCommandName(CommandsConstants::GET_PID_LOAD_INFO);
        $commandsDto->setPid($pid);

        return $this->getCommandExecutionResult($commandsDto);
    }
146295
public function findMediaByCategoryId(int $catId = null)
    {
        if (null === $catId) {
            return;
        }

        $this->sql = <<<SQL
select
    mc.category,
    m.id,
    m.file,
    m.caption
from media_category mc
join media_category_map mcp on mc.id = mcp.category_id
join media m on mcp.media_id = m.id
where mc.id = ?
SQL;
        $this->bindValues[] = $catId;
        return $this->find();
    }
47621
public function inCategory($sCatNid)
    {
        $blIn = false;
        if (($oParent = $this->getParent())) {
            $blIn = $oParent->inCategory($sCatNid);
        }

        return $blIn;
    }