Курс 2016 года “Разработка на UMI.CMS от 0 до готового сайта”

0 Пользователей и 1 Гость просматривают эту тему.

*

diii3

  • ***
  • 154
  • +6/-0
    • Просмотр профиля
Re:Добавление объекта каталога посетителем
« Ответ #30 : 28 Января 2012, 16:45:41 »
то есть мне нужно в папке classes/modules/catalog в файл __custom.php добавить весь код public function addCatalogObject() из class.php и в него добавить код на примере этого:

$message_id  = $event->getParam('message_id');
 
   $Name = "otnoshenialux.ru"; //senders name
   $email = "info@otnoshenialux.ru"; //senders e-mail adress
   $recipient = "djalimaria@gmail.com"; //recipient
   $mail_body = "The new comment on a site. For its editing follow the link: http://otnoshenialux.ru/admin/comments/edit/$message_id"; //mail body
   $subject = "New comment"; //subject
   $header = "From: ". $Name . " <" . $email . ">\r\n"; //optional headerfields
 
   if(mail($recipient, $subject, $mail_body, $header)){
      return true;
   } else {
      return false;
   }
}      

Я правильно понял?)

*

admin

  • *****
  • 2444
  • +172/-1
    • Просмотр профиля
Re:Добавление объекта каталога посетителем
« Ответ #31 : 28 Января 2012, 16:58:47 »
суть да, только я бы убрал строчку
$message_id  = $event->getParam('message_id');
так как это уже функция не для обработки события и $event у неё просто не будет, $message_id вы уже получали выше при создании нового объекта

и вот так
if(mail($recipient, $subject, $mail_body, $header)){
      return true;
   } else {
      return false;
   }
я почту еще не отправлял, всегда пользовался api классом для отправки почты, но на работоспособность этой функции мой личный опыт конечно вряд ли повлияет))

*

diii3

  • ***
  • 154
  • +6/-0
    • Просмотр профиля
Re:Добавление объекта каталога посетителем
« Ответ #32 : 28 Января 2012, 17:05:57 »
Спасибо большое!! Попробую. Только я не понял - второй код указанный вами тоже убрать из общего кода?

*

diii3

  • ***
  • 154
  • +6/-0
    • Просмотр профиля
Re:Добавление объекта каталога посетителем
« Ответ #33 : 28 Января 2012, 17:50:26 »
Что-то не получается отправка( Вот весь код, может я что-то не так понял?

<?php
   abstract class __custom_catalog {
      //TODO: Write here your own macroses
   };
   
   
   function addCatalogObject() {
      $hierarchy = umiHierarchy::getInstance();
      $hierarchyTypes = umiHierarchyTypesCollection::getInstance();
      $objectTypes = umiObjectTypesCollection::getInstance();
      $cmsController = cmsController::getInstance();

      $parent_id = (int) getRequest('param0');
      $object_type_id = (int) getRequest('param1');
      $title = htmlspecialchars(trim(getRequest('title')));

      $parentElement = $hierarchy->getElement($parent_id);
      $tpl_id      = $parentElement->getTplId();
      $domain_id   = $parentElement->getDomainId();
      $lang_id   = $parentElement->getLangId();

      $hierarchy_type_id = $hierarchyTypes->getTypeByName("catalog", "object")->getId();
      if(!$object_type_id) {
         $object_type_id = $objectTypes->getBaseType("catalog", "object");
      }

      if($parentElement instanceof umiHierarchyElement) {
         if($type_id = $hierarchy->getDominantTypeId($parent_id)) {
            $object_type_id = $type_id;
         }
      }


      $object_type = $objectTypes->getType($object_type_id);
      if($object_type->getHierarchyTypeId() != $hierarchy_type_id) {
         $this->errorNewMessage("Object type and hierarchy type doesn't match");
         $this->errorPanic();
      }

      $element_id = $hierarchy->addElement($parent_id, $hierarchy_type_id, $title, $title, $object_type_id, $domain_id, $lang_id, $tpl_id);

      $users = $cmsController->getModule("users");
      if($users instanceof def_module) {
         $users->setDefaultPermissions($element_id);
      }

      $element = $hierarchy->getElement($element_id, true);

      $element->setIsActive(true);
      $element->setIsVisible(false);
      $element->setName($title);

      $data = $cmsController->getModule("data");
      if($data instanceof def_module) {
         $object_id = $element->getObjectId();
         $data->saveEditedObject($object_id, true);
      }
      $element->getObject()->commit();
      $element->commit();
      $parentElement->setUpdateTime(time());
      $parentElement->commit();

      if($is_xslt) {
         return Array("node:result" => "ok");
      } else {
         if($element->getIsActive()) {
            $referer_url = $hierarchy->getPathById($element_id);
         } else {
            $referer_url = getServer('HTTP_REFERER');
         }
         $this->redirect($referer_url);
      }
      
      
      
      
      $Name = "vladcity33.ru"; //senders name
   $email = "info@vladcity33.ru"; //senders e-mail adress
   $recipient = "diii3@yandex.ru"; //recipient
   $mail_body = "The new comment on a site."; //mail body
   $subject = "New comment"; //subject
   $header = "From: ". $Name . " <" . $email . ">\r\n"; //optional headerfields
 

   if(mail($recipient, $subject, $mail_body, $header)){
      return true;
   } else {
      return false;
   }   
      
      
      
      
   };

   
   
   
   
   
   
?>

*

admin

  • *****
  • 2444
  • +172/-1
    • Просмотр профиля
Re:Добавление объекта каталога посетителем
« Ответ #34 : 28 Января 2012, 19:21:04 »
часть с отправкой почты не отрабатывается, так как выше стоит блок который делает редирект

 if($is_xslt) {
         return Array("node:result" => "ok");
      } else {
         if($element->getIsActive()) {
            $referer_url = $hierarchy->getPathById($element_id);
         } else {
            $referer_url = getServer('HTTP_REFERER');
         }
         $this->redirect($referer_url);
      }

этот блок должен быть самым последним

*

diii3

  • ***
  • 154
  • +6/-0
    • Просмотр профиля
Re:Добавление объекта каталога посетителем
« Ответ #35 : 28 Января 2012, 20:19:39 »
Не работает, к сожалению, вот весь код, может я что-то упустил?

<?php
   abstract class __custom_catalog {
      //TODO: Write here your own macroses
   };
   
   
   function addCatalogObject() {
      $hierarchy = umiHierarchy::getInstance();
      $hierarchyTypes = umiHierarchyTypesCollection::getInstance();
      $objectTypes = umiObjectTypesCollection::getInstance();
      $cmsController = cmsController::getInstance();

      $parent_id = (int) getRequest('param0');
      $object_type_id = (int) getRequest('param1');
      $title = htmlspecialchars(trim(getRequest('title')));

      $parentElement = $hierarchy->getElement($parent_id);
      $tpl_id      = $parentElement->getTplId();
      $domain_id   = $parentElement->getDomainId();
      $lang_id   = $parentElement->getLangId();

      $hierarchy_type_id = $hierarchyTypes->getTypeByName("catalog", "object")->getId();
      if(!$object_type_id) {
         $object_type_id = $objectTypes->getBaseType("catalog", "object");
      }

      if($parentElement instanceof umiHierarchyElement) {
         if($type_id = $hierarchy->getDominantTypeId($parent_id)) {
            $object_type_id = $type_id;
         }
      }


      $object_type = $objectTypes->getType($object_type_id);
      if($object_type->getHierarchyTypeId() != $hierarchy_type_id) {
         $this->errorNewMessage("Object type and hierarchy type doesn't match");
         $this->errorPanic();
      }

      $element_id = $hierarchy->addElement($parent_id, $hierarchy_type_id, $title, $title, $object_type_id, $domain_id, $lang_id, $tpl_id);

      $users = $cmsController->getModule("users");
      if($users instanceof def_module) {
         $users->setDefaultPermissions($element_id);
      }

      $element = $hierarchy->getElement($element_id, true);

      $element->setIsActive(true);
      $element->setIsVisible(false);
      $element->setName($title);

      $data = $cmsController->getModule("data");
      if($data instanceof def_module) {
         $object_id = $element->getObjectId();
         $data->saveEditedObject($object_id, true);
      }
      $element->getObject()->commit();
      $element->commit();
      $parentElement->setUpdateTime(time());
      $parentElement->commit();


      
      
      
      
      $Name = "vladcity33.ru"; //senders name
   $email = "diii3@yandex.ru"; //senders e-mail adress
   $recipient = "diii3@yandex.ru"; //recipient
   $mail_body = "The new comment on a site."; //mail body
   $subject = "New comment"; //subject
   $header = "From: ". $Name . " <" . $email . ">\r\n"; //optional headerfields
 

   if(mail($recipient, $subject, $mail_body, $header)){
      return true;
   } else {
      return false;
   }   
      
      
   
         if($is_xslt) {
         return Array("node:result" => "ok");
      } else {
         if($element->getIsActive()) {
            $referer_url = $hierarchy->getPathById($element_id);
         } else {
            $referer_url = getServer('HTTP_REFERER');
         }
         $this->redirect($referer_url);
      }
   
      
      
   };

   
   
   
   
   
   
?>



*

diii3

  • ***
  • 154
  • +6/-0
    • Просмотр профиля
Re:Добавление объекта каталога посетителем
« Ответ #36 : 31 Января 2012, 00:15:58 »
Я вот что подумал - может добавлять   function addCatalogObject()  нужно именно внутри в класс

 abstract class __custom_catalog {
      //TODO: Write here your own macroses
   };

??

*

BaceH

  • ***
  • 141
  • +21/-0
    • Просмотр профиля
Re:Добавление объекта каталога посетителем
« Ответ #37 : 31 Января 2012, 00:46:29 »
совершенно верно :)

*

diii3

  • ***
  • 154
  • +6/-0
    • Просмотр профиля
Re:Добавление объекта каталога посетителем
« Ответ #38 : 31 Января 2012, 00:50:19 »
Блин, все равно не работает)

*

BaceH

  • ***
  • 141
  • +21/-0
    • Просмотр профиля
Re:Добавление объекта каталога посетителем
« Ответ #39 : 31 Января 2012, 01:24:14 »
<?php
   abstract class __custom_catalog {
      //TODO: Write here your own macroses


function addCatalogObject() {
...
   }
};
точка с запятой ставиться только после скобки закрывающей класс, после функции ;  ставить не нужно.

*

diii3

  • ***
  • 154
  • +6/-0
    • Просмотр профиля
Re:Добавление объекта каталога посетителем
« Ответ #40 : 31 Января 2012, 09:13:37 »
Да, спасибо)

*

diii3

  • ***
  • 154
  • +6/-0
    • Просмотр профиля
Re:Добавление объекта каталога посетителем
« Ответ #41 : 31 Января 2012, 09:18:19 »
Вы знаете, что интересно - получается отправка, если добавить непосредственно в функцию addCatalogObject в class.php.........Может _custom.php вообще не обрабатывается?  Я даже пробовал в этом файле убирать часть кода, а объект как добавлялся, так и добавляется....Получается, что система обрабатывает функцию в class.php, а не _custom.php?

*

BaceH

  • ***
  • 141
  • +21/-0
    • Просмотр профиля
Re:Добавление объекта каталога посетителем
« Ответ #42 : 31 Января 2012, 09:38:45 »
addCatalogObject стандартная функция, измените имя к примеру addCatalogObjectSuper, при вызове также используйте это имя.
добавте к вызову public  function addCatalogObjectSuper() ...

*

diii3

  • ***
  • 154
  • +6/-0
    • Просмотр профиля
Re:Добавление объекта каталога посетителем
« Ответ #43 : 31 Января 2012, 09:52:38 »
Вызов вы имеет ввиду в форме добавления объекта?

<form  method="post" action="/catalog/addCatalogObject/{$catnam}/{$catid}" enctype="multipart/form-data" class="formtastic tender_placement_object">

Или в файле _custom.php?

*

BaceH

  • ***
  • 141
  • +21/-0
    • Просмотр профиля
Re:Добавление объекта каталога посетителем
« Ответ #44 : 31 Января 2012, 09:57:18 »
файле _custom.php прописываете

<?php
   abstract class __custom_catalog {
      //TODO: Write here your own macroses

public  function addCatalogObjectSuper(){
...
}

};
?>
форме добавления:
<form  method="post" action="/catalog/addCatalogObjectSuper/{$catnam}/{$catid}" enctype="multipart/form-data" class="formtastic tender_placement_object">