Ejemplo n.º 1
0
    /**
     * Execute the controller action as required. If a registered action accept 
     * the current request the controller calls it.
     * 
     * If not action is accept the current request and current action is "share"
     * the controller execute the "send to portfolio" action
     * 
     * @return PortfolioController
     */
    function run()
    {
        if (!$this->accept()) {
            return $this;
        }

        $actions = self::actions();
        foreach ($actions as $action) {
            if ($action->accept()) {
                return $action->run();
            }
        }

        $action = $this->get_action();
        if ($action == self::ACTION_SHARE) {

            $user = new \Portfolio\User();
            $user->email = Chamilo::user()->email();

            $tool = $this->get_tool();
            $id = $this->get_id();
            $url = Portfolio::download_url($id, $tool);

            $artefact = new Portfolio\Artefact($url);

            $name = $this->get_portfolio();
            $result = Portfolio::get($name)->send($user, $artefact);
            if ($result) {
                $this->message = Display::return_message(get_lang('SentSuccessfully'), 'normal');
            } else {
                $this->message = Display::return_message(get_lang('SentFailed'), 'error');
            }
            return $this;
        } else {
            $this->message = '';
        }
        return $this;
    }