コード例 #1
0
ファイル: project.php プロジェクト: kenjs/Goteo
 public static function get($id, $lang = null)
 {
     try {
         // metemos los datos del proyecto en la instancia
         $query = self::query("SELECT * FROM project WHERE id = ?", array(urldecode($id)));
         $project = $query->fetchObject(__CLASS__);
         if (!$project instanceof \Goteo\Model\Project) {
             throw new \Goteo\Core\Error('404', Text::html('fatal-error-project'));
         }
         // 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.motivation, project.motivation) as motivation,\n                            IFNULL(project_lang.video, project.video) as video,\n                            IFNULL(project_lang.about, project.about) as about,\n                            IFNULL(project_lang.goal, project.goal) as goal,\n                            IFNULL(project_lang.related, project.related) as related,\n                            IFNULL(project_lang.reward, project.reward) as reward,\n                            IFNULL(project_lang.keywords, project.keywords) as keywords,\n                            IFNULL(project_lang.media, project.media) as media,\n                            IFNULL(project_lang.subtitle, project.subtitle) as subtitle,\n                            IFNULL(project_lang.evaluation, project.evaluation) as evaluation\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;
             }
         }
         if (isset($project->media)) {
             $project->media = new Project\Media($project->media);
         }
         if (isset($project->video)) {
             $project->video = new Project\Media($project->video);
         }
         // owner
         $project->user = User::get($project->owner, $lang);
         // galeria
         $project->gallery = Project\Image::getGallery($project->id);
         // imágenes por sección
         foreach (Project\Image::sections() as $sec => $val) {
             if ($sec != '') {
                 $project->secGallery[$sec] = Project\Image::get($project->id, $sec);
             }
         }
         // categorias
         $project->categories = Project\Category::get($id);
         // skills
         $project->skills = Project\Skill::get($id);
         // costes y los sumammos
         $project->costs = Project\Cost::getAll($id, $lang);
         $project->minmax();
         // retornos colectivos
         $project->social_rewards = Project\Reward::getAll($id, 'social', $lang);
         // retornos individuales
         $project->individual_rewards = Project\Reward::getAll($id, 'individual', $lang);
         // colaboraciones
         $project->supports = Project\Support::getAll($id, $lang);
         //-----------------------------------------------------------------
         // Diferentes verificaciones segun el estado del proyecto
         //-----------------------------------------------------------------
         $project->investors = Invest::investors($id);
         $project->num_investors = Invest::numInvestors($id);
         $amount = Invest::invested($id);
         if ($project->invested != $amount) {
             self::query("UPDATE project SET amount = '{$amount}' WHERE id = ?", array($id));
         }
         $project->invested = $amount;
         $project->amount = $amount;
         //mensajes y mensajeros
         $messegers = array();
         $project->messages = Message::getAll($id, $lang);
         $project->num_messages = 0;
         foreach ($project->messages as $msg) {
             $project->num_messages++;
             $project->num_messages += count($msg->responses);
             $messegers[$msg->user] = $msg->user;
         }
         $project->num_messegers = count($messegers);
         $project->setDays();
         $project->setTagmark();
         // fecha final primera ronda (fecha campaña + 40)
         if (!empty($project->published)) {
             $ptime = strtotime($project->published);
             $project->willpass = date('Y-m-d', \mktime(0, 0, 0, date('m', $ptime), date('d', $ptime) + 40, date('Y', $ptime)));
         }
         //-----------------------------------------------------------------
         // Fin de verificaciones
         //-----------------------------------------------------------------
         return $project;
     } catch (\PDOException $e) {
         throw new \Goteo\Core\Exception($e->getMessage());
     } catch (\Goteo\Core\Error $e) {
         throw new \Goteo\Core\Error('404', Text::html('fatal-error-project'));
     }
 }