示例#1
0
 /**
  * Vérifie les attributs d'une technote
  * @param array $param Les attributs à vérifier
  * @return object 2 attributs, bool success et array string msg
  * @static
  */
 private static function checkTechnote(&$param, &$files, $typeCheck)
 {
     $std = (object) array('success' => false, 'msg' => array());
     if (($res = Technote::checkDescription($param['description'])) !== true) {
         $std->msg[] = $res;
     }
     if (($res = Technote::checkPublie($param['publie'])) !== true) {
         $std->msg[] = $res;
     }
     if (($res = Technote::checkTitre($param['titre'])) !== true) {
         $std->msg[] = $res;
     }
     if (($res = Technote::checkContenu($param['contenu'])) !== true) {
         $std->msg[] = $res;
     }
     // Si on ajoute une technote, ou que c'est une édition avec modification de l'image
     if ($typeCheck == 'add' || !empty($files['image'])) {
         if (($res = Technote::checkImage($files['image'])) !== true) {
             $std->msg[] = $res;
         }
         // On génère un nom aléatoire
         do {
             $gen = uniqid(rand());
             $nom = pathinfo($files['image']['name'], PATHINFO_FILENAME);
             $extension = pathinfo($files['image']['name'], PATHINFO_EXTENSION);
             $base = dirname(__FILE__) . '/..';
             $chemin = '/assets/images/uploads/' . $nom . $gen . '.' . $extension;
         } while (file_exists($base . $chemin));
         if (move_uploaded_file($files['image']['tmp_name'], $base . $chemin)) {
             $param['url_image'] = $chemin;
         } else {
             $std->msg[] = 'Problème de déplacement de l\'image sur le serveur, veuillez contacter un admin';
         }
     } else {
         if (($res = Technote::checkURLImage($param['url_image'])) !== true) {
             $std->msg[] = $res;
         }
     }
     if (!empty($param['id_mot_cle'])) {
         foreach ($param['id_mot_cle'] as $id_mot_cle) {
             if (($res = MotCle::checkExiste($id_mot_cle)) !== true) {
                 $std->msg[] = $res;
             }
         }
     }
     if (empty($std->msg)) {
         $std->success = true;
     }
     return $std;
 }