Beispiel #1
0
 public static function investors($project, $projNum = false, $showall = false)
 {
     $worth = array();
     $investors = array();
     $sql = "\n                SELECT\n                    invest.user as user,\n                    user.name as name,\n                    user.avatar as avatar,\n                    user.worth as worth,\n                    invest.amount as amount,\n                    DATE_FORMAT(invest.invested, '%d/%m/%Y') as date,\n                    ";
     $sql .= "user.hide as hide,\n                     invest.anonymous as anonymous\n                FROM    invest\n                INNER JOIN user\n                    ON  user.id = invest.user\n                WHERE   project = ?\n                AND     invest.status IN ('0', '1', '3', '4')\n                ORDER BY invest.invested DESC, invest.id DESC\n                ";
     $query = self::query($sql, array($project));
     foreach ($query->fetchAll(\PDO::FETCH_OBJ) as $investor) {
         $investor->avatar = Image::get($investor->avatar);
         if (empty($investor->avatar->id) || !$investor->avatar instanceof Image) {
             $investor->avatar = Image::get(1);
         }
         // si el usuario es hide o el aporte es anonymo, lo ponemos como el usuario anonymous (avatar 1)
         if (!$showall && ($investor->hide == 1 || $investor->anonymous == 1)) {
             // mantenemos la fecha del anonimo mas reciente
             $anonymous_date = empty($investors['anonymous']->date) ? $investor->date : $investors['anonymous']->date;
             $investors[] = (object) array('user' => 'anonymous', 'name' => Text::get('regular-anonymous'), 'projects' => null, 'avatar' => Image::get(1), 'worth' => $investor->worth, 'amount' => $investor->amount, 'date' => $investor->date);
         } else {
             if (!isset($worth[$investor->user])) {
                 $worth[$investor->user] = \Goteo\Model\User::calcWorth($investor->user);
             }
             $investors[] = (object) array('user' => $investor->user, 'name' => $investor->name, 'projects' => $investor->projects, 'avatar' => $investor->avatar, 'worth' => $worth[$investor->user], 'amount' => $investor->amount, 'date' => $investor->date);
         }
     }
     return $investors;
 }