Beispiel #1
0
 public function check()
 {
     $errors =& $this->errors;
     $okeys =& $this->okeys;
     // reseteamos la puntuación
     $this->setScore(0, 0, true);
     /***************** Revisión de campos del paso 1, PERFIL *****************/
     $score = 0;
     // obligatorios: nombre, email, ciudad
     if (empty($this->user->name)) {
         $errors['userProfile']['name'] = Text::get('validate-user-field-name');
     } else {
         $okeys['userProfile']['name'] = 'ok';
         ++$score;
     }
     // se supone que tiene email porque sino no puede tener usuario, no?
     if (!empty($this->user->email)) {
         ++$score;
     }
     if (empty($this->user->location)) {
         $errors['userProfile']['location'] = Text::get('validate-user-field-location');
     } else {
         $okeys['userProfile']['location'] = 'ok';
         ++$score;
     }
     if (!empty($this->user->avatar) && $this->user->avatar->id != 1) {
         $okeys['userProfile']['avatar'] = empty($errors['userProfile']['avatar']) ? 'ok' : null;
         $score += 2;
     }
     if (!empty($this->user->about)) {
         $okeys['userProfile']['about'] = 'ok';
         ++$score;
         // otro +1 si tiene más de 1000 caracteres (pero menos de 2000)
         if (\strlen($this->user->about) > 1000 && \strlen($this->user->about) < 2000) {
             ++$score;
         }
     } else {
         $errors['userProfile']['about'] = Text::get('validate-user-field-about');
     }
     if (!empty($this->user->interests)) {
         $okeys['userProfile']['interests'] = 'ok';
         ++$score;
     }
     /* Aligerando superform
                 if (!empty($this->user->keywords)) {
                     $okeys['userProfile']['keywords'] = 'ok';
                     ++$score;
                 }
     
                 if (!empty($this->user->contribution)) {
                     $okeys['userProfile']['contribution'] = 'ok';
                     ++$score;
                 }
                  */
     if (empty($this->user->webs)) {
         $errors['userProfile']['webs'] = Text::get('validate-project-userProfile-web');
     } else {
         $okeys['userProfile']['webs'] = 'ok';
         ++$score;
         if (count($this->user->webs) > 2) {
             ++$score;
         }
         $anyerror = false;
         foreach ($this->user->webs as $web) {
             if (trim(str_replace('http://', '', $web->url)) == '') {
                 $anyerror = !$anyerror ?: true;
                 $errors['userProfile']['web-' . $web->id . '-url'] = Text::get('validate-user-field-web');
             } else {
                 $okeys['userProfile']['web-' . $web->id . '-url'] = 'ok';
             }
         }
         if ($anyerror) {
             unset($okeys['userProfile']['webs']);
             $errors['userProfile']['webs'] = Text::get('validate-project-userProfile-any_error');
         }
     }
     if (!empty($this->user->facebook)) {
         $okeys['userProfile']['facebook'] = 'ok';
         ++$score;
     }
     if (!empty($this->user->twitter)) {
         $okeys['userProfile']['twitter'] = 'ok';
         ++$score;
     }
     if (!empty($this->user->linkedin)) {
         $okeys['userProfile']['linkedin'] = 'ok';
     }
     //puntos
     $this->setScore($score, 12);
     /***************** FIN Revisión del paso 1, PERFIL *****************/
     /***************** Revisión de campos del paso 2,DATOS PERSONALES *****************/
     $score = 0;
     // obligatorios: todos
     if (empty($this->contract_name)) {
         $errors['userPersonal']['contract_name'] = Text::get('mandatory-project-field-contract_name');
     } else {
         $okeys['userPersonal']['contract_name'] = 'ok';
         ++$score;
     }
     if (empty($this->contract_nif)) {
         $errors['userPersonal']['contract_nif'] = Text::get('mandatory-project-field-contract_nif');
     } elseif (!Check::nif($this->contract_nif) && !Check::vat($this->contract_nif)) {
         $errors['userPersonal']['contract_nif'] = Text::get('validate-project-value-contract_nif');
     } else {
         $okeys['userPersonal']['contract_nif'] = 'ok';
         ++$score;
     }
     if (empty($this->contract_email)) {
         $errors['userPersonal']['contract_email'] = Text::get('mandatory-project-field-contract_email');
     } elseif (!Check::mail($this->contract_email)) {
         $errors['userPersonal']['contract_email'] = Text::get('validate-project-value-contract_email');
     } else {
         $okeys['userPersonal']['contract_email'] = 'ok';
     }
     if (empty($this->contract_birthdate)) {
         $errors['userPersonal']['contract_birthdate'] = Text::get('mandatory-project-field-contract_birthdate');
     } else {
         $okeys['userPersonal']['contract_birthdate'] = 'ok';
     }
     if (empty($this->phone)) {
         $errors['userPersonal']['phone'] = Text::get('mandatory-project-field-phone');
     } elseif (!Check::phone($this->phone)) {
         $errors['userPersonal']['phone'] = Text::get('validate-project-value-phone');
     } else {
         $okeys['userPersonal']['phone'] = 'ok';
         ++$score;
     }
     if (empty($this->address)) {
         $errors['userPersonal']['address'] = Text::get('mandatory-project-field-address');
     } else {
         $okeys['userPersonal']['address'] = 'ok';
         ++$score;
     }
     if (empty($this->zipcode)) {
         $errors['userPersonal']['zipcode'] = Text::get('mandatory-project-field-zipcode');
     } else {
         $okeys['userPersonal']['zipcode'] = 'ok';
         ++$score;
     }
     if (empty($this->location)) {
         $errors['userPersonal']['location'] = Text::get('mandatory-project-field-residence');
     } else {
         $okeys['userPersonal']['location'] = 'ok';
     }
     if (empty($this->country)) {
         $errors['userPersonal']['country'] = Text::get('mandatory-project-field-country');
     } else {
         $okeys['userPersonal']['country'] = 'ok';
         ++$score;
     }
     $this->setScore($score, 6);
     /***************** FIN Revisión del paso 2, DATOS PERSONALES *****************/
     /***************** Revisión de campos del paso 3, DESCRIPCION *****************/
     $score = 0;
     // obligatorios: nombre, subtitulo, imagen, descripcion, about, motivation, categorias, video, localización
     if (empty($this->name)) {
         $errors['overview']['name'] = Text::get('mandatory-project-field-name');
     } else {
         $okeys['overview']['name'] = 'ok';
         ++$score;
     }
     if (!empty($this->subtitle)) {
         $okeys['overview']['subtitle'] = 'ok';
     }
     if (empty($this->gallery) && empty($errors['overview']['image'])) {
         $errors['overview']['image'] .= Text::get('mandatory-project-field-image');
     } else {
         $okeys['overview']['image'] = empty($errors['overview']['image']) ? 'ok' : null;
         ++$score;
         if (count($this->gallery) >= 2) {
             ++$score;
         }
     }
     if (empty($this->description)) {
         $errors['overview']['description'] = Text::get('mandatory-project-field-description');
     } elseif (!Check::words($this->description, 80)) {
         $errors['overview']['description'] = Text::get('validate-project-field-description');
     } else {
         $okeys['overview']['description'] = 'ok';
         ++$score;
     }
     if (empty($this->about)) {
         $errors['overview']['about'] = Text::get('mandatory-project-field-about');
     } else {
         $okeys['overview']['about'] = 'ok';
         ++$score;
     }
     if (empty($this->motivation)) {
         $errors['overview']['motivation'] = Text::get('mandatory-project-field-motivation');
     } else {
         $okeys['overview']['motivation'] = 'ok';
         ++$score;
     }
     if (!empty($this->goal)) {
         $okeys['overview']['goal'] = 'ok';
         ++$score;
     }
     if (!empty($this->related)) {
         $okeys['overview']['related'] = 'ok';
         ++$score;
     }
     if (empty($this->categories)) {
         $errors['overview']['categories'] = Text::get('mandatory-project-field-category');
     } else {
         $okeys['overview']['categories'] = 'ok';
         ++$score;
     }
     if (empty($this->media)) {
         $errors['overview']['media'] = Text::get('mandatory-project-field-media');
     } else {
         $okeys['overview']['media'] = 'ok';
         $score += 3;
     }
     if (empty($this->project_location)) {
         $errors['overview']['project_location'] = Text::get('mandatory-project-field-location');
     } else {
         $okeys['overview']['project_location'] = 'ok';
         ++$score;
     }
     $this->setScore($score, 13);
     /***************** FIN Revisión del paso 3, DESCRIPCION *****************/
     /***************** Revisión de campos del paso 4, COSTES *****************/
     $score = 0;
     $scoreName = $scoreDesc = $scoreAmount = $scoreDate = 0;
     if (count($this->costs) < 2) {
         $errors['costs']['costs'] = Text::get('mandatory-project-costs');
     } else {
         $okeys['costs']['costs'] = 'ok';
         ++$score;
     }
     $anyerror = false;
     foreach ($this->costs as $cost) {
         if (empty($cost->cost)) {
             $errors['costs']['cost-' . $cost->id . '-cost'] = Text::get('mandatory-cost-field-name');
             $anyerror = !$anyerror ?: true;
         } else {
             $okeys['costs']['cost-' . $cost->id . '-cost'] = 'ok';
             $scoreName = 1;
         }
         if (empty($cost->type)) {
             $errors['costs']['cost-' . $cost->id . '-type'] = Text::get('mandatory-cost-field-type');
             $anyerror = !$anyerror ?: true;
         } else {
             $okeys['costs']['cost-' . $cost->id . '-type'] = 'ok';
         }
         if (empty($cost->description)) {
             $errors['costs']['cost-' . $cost->id . '-description'] = Text::get('mandatory-cost-field-description');
             $anyerror = !$anyerror ?: true;
         } else {
             $okeys['costs']['cost-' . $cost->id . '-description'] = 'ok';
             $scoreDesc = 1;
         }
         if (empty($cost->amount)) {
             $errors['costs']['cost-' . $cost->id . '-amount'] = Text::get('mandatory-cost-field-amount');
             $anyerror = !$anyerror ?: true;
         } else {
             $okeys['costs']['cost-' . $cost->id . '-amount'] = 'ok';
             $scoreAmount = 1;
         }
         if ($cost->type == 'task' && (empty($cost->from) || empty($cost->until))) {
             $errors['costs']['cost-' . $cost->id . '-dates'] = Text::get('mandatory-cost-field-task_dates');
             $anyerror = !$anyerror ?: true;
         } elseif ($cost->type == 'task') {
             $okeys['costs']['cost-' . $cost->id . '-dates'] = 'ok';
             $scoreDate = 1;
         }
     }
     if ($anyerror) {
         unset($okeys['costs']['costs']);
         $errors['costs']['costs'] = Text::get('validate-project-costs-any_error');
     }
     $score = $score + $scoreName + $scoreDesc + $scoreAmount + $scoreDate;
     $costdif = $this->maxcost - $this->mincost;
     $maxdif = $this->mincost * 0.5;
     $scoredif = $this->mincost * 0.35;
     if ($this->mincost == 0) {
         $errors['costs']['total-costs'] = Text::get('mandatory-project-total-costs');
     } elseif ($costdif > $maxdif) {
         $errors['costs']['total-costs'] = Text::get('validate-project-total-costs');
     } else {
         $okeys['costs']['total-costs'] = 'ok';
     }
     if ($costdif <= $scoredif) {
         ++$score;
     }
     $this->setScore($score, 6);
     /***************** FIN Revisión del paso 4, COSTES *****************/
     /***************** Revisión de campos del paso 5, RETORNOS *****************/
     $score = 0;
     $scoreName = $scoreDesc = $scoreAmount = $scoreLicense = 0;
     if (empty($this->social_rewards)) {
         $errors['rewards']['social_rewards'] = Text::get('validate-project-social_rewards');
     } else {
         $okeys['rewards']['social_rewards'] = 'ok';
         if (count($this->social_rewards) >= 2) {
             ++$score;
         }
     }
     if (empty($this->individual_rewards)) {
         $errors['rewards']['individual_rewards'] = Text::get('validate-project-individual_rewards');
     } else {
         $okeys['rewards']['individual_rewards'] = 'ok';
         if (count($this->individual_rewards) >= 3) {
             ++$score;
         }
     }
     $anyerror = false;
     foreach ($this->social_rewards as $social) {
         if (empty($social->reward)) {
             $errors['rewards']['social_reward-' . $social->id . 'reward'] = Text::get('mandatory-social_reward-field-name');
             $anyerror = !$anyerror ?: true;
         } else {
             $okeys['rewards']['social_reward-' . $social->id . 'reward'] = 'ok';
             $scoreName = 1;
         }
         if (empty($social->description)) {
             $errors['rewards']['social_reward-' . $social->id . '-description'] = Text::get('mandatory-social_reward-field-description');
             $anyerror = !$anyerror ?: true;
         } else {
             $okeys['rewards']['social_reward-' . $social->id . '-description'] = 'ok';
             $scoreDesc = 1;
         }
         if (empty($social->icon)) {
             $errors['rewards']['social_reward-' . $social->id . '-icon'] = Text::get('mandatory-social_reward-field-icon');
             $anyerror = !$anyerror ?: true;
         } else {
             $okeys['rewards']['social_reward-' . $social->id . '-icon'] = 'ok';
         }
         if (!empty($social->license)) {
             $scoreLicense = 1;
         }
     }
     if ($anyerror) {
         unset($okeys['rewards']['social_rewards']);
         $errors['rewards']['social_rewards'] = Text::get('validate-project-social_rewards-any_error');
     }
     $score = $score + $scoreName + $scoreDesc + $scoreLicense;
     $scoreName = $scoreDesc = $scoreAmount = 0;
     $anyerror = false;
     foreach ($this->individual_rewards as $individual) {
         if (empty($individual->reward)) {
             $errors['rewards']['individual_reward-' . $individual->id . '-reward'] = Text::get('mandatory-individual_reward-field-name');
             $anyerror = !$anyerror ?: true;
         } else {
             $okeys['rewards']['individual_reward-' . $individual->id . '-reward'] = 'ok';
             $scoreName = 1;
         }
         if (empty($individual->description)) {
             $errors['rewards']['individual_reward-' . $individual->id . '-description'] = Text::get('mandatory-individual_reward-field-description');
             $anyerror = !$anyerror ?: true;
         } else {
             $okeys['rewards']['individual_reward-' . $individual->id . '-description'] = 'ok';
             $scoreDesc = 1;
         }
         if (empty($individual->amount)) {
             $errors['rewards']['individual_reward-' . $individual->id . '-amount'] = Text::get('mandatory-individual_reward-field-amount');
             $anyerror = !$anyerror ?: true;
         } else {
             $okeys['rewards']['individual_reward-' . $individual->id . '-amount'] = 'ok';
             $scoreAmount = 1;
         }
         if (empty($individual->icon)) {
             $errors['rewards']['individual_reward-' . $individual->id . '-icon'] = Text::get('mandatory-individual_reward-field-icon');
             $anyerror = !$anyerror ?: true;
         } else {
             $okeys['rewards']['individual_reward-' . $individual->id . '-icon'] = 'ok';
         }
     }
     if ($anyerror) {
         unset($okeys['rewards']['individual_rewards']);
         $errors['rewards']['individual_rewards'] = Text::get('validate-project-individual_rewards-any_error');
     }
     $score = $score + $scoreName + $scoreDesc + $scoreAmount;
     $this->setScore($score, 8);
     /***************** FIN Revisión del paso 5, RETORNOS *****************/
     /***************** Revisión de campos del paso 6, COLABORACIONES *****************/
     $scorename = $scoreDesc = 0;
     foreach ($this->supports as $support) {
         if (!empty($support->support)) {
             $okeys['supports']['support-' . $support->id . '-support'] = 'ok';
             $scoreName = 1;
         }
         if (!empty($support->description)) {
             $okeys['supports']['support-' . $support->id . '-description'] = 'ok';
             $scoreDesc = 1;
         }
     }
     $score = $scoreName + $scoreDesc;
     $this->setScore($score, 2);
     /***************** FIN Revisión del paso 6, COLABORACIONES *****************/
     //-------------- Calculo progreso ---------------------//
     $this->setProgress();
     //-------------- Fin calculo progreso ---------------------//
     return true;
 }
Beispiel #2
0
 public function validate(&$errors = array())
 {
     if (empty($this->year)) {
         $this->year = self::$currYear;
     }
     if (!empty($this->nif) && !Check::nif($this->nif)) {
         $errors['nif'] = Text::get('validate-project-value-contract_nif');
     }
 }
Beispiel #3
0
 public function getList($filters = array(), $csv = false)
 {
     // naturaleza según tipo de persona (F, J)
     $nt = array('nif' => 'F', 'nie' => 'F', 'cif' => 'J');
     // porcentaje segun tipo de persona (25, 35)
     $pt = array('nif' => '25', 'nie' => '25', 'cif' => '35');
     $year = empty($filter['year']) ? static::$currYear : $filter['year'];
     $year0 = $year;
     $year1 = $year + 1;
     $values = array();
     $list = array();
     $sqlFilter = '';
     if (!empty($filters['user'])) {
         $user = $filters['user'];
         $sqlFilter .= " AND (user.id LIKE :user OR user.name LIKE :user OR user.email LIKE :user)";
         $values[':user'] = "******";
     }
     if (!empty($filters['year'])) {
         $ayear = $filters['year'];
         $sqlFilter .= " AND DATE_FORMAT(invest.invested,'%Y') = :ayear";
         $values[':ayear'] = $ayear;
     }
     if (!empty($filters['status'])) {
         switch ($filters['status']) {
             case 'pending':
                 // Pendientes de confirmar
                 $sqlFilter .= " AND user_donation.user IS NULL";
                 break;
             case 'edited':
                 // Revisados
                 $sqlFilter .= " AND user_donation.edited = 1 AND (user_donation.confirmed IS NULL OR user_donation.confirmed = 0)";
                 break;
             case 'confirmed':
                 // Confirmados
                 $sqlFilter .= " AND user_donation.confirmed = 1";
                 break;
             case 'emited':
                 // Certificado emitido
                 $sqlFilter .= " AND (user_donation.pdf IS NOT NULL OR user_donation.pdf != '')";
                 break;
             case 'notemited':
                 //Confirmado pero no emitido
                 $sqlFilter .= " AND user_donation.confirmed = 1 AND (user_donation.pdf IS NULL OR user_donation.pdf = '')";
                 break;
         }
     }
     $sql = "SELECT\n                        user.id as id,\n                        user.email,\n                        IFNULL(user_donation.name, invest_address.name) as name,\n                        IFNULL(user_donation.nif, invest_address.nif) as nif,\n                        IFNULL(user_donation.address, invest_address.address) as address,\n                        IFNULL(user_donation.zipcode, invest_address.zipcode) as zipcode,\n                        IFNULL(user_donation.location, invest_address.location) as location,\n                        IFNULL(user_donation.country, invest_address.country) as country,\n                        IFNULL(user_donation.amount, SUM(invest.amount)) as amount,\n                        IFNULL(user_donation.numproj, COUNT(DISTINCT(invest.project))) as numproj,\n                        CONCAT('{$year}') as year,\n                        IFNULL(user_donation.user, 'Pendiente') as pending,\n                        user_donation.edited as edited,\n                        user_donation.confirmed as confirmed,\n                        user_donation.pdf as pdf\n                FROM  invest\n                INNER JOIN project\n                    ON project.id = invest.project\n                    AND (project.passed IS NOT NULL AND project.passed != '0000-00-00')\n                INNER JOIN user ON user.id = invest.user\n                LEFT JOIN user_donation ON user_donation.user = invest.user AND user_donation.year = '{$year}'\n                LEFT JOIN invest_address ON invest_address.invest = invest.id\n                WHERE   invest.status IN ('1', '3')\n                AND (\n                    (invest.invested >= '{$year0}-01-01' AND invest.invested < '{$year1}-01-01') \n                    OR (invest.invested < '{$year0}-01-01' AND project.passed >= '{$year0}-01-01')\n                )\n                {$sqlFilter}\n                GROUP BY invest.user\n                ORDER BY user.email ASC";
     $query = self::query($sql, $values);
     $items = $query->fetchAll(\PDO::FETCH_OBJ);
     foreach ($items as $item) {
         if (empty($item->country)) {
             $prov = '';
         } else {
             // dos dígitos para la provincia  (99 si no es españa)
             $prov = static::esPana($item->country) ? substr($item->zipcode, 0, 2) : '99';
         }
         // tipo de persona segun nif/nie/cif
         $type = '';
         Check::nif($item->nif, $type);
         $per = $pt[$type];
         $nat = $nt[$type];
         // NIF;NIF_REPRLEGAL;Nombre;Provincia;CLAVE;PORCENTAJE;VALOR;EN_ESPECIE;COMUNIDAD;PORCENTAJE_CA;NATURALEZA;REVOCACION;EJERCICIO;TIPOBIEN;BIEN
         $list[] = array($item->nif, '', $item->name, $prov, 'A', $per, $item->amount, '', '', '', $nat, '', $item->year, '', '', '');
     }
     return $list;
 }