Exemple #1
0
 /**
  * Metodo que actualiza las categorías vinculadas al post. Se comprueba si ha 
  * borrado y agregado categorías vinculas al post.
  * @param array $relationshipsCategoriesID Identificadores de las categorías.
  * @param int $postID Identificador del post.
  */
 private function updateRelationshipsCategories($relationshipsCategoriesID, $postID)
 {
     if (!empty($relationshipsCategoriesID)) {
         $postsCategories = PostsCategories::selectByPostID($postID);
         //Se combina en un unico array las nuevas categorías y las existentes.
         $merge = \array_merge($relationshipsCategoriesID, $postsCategories);
         /*
          * Se comprueba sus diferencias.
          * 
          * Al obtener la diferencias se mantienen los indices del array $MERGE
          * con array_merge se reinician los indices, evitando problemas en los modelos.
          */
         //se obtiene las categorías a eliminar
         $delete = \array_merge(\array_diff($merge, $relationshipsCategoriesID));
         //y las categorías a insertar.
         $insert = \array_merge(\array_diff($merge, $postsCategories));
         $this->deleteRelationshipsCategories($delete, $postID);
         $this->insertRelationshipsCategories($insert, $postID);
     }
 }