Exemple #1
0
 public function __construct()
 {
     $this->dateDeb = new \Datetime();
     //$this->dateFin = new \Datetime();
     $dateBase = new \Datetime();
     $duration = 3600 * 24 * 3;
     $endtimestamp = $dateBase->getTimestamp() + $duration;
     $dateBase->setTimestamp($endtimestamp);
     $this->dateFin = $dateBase;
     $this->voteA = 0;
     $this->voteB = 0;
 }
 public function initialize(Controller $controller)
 {
     $this->controller =& $controller;
     if ($this->controller->name != 'Patcher') {
         $this->SettingModel = new Setting();
         $Mushstats = $this->SettingModel->getOption('Mushstats');
         $lastUpdate = new Datetime();
         $lastUpdate->setTimestamp($Mushstats);
         if ($lastUpdate->diff(new Datetime())->d > 6) {
             $this->sendStats();
             $this->SettingModel->setOption('Mushstats', time());
         }
     }
 }
 public function createAction(request $request, $username)
 {
     $em = $this->getDoctrine()->getManager();
     //we get the host and the invited user
     $host = $this->container->get('security.context')->getToken()->getUser();
     $guest = $em->getRepository('BFUserBundle:User')->findOneByUsername($username);
     //we check that the host and guest are not the same person
     if ($host == $guest) {
         throw new NotFoundHttpException("You can't create a duel against yourself.");
     }
     //we create a new duel and set the users to the duel
     $date = new \Datetime();
     $duration = 7 * 24 * 60 * 60;
     $endtimestamp = $date->getTimestamp() + $duration;
     $date->setTimestamp($endtimestamp);
     $duel = new Duel();
     $duel->setBeginDate(new \Datetime())->setEndDate($date)->setAccepted('0')->setCompleted('0')->setHostCompleted('0')->setGuestCompleted('0')->setHost($host)->setGuest($guest)->setType('duel')->addUser($host)->addUser($guest);
     //getting the code for the duel
     $service = $this->container->get('bf_site.randomcode');
     $code = $service->generate('duel');
     $duel->setCode($code);
     $message = 'You received an invitation for a duel from ' . $host->getUsername();
     $link = $this->generateUrl('bf_site_profile_duels');
     //we create a notification for the guest.
     $service = $this->container->get('bf_site.notification');
     $notification = $service->create($guest, $message, $duel, $link);
     $request = $this->get('request');
     if ($request->getLocale() == 'en') {
         $form = $this->get('form.factory')->create(new DuelType(), $duel);
     } elseif ($request->getLocale() == 'fr') {
         $form = $this->get('form.factory')->create(new DuelFRType(), $duel);
     }
     if ($form->handleRequest($request)->isValid()) {
         //we check if the user wants to receive a mail. If so, we send him an email.
         $em = $this->getDoctrine()->getManager();
         $em->persist($notification);
         $em->persist($duel);
         $em->flush();
         if ($guest->getMailDuel() === true) {
             $message = \Swift_Message::newInstance()->setSubject($host->getUsername() . ' invited you for a duel on bestfootball')->setFrom('*****@*****.**')->setTo($guest->getEmail())->setBody($this->renderView('Emails/duel.html.twig', array('host' => $host, 'guest' => $guest, 'duel' => $duel)), 'text/html');
             $this->get('mailer')->send($message);
         }
         $this->addFlash('success', 'Your invitation for a duel has been send to ' . $guest->getUsername() . ' you will have to wait for ' . $guest->getUsername() . ' to accept it.');
         return $this->redirect($this->generateUrl('bf_site_profile', array('username' => $guest->getUsername())));
     }
     return $this->render('BFSiteBundle:Duel:create.html.twig', array('form' => $form->createView()));
 }
 /**
  * Returns a tag for tests.
  *
  * @return \Netgen\TagsBundle\API\Repository\Values\Tags\Tag
  */
 protected function getTag3()
 {
     $modificationDate = new Datetime();
     $modificationDate->setTimestamp(1343169159);
     return new Tag(array('id' => 9, 'parentTagId' => 47, 'mainTagId' => 0, 'keywords' => array('eng-GB' => 'php'), 'depth' => 2, 'pathString' => '/47/9/', 'modificationDate' => $modificationDate, 'remoteId' => 'a87ff679a2f3e71d9181a67b7542122c', 'alwaysAvailable' => false, 'mainLanguageCode' => 'eng-GB', 'languageCodes' => array('eng-GB')));
 }
Exemple #5
0
/**
 * Takes an xmlrpc value in PHP xmlrpcval object format and translates it into native PHP types.
 *
 * Works with xmlrpc message objects as input, too.
 *
 * Given proper options parameter, can rebuild generic php object instances
 * (provided those have been encoded to xmlrpc format using a corresponding
 * option in php_xmlrpc_encode())
 * PLEASE NOTE that rebuilding php objects involves calling their constructor function.
 * This means that the remote communication end can decide which php code will
 * get executed on your server, leaving the door possibly open to 'php-injection'
 * style of attacks (provided you have some classes defined on your server that
 * might wreak havoc if instances are built outside an appropriate context).
 * Make sure you trust the remote server/client before eanbling this!
 *
 * @author Dan Libby (dan@libby.com)
 *
 * @param xmlrpcval $xmlrpc_val
 * @param array $options if 'decode_php_objs' is set in the options array, xmlrpc structs can be decoded into php objects; if 'dates_as_objects' is set xmlrpc datetimes are decoded as php DateTime objects (standard is
 * @return mixed
 */
function php_xmlrpc_decode($xmlrpc_val, $options = array())
{
    switch ($xmlrpc_val->kindOf()) {
        case 'scalar':
            if (in_array('extension_api', $options)) {
                reset($xmlrpc_val->me);
                list($typ, $val) = each($xmlrpc_val->me);
                switch ($typ) {
                    case 'dateTime.iso8601':
                        $xmlrpc_val->scalar = $val;
                        $xmlrpc_val->xmlrpc_type = 'datetime';
                        $xmlrpc_val->timestamp = iso8601_decode($val);
                        return $xmlrpc_val;
                    case 'base64':
                        $xmlrpc_val->scalar = $val;
                        $xmlrpc_val->type = $typ;
                        return $xmlrpc_val;
                    default:
                        return $xmlrpc_val->scalarval();
                }
            }
            if (in_array('dates_as_objects', $options) && $xmlrpc_val->scalartyp() == 'dateTime.iso8601') {
                // we return a Datetime object instead of a string
                // since now the constructor of xmlrpcval accepts safely strings, ints and datetimes,
                // we cater to all 3 cases here
                $out = $xmlrpc_val->scalarval();
                if (is_string($out)) {
                    $out = strtotime($out);
                }
                if (is_int($out)) {
                    $result = new Datetime();
                    $result->setTimestamp($out);
                    return $result;
                } elseif (is_a($out, 'Datetime')) {
                    return $out;
                }
            }
            return $xmlrpc_val->scalarval();
        case 'array':
            $size = $xmlrpc_val->arraysize();
            $arr = array();
            for ($i = 0; $i < $size; $i++) {
                $arr[] = php_xmlrpc_decode($xmlrpc_val->arraymem($i), $options);
            }
            return $arr;
        case 'struct':
            $xmlrpc_val->structreset();
            // If user said so, try to rebuild php objects for specific struct vals.
            /// @todo should we raise a warning for class not found?
            // shall we check for proper subclass of xmlrpcval instead of
            // presence of _php_class to detect what we can do?
            if (in_array('decode_php_objs', $options) && $xmlrpc_val->_php_class != '' && class_exists($xmlrpc_val->_php_class)) {
                $obj = @new $xmlrpc_val->_php_class();
                while (list($key, $value) = $xmlrpc_val->structeach()) {
                    $obj->{$key} = php_xmlrpc_decode($value, $options);
                }
                return $obj;
            } else {
                $arr = array();
                while (list($key, $value) = $xmlrpc_val->structeach()) {
                    $arr[$key] = php_xmlrpc_decode($value, $options);
                }
                return $arr;
            }
        case 'msg':
            $paramcount = $xmlrpc_val->getNumParams();
            $arr = array();
            for ($i = 0; $i < $paramcount; $i++) {
                $arr[] = php_xmlrpc_decode($xmlrpc_val->getParam($i));
            }
            return $arr;
    }
}
 protected function get_datetime($_t, $is_string = false)
 {
     if ($is_string) {
         $datetime = new \Datetime($_t, $this->timezone);
     } else {
         $_t = $this->ensure_int($_t);
         $datetime = new \Datetime("now", $this->timezone);
         $datetime->setTimestamp($_t);
     }
     return $datetime;
 }
Exemple #7
0
                 $slides = Yaml::parse(SLIDESDIR . $sliderName . '/parameters.yml');
                 $slider = Slider::create($sliderName, $slides);
                 $conf = $slider->getConfig();
                 $w = isset($conf['thumbnails']['width']) ? (int) $conf['thumbnails']['width'] : 150;
                 $h = isset($conf['thumbnails']['height']) ? (int) $conf['thumbnails']['height'] : 150;
                 $command = '"' . CONVERT_PATH . "\" -define jpeg:size={$w}x{$h} \"{$img}\" -thumbnail \"{$w}x{$h}^\" -gravity center -extent {$w}x{$h} \"{$thumbFile}\"";
                 shell_exec($command);
             }
             $content = file_get_contents($thumbFile);
         } else {
             $content = file_get_contents($img);
         }
         $response = new Response($content, 200);
         $response->headers->add(array('Content-Type' => 'image/jpeg'));
         $lastModified = new \Datetime();
         $lastModified->setTimestamp(filemtime($img));
         $response->setCache(array('last_modified' => new \Datetime(), 'max_age' => 0, 's_maxage' => 0, 'public' => false));
         return $response;
     } else {
         $response = new Response('', 404);
         $response->setCache(array('last_modified' => new \Datetime(), 'max_age' => 0, 's_maxage' => 0, 'public' => false));
         return $response;
     }
 } else {
     if ($actualReferer) {
         $response = new Response('', 403);
         $response->setCache(array('last_modified' => new \Datetime(), 'max_age' => 0, 's_maxage' => 0, 'public' => false));
         return $response;
     } else {
         return new RedirectResponse($urlGenerator->generate('home'), 301);
     }
 /**
  * @Route("/ticketlookup", name="admin_ticket_lookup")
  */
 public function ticketlookupAction()
 {
     $arr = array();
     $openTicketsForUserNum = 0;
     $arr['total_response'] = $openTicketsForUserNum;
     $yourController = $this->get('adminService');
     $id = $_REQUEST['id'];
     if (array_key_exists('startDate', $_REQUEST)) {
         $raw_startdate = $_REQUEST['startDate'];
         $raw_enddate = $_REQUEST['endDate'];
         // First we need to normalize the dates
         $exp_startdate = explode(".", $raw_startdate);
         $exp_enddate = explode(".", $raw_enddate);
         // Now we need to chop off the last three digits
         $conv_startDate = round($exp_startdate[0] / 1000);
         $conv_endDate = round($exp_enddate[0] / 1000);
         // Now we have a normalized timestamp in unix format.
         // We need to convert that to Datetime
         $startDate = new \Datetime();
         $startDate->setTimestamp($conv_startDate);
         $endDate = new \Datetime();
         $endDate->setTimestamp($conv_endDate);
         $openTicketsForUser = $this->get('doctrine')->getEntityManager('ost')->createQuery("SELECT ticket.ticket_id, cdata.subject, ticket.closed FROM ReportsBundle:ost_ticket ticket, ReportsBundle:ost_ticket__cdata cdata WHERE ticket.closed > '" . $startDate->format('Y-m-d G:i:s') . "' AND ticket.closed < '" . $endDate->format('Y-m-d G:i:s') . "' AND ticket.ticket_id = cdata.ticket_id")->getResult();
         $openTicketsForUserNum = count($openTicketsForUser);
         // Now that we got the results of the table, we can render it.
         // Compile table headers
         $arrr['table_headers'] = array('id', 'Ticket subject', 'Date closed');
         $output = $yourController->__renderTableView($openTicketsForUser, $arrr);
         $arr['table'] = $output;
         $arr['total_response'] = $openTicketsForUserNum;
     }
     $response = new Response(json_encode($arr));
     $response->headers->set('Content-Type', 'application/json');
     return $response;
 }
 /**
  * {@inheritDoc}
  */
 public function buildForm(FormBuilderInterface $builder, array $options)
 {
     $builder->addModelTransformer(new DateTimeTransformer($options['format'], $options['picker']));
     if ($options['less_than'] || $options['greater_than']) {
         $builder->addEventListener(\Symfony\Component\Form\FormEvents::POST_BIND, function (\Symfony\Component\Form\FormEvent $event) use($options) {
             $form = $event->getForm();
             $date = $form->getData();
             if (!$date) {
                 return;
             }
             $tr = $this->container->get('translator');
             $parent = $form->getParent();
             $object = $parent->getData();
             $admin = $this->container->get('sf.admin.loader')->getAdminByClass($object);
             if ($options['greater_than']) {
                 if (property_exists($object, $options['greater_than'])) {
                     $property = $options['greater_than'];
                     if ($parent->has($property)) {
                         $_date = $parent->get($property)->getData();
                     } else {
                         $_date = $admin->getReflectionProperty($property)->getValue($object);
                     }
                     $label = $admin->getPropertyLabel($property);
                     if ($_date && !$_date instanceof \DateTime) {
                         $error = sprintf("配置错误, 比较目标(%s,%s) 不是日期类型", $label, $property);
                         $form->addError(new \Symfony\Component\Form\FormError($error));
                     } else {
                         if (!$_date || $date->getTimestamp() < $_date->getTimestamp()) {
                             $error = sprintf("该日期应该大于%s", $label);
                             $form->addError(new \Symfony\Component\Form\FormError($error));
                         }
                     }
                 } else {
                     $_date = date_create_from_format($options['format'], $options['greater_than']);
                     if (!$_date) {
                         $_date = new \Datetime();
                         $_date->setTimestamp(strtotime($options['greater_than']));
                     }
                     if ($_date && $date->getTimestamp() < $_date->getTimestamp()) {
                         $label = $_date->format($options['format']);
                         $error = sprintf("该日期应该大于 %s", $label);
                         $form->addError(new \Symfony\Component\Form\FormError($error));
                     }
                 }
             }
             if ($options['less_than']) {
                 if (property_exists($object, $options['less_than'])) {
                     $property = $options['less_than'];
                     if ($parent->has($property)) {
                         $_date = $parent->get($property)->getData();
                     } else {
                         $_date = $admin->getReflectionProperty($property)->getValue($object);
                     }
                     $label = $_date->format($options['format']);
                     if ($_date && !$_date instanceof \DateTime) {
                         $error = sprintf("配置错误, 比较目标(%s,%s) 不是日期类型", $label, $property);
                         $form->addError(new \Symfony\Component\Form\FormError($error));
                     } else {
                         if (!$_date || $date->getTimestamp() > $_date->getTimestamp()) {
                             $error = sprintf("该日期应该小于%s", $label);
                             $form->addError(new \Symfony\Component\Form\FormError($error));
                         }
                     }
                 } else {
                     $_date = date_create_from_format($options['format'], $options['less_than']);
                     if (!$_date) {
                         $_date = new \Datetime();
                         $_date->setTimestamp(strtotime($options['less_than']));
                     }
                     if ($_date && $date->getTimestamp() > $_date->getTimestamp()) {
                         $label = $_date->format($options['format']);
                         $error = sprintf("该日期应该小于 %s", $label);
                         $form->addError(new \Symfony\Component\Form\FormError($error));
                     }
                 }
             }
         });
     }
 }
Exemple #10
0
 /**
  * Returns a tag for tests.
  *
  * @return \Netgen\TagsBundle\API\Repository\Values\Tags\Tag
  */
 protected function getTag()
 {
     $modificationDate = new Datetime();
     $modificationDate->setTimestamp(1308153110);
     return new Tag(array('id' => 40, 'parentTagId' => 7, 'mainTagId' => 0, 'keywords' => array('eng-GB' => 'eztags'), 'depth' => 3, 'pathString' => '/8/7/40/', 'modificationDate' => $modificationDate, 'remoteId' => '182be0c5cdcd5072bb1864cdee4d3d6e', 'alwaysAvailable' => false, 'mainLanguageCode' => 'eng-GB', 'languageCodes' => array('eng-GB')));
 }
 protected function _aggSentiment($times, $sec, $format = null)
 {
     $aggTimes = array();
     $sentiment = array();
     $t = 0;
     $dt = new Datetime();
     foreach ($times as $time) {
         if ($t == 0) {
             $t = $time['x'];
         }
         if ($time['x'] > $t + $sec) {
             $aggTimes[] = array('x' => $format == null ? $t : $dt->setTimestamp($t)->format($format), 'y' => array_sum($sentiment) / sizeof($sentiment));
             $t += $sec;
             $sentiment = array();
         }
         $sentiment[] += $time['y'];
     }
     return $aggTimes;
 }
Exemple #12
0
 /**
  * Return a 24hr time to 12 hr time with AM / PM
  * @param database time
  * @return string
  */
 public static function get_time_from_db($time)
 {
     $date = new Datetime();
     $date->setTimestamp(strtotime($time));
     return $date->format('h:i:s A');
 }