setUser() публичный Метод

public setUser ( $user )
$user
Пример #1
0
 /**
  * @param $object
  * @param $title
  */
 public function addNoteOnObject($object, $title)
 {
     $note = new Model\Element\Note();
     $note->setElement($object);
     $note->setDate(time());
     $note->setType("newsletter");
     $note->setTitle($title);
     $note->setUser(0);
     $note->setData(["ip" => ["type" => "text", "data" => Tool::getClientIp()]]);
     $note->save();
 }
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $newsletter = Model\Tool\Newsletter\Config::getByName($input->getArgument("id"));
     if ($newsletter) {
         $pidFile = $newsletter->getPidFile();
         if (file_exists($pidFile)) {
             \Logger::alert("Cannot send newsletters because there's already one active sending process");
             exit;
         }
         $elementsPerLoop = 10;
         $objectList = "\\Pimcore\\Model\\Object\\" . ucfirst($newsletter->getClass()) . "\\Listing";
         $list = new $objectList();
         $conditions = array("(newsletterActive = 1 AND newsletterConfirmed = 1)");
         if ($newsletter->getObjectFilterSQL()) {
             $conditions[] = $newsletter->getObjectFilterSQL();
         }
         if ($newsletter->getPersonas()) {
             $class = Model\Object\ClassDefinition::getByName($newsletter->getClass());
             if ($class && $class->getFieldDefinition("persona")) {
                 $personas = array();
                 $p = explode(",", $newsletter->getPersonas());
                 if ($class->getFieldDefinition("persona") instanceof \Pimcore\Model\Object\ClassDefinition\Data\Persona) {
                     foreach ($p as $value) {
                         if (!empty($value)) {
                             $personas[] = $list->quote($value);
                         }
                     }
                     $conditions[] = "persona IN (" . implode(",", $personas) . ")";
                 } else {
                     if ($class->getFieldDefinition("persona") instanceof \Pimcore\Model\Object\ClassDefinition\Data\Personamultiselect) {
                         $personasCondition = array();
                         foreach ($p as $value) {
                             $personasCondition[] = "persona LIKE " . $list->quote("%," . $value . ",%");
                         }
                         $conditions[] = "(" . implode(" OR ", $personasCondition) . ")";
                     }
                 }
             }
         }
         $list->setCondition(implode(" AND ", $conditions));
         $list->setOrderKey("email");
         $list->setOrder("ASC");
         $elementsTotal = $list->getTotalCount();
         $count = 0;
         $pidContents = array("start" => time(), "lastUpdate" => time(), "newsletter" => $newsletter->getName(), "total" => $elementsTotal, "current" => $count);
         $this->writePid($pidFile, $pidContents);
         for ($i = 0; $i < ceil($elementsTotal / $elementsPerLoop); $i++) {
             $list->setLimit($elementsPerLoop);
             $list->setOffset($i * $elementsPerLoop);
             $objects = $list->load();
             foreach ($objects as $object) {
                 try {
                     $count++;
                     \Logger::info("Sending newsletter " . $count . " / " . $elementsTotal . " [" . $newsletter->getName() . "]");
                     \Pimcore\Tool\Newsletter::sendMail($newsletter, $object, null, $input->getArgument("hostUrl"));
                     $note = new Model\Element\Note();
                     $note->setElement($object);
                     $note->setDate(time());
                     $note->setType("newsletter");
                     $note->setTitle("sent newsletter: '" . $newsletter->getName() . "'");
                     $note->setUser(0);
                     $note->setData(array());
                     $note->save();
                     \Logger::info("Sent newsletter to: " . $this->obfuscateEmail($object->getEmail()) . " [" . $newsletter->getName() . "]");
                 } catch (\Exception $e) {
                     \Logger::err($e);
                 }
             }
             // check if pid exists
             if (!file_exists($pidFile)) {
                 \Logger::alert("Newsletter PID not found, cancel sending process");
                 exit;
             }
             // update pid
             $pidContents["lastUpdate"] = time();
             $pidContents["current"] = $count;
             $this->writePid($pidFile, $pidContents);
             \Pimcore::collectGarbage();
         }
         // remove pid
         @unlink($pidFile);
     } else {
         \Logger::emerg("Newsletter '" . $input->getArgument("id") . "' doesn't exist");
     }
 }
Пример #3
0
 /**
  * Creates a note for an action with a transition
  * @param Element\AbstractElement $element
  * @param string $type
  * @param string $title
  * @param string $description
  * @param array $noteData
  * @return Element\Note $note
  */
 public static function createActionNote($element, $type, $title, $description, $noteData, $user = null)
 {
     //prepare some vars for creating the note
     if (!$user) {
         $user = \Pimcore\Tool\Admin::getCurrentUser();
     }
     $note = new Element\Note();
     $note->setElement($element);
     $note->setDate(time());
     $note->setType($type);
     $note->setTitle($title);
     $note->setDescription($description);
     $note->setUser($user->getId());
     if (is_array($noteData)) {
         foreach ($noteData as $row) {
             $note->addData($row['key'], $row['type'], $row['value']);
         }
     }
     $note->save();
     return $note;
 }
 writePid($pidFile, $pidContents);
 for ($i = 0; $i < ceil($elementsTotal / $elementsPerLoop); $i++) {
     $list->setLimit($elementsPerLoop);
     $list->setOffset($i * $elementsPerLoop);
     $objects = $list->load();
     foreach ($objects as $object) {
         try {
             $count++;
             \Logger::info("Sending newsletter " . $count . " / " . $elementsTotal . " [" . $newsletter->getName() . "]");
             \Pimcore\Tool\Newsletter::sendMail($newsletter, $object, null, $argv[2]);
             $note = new Model\Element\Note();
             $note->setElement($object);
             $note->setDate(time());
             $note->setType("newsletter");
             $note->setTitle("sent newsletter: '" . $newsletter->getName() . "'");
             $note->setUser(0);
             $note->setData(array());
             $note->save();
             \Logger::info("Sent newsletter to: " . obfuscateEmail($object->getEmail()) . " [" . $newsletter->getName() . "]");
         } catch (\Exception $e) {
             \Logger::err($e);
         }
     }
     // check if pid exists
     if (!file_exists($pidFile)) {
         \Logger::alert("Newsletter PID not found, cancel sending process");
         exit;
     }
     // update pid
     $pidContents["lastUpdate"] = time();
     $pidContents["current"] = $count;
 /**
  * @param $code string
  * @return bool
  */
 public function confirmParticipationByCode($code)
 {
     $participation = Participation::getByConfirmationCode($code, 1);
     if (is_object($participation)) {
         $participation->SetIpConfirmed($_SERVER['REMOTE_ADDR']);
         $participation->setConfirmed(true);
         $participation->save();
         $note = new Note();
         $note->setElement($participation);
         $note->setDate(time());
         $note->setType("confirmation");
         $note->setTitle("Code confirmed");
         $note->addData("code", "text", $code);
         $note->setUser(0);
         $note->save();
         return true;
     }
     return false;
 }