public static function getAll($project, $filter = null) { /* * Estos son los filtros */ $filters = array('date' => Text::_('Fecha'), 'user' => Text::_('Usuario'), 'reward' => Text::_('Recompensa'), 'pending' => Text::_('Pendientes'), 'fulfilled' => Text::_('Cumplidos')); $invests = array(); $query = static::query("\n SELECT *\n FROM invest\n WHERE invest.project = ?\n AND invest.status IN ('0', '1', '3', '4')\n ", array($project)); foreach ($query->fetchAll(\PDO::FETCH_CLASS, __CLASS__) as $invest) { // datos del usuario $invest->user = User::get($invest->user); $query = static::query("\n SELECT *\n FROM invest_reward\n INNER JOIN reward\n ON invest_reward.reward = reward.id\n WHERE invest_reward.invest = ?\n ", array($invest->id)); $invest->rewards = $query->fetchAll(\PDO::FETCH_OBJ); $query = static::query("\n SELECT address, zipcode, location, country\n FROM invest_address\n WHERE invest_address.invest = ?\n ", array($invest->id)); $invest->address = $query->fetchObject(); // si no tiene dirección, sacamos la dirección del usuario if (empty($invest->address)) { $usr_address = User::getPersonal($invest->user->id); $invest->address = $usr_address; } $invests[$invest->id] = $invest; } return $invests; }
/** * Inserta un proyecto con los datos mínimos * * @param array $data * @return boolean */ public function create($node = \GOTEO_NODE, &$errors = array()) { $user = $_SESSION['user']->id; if (empty($user)) { return false; } // cojemos el número de proyecto de este usuario $query = self::query("SELECT COUNT(id) as num FROM project WHERE owner = ?", array($user)); if ($now = $query->fetchObject()) { $num = $now->num + 1; } else { $num = 1; } // datos del usuario que van por defecto: name->contract_name, location->location $userProfile = User::get($user); // datos del userpersonal por defecto a los cammpos del paso 2 $userPersonal = User::getPersonal($user); $values = array(':id' => md5($user . '-' . $num), ':name' => Text::_("El nuevo proyecto de ") . $userProfile->name, ':lang' => 'es', ':status' => 1, ':progress' => 0, ':owner' => $user, ':node' => $node, ':amount' => 0, ':days' => 0, ':created' => date('Y-m-d'), ':contract_name' => $userPersonal->contract_name ? $userPersonal->contract_name : $userProfile->name, ':contract_nif' => $userPersonal->contract_nif, ':phone' => $userPersonal->phone, ':address' => $userPersonal->address, ':zipcode' => $userPersonal->zipcode, ':location' => $userPersonal->location ? $userPersonal->location : $userProfile->location, ':country' => $userPersonal->country ? $userPersonal->country : Check::country(), ':project_location' => $userPersonal->location ? $userPersonal->location : $userProfile->location); $campos = array(); foreach (\array_keys($values) as $campo) { $campos[] = \str_replace(':', '', $campo); } $sql = "REPLACE INTO project (" . implode(',', $campos) . ")\n VALUES (" . implode(',', \array_keys($values)) . ")"; try { self::query($sql, $values); foreach ($campos as $campo) { $this->{$campo} = $values[":{$campo}"]; } return $this->id; } catch (\PDOException $e) { $errors[] = Text::_("ERROR al crear un nuevo proyecto") . "<br />{$sql}<br /><pre>" . print_r($values, 1) . "</pre>"; \trace($this); die($errors[0]); return false; } }
echo new View('view/m/project/widget/investMsg.html.php', array('message' => $step, 'user' => $user)), new View('view/m/project/widget/invest_redirect.html.php', array('project' => $project, 'personal' => $personalData, 'step' => $step, 'allowpp'=> $this['allowpp'])); break; case 'ok': echo new View('view/m/project/widget/investMsg.html.php', array('message' => $step, 'user' => $user)), new View('view/project/widget/spread.html.php',array('project' => $project)); //sacarlo de div#center $printSendMsg=true; break; case 'fail': echo new View('view/m/project/widget/investMsg.html.php', array('message' => $step, 'user' => User::get($_SESSION['user']->id))), new View('view/m/project/widget/invest.html.php', array('project' => $project, 'personal' => User::getPersonal($_SESSION['user']->id), 'allowpp'=> $this['allowpp'])); break; default: echo new View('view/m/project/widget/investMsg.html.php', array('message' => $step, 'user' => $user)), new View('view/m/project/widget/invest.html.php', array('project' => $project, 'personal' => $personalData, 'step' => $step, 'allowpp'=> $this['allowpp'])); break; } } else { echo new View('view/m/project/widget/supporters.html.php', $this), new View('view/m/worth/legend.html.php'); } break; case 'messages':
} break; case 'supporters': // segun el paso de aporte if (!empty($step) && in_array($step, array('start', 'login', 'confirm', 'continue', 'ok', 'fail'))) { switch ($step) { case 'continue': echo new View('view/project/widget/investMsg.html.php', array('message' => $step, 'user' => $user)), new View('view/project/widget/invest_redirect.html.php', array('project' => $project, 'personal' => $personalData, 'step' => $step, 'allowpp' => $this['allowpp'])); break; case 'ok': echo new View('view/project/widget/investMsg.html.php', array('message' => $step, 'user' => $user)), new View('view/project/widget/spread.html.php', array('project' => $project)); //sacarlo de div#center $printSendMsg = true; break; case 'fail': echo new View('view/project/widget/investMsg.html.php', array('message' => $step, 'user' => User::get($_SESSION['user']->id))), new View('view/project/widget/invest.html.php', array('project' => $project, 'personal' => User::getPersonal($_SESSION['user']->id), 'allowpp' => $this['allowpp'])); break; default: echo new View('view/project/widget/investMsg.html.php', array('message' => $step, 'user' => $user)), new View('view/project/widget/invest.html.php', array('project' => $project, 'personal' => $personalData, 'step' => $step, 'allowpp' => $this['allowpp'])); break; } } else { echo new View('view/project/widget/supporters.html.php', $this), new View('view/worth/legend.html.php'); } break; case 'messages': echo new View('view/project/widget/messages.html.php', array('project' => $project)); break; case 'rewards': echo new View('view/project/widget/rewards-summary.html.php', array('project' => $project)); break;
public function profile($option = 'profile', $action = 'edit') { // tratamos el post segun la opcion y la acion $user = $_SESSION['user']; // salto al perfil público if ($option == 'public') { throw new Redirection('/user/profile/' . $user->id); } // vip/recomendador tiene una imagen adicional $vip = $option == 'profile' && isset($user->roles['vip']) ? Model\User\Vip::get($user->id) : null; if ($_SERVER['REQUEST_METHOD'] == 'POST') { $log_action = null; $errors = array(); switch ($option) { // perfil publico case 'profile': Dashboard\Profile::process_profile($user, $vip, $errors, $log_action); break; // datos personales // datos personales case 'personal': Dashboard\Profile::process_personal($user->id, $errors, $log_action); break; //cambio de email y contraseña //cambio de email y contraseña case 'access': Dashboard\Profile::process_access($user, $errors, $log_action); break; // preferencias de notificación // preferencias de notificación case 'preferences': Dashboard\Profile::process_preferences($user->id, $errors, $log_action); break; } if (!empty($log_action)) { // Evento Feed $log = new Feed(); $log->setTarget($user->id, 'user'); $log->populate('usuario ' . $log_action . ' (dashboard)', '/admin/users', \vsprintf('%s ha %s desde su dashboard', array(Feed::item('user', $user->name, $user->id), Feed::item('relevant', $log_action)))); $log->doAdmin('user'); unset($log); } } $viewData = array('menu' => self::menu(), 'section' => __FUNCTION__, 'option' => $option, 'action' => $action, 'errors' => $errors, 'user' => $user); switch ($option) { case 'profile': $viewData['interests'] = Model\User\Interest::getAll(); if ($_POST) { foreach ($_POST as $k => $v) { if (!empty($v) && preg_match('/web-(\\d+)-edit/', $k, $r)) { $viewData[$k] = true; break; } } } if (!empty($_POST['web-add'])) { $last = end($user->webs); if ($last !== false) { $viewData["web-{$last->id}-edit"] = true; } } if (isset($user->roles['vip'])) { $viewData['vip'] = Model\User\Vip::get($user->id); } break; case 'personal': $viewData['personal'] = Model\User::getPersonal($user->id); break; case 'access': // si es recover, en contraseña actual tendran que poner el username if ($action == 'recover') { $viewData['message'] = Text::get('dashboard-password-recover-advice'); } break; case 'preferences': $viewData['preferences'] = Model\User::getPreferences($user->id); break; } return new View('view/dashboard/index.html.php', $viewData); }