public function delete($id, $project) { Model\Message::get($id)->delete(); throw new Redirection("/project/{$project}/messages", Redirection::TEMPORARY); }
private function process_supports(&$project, &$errors) { if (!isset($_POST['process_supports'])) { return false; } // tratar colaboraciones existentes foreach ($project->supports as $key => $support) { // quitar las colaboraciones marcadas para quitar if (!empty($_POST["support-{$support->id}-remove"])) { unset($project->supports[$key]); continue; } if (isset($_POST['support-' . $support->id . '-support'])) { $support->support = $_POST['support-' . $support->id . '-support']; $support->description = $_POST['support-' . $support->id . '-description']; $support->type = $_POST['support-' . $support->id . '-type']; if (!empty($support->thread)) { // actualizar ese mensaje $msg = Model\Message::get($support->thread); $msg->date = date('Y-m-d'); $msg->message = "{$support->support}: {$support->description}"; $msg->blocked = true; $msg->save($errors); } else { // grabar nuevo mensaje $msg = new Model\Message(array('user' => $project->owner, 'project' => $project->id, 'date' => date('Y-m-d'), 'message' => "{$support->support}: {$support->description}", 'blocked' => true)); if ($msg->save($errors)) { // asignado a la colaboracion como thread inicial $support->thread = $msg->id; } } } } // añadir nueva colaboracion if (!empty($_POST['support-add'])) { $project->supports[] = new Model\Project\Support(array('project' => $project->id, 'support' => 'Nueva colaboración', 'type' => 'task', 'description' => '')); } return true; }
/** * Perfil público de usuario. * * @param string $id Nombre de usuario */ public function profile($id, $show = 'profile', $category = null) { if (!in_array($show, array('profile', 'investors', 'sharemates', 'message'))) { $show = 'profile'; } $user = Model\User::get($id, LANG); if (!$user instanceof Model\User || $user->hide) { throw new Error('404', Text::html('fatal-error-user')); } //--- para usuarios públicos--- if (empty($_SESSION['user'])) { // la subpágina de mensaje también está restringida if ($show == 'message') { $_SESSION['jumpto'] = '/user/profile/' . $id . '/message'; Message::Info(Text::get('user-login-required-to_message')); throw new Redirection(SEC_URL . "/user/login"); } // a menos que este perfil sea de un vip, no pueden verlo if (!isset($user->roles['vip'])) { $_SESSION['jumpto'] = '/user/profile/' . $id . '/' . $show; Message::Info(Text::get('user-login-required-to_see')); throw new Redirection(SEC_URL . "/user/login"); } /* // subpágina de cofinanciadores if ($show == 'investors') { Message::Info(Text::get('user-login-required-to_see-supporters')); throw new Redirection('/user/profile/' . $id); } */ } //--- el resto pueden seguir --- // impulsor y usuario solamente pueden comunicarse si: if ($show == 'message') { $is_author = false; // si es autor de un proyecto publicado $is_investor = false; // si es cofinanciador $is_messeger = false; // si es participante // si el usuario logueado es impulsor (autro de proyecto publicado $user_created = Model\Project::ofmine($_SESSION['user']->id, true); if (!empty($user_created)) { $is_author = true; } // si el usuario del perfil es cofin. o partic. // proyectos que es cofinanciador este usuario (el del perfil) $user_invested = Model\User::invested($id, true); foreach ($user_invested as $a_project) { if ($a_project->owner == $_SESSION['user']->id) { $is_investor = true; break; } } // proyectos que es participante este usuario (el del perfil) (que ha enviado algún mensaje) $user_messeged = Model\Message::getMesseged($id, true); foreach ($user_messeged as $a_project) { if ($a_project->owner == $_SESSION['user']->id) { $is_messeger = true; break; } } // si el usuario logueado es el usuario cofin./partic. // si el usuario del perfil es impulsor de un proyecto cofinanciado o en el que ha participado // proyectos que es cofinanciador el usuario logueado $user_invested = Model\User::invested($_SESSION['user']->id, true); foreach ($user_invested as $a_project) { if ($a_project->owner == $id) { $is_investor = true; break; } } // proyectos que es participante el usuario logueado (que ha enviado algún mensaje) $user_messeged = Model\Message::getMesseged($_SESSION['user']->id, true); foreach ($user_messeged as $a_project) { if ($a_project->owner == $id) { $is_messeger = true; break; } } if (!$is_investor && !$is_messeger && !$is_author) { Message::Info(Text::get('user-message-restricted')); throw new Redirection('/user/profile/' . $id); } else { $_SESSION['message_autorized'] = true; } } // vip profile $viewData = array(); $viewData['user'] = $user; $projects = Model\Project::ofmine($id, true); $viewData['projects'] = $projects; //mis cofinanciadores // array de usuarios con: // foto, nombre, nivel, cantidad a mis proyectos, fecha ultimo aporte, nº proyectos que cofinancia $investors = array(); foreach ($projects as $kay => $project) { // quitamos los caducados if ($project->status == 0) { unset($projects[$kay]); continue; } foreach (Model\Invest::investors($project->id) as $key => $investor) { // convocadores no, gracias if (!empty($investor->campaign)) { continue; } if (\array_key_exists($investor->user, $investors)) { // ya está en el array, quiere decir que cofinancia este otro proyecto // , añadir uno, sumar su aporte, actualizar la fecha ++$investors[$investor->user]->projects; $investors[$investor->user]->amount += $investor->amount; $investors[$investor->user]->date = $investor->date; } else { $investors[$investor->user] = (object) array('user' => $investor->user, 'name' => $investor->name, 'projects' => 1, 'avatar' => $investor->avatar, 'worth' => $investor->worth, 'amount' => $investor->amount, 'date' => $investor->date); } } } $viewData['investors'] = $investors; // comparten intereses $viewData['shares'] = Model\User\Interest::share($id, $category); if ($show == 'sharemates' && empty($viewData['shares'])) { $show = 'profile'; } if (!empty($category)) { $viewData['category'] = $category; } // proyectos que cofinancio $invested = Model\User::invested($id, true); // agrupacion de proyectos que cofinancia y proyectos suyos $viewData['lists'] = array(); if (!empty($invested)) { $viewData['lists']['invest_on'] = Listing::get($invested, 2); } if (!empty($projects)) { $viewData['lists']['my_projects'] = Listing::get($projects, 2); } return new View('view/user/' . $show . '.html.php', $viewData); }
/** * Graba las colaboraciones con lo recibido por POST * * @param object $project Instancia de proyecto de trabajo * @param array $errors (por referncia) * @return object $project Instancia de proyecto modificada */ public static function process_supports($project, &$errors = array()) { // tratar colaboraciones existentes foreach ($project->supports as $key => $support) { // quitar las colaboraciones marcadas para quitar if (!empty($_POST["support-{$support->id}-remove"])) { unset($project->supports[$key]); continue; } if (isset($_POST['support-' . $support->id . '-support'])) { $support->support = $_POST['support-' . $support->id . '-support']; $support->description = $_POST['support-' . $support->id . '-description']; $support->type = $_POST['support-' . $support->id . '-type']; if (!empty($support->thread)) { // actualizar ese mensaje $msg = Model\Message::get($support->thread); $msg->date = date('Y-m-d'); $msg->message = "{$support->support}: {$support->description}"; $msg->blocked = true; $msg->save(); } else { // grabar nuevo mensaje $msg = new Model\Message(array('user' => $project->owner, 'project' => $project->id, 'date' => date('Y-m-d'), 'message' => "{$support->support}: {$support->description}", 'blocked' => true)); if ($msg->save()) { // asignado a la colaboracion como thread inicial $support->thread = $msg->id; // Evento Feed $log = new Feed(); $log->setTarget($project->id); $log->populate('usuario pone una nueva colaboracion en su proyecto (dashboard)', '/admin/projects', \vsprintf('%s ha publicado una nueva %s en el proyecto %s, con el título "%s"', array(Feed::item('user', $_SESSION['user']->name, $_SESSION['user']->id), Feed::item('message', 'Colaboración'), Feed::item('project', $project->name, $project->id), Feed::item('update', $support->support, $project->id . '/messages#message' . $msg->id)))); $log->doAdmin('user'); // evento público, si el proyecto es público if ($project->status > 2) { $log->populate($_SESSION['user']->name, '/user/profile/' . $_SESSION['user']->id, Text::html('feed-new_support', Feed::item('project', $project->name, $project->id), Feed::item('update', $support->support, $project->id . '/messages#message' . $msg->id)), $_SESSION['user']->avatar->id); $log->doPublic('community'); } unset($log); } } } } // añadir nueva colaboracion (no hacemos lo del mensaje porque esta sin texto) if (!empty($_POST['support-add'])) { $new_support = new Model\Project\Support(array('project' => $project->id, 'support' => 'Nueva colaboración', 'type' => 'task', 'description' => '')); if ($new_support->save($errors)) { $project->supports[] = $new_support; $_POST['support-' . $new_support->id . '-edit'] = true; } else { $project->supports[] = new Model\Project\Support(array('project' => $project->id, 'support' => 'Nueva colaboración', 'type' => 'task', 'description' => '')); } } // guardamos los datos que hemos tratado y los errores de los datos $project->save($errors); return $project; }
public function translates($option = 'overview', $action = 'list', $id = null) { $user = $_SESSION['user']; $errors = array(); $langs = \Goteo\Library\i18n\Lang::getAll(); if ($action == 'lang' && !empty($_POST['lang'])) { $_SESSION['translate_lang'] = $_POST['lang']; } elseif (empty($_SESSION['translate_lang'])) { $_SESSION['translate_lang'] = 'en'; } $projects = Model\User\Translate::getMyProjects($user->id); // al seleccionar controlamos: translate_type if ($action == 'select' && !empty($_POST['type'])) { unset($_SESSION['translate_project']); // quitamos el proyecto de traducción $type = $_POST['type']; if (!empty($_POST[$type])) { $_SESSION['translate_type'] = $type; $_SESSION['translate_' . $type] = $_POST[$type]; } else { $_SESSION['translate_type'] = 'profile'; } } // view data basico para esta seccion $viewData = array('menu' => self::menu(), 'section' => __FUNCTION__, 'option' => $option, 'action' => $action, 'langs' => $langs, 'projects' => $projects, 'errors' => $errors, 'success' => $success); // aqui, segun lo que este traduciendo, necesito tener un proyecto de trabajo, una convocatoria o mi perfil personal switch ($_SESSION['translate_type']) { case 'project': try { // si lo que tenemos en sesion no es una instancia de proyecto (es una id de proyecto) if ($_SESSION['translate_project'] instanceof Model\Project) { $project = Model\Project::get($_SESSION['translate_project']->id, $_SESSION['translate_lang']); } else { $project = Model\Project::get($_SESSION['translate_project'], $_SESSION['translate_lang']); } } catch (\Goteo\Core\Error $e) { $project = null; } if (!$project instanceof Model\Project) { Message::Error('Ha fallado al cargar los datos del proyecto'); $_SESSION['translate_type'] = 'profile'; throw new Redirection('/dashboard/translates'); } $_SESSION['translate_project'] = $project; $project->lang_name = $langs[$project->lang]->name; unset($viewData['langs'][$project->lang]); // quitamos el idioma original //// Control de traduccion de proyecto if ($option == 'updates') { // sus novedades $blog = Model\Blog::get($project->id); if ($action != 'edit') { $action = 'list'; } } // tratar lo que llega por post para guardar los datos if ($_SERVER['REQUEST_METHOD'] == 'POST') { switch ($option) { case 'profile': if ($action == 'save') { $user = Model\User::get($_POST['id'], $_SESSION['translate_lang']); $user->about_lang = $_POST['about']; $user->keywords_lang = $_POST['keywords']; $user->contribution_lang = $_POST['contribution']; $user->lang = $_SESSION['translate_lang']; $user->saveLang($errors); } break; case 'overview': if ($action == 'save') { $project->description_lang = $_POST['description']; $project->motivation_lang = $_POST['motivation']; $project->video_lang = $_POST['video']; $project->about_lang = $_POST['about']; $project->goal_lang = $_POST['goal']; $project->related_lang = $_POST['related']; $project->reward_lang = $_POST['reward']; $project->keywords_lang = $_POST['keywords']; $project->media_lang = $_POST['media']; $project->subtitle_lang = $_POST['subtitle']; $project->lang_lang = $_SESSION['translate_lang']; $project->saveLang($errors); } break; case 'costs': if ($action == 'save') { foreach ($project->costs as $key => $cost) { if (isset($_POST['cost-' . $cost->id . '-cost'])) { $cost->cost_lang = $_POST['cost-' . $cost->id . '-cost']; $cost->description_lang = $_POST['cost-' . $cost->id . '-description']; $cost->lang = $_SESSION['translate_lang']; $cost->saveLang($errors); } } } break; case 'rewards': if ($action == 'save') { foreach ($project->social_rewards as $k => $reward) { if (isset($_POST['social_reward-' . $reward->id . '-reward'])) { $reward->reward_lang = $_POST['social_reward-' . $reward->id . '-reward']; $reward->description_lang = $_POST['social_reward-' . $reward->id . '-description']; $reward->other_lang = $_POST['social_reward-' . $reward->id . '-other']; $reward->lang = $_SESSION['translate_lang']; $reward->saveLang($errors); } } foreach ($project->individual_rewards as $k => $reward) { if (isset($_POST['individual_reward-' . $reward->id . '-reward'])) { $reward->reward_lang = $_POST['individual_reward-' . $reward->id . '-reward']; $reward->description_lang = $_POST['individual_reward-' . $reward->id . '-description']; $reward->other_lang = $_POST['individual_reward-' . $reward->id . '-other']; $reward->lang = $_SESSION['translate_lang']; $reward->saveLang($errors); } } } break; case 'supports': if ($action == 'save') { // tratar colaboraciones existentes foreach ($project->supports as $key => $support) { if (isset($_POST['support-' . $support->id . '-support'])) { // guardamos los datos traducidos $support->support_lang = $_POST['support-' . $support->id . '-support']; $support->description_lang = $_POST['support-' . $support->id . '-description']; $support->lang = $_SESSION['translate_lang']; $support->saveLang($errors); // actualizar el Mensaje correspondiente, solamente actualizar $msg = Model\Message::get($support->thread); $msg->message_lang = "{$support->support_lang}: {$support->description_lang}"; $msg->lang = $_SESSION['translate_lang']; $msg->saveLang($errors); } } } break; case 'updates': if (empty($_POST['blog']) || empty($_POST['id'])) { break; } $post = Model\Blog\Post::get($_POST['id']); $post->title_lang = $_POST['title']; $post->text_lang = $_POST['text']; $post->media_lang = $_POST['media']; $post->legend_lang = $_POST['legend']; $post->lang = $_SESSION['translate_lang']; $post->saveLang($errors); $action = 'edit'; break; } } switch ($option) { case 'profile': $viewData['user'] = Model\User::get($project->owner, $_SESSION['translate_lang']); break; case 'overview': break; case 'costs': if ($_POST) { foreach ($_POST as $k => $v) { if (!empty($v) && preg_match('/cost-(\\d+)-edit/', $k, $r)) { $viewData[$k] = true; } } } break; case 'rewards': if ($_POST) { foreach ($_POST as $k => $v) { if (!empty($v) && preg_match('/((social)|(individual))_reward-(\\d+)-edit/', $k)) { $viewData[$k] = true; break; } } } break; case 'supports': if ($_POST) { foreach ($_POST as $k => $v) { if (!empty($v) && preg_match('/support-(\\d+)-edit/', $k, $r)) { $viewData[$k] = true; break; } } } break; // publicar actualizaciones // publicar actualizaciones case 'updates': $viewData['blog'] = $blog; if ($action == 'edit') { $post = Model\Blog\Post::get($id, $_SESSION['translate_lang']); $viewData['post'] = $post; } else { $posts = array(); foreach ($blog->posts as $post) { $posts[] = Model\Blog\Post::get($post->id, $_SESSION['translate_lang']); } $viewData['posts'] = $posts; } break; } $viewData['project'] = $project; //// FIN Control de traduccion de proyecto break; default: // profile $viewData['option'] = 'profile'; unset($langs['es']); if ($_SERVER['REQUEST_METHOD'] == 'POST') { if ($action == 'save') { $user = Model\User::get($_POST['id'], $_SESSION['translate_lang']); $user->about_lang = $_POST['about']; $user->keywords_lang = $_POST['keywords']; $user->contribution_lang = $_POST['contribution']; $user->lang = $_SESSION['translate_lang']; $user->saveLang($errors); } } $viewData['user'] = Model\User::get($user->id, $_SESSION['translate_lang']); } if (!empty($errors)) { Message::Error('HA HABIDO ERRORES: <br />' . implode('<br />', $errors)); } return new View('view/dashboard/index.html.php', $viewData); }
public function publish(&$errors = array()) { try { $sql = "UPDATE project SET passed = NULL, status = :status, published = :published WHERE id = :id"; self::query($sql, array(':status' => 3, ':published' => date('Y-m-d'), ':id' => $this->id)); // borramos mensajes anteriores que sean de colaboraciones self::query("DELETE FROM message WHERE id IN (SELECT thread FROM support WHERE project = ?)", array($this->id)); // creamos los hilos de colaboración en los mensajes foreach ($this->supports as $id => $support) { $msg = new Message(array('user' => $this->owner, 'project' => $this->id, 'date' => date('Y-m-d'), 'message' => "{$support->support}: {$support->description}", 'blocked' => true)); if ($msg->save()) { // asignado a la colaboracion como thread inicial $sql = "UPDATE support SET thread = :message WHERE id = :support"; self::query($sql, array(':message' => $msg->id, ':support' => $support->id)); } unset($msg); } return true; } catch (\PDOException $e) { $errors[] = Text::_('No se ha grabado correctamente. ') . $e->getMessage(); return false; } }