peter2
1/13/2015 - 2:23 PM

ignoreenablefields

ignoreenablefields

<?php

namespace Example\Key\Domain\Repository;

class BarRepository {

	/**
	 * Override default findByUid function to enable also the option to turn off
	 * the enableField setting
	 *
	 * @param integer $uid id of record
	 * @param boolean $ignoreEnableFields if set to true, hidden records are shown
	 * @return \Example\Key\Domain\Model\Bar
	 */
	public function findByUid($uid, $ignoreEnableFields = false) {
		$query = $this->createQuery();
		$query->getQuerySettings()->setIgnoreEnableFields($ignoreEnableFields);

		return $query->matching(
			$query->logicalAnd(
				$query->equals('uid', $uid),
				$query->equals('deleted', 0)
			)
		)->execute()->getFirst();
	}

}
?>
<?php

namespace Example\Key\Domain\Model;

class Foo {

	/**
	 * BarRepository
	 *
	 * @var \Example\Key\Domain\Repository\BarRepository
	 * @inject
	 */
	protected $barRepository;

	/**
	 * save reference only as integer
	 *
	 * @var integer
	 */
	protected $bar;

	/**
	 * Returns the Bar
	 *
	 * @return \Example\Key\Domain\Model\Bar $bar
	 */
	public function getBar() {
		return $this->barRepository->findByUid($this->bar, true);
	}

	/**
	 * Sets the Bar
	 *
	 * @param \Example\Key\Domain\Model\Bar $bar
	 * @return this
	 */
	public function setBar(\Example\Key\Domain\Model\Bar $bar) {
		$this->bar = $bar->getUid();
		return $this;
	}

}