Пример #1
0
 public static function getMedium($id, $lang = \LANG)
 {
     try {
         // metemos los datos del proyecto en la instancia
         $query = self::query("SELECT * FROM project WHERE id = ?", array($id));
         $project = $query->fetchObject(__CLASS__);
         // primero, que no lo grabe
         $project->dontsave = true;
         // si recibimos lang y no es el idioma original del proyecto, ponemos la traducción y mantenemos para el resto de contenido
         if ($lang == $project->lang) {
             $lang = null;
         } elseif (!empty($lang)) {
             $sql = "\n                        SELECT\n                            IFNULL(project_lang.description, project.description) as description,\n                            IFNULL(project_lang.subtitle, project.subtitle) as subtitle\n                        FROM project\n                        LEFT JOIN project_lang\n                            ON  project_lang.id = project.id\n                            AND project_lang.lang = :lang\n                        WHERE project.id = :id\n                        ";
             $query = self::query($sql, array(':id' => $id, ':lang' => $lang));
             foreach ($query->fetch(\PDO::FETCH_ASSOC) as $field => $value) {
                 $project->{$field} = $value;
             }
         }
         // owner
         $project->user = User::getMini($project->owner);
         // imagen
         $project->image = Project\Image::getFirst($project->id);
         // categorias
         $project->categories = Project\Category::getNames($id, 2);
         // skills
         $project->skills = Project\Skill::getNames($id, 2);
         // retornos colectivos
         $project->social_rewards = Project\Reward::getAll($id, 'social', $lang);
         // retornos individuales
         $project->individual_rewards = Project\Reward::getAll($id, 'individual', $lang);
         $amount = Invest::invested($id);
         $project->invested = $amount;
         $project->amount = $amount;
         $project->num_investors = Invest::numInvestors($id);
         $project->num_messegers = Message::numMessegers($id);
         // sacamos rapidamente el presupuesto mínimo y óptimo
         $costs = self::calcCosts($id);
         $project->mincost = $costs->mincost;
         $project->maxcost = $costs->maxcost;
         $project->setDays();
         $project->setTagmark();
         return $project;
     } catch (\PDOException $e) {
         throw new \Goteo\Core\Exception($e->getMessage());
     }
 }