예제 #1
0
 /**
  * @param $VinculedBaseVO qualquer classe que tenha getId e a propriedade table
  * @return ReturnResultVO de preferencia
  */
 public function commit($VinculedBaseVO = NULL)
 {
     //considerando que as informações principais já foram passadas na construct
     if ($VinculedBaseVO) {
         //se passar o VinculedBaseVO ele atribui a table e table_id para todas as entradas
         $this->ImageInfoPostHandler->setLinkedTableAndTableId($VinculedBaseVO->getTable(), $VinculedBaseVO->getId());
     }
     //agora sim vai usar o modulo de imagem
     $FacilImage = new FacilImage();
     //configurar o geral do FacilImage
     //$FacilImage->defaultFolderForNewImages = "";
     $ReturnResultVO = new ReturnResultVO();
     $ReturnResultVO->result = TRUE;
     foreach ($this->ImageInfoPostHandler->getArrayInfoPost() as $InfoPost) {
         $FacilImage->resetInfoPost($InfoPost);
         $ReturnResultVOtemp = $FacilImage->insert();
         if (!$ReturnResultVOtemp->result) {
             $ReturnResultVO->result = $ReturnResultVOtemp->result;
         }
     }
     // ve se foi enviado a array de delete e passa para o metodo delete
     foreach ($this->ImageInfoPostHandler->getArrayToDelete() as $delete_id) {
         //nesse caso não trata o retorno, simplesmente manda fazer
         $this->delete($delete_id);
     }
 }
예제 #2
0
파일: Image.php 프로젝트: reytuty/facil
 public function insert($echo_json = TRUE)
 {
     //para inserir imagem precisa estar logado como admin
     if (UserClient::getTypeId() == Config::ADMIN_USER_TYPE_ID && UserClient::getActiveTime() && UserClient::getActive()) {
         //se tiver ok, blz, o que me importa é o else
     } else {
         //exit();//sem explicações
     }
     $this->infoPost = new ImageInfoPostVO();
     $this->infoPost->file_data = $_FILES["Filedata"];
     //passando como null o table, ele não linka
     $this->infoPost->table = NULL;
     $retorno = parent::insert();
     if ($retorno->success) {
         //vai pegar a url da imagem
         include_once "library/facil3/core/modules/image/vo/ImageVO.class.php";
         $ImageVO = new ImageVO();
         $ImageVO->setId($retorno->result, TRUE);
         if ($this->infoPost->table_id) {
             //foi enviado para linkar, então pega o id
             $url = $ImageVO->getUrl();
             //pre-conceito na moral de que se uma imagem é enviada, é para produto
             include_once Config::FOLDER_APPLICATION . "modules/product_model/vo/ProductModelQuadroVO.class.php";
             $ProductModelQuadroVO = new ProductModelQuadroVO();
             $retorno_product = $ProductModelQuadroVO->setId($this->infoPost->table_id, TRUE);
             //ve se existe o produto
             if ($retorno_product->success) {
                 //atualiza url
                 $ProductModelQuadroVO->setQuadroImagePath($url);
                 //grava
                 $ProductModelQuadroVO->commit();
             }
         }
     }
     if ($echo_json) {
         echo utf8_encode($retorno->toJson());
         exit;
     } else {
         return $retorno;
     }
 }
예제 #3
0
파일: Content.php 프로젝트: reytuty/facil
 /**
  * Da redirect
  * Envie redirect_with_id para o seu redirect_to ir com o parametro id no final
  * @return void
  */
 public function commit($redirect_page = TRUE, $link_table = "image")
 {
     $contentVO = new ContentSiteVO();
     if (isset($_POST["id"])) {
         $contentVO->setId($_POST["id"], TRUE);
     }
     $contentVO->setFetchArray($_POST);
     //antes de tudo, faz a validação
     $ValidationReturnResultVO = new ReturnResultVO();
     $ValidationReturnResultVO->success = TRUE;
     if (DataHandler::getValueByArrayIndex($_POST, "array_validation")) {
         $array_validation = DataHandler::getValueByArrayIndex($_POST, "array_validation");
         //array de fields que deveriam ser validados e estão errados
         $array_fields_errors = array();
         if (is_array($array_validation)) {
             //se for array, valida a array
             //varre a validação
             foreach ($array_validation as $field_name) {
                 $temp_ReturnResultVO = $this->validateContentFields($field_name, $contentVO);
                 if (!$temp_ReturnResultVO->success) {
                     //echo Debug::li("Content.php erro na validacao : $field_name ");
                     //da o push na array_fields error
                     $array_fields_errors[] = $field_name;
                     //já muda o success do result para false para saber que não precisa mais commitar
                     $ValidationReturnResultVO->success = FALSE;
                 }
             }
         } else {
             if (is_string($array_validation)) {
                 //se for só uma string valida só 1 deles
                 $temp_ReturnResultVO = $this->validateContentFields($field_name, $contentVO);
                 if (!$temp_ReturnResultVO->success) {
                     //da o push na array_fields error
                     $array_fields_errors[] = $field_name;
                     //já muda o success do result para false para saber que não precisa mais commitar
                     $ValidationReturnResultVO->success = FALSE;
                 }
             }
         }
     }
     if (!$ValidationReturnResultVO->success) {
         //coloco na result a array de fields com error
         $ValidationReturnResultVO->result = $array_fields_errors;
         //retorna para o edit de quem extends essa classe
         return $this->{$my_edit_method}($ValidationReturnResultVO);
         //daqui nao passa
         exit;
     }
     //vai criar as key_words do content
     $key_words = "";
     $key_words .= " " . DataHandler::removeAccent($contentVO->getAuthor());
     $key_words .= " " . DataHandler::removeAccent($contentVO->getContent());
     $key_words .= " " . DataHandler::removeAccent($contentVO->getDescription());
     $key_words .= " " . DataHandler::removeAccent($contentVO->getHat());
     $key_words .= " " . DataHandler::removeAccent($contentVO->getName());
     $key_words .= " " . DataHandler::removeAccent($contentVO->getSlug());
     $key_words .= " " . DataHandler::removeAccent($contentVO->getTitle());
     $contentVO->setKeyWords($key_words);
     $returnResultVO = $contentVO->commit();
     $content_id = $contentVO->getId();
     //adicionando link com categoria(s) enviada(s)
     //pega a instancia
     $LinkDAO = LinkDAO::getInstance();
     if (FALSE) {
         $LinkDAO = new LinkDAO();
     }
     //deleta vinculos com categoria
     $LinkDAO->deleteAllFromLinkedTableByTableAndTableId('content', $content_id, 'category');
     $have_category_to_commit = FALSE;
     if (!is_array($_POST["category"])) {
         $_POST["category"] = array($_POST["category"]);
     }
     $arrayCategory = $_POST["category"];
     //Debug::print_r($arrayCategory);exit();
     $order = 10;
     if (!is_array($_POST["order"])) {
         $order = $_POST["order"];
     }
     foreach ($arrayCategory as $category_id) {
         ///print_r($category_id);
         //echo Debug::li("categoria id:".$category_id);
         //cada categoria enviada é mais um link com categoria que deve ser adicionado
         //echo $order;exit();
         $LinkDAO->insert('category', $category_id, 'content', $contentVO->getId(), 1, $order);
         // $contentVO->addLink("category", $category_id);
         $have_category_to_commit = TRUE;
     }
     //exit();
     //caso tenha o que adicionar como link em categoria, commita
     if ($have_category_to_commit) {
         $contentVO->commit();
     }
     //fim da adição do content em categoria
     //-----------------------------==================================== [[[  add imagens ]]]
     $array_image_file = DataHandler::getValueByArrayIndex($_FILES, "image");
     include_once "library/facil3/core/controller/image/FacilImage.php";
     $FacilImage = new FacilImage();
     //echo Debug::li(":link_table   [".$link_table."]");exit();
     $FacilImage->moduleName = $link_table;
     $FacilImage->defaultFolderForNewImages = "upload/image/";
     for ($i = 0; $i < count($array_image_file["name"]); $i++) {
         //Debug::print_r($array_image_file);
         $file_image = array();
         $file_image["name"] = $array_image_file["name"][$i];
         $file_image["type"] = $array_image_file["type"][$i];
         $file_image["tmp_name"] = $array_image_file["tmp_name"][$i];
         $file_image["error"] = $array_image_file["error"][$i];
         $file_image["size"] = $array_image_file["size"][$i];
         //adicionar cada image utilizando o módulo de imagem
         $array_config_info_post = array();
         $image_id = NULL;
         if (DataHandler::getValueByArrayIndex($_POST, "image_info_id")) {
             if (DataHandler::getValueByArrayIndex($_POST["image_info_id"], $i)) {
                 $image_id = $_POST["image_info_id"][$i];
             }
         }
         $array_config_info_post["image_info_id"] = $image_id;
         $array_config_info_post["image_info_name"] = isset($_POST["image_info_name"]) ? $_POST["image_info_name"][$i] : "";
         $array_config_info_post["image_info_description"] = isset($_POST["image_info_description"]) ? $_POST["image_info_description"][$i] : "";
         $array_config_info_post["image_info_order"] = isset($_POST["image_info_order"]) ? $_POST["image_info_order"][$i] : "";
         $array_config_info_post["image_info_locale"] = NULL;
         //$_POST["image_info_locale"][$i];
         $array_config_info_post["image_info_author"] = isset($_POST["image_info_author"][$i]) ? $_POST["image_info_author"][$i] : "";
         $array_config_info_post["table"] = "content";
         $array_config_info_post["table_id"] = $content_id;
         $array_config_info_post["Filedata"] = $file_image;
         $ImageInfoPostVO = new ImageInfoPostVO($array_config_info_post);
         //agora inicia o módulo passando esse info post configurado
         $FacilImage->resetInfoPost($ImageInfoPostVO);
         $ReturnResultVO = $FacilImage->insert();
     }
     //-----------------------------==================================== [[[  add file ]]]
     $array_image_file = DataHandler::getValueByArrayIndex($_FILES, "file");
     include_once "library/facil3/core/controller/file/FacilFile.php";
     $FacilFile = new FacilFile();
     //nome do módulo no sistema
     $FacilFile->moduleName = "file";
     $FacilFile->defaultFolderForNewFiles = "upload/file/";
     for ($i = 0; $i < count($array_image_file["name"]); $i++) {
         $file_image = array();
         $file_image["name"] = $array_image_file["name"][$i];
         $file_image["type"] = $array_image_file["type"][$i];
         $file_image["tmp_name"] = $array_image_file["tmp_name"][$i];
         $file_image["error"] = $array_image_file["error"][$i];
         $file_image["size"] = $array_image_file["size"][$i];
         //adicionar cada image utilizando o módulo de imagem
         $array_config_info_post = array();
         $array_config_info_post["file_info_id"] = isset($_POST["file_info_id"]) ? $_POST["file_info_id"][$i] : "";
         //$_POST["file_info_id"][$i];
         $array_config_info_post["file_info_name"] = isset($_POST["file_info_name"]) ? $_POST["file_info_name"][$i] : "";
         //$_POST["file_info_name"][$i];
         $array_config_info_post["file_info_description"] = isset($_POST["file_info_description"]) ? $_POST["file_info_description"][$i] : "";
         //$_POST["file_info_description"][$i];
         $array_config_info_post["file_info_order"] = isset($_POST["file_info_order"]) ? $_POST["file_info_order"][$i] : "";
         //$_POST["file_info_order"][$i];
         $array_config_info_post["file_info_locale"] = NULL;
         //$_POST["file_info_locale"][$i];
         $array_config_info_post["file_info_author"] = isset($_POST["file_info_author"]) ? $_POST["file_info_author"][$i] : "";
         //$_POST["file_info_author"][$i];
         $array_config_info_post["table"] = "content";
         $array_config_info_post["table_id"] = $content_id;
         $array_config_info_post["Filedata"] = $file_image;
         $FileInfoPostVO = new FileInfoPostVO($array_config_info_post);
         //agora inicia o módulo passando esse info post configurado
         $FacilFile->resetInfoPost($FileInfoPostVO);
         $FacilFile->insert();
     }
     //falta terminar
     //Navigation::redirect("admin/content/");
     $redirect_to = $this->my_redirect;
     if (DataHandler::getValueByArrayIndex($_POST, "redirect_to")) {
         $redirect_to = DataHandler::getValueByArrayIndex($_POST, "redirect_to");
     }
     if ($this->redirect_with_id) {
         $redirect_to .= "/id." . $content_id;
     }
     if ($redirect_page) {
         Navigation::redirect($redirect_to);
         exit;
     } else {
         return $contentVO;
     }
 }