???
@param $skip
@param $owner
@param $level
@return string
962352
private function selectList($skip=0, $owner = 0, $level = 0)
    {
        $items = Eresus_CMS::getLegacyKernel()->sections->
            children($owner, Eresus_CMS::getLegacyKernel()->user['access']);
        $result = array(array(), array());
        foreach ($items as $item)
        {
            if ($item['id'] != $skip)
            {
                $item['caption'] = trim($item['caption']);
                if (empty($item['caption']))
                {
                    $item['caption'] = ADM_NA;
                }
                $result[0][] = $item['id'];
                $result[1][] = str_repeat('&nbsp;', $level*2).$item['caption'];
                $children = $this->selectList($skip, $item['id'], $level+1);
                $result[0] = array_merge($result[0], $children[0]);
                $result[1] = array_merge($result[1], $children[1]);
            }
        }
        return $result;
    }
1321116
protected function _owner()
    {
        static $owner = false;

        if ( $owner === false )
        {
            $owner = eZUser::fetch( $this->owner_id );
        }

        return $owner;
    }
198717
public function scopeWhereNotOwnedBy(Builder $query, CanBeOwnerContract $owner)
    {
        return $query->where(function (Builder $q) use ($owner) {
            $q->where('owned_by_id', '!=', $owner->getKey())
                ->orWhere('owned_by_type', '!=', $owner->getMorphClass());
        });
    }
1092780
private function traverse($id, $level = -1)
    {
        $lft = $this->count;
        ++$this->count;
        if (isset($this->parents[$id])) {
            foreach ($this->parents[$id] as $child) {
                $this->traverse($child, $level + 1);
            }
            unset($this->parents[$id]);
        }
        $rgt = $this->count;
        ++$this->count;
        $this->update[$id] = array('level' => $level, 'lft' => $lft, 'rgt' => $rgt);
    }
970939
protected function _skip($skips)
    {
        $skipped = '';
        $count = $this->count();
        while ($this->_current < $count) {
            if (!isset($skips[$this->_data[$this->_current][0]])) {
                break;
            }
            $skipped .= $this->_data[$this->_current][1];
            $this->_current++;
        }
        return $skipped;
    }
87174
public function change_owner($owner)
    {

        if (empty($owner) || !is_int($owner) || $this->owner != getmyuid()) return false;

        if (!empty($this->fp)) fclose($this->fp);

        if (chown($this->path . $this->filename, $owner)) {
            return $this->open($this->path . $this->filename);
        }

        return false;
    }
329646
public function getReferers( $skip )
	{
		$referers		= array();
		foreach( $this->data as $entry )
		{
			if( $entry['remote_addr'] != $this->skip )
			{
				if( $entry['referer_uri'] && !preg_match( "#.*".$skip.".*#si", $entry['referer_uri'] ) )
				{
					if( isset( $referers[$entry['referer_uri']] ) )
						$referers[$entry['referer_uri']] ++;
					else
						$referers[$entry['referer_uri']]	= 1;
				}
			}
		}
		arsort( $referers );
		foreach( $referers as $referer => $count )
			$lines[]	= "<tr><td>".$referer."</td><td>".$count."</td></tr>";
		$lines	= implode( "\n\t", $lines );
		$content	= "<table>".$lines."</table>";
		return $content;
	}
825878
private function getRules (stdClass $model, array $skip, bool $multiLanguage)
    {
        $output = '';

        if (!empty($model)) {
            $tpl = file_get_contents (__DIR__ . '/../templates/shared/array.element.hctpl');

            foreach ($model->columns as $column) {
                if (in_array ($column->Field, $skip))
                    continue;

                $key = $column->Field;

                if ($multiLanguage)
                    $key = 'translations.*.' . $key;

                if ($column->Null == "NO") {
                    $line = str_replace ('{key}', $key, $tpl);
                    $line = str_replace ('{value}', 'required', $line);

                    $output .= $line;
                }
            }
        }

        return $output;
    }
1289889
public function isEmpty($owner, $type = 'default')
    {
        $owner_id = spl_object_id($owner);

        if (!isset($this->_pool[$owner_id][$type])) {
            throw new NotExistsException(['`:type` pool of `:owner` is not exists', 'type' => $type, 'owner' => get_class($owner)]);
        }

        $queue = $this->_pool[$owner_id][$type];

        return $queue->isEmpty();
    }
191475
public function tocAction($owner, $ownerId)
    {
        /** @var BlockProviderInterface $provider */
        $provider = $this->get('opifer.content.block_provider_pool')->getProvider($owner);
        $object = $provider->getBlockOwner($ownerId);

        /** @var Environment $environment */
        $environment = $this->get('opifer.content.block_environment');
        $environment->setDraft(true)->setObject($object);
        $environment->setBlockMode('manage');

        $twigAnalyzer = $this->get('opifer.content.twig_analyzer');

        $parameters = [
            'environment' => $environment,
            'analyzer' => $twigAnalyzer,
            'object' => $environment->getObject(),
        ];

        return $this->render('OpiferContentBundle:Content:toc.html.twig', $parameters);
    }
681600
public function migrateDown( $levels = NULL )
    {
        if ( NULL !== $levels )
        {
            $this->levels = $levels;
        }
        
        $migrations = $this->getAppliedMigrations( );
        
        $i = 0;
        
        if ( self::MIGRATE_ALL === $this->levels || $this->levels > count( $migrations ) )
        {
            $this->levels = count( $migrations );
        }
        
        while ( $i < $this->levels )
        {
            $class = $migrations[ $i ];
            
            $migration = new $class( );
            
            $method = new \ReflectionMethod( $class, 'migrateDown' );
            
            // run migrateDown
            if ( $class === $method->getDeclaringClass( )->name )
            {
                $migration->migrateDown( $this->db );
                
                // delete migration from table
                if ( FALSE === $this->_deleteMigrationRecord( $class ) )
                {
                    throw new MigrationException( 'Failed to delete migration record: ' . $class );
                }
            }
            else // run safeMigrateDown
            {
                $method = new \ReflectionMethod( $class, 'safeMigrateDown' );
            
                if ( $class === $method->getDeclaringClass( )->name )
                {
                    try
                    {
                        // start transaction
                        $this->db->startTransaction( );

                        // turn off auto commit
                        $this->db->setTransactionAutocommit( FALSE );

                        // run safeMigrateDown
                        $migration->safeMigrateDown( $this->db );

                        // delete migration record
                        if ( FALSE === $this->_deleteMigrationRecord( $class ) )
                        {
                            throw new MigrationException( 
                                    'Failed to delete migration record: ' . $class );
                            
                            $this->db->rollbackTransaction();
                        }

                        // commit transaction
                        $this->db->commitTransaction( );
                    }
                    catch ( \Exception $e )
                    {
                        // rollback transaction
                        $this->db->rollbackTransaction( );

                        throw $e;
                    }
                }
            }
            
            $i++;
            
            if ( $this->levels === $i )
            {
                $this->doAction( self::ON_MIGRATE_DOWN_ACTION );
                
                return;
            }
        }
    }
1347769
private function renderPagesMenu(&$opened, $owner = 0, $level = 0)
    {
        $theme = $this->getUITheme();

        $result = '';
        $items = Eresus_CMS::getLegacyKernel()->
            sections->children($owner, Eresus_CMS::getLegacyKernel()->user['access'], SECTIONS_ACTIVE);

        if (count($items))
        {
            foreach ($items as $item)
            {
                if (empty($item['caption']))
                {
                    $item['caption'] = ADM_NA;
                }

                if (
                    isset(Eresus_CMS::getLegacyKernel()->request['arg']['section']) &&
                    $item['id'] == arg('section')
                )
                {
                    $this->title = $item['caption']; # title - массив?
                }

                $sub = $this->renderPagesMenu($opened, $item['id'], $level+1);
                $current = (arg('mod') == 'content') && (arg('section') == $item['id']);

                if ($current)
                {
                    $opened = $level;
                }

                // Альтернативный текст
                $alt = '[&nbsp;]';
                // Подсказка
                $title = '';
                // Классы пункта меню
                $classes = array();

                if ($opened == $level + 1)
                {
                    $display = 'block';
                    $classes []= 'opened';
                    $opened--;
                }
                else
                {
                    $display = 'none';
                }

                if ($sub)
                {
                    $classes []= 'parrent';
                    $alt = '[+]';
                    $title = 'Развернуть';
                }

                if ($current)
                {
                    $classes []= 'current';
                }

                if (!$item['visible'])
                {
                    $classes []= 'invisible';
                }

                $classes = implode(' ', $classes);

                $result .=
                    '<li' . ($classes ? ' class="' . $classes . '"' : '') . '>' .
                    '<img src="' . Eresus_CMS::getLegacyKernel()->root . $theme->getImage('dot.gif') . '" alt="' .
                    $alt . '" title="' . $title . '" /> ' .
                    '<a href="' . Eresus_CMS::getLegacyKernel()->root . 'admin.php?mod=content&amp;section=' .
                    $item['id'] .
                    '" title="ID: '.$item['id'].' ('.$item['name'].')">'.$item['caption']."</a>\n";

                if (!empty($sub))
                {
                    $result .= '<ul style="display: '.$display.';">'.$sub.'</ul>';
                }
            }
        }

        return $result;
    }
304025
protected function _getActiveMenuPattern($level = 0, $urlInfo = null) {
		if (empty($urlInfo) || !is_array($urlInfo)) {
			return false;
		}

		$level = (int)$level;
		extract($urlInfo);
		if (($level < 0) || ($level > 2)) {
			$level = 0;
		}

		if ($level > 1) {
			$action = 'index';
		}
		if ($level == 0) {
			$userPrefix = $this->Session->read('Auth.User.prefix');
			if (empty($prefix) && !empty($userPrefix)) {
				$prefix = $userPrefix;
			}
		}

		$url = compact(
			'controller',
			'action',
			'plugin',
			'prefix'
		);
		if (!empty($prefix)) {
			$url[$prefix] = true;
		}
		$href = $this->url($url);
		$href = preg_quote($href, '/');
		if (!empty($pass) || !empty($named)) {
			if (((($level == 0) && (mb_stripos($action, 'index') === false)) ||
				($level == 2)) && ($href !== '\/')) {
				$href .= '\/?.*';
			}
		}
		$activePattern = '/<a\s+href=\"' . $href . '\".*>/iu';

		return $activePattern;
	}
1278258
public function setOwner(\WobbleCode\UserBundle\Document\User $owner)
    {
        $this->owner = $owner;
        return $this;
    }
1350823
public function branch($owner, $access = GUEST, $flags = 0)
    {
        $result = array();
        // Создаём индекс
        if (!$this->index)
        {
            $this->index();
        }
        // Находим ID разделов ветки.
        $set = $this->branchIds($owner);
        if (count($set))
        {
            $list = array();
            /* Читаем из кэша */
            for ($i=0; $i < count($set); $i++)
            {
                if (isset($this->cache[$set[$i]]))
                {
                    $list[] = $this->cache[$set[$i]];
                    array_splice($set, $i, 1);
                    $i--;
                }
            }
            if (count($set))
            {
                $fieldset = '';//implode(',', array_diff($this->fields(), array('content')));
                /* Читаем из БД */
                $set = implode(',', $set);
                $items = Eresus_CMS::getLegacyKernel()->db->select($this->table,
                    "FIND_IN_SET(`id`, '$set') AND `access` >= $access", 'position', $fieldset);
                for ($i=0; $i<count($items); $i++)
                {
                    $this->cache[$items[$i]['id']] = $items[$i];
                    $list[] = $items[$i];
                }
            }

            if ($flags)
            {
                for ($i=0; $i<count($list); $i++)
                {
                    /* Фильтруем с учётом переданных флагов */
                    $filterByActivePassed = !($flags & SECTIONS_ACTIVE) || $list[$i]['active'];
                    $filterByVisiblePassed = !($flags & SECTIONS_VISIBLE) || $list[$i]['visible'];

                    if ($filterByActivePassed && $filterByVisiblePassed)
                    {
                        $result[] = $list[$i];
                    }
                }
            }
            else
            {
                $result = $list;
            }
        }
        return $result;
    }
1002338
public function findRootJobByOwnerIdAndJobName($ownerId, $jobName)
    {
        return $this->createJobQueryBuilder('job')
            ->where('job.ownerId = :ownerId AND job.name = :jobName')
            ->andWhere('job.rootJob is NULL')
            ->setParameter('ownerId', $ownerId)
            ->setParameter('jobName', $jobName)
            ->getQuery()
            ->getOneOrNullResult();
    }
1097255
public function withOwner($owner, callable $callback, $args = [])
    {
        try {
            $this->setOwner($owner);
            return $callback(...$args);
        } finally {
            $this->clearOwner();
        }
    }