@param Portfolio $portfolio

@return bool True on successfull processing, false otherwise
512004
public function handleAdd(Portfolio $portfolio)
    {
        $form = $this->getAddForm();
        $form->setData($portfolio);

        $request = $this->requestStack->getCurrentRequest();
        if ($request->isMethod('POST')) {
            $form->submit($request);

            if ($form->isValid()) {
                $this->portfolioManager->addPortfolio($portfolio);

                return true;
            }
        }

        return false;
    }
822492
public function getCommentsByPortfolio(Portfolio $portfolio)
    {
        $comments = [];

        /** @var \Icap\PortfolioBundle\Entity\PortfolioComment[] $commentObjects */
        $commentObjects = $this->entityManager->getRepository('IcapPortfolioBundle:PortfolioComment')->findByPortfolio($portfolio);

        foreach ($commentObjects as $commentObject) {
            $comments[] = $commentObject->getData();
        }

        return $comments;
    }
202039
public function process_stage_confirm() {
        global $CFG, $DB, $OUTPUT;

        $previous = $DB->get_records(
            'portfolio_log',
            array(
                'userid'      => $this->user->id,
                'portfolio'   => $this->instance->get('id'),
                'caller_sha1' => $this->caller->get_sha1(),
            )
        );
        if (isset($this->noexportconfig) && empty($previous)) {
            return true;
        }
        $strconfirm = get_string('confirmexport', 'portfolio');
        $baseurl = $CFG->wwwroot . '/portfolio/add.php?sesskey=' . sesskey() . '&id=' . $this->get('id');
        $yesurl = $baseurl . '&stage=' . PORTFOLIO_STAGE_QUEUEORWAIT;
        $nourl  = $baseurl . '&cancel=1';
        $this->print_header(get_string('confirmexport', 'portfolio'));
        echo $OUTPUT->box_start();
        echo $OUTPUT->heading(get_string('confirmsummary', 'portfolio'), 3);
        $mainsummary = array();
        if (!$this->instance->get_export_config('hideformat')) {
            $mainsummary[get_string('selectedformat', 'portfolio')] = get_string('format_' . $this->instance->get_export_config('format'), 'portfolio');
        }
        if (!$this->instance->get_export_config('hidewait')) {
            $mainsummary[get_string('selectedwait', 'portfolio')] = get_string(($this->instance->get_export_config('wait') ? 'yes' : 'no'));
        }
        if ($previous) {
            $previousstr = '';
            foreach ($previous as $row) {
                $previousstr .= userdate($row->time);
                if ($row->caller_class != get_class($this->caller)) {
                    if (!empty($row->caller_file)) {
                        portfolio_include_callback_file($row->caller_file);
                    } else if (!empty($row->caller_component)) {
                        portfolio_include_callback_file($row->caller_component);
                    } else { // Ok, that's weird - this should never happen. Is the apocalypse coming?
                        continue;
                    }
                    $previousstr .= ' (' . call_user_func(array($row->caller_class, 'display_name')) . ')';
                }
                $previousstr .= '<br />';
            }
            $mainsummary[get_string('exportedpreviously', 'portfolio')] = $previousstr;
        }
        if (!$csummary = $this->caller->get_export_summary()) {
            $csummary = array();
        }
        if (!$isummary = $this->instance->get_export_summary()) {
            $isummary = array();
        }
        $mainsummary = array_merge($mainsummary, $csummary, $isummary);
        $table = new html_table();
        $table->attributes['class'] = 'generaltable exportsummary';
        $table->data = array();
        foreach ($mainsummary as $string => $value) {
            $table->data[] = array($string, $value);
        }
        echo html_writer::table($table);
        echo $OUTPUT->confirm($strconfirm, $yesurl, $nourl);
        echo $OUTPUT->box_end();
        echo $OUTPUT->footer();
        return false;
    }
304791
public function edit(PortfolioRequest $request, Portfolio $portfolio)
    {
        return $this->response->title(trans('app.edit') . ' ' . trans('portfolio::portfolio.name'))
            ->view('portfolio::portfolio.edit', true)
            ->data(compact('portfolio'))
            ->output();
    }
639554
public function checkPortfolioToolAccess(User $user = null, Portfolio $portfolio = null)
    {
        if (!$this->getPortfolioToolAccess()) {
            throw $this->createNotFoundException();
        }

        if (null !== $user && null !== $portfolio && $portfolio->getUser() !== $user) {
            $portfolioGuide = $this->getPortfolioGuideManager()->getByPortfolioAndGuide($portfolio, $user);

            if (null === $portfolioGuide) {
                throw $this->createNotFoundException();
            }
        }
    }
279434
public function hasScope(Scope $scope)
    {
        foreach ($scope->toArray() as $scopeToken) {
            if (!$this->hasScopeToken($scopeToken)) {
                return false;
            }
        }

        return true;
    }
680812
public function findByPortfolioAndUser(Portfolio $portfolio, User $user, $executeQuery = true)
    {
        $queryBuilder = $this->createQueryBuilder('pg')
            ->andWhere('pg.portfolio = :portfolio')
            ->andWhere('pg.user = :user')
            ->setParameter('portfolio', $portfolio)
            ->setParameter('user', $user)
        ;

        return $executeQuery ? $queryBuilder->getQuery()->getOneOrNullResult() : $queryBuilder->getQuery();
    }
402209
public function handleVisibility(Portfolio $portfolio)
    {
        $originalPortfolioUsers = $portfolio->getPortfolioUsers();
        $originalPortfolioGroups = $portfolio->getPortfolioGroups();
        $originalPortfolioTeams = $portfolio->getPortfolioTeams();
        $form = $this->getVisibilityForm($portfolio);

        $request = $this->requestStack->getCurrentRequest();
        if ($request->isMethod('POST')) {
            $form->submit($request);

            if ($form->isValid()) {
                $this->portfolioManager->updateVisibility($portfolio, $originalPortfolioUsers, $originalPortfolioGroups, $originalPortfolioTeams);

                return true;
            }
        }

        return false;
    }
692342
public function setPortfolioTeams($portfolioTeams)
    {
        foreach ($portfolioTeams as $portfolioTeam) {
            $portfolioTeam->setPortfolio($this);
        }

        $this->portfolioTeams = $portfolioTeams;

        return $this;
    }
678817
public function getAllAction(User $loggedUser, Portfolio $portfolio)
    {
        $this->checkPortfolioToolAccess($loggedUser, $portfolio);

        $response = new JsonResponse($this->getCommentsManager()->getCommentsByPortfolio($portfolio), Response::HTTP_OK);

        return $response;
    }
188289
public function load_data() {
        global $DB;
        if (!$this->cm = get_coursemodule_from_id('glossary', $this->id)) {
            throw new portfolio_caller_exception('invalidid', 'glossary');
        }
        if (!$this->glossary = $DB->get_record('glossary', array('id' => $this->cm->instance))) {
            throw new portfolio_caller_exception('invalidid', 'glossary');
        }
        $entries = $DB->get_records('glossary_entries', array('glossaryid' => $this->glossary->id));
        list($where, $params) = $DB->get_in_or_equal(array_keys($entries));

        $aliases = $DB->get_records_select('glossary_alias', 'entryid ' . $where, $params);
        $categoryentries = $DB->get_records_sql('SELECT ec.entryid, c.name FROM {glossary_entries_categories} ec
            JOIN {glossary_categories} c
            ON c.id = ec.categoryid
            WHERE ec.entryid ' . $where, $params);

        $this->exportdata = array('entries' => $entries, 'aliases' => $aliases, 'categoryentries' => $categoryentries);
        $fs = get_file_storage();
        $context = context_module::instance($this->cm->id);
        $this->multifiles = array();
        foreach (array_keys($entries) as $entry) {
            $this->keyedfiles[$entry] = array_merge(
                $fs->get_area_files($context->id, 'mod_glossary', 'attachment', $entry, "timemodified", false),
                $fs->get_area_files($context->id, 'mod_glossary', 'entry', $entry, "timemodified", false)
            );
            $this->multifiles = array_merge($this->multifiles, $this->keyedfiles[$entry]);
        }
    }
525361
public function uninstall_cleanup() {
        global $DB;

        // Get all instances of this portfolio.
        $count = $DB->count_records('portfolio_instance', array('plugin' => $this->name));
        if ($count > 0) {
            // This portfolio is in use, get the it's ID.
            $rec = $DB->get_record('portfolio_instance', array('plugin' => $this->name));

            // Remove all records from portfolio_instance_config.
            $DB->delete_records('portfolio_instance_config', array('instance' => $rec->id));
            // Remove all records from portfolio_instance_user.
            $DB->delete_records('portfolio_instance_user', array('instance' => $rec->id));
            // Remove all records from portfolio_log.
            $DB->delete_records('portfolio_log', array('portfolio' => $rec->id));
            // Remove all records from portfolio_tempdata.
            $DB->delete_records('portfolio_tempdata', array('instance' => $rec->id));

            // Remove the record from the portfolio_instance table.
            $DB->delete_records('portfolio_instance', array('id' => $rec->id));
        }

        parent::uninstall_cleanup();
    }
1242717
public function destroy(PortfolioRequest $request, Portfolio $portfolio)
    {
        try {

            $portfolio->delete();
            return $this->response->message(trans('messages.success.deleted', ['Module' => trans('portfolio::portfolio.name')]))
                ->code(202)
                ->status('success')
                ->url(guard_url('portfolio/portfolio/0'))
                ->redirect();

        } catch (Exception $e) {

            return $this->response->message($e->getMessage())
                ->code(400)
                ->status('error')
                ->url(guard_url('portfolio/portfolio/' . $portfolio->getRouteKey()))
                ->redirect();
        }

    }
110776
public function isFinalized($error = false)
    {
        if ($this->finalized && $error) {
            $this->triggerError($error, E_USER_ERROR);
        }
        return $this->finalized;
    }
1078085
public function hasTarget(Target $target): bool
    {
        foreach ($this->_allOfType($target->type()) as $t) {
            if ($target->equals($t)) {
                return true;
            }
        }
        return false;
    }
1209360
function hasAppPerms($app)
    {
        foreach ($this->getAllRoles() as $perm) {
            if (0 === strpos($perm, $app . '.')) {
                return true;
            }
        }
        return false;
    }
82459
public function setPortfolioUsers($portfolioUsers)
    {
        foreach ($portfolioUsers as $portfolioUser) {
            $portfolioUser->setPortfolio($this);
        }

        $this->portfolioUsers = $portfolioUsers;

        return $this;
    }