Example #1
0
 public function editCustomRecord($parameters)
 {
     $parameters['packages'] = Package::all();
     $date = new \DateTime();
     $parameters['lastRun'] = $date->setTimestamp($parameters['object']->last_run_011)->format('d-m-Y H:i:s');
     $parameters['nextRun'] = $date->setTimestamp($parameters['object']->next_run_011)->format('d-m-Y H:i:s');
     return $parameters;
 }
Example #2
0
	/**
	 * Set the data/time of this object.
	 *
	 * If a unix timestamp is used, it is automatically set as GMT.
	 * If a formatted date it used, the TIME_DEFAULT_TIMEZONE is used instead.
	 *
	 * @param $datetime string|int
	 */
	public function setDate($datetime){
		//echo "Incoming date: [" . $datetime . "]<br/>"; die();
		// If the number coming in is strictly numeric, interpret that as a unix timestamp in GMT.
		if(is_numeric($datetime)){
			$this->_dt = new DateTime(null, self::_GetTimezone('GMT'));
			$this->_dt->setTimestamp($datetime);
		}
		else{
			$this->_dt = new DateTime($datetime, self::_GetTimezone(TIME_DEFAULT_TIMEZONE));
		}
	}
 /**
  * @param Request $request
  *
  * @return $this
  */
 protected function setModifiedSince(Request $request)
 {
     $this->since = new \DateTime();
     if ($request->headers->has('If-Modified-Since')) {
         $string = $request->headers->get('If-Modified-Since');
         $this->since = \DateTime::createFromFormat(\DateTime::RSS, $string);
     } else {
         $this->since->setTimestamp(1);
     }
     return $this;
 }
Example #4
0
 /**
  * Extend the expiration datetime by the set TTL.
  *
  * If there is no expiration datetime initialized, it will be.
  *
  * @throws \DomainException If there is no TTL set.
  */
 public function extendExpiration()
 {
     if (null === $this->ttl) {
         throw new DomainException('There is no TTL set for this Lock.');
     }
     if (!$this->expiresAt) {
         $this->expiresAt = new \DateTime();
         $this->expiresAt->setTimestamp(time());
     }
     $this->expiresAt->add($this->ttl);
 }
Example #5
0
 public function rt_liste()
 {
     $args = "objectid,type_intervention,commune,adresse,niveau_gene,descr_gene1,descr_gene2,descr_gene3,date_debut,date_fin";
     $travaux = json_decode(file_get_contents("https://geoservices.grand-nancy.org/arcgis/rest/services/public/VOIRIE_Info_Travaux_Niveau/MapServer/0/query?text=&geometry=&geometryType=esriGeometryEnvelope&inSR=&spatialRel=esriSpatialRelIntersects&relationParam=&objectIds=&where=1%3D1&time=&returnIdsOnly=false&returnGeometry=true&maxAllowableOffset=&outSR=4326&outFields=" . $args . "&f=pjson"));
     foreach ($travaux->features as $value) {
         $date = new DateTime();
         $date->setTimestamp(substr($value->attributes->DATE_DEBUT, 0, -3));
         $date_debut = $date->format('Y-m-d H:i');
         $date->setTimestamp(substr($value->attributes->DATE_FIN, 0, -3));
         $date_fin = $date->format('Y-m-d H:i');
         $result[] = array('lat' => $value->geometry->y, 'lng' => $value->geometry->x, 'niveau_gen' => $value->attributes->NIVEAU_GENE, 'adresse' => $value->attributes->ADRESSE, 'commune' => $value->attributes->COMMUNE, 'type_inter' => $value->attributes->TYPE_INTERVENTION, 'date_debut' => $date_debut, 'date_fin' => $date_fin, 'descr_gene' => $value->attributes->DESCR_GENE1, 'descr_ge_1' => $value->attributes->DESCR_GENE2, 'descr_ge_2' => $value->attributes->DESCR_GENE3);
     }
     $retour['travaux'] = $result;
     retour('liste des travaux', TRUE, $retour);
 }
Example #6
0
 public function decode($string, $intention)
 {
     $dotCount = substr_count($string, '.');
     if ($dotCount < 2) {
         throw new InvalidSignedStringException();
     }
     list($algorithm, $hash, $data) = explode('.', $string, 3);
     $expectedHash = $this->getSign($data, $algorithm);
     if ($hash !== $expectedHash) {
         throw new InvalidSignerException();
     }
     $decoded = $this->filter->decode($data);
     if (!isset($decoded['intention']) || $decoded['intention'] !== $intention) {
         $exception = new InvalidIntentionException($intention, $decoded['intention']);
         $exception->setData($decoded);
         throw $exception;
     }
     $now = new \DateTime();
     if (null !== $decoded['expires'] && $decoded['expires'] < $now->getTimestamp()) {
         $exception = new ExpiredException();
         $exception->setData($decoded);
         throw $exception;
     }
     $data = new Data();
     $data->setIntention($decoded['intention'])->setData($decoded['data']);
     if ($decoded['expires']) {
         $expires = new \DateTime();
         $expires->setTimestamp($decoded['expires']);
         $data->setExpires($expires);
     }
     return $data;
 }
 /**
  * @override
  *
  * provide database fields types translators
  */
 public function __set_translators()
 {
     return array_merge(parent::__set_translators(), ['integer' => 'intval', 'float' => 'floatval', 'double' => 'doubleval', 'boolean' => function ($val) {
         return empty($val) ? false : true;
     }, 'datetime' => function ($val) {
         if ($val instanceof DateTime) {
             return $val;
         }
         // try to convert using strtotime(), this is expect to work for
         // database formated dates.
         $ret = null;
         $t = strtotime($val);
         if ($t) {
             $ret = new DateTime();
             $ret->setTimestamp($t);
         } else {
             $ret = s_to_datetime($val);
         }
         if (!$ret) {
             throw new InvalidArgumentException("{$val}: could not translate into datetime");
         }
         return $ret;
     }, 'json' => function ($val) {
         if (!is_string($val)) {
             $val = json_encode($val);
         }
         return json_decode($val);
     }, 'uuidv4' => function ($val) {
         return is_uuidv4(trim($val)) ? strtolower(trim($val)) : null;
     }]);
 }
 /**
  * @param string $token
  * @param string $type The token type (from OAuth2 key 'token_type').
  * @param array  $data Other token data.
  */
 public function __construct($token, $type, array $data = [])
 {
     $this->token = $token;
     $this->type = $type;
     $this->data = $data;
     if (isset($data['expires'])) {
         $this->expires = new \DateTime();
         $this->expires->setTimestamp($data['expires']);
     } elseif (isset($data['expires_in'])) {
         $this->expires = new \DateTime();
         $this->expires->add(new \DateInterval(sprintf('PT%sS', $data['expires_in'])));
     }
     if (isset($data['refresh_token'])) {
         $this->refreshToken = new self($data['refresh_token'], 'refresh_token');
     }
 }
 public function addAction()
 {
     $form = new CalendarForm();
     $request = $this->getRequest();
     $calendarDAO = CalendarDAO::getInstance($this->getServiceLocator());
     $query = $request->getQuery();
     if ($request->isPost()) {
         $post = $request->getPost()->toArray();
         $form->setData($post);
         if ($form->isValid()) {
             $data = $form->getData();
             $dateTime = new \DateTime();
             $dateTime->setTimestamp(strtotime($data['date']));
             $data['date'] = $dateTime;
             $userData = new Calendar();
             $userData->setTitle($data['title']);
             $userData->setDescription($data['description']);
             $userData->setDate($data['date']);
             $calendarDAO->save($userData);
             $viewModel = new ViewModel(array('done' => true));
             $viewModel->setTerminal(true);
             return $viewModel;
         } else {
             $form->getMessages();
         }
     } elseif (!empty($query)) {
         $date = $query->date;
         $form->get('date')->setValue(date('d-M-Y', strtotime($date)));
     }
     $viewModel = new ViewModel(array('form' => $form));
     $viewModel->setTerminal(true);
     return $viewModel;
 }
Example #10
0
function date_from_timestamp($timestamp)
{
    $CI =& get_instance();
    $date = new DateTime();
    $date->setTimestamp($timestamp);
    return $date->format($CI->mdl_settings->setting('date_format'));
}
Example #11
0
 public function getCreationDate()
 {
     $date = new \DateTime();
     $date->setTimezone(new \DateTimeZone('UTC'));
     $date->setTimestamp(filemtime($this->getDir()));
     return $date;
 }
Example #12
0
 public function __construct($config, $destination)
 {
     date_default_timezone_set('UTC');
     $this->destination = $destination;
     foreach ($this->mandatoryConfigColumns as $c) {
         if (!isset($config[$c])) {
             throw new Exception("Mandatory column '{$c}' not found or empty.");
         }
         $this->config[$c] = $config[$c];
     }
     foreach (array('start_date', 'end_date') as $dateId) {
         $timestamp = strtotime($this->config[$dateId]);
         if ($timestamp === FALSE) {
             throw new Exception("Invalid time value in field " . $dateId);
         }
         $dateTime = new DateTime();
         $dateTime->setTimestamp($timestamp);
         $this->config[$dateId] = $dateTime->format('Y-m-d');
     }
     if (!is_array($this->config['queries'])) {
         throw new Exception("You have to put some queries in queries list.");
     }
     // API initialization
     $this->api = new RestClient(array('base_url' => "https://www.zuora.com/apps", 'headers' => array('Accept' => 'application/json', 'Content-Type' => 'application/json'), 'username' => $this->config['username'], 'password' => $this->config['#password']));
     $this->api->register_decoder('json', create_function('$a', "return json_decode(\$a, TRUE);"));
 }
Example #13
0
 /**
  * 
  * function val - This function allows validate the date format and if it's true
  * return the same date if it's not throw and exception.
  * 
  * @param string $val 
  * @return string
  * @throws \SimplOn\DataValidationException
  */
 function val($val = null)
 {
     // if $val is defined and isn't null, start to verify the value
     if (isset($val) && $val) {
         $val = trim($val);
         //if $val is empty and is required then throw an exception.
         if (!$val && $this->required) {
             throw new \SimplOn\DataValidationException($this->validationDate);
         } else {
             try {
                 if (is_numeric($val)) {
                     $dateObj = new \DateTime();
                     $dateObj->setTimestamp($val);
                 } else {
                     $dateObj = new \DateTime($val);
                     // throw new \SimplOn\DataValidationException($this->isnotNumeric);
                 }
             } catch (\Exception $e) {
                 throw new \SimplOn\DataValidationException($this->validationDate);
             }
         }
         // $this->val save the date with format for database
         $this->val = $dateObj->format($this->dbFormat);
         // $this->viewVal save the the date with format to show in the view
         $this->viewVal = $dateObj->format($this->viewFormat);
     } else {
         return $this->val;
     }
 }
Example #14
0
 public static function time_ago($timestamp)
 {
     $now = new DateTime('now');
     $from = new DateTime();
     $from->setTimestamp($timestamp);
     $diff = date_diff($now, $from);
     if ($diff->y > 0) {
         $message = $diff->y . ' year' . ($diff->y > 1 ? 's' : '');
     } else {
         if ($diff->m > 0) {
             $message = $diff->m . ' month' . ($diff->m > 1 ? 's' : '');
         } else {
             if ($diff->d > 0) {
                 $message = $diff->d . ' day' . ($diff->d > 1 ? 's' : '');
             } else {
                 if ($diff->h > 0) {
                     $message = $diff->h . ' hour' . ($diff->h > 1 ? 's' : '');
                 } else {
                     if ($diff->i > 0) {
                         $message = $diff->i . ' minute' . ($diff->i > 1 ? 's' : '');
                     } else {
                         if ($diff->s > 0) {
                             $message = $diff->s . ' second' . ($diff->s > 1 ? 's' : '');
                         } else {
                             $message = 'a moment';
                         }
                     }
                 }
             }
         }
     }
     return $message . ' ago';
 }
Example #15
0
 public static function getLicenceInfos()
 {
     if (file_exists("../licence/licence.php")) {
         $key = implode("", file("../licence/licence.php"));
         $datas = explode("|", $key);
         $dtf = ($datas[2] + CoreManager::$v2) / CoreManager::$v1;
         $plateform = $datas[3];
         $nbf = $datas[4] * (CoreManager::$v2 / CoreManager::$v3) / (CoreManager::$v7 / 2);
         $nbs = ($datas[5] + CoreManager::$v5) / CoreManager::$v4;
         $stats = $datas[6];
         $nomClient = $datas[9];
         $socClient = $datas[7];
         $domains = $datas[8];
         $key = $datas[1];
         $calculation = md5($datas[2] . ":" . $datas[3] . ":" . $datas[4] . ":" . $datas[5] . ":" . $datas[6] . ":" . $datas[8] . ":" . $datas[7]);
         if ($key != $calculation) {
             throw new \Exception("Licence is not valid");
         }
         $eol = new \DateTime();
         $eol->setTimestamp($dtf);
         $now = new \DateTime();
         if ($eol < $now) {
             throw new \Exception("Licence expirée");
         }
         return array("isvalid" => true, "dtf" => $dtf, "plateform" => $plateform, "nbf" => $nbf, "nbs" => $nbs, "stats" => $stats, "nom" => $nomClient, "societe" => $socClient, "domains" => explode(',', $domains));
     } else {
         throw new \Exception("Licence file not found");
     }
 }
 /**
  * {@inheritDoc}
  */
 public function load(ObjectManager $manager)
 {
     $data = $this->userFixtureDataSource();
     // Have to keep a reference to all the user objects
     // or else they can't be flushed all at once.
     $items = array();
     $user = new User();
     foreach ($data['User'] as $item) {
         $user = new User();
         $user->setUuid($item['uuid'])->setUsername($item['username'])->setPassword($item['password'])->setEmail($item['email'])->setIsActive($item['is_active']);
         $this->addReference($user->getUuid(), $user);
         $items[] = $user;
         $manager->persist($user);
     }
     $manager->flush();
     $items = array();
     foreach ($data['Record'] as $item) {
         $record = new Record();
         $record->setCategory($item['category'])->setKey($item['aKey'])->setData($item['data'])->setOwner($manager->merge($this->getReference($item['owner_uuid'])));
         $timestamp = new \DateTime('now');
         if (!empty($item['timestamp'])) {
             $timestamp->setTimestamp($item['timestamp']);
         }
         $record->setTimestamp($timestamp);
         $items[] = $record;
         $manager->persist($record);
     }
     $manager->flush();
 }
Example #17
0
 /**
  * @param AssetInterface $asset
  * @param AssetWriter $writer
  * @param array $cachePath
  * @param array $headers
  */
 public function __construct(AssetInterface $asset, AssetWriter $writer, $cachePath, array $headers = [])
 {
     $file = $asset->getTargetPath();
     $cachePath = $cachePath . '/' . $file;
     $cached = false;
     $cacheTime = time();
     if (is_file($cachePath)) {
         $mTime = $asset->getLastModified();
         $cacheTime = filemtime($cachePath);
         if ($mTime > $cacheTime) {
             @unlink($cachePath);
             $cacheTime = $mTime;
         } else {
             $cached = true;
         }
     }
     if (!$cached) {
         $writer->writeAsset($asset);
     }
     $stream = function () use($cachePath) {
         readfile($cachePath);
     };
     $headers['Content-Length'] = filesize($cachePath);
     if (preg_match('/.+\\.([a-zA-Z0-9]+)/', $file, $matches)) {
         $ext = $matches[1];
         if (isset($this->mimeTypes[$ext])) {
             $headers['Content-Type'] = $this->mimeTypes[$ext];
         }
     }
     parent::__construct($stream, 200, $headers);
     $date = new \DateTime();
     $date->setTimestamp($cacheTime);
     $this->setLastModified($date);
 }
Example #18
0
 /**
  * Sets the date and time based on an Unix timestamp
  *
  * @param integer $timestamp Unix timestamp representing the date.
  * @return KDate or FALSE on failure.
  */
 public function setTimestamp($timestamp)
 {
     if ($this->_date->setTimestamp($timestamp) === false) {
         return false;
     }
     return $this;
 }
Example #19
0
 public function render(Request $request, $name, $pos = null)
 {
     if (!$this->enableProfiler && null !== $this->profiler) {
         $this->profiler->disable();
     }
     if (!$this->am->has($name)) {
         throw new NotFoundHttpException(sprintf('The "%s" asset could not be found.', $name));
     }
     $asset = $this->am->get($name);
     if (null !== $pos && !($asset = $this->findAssetLeaf($asset, $pos))) {
         throw new NotFoundHttpException(sprintf('The "%s" asset does not include a leaf at position %d.', $name, $pos));
     }
     $response = $this->createResponse();
     $response->setExpires(new \DateTime());
     $this->configureAssetValues($asset, $request);
     // last-modified
     if (null !== ($lastModified = $this->am->getLastModified($asset))) {
         $date = new \DateTime();
         $date->setTimestamp($lastModified);
         $response->setLastModified($date);
     }
     // etag
     if ($this->am->hasFormula($name)) {
         $formula = $this->am->getFormula($name);
         $formula['last_modified'] = $lastModified;
         $response->setETag(md5(serialize($formula)));
     }
     if ($response->isNotModified($request)) {
         return $response;
     }
     $etagCacheKeyFilter = new AssetCacheKeyFilter($response->getEtag());
     $response->setContent($this->cachifyAsset($asset)->dump($etagCacheKeyFilter));
     return $response;
 }
 public function hydrate($document, $data, array $hints = array())
 {
     $hydratedData = array();
     /** @Field(type="id") */
     if (isset($data['_id'])) {
         $value = $data['_id'];
         $return = (string) $value;
         $this->class->reflFields['id']->setValue($document, $return);
         $hydratedData['id'] = $return;
     }
     /** @Field(type="string") */
     if (isset($data['name'])) {
         $value = $data['name'];
         $return = (string) $value;
         $this->class->reflFields['name']->setValue($document, $return);
         $hydratedData['name'] = $return;
     }
     /** @Field(type="int") */
     if (isset($data['length'])) {
         $value = $data['length'];
         $return = (int) $value;
         $this->class->reflFields['length']->setValue($document, $return);
         $hydratedData['length'] = $return;
     }
     /** @Field(type="date") */
     if (isset($data['uploadDate'])) {
         $value = $data['uploadDate'];
         if ($value instanceof \MongoDate) {
             $date = new \DateTime();
             $date->setTimestamp($value->sec);
             $return = $date;
         } else {
             $return = new \DateTime($value);
         }
         $this->class->reflFields['uploadDate']->setValue($document, clone $return);
         $hydratedData['uploadDate'] = $return;
     }
     /** @Field(type="int") */
     if (isset($data['chunkSize'])) {
         $value = $data['chunkSize'];
         $return = (int) $value;
         $this->class->reflFields['chunkSize']->setValue($document, $return);
         $hydratedData['chunkSize'] = $return;
     }
     /** @Field(type="string") */
     if (isset($data['md5'])) {
         $value = $data['md5'];
         $return = (string) $value;
         $this->class->reflFields['md5']->setValue($document, $return);
         $hydratedData['md5'] = $return;
     }
     /** @Field(type="file") */
     if (isset($data['file'])) {
         $value = $data['file'];
         $return = $value;
         $this->class->reflFields['file']->setValue($document, $return);
         $hydratedData['file'] = $return;
     }
     return $hydratedData;
 }
Example #21
0
 /**
  * Gets a date object that fits the requirements (correct timestamp and time zone).
  *
  * @param integer|DateTime|null $timestamp Unix timestamp or a DateTime object that's already configured
  * @param string|null $timeZoneString String time zone. If null, uses default (and can use date object optimization if available)
  *
  * @return DateTime
  */
 protected static function _getDateObject($timestamp = null, $timeZoneString = null)
 {
     if ($timestamp instanceof DateTime) {
         return $timestamp;
     } else {
         if ($timestamp === null) {
             $timestamp = XenForo_Application::$time;
         }
     }
     if ($timeZoneString) {
         $timeZone = new DateTimeZone($timeZoneString);
     } else {
         if (!self::$_timeZone) {
             self::setDefaultTimeZone('UTC');
         }
         if (self::$_dateObj) {
             self::$_dateObj->setTimestamp($timestamp);
             return self::$_dateObj;
         }
         $timeZone = self::$_timeZone;
     }
     $dt = new DateTime('@' . $timestamp);
     $dt->setTimezone($timeZone);
     return $dt;
 }
Example #22
0
 public function testMapToCustomClass()
 {
     $imageClass = 'Mechpave\\ImgurClient\\Tests\\Entity\\CustomImage';
     $objectMapper = $this->getMockBuilder('Mechpave\\ImgurClient\\Mapper\\ObjectMapper')->disableOriginalConstructor()->getMock();
     $objectMapper->expects($this->once())->method('getImageClass')->willReturn($imageClass);
     $uploadedAt = new \DateTime();
     $uploadedAt->setTimestamp((int) $this->imageData['datetime']);
     /** @noinspection PhpParamsInspection */
     $imageMapper = new ImageMapper($objectMapper);
     $image = $imageMapper->buildImage($this->imageData);
     $this->assertTrue($image instanceof $imageClass);
     $this->assertEquals($image->getImageId(), $this->imageData['id']);
     $this->assertEquals($image->getTitle(), $this->imageData['title']);
     $this->assertEquals($image->getDescription(), $this->imageData['description']);
     $this->assertEquals($image->getType(), $this->imageData['type']);
     $this->assertEquals($image->isAnimated(), $this->imageData['animated']);
     $this->assertEquals($image->getWidth(), $this->imageData['width']);
     $this->assertEquals($image->getHeight(), $this->imageData['height']);
     $this->assertEquals($image->getSize(), $this->imageData['size']);
     $this->assertEquals($image->getViews(), $this->imageData['views']);
     $this->assertEquals($image->getBandwith(), $this->imageData['bandwith']);
     $this->assertEquals($image->getDeleteHash(), $this->imageData['deletehash']);
     $this->assertEquals($image->getName(), $this->imageData['name']);
     $this->assertEquals($image->getSection(), $this->imageData['section']);
     $this->assertEquals($image->getLink(), $this->imageData['link']);
     $this->assertEquals($image->getGifv(), $this->imageData['gifv']);
     $this->assertEquals($image->getMp4(), $this->imageData['mp4']);
     $this->assertEquals($image->getWebm(), $this->imageData['webm']);
     $this->assertEquals($image->isLooping(), $this->imageData['looping']);
     $this->assertEquals($image->isFavorite(), $this->imageData['favorite']);
     $this->assertEquals($image->isNsfw(), $this->imageData['nsfw']);
     $this->assertEquals($image->getVote(), $this->imageData['vote']);
     $this->assertEquals($image->getUploadedAt(), $uploadedAt);
 }
 public function __construct($id = null, $timeout = null)
 {
     $sessionIdType = gettype($id);
     // Checking sessionId
     if (isset($id) && $id !== null) {
         if ($sessionIdType !== "string") {
             trigger_error(__CLASS__ . "::" . __FUNCTION__ . " (" . __LINE__ . ") \$authKey must be a string ({$sessionIdType} given)", E_USER_ERROR);
             $id = null;
         } else {
             if (!preg_match("/^[A-Z0-9]+\$/i", $id)) {
                 trigger_error(__CLASS__ . "::" . __FUNCTION__ . " (" . __LINE__ . ") \$id must contain only hexadecimal figures (\"" . htmlspecialchars($id) . "\" given)", E_USER_ERROR);
                 $id = null;
             }
         }
     }
     // Checking timeout
     if (isset($timeout) && $timeout !== null) {
         if (!$timeout instanceof DateTime) {
             if ((int) $timeout === $timeout && $timeout <= PHP_INT_MAX && $timeout >= ~PHP_INT_MAX) {
                 $timestamp = $timeout;
                 $timeout = new DateTime("now", new DateTimeZone("UTC"));
                 $timeout->setTimestamp($timestamp);
                 unset($timestamp);
             } else {
                 trigger_error(__CLASS__ . "::" . __FUNCTION__ . " (" . __LINE__ . ") \$timeout must contain a valid unix timestamp or DateTime object (\"" . htmlspecialchars($timeout) . "\" given)", E_USER_ERROR);
                 $timeout = null;
             }
         }
     }
     // Setting the new object
     $this->_id = $id;
     $this->_timeout = $timeout;
     $this->computeState();
 }
 /**
  * @param string $login
  * @param string $password
  * @param bool $rememberMe
  * @return Token
  */
 public function login($login, $password, $rememberMe = true)
 {
     try {
         $account = $this->accountService->getRepository()->findByLogin($login);
         if ($rememberMe === true) {
             $config = Game::getInstance()->getConfig();
             $rememberDays = $config["app"]["remember_days"];
             $endTime = time() + 3600 * 24 * $rememberDays;
         } else {
             $endTime = time() + 600;
         }
         $endDate = new \DateTime();
         $endDate->setTimestamp($endTime);
         if (is_null($account->getAuthToken())) {
             $token = $this->tokenService->generateToken($account, $endDate);
             $account->setAuthToken($token);
         } elseif (!$this->tokenService->isValid($account->getAuthToken()->getValue())) {
             $token = $this->tokenService->generateToken($account, $endDate);
             $account->setAuthToken($token);
         }
         $this->accountService->getRepository()->save($account);
         return $account->getAuthToken();
     } catch (EntityNotFoundException $e) {
         return false;
     }
 }
Example #25
0
 function getEvents($feedURL, $maxItems = 10, $backfill = 0)
 {
     $eventsXML = simplexml_load_file($feedURL);
     if (!$eventsXML) {
         echo 'Visit events.uoit.ca to see all events.';
     }
     $minItems = 5;
     $itemCount = 1;
     foreach ($eventsXML->channel->item as $event) {
         if ($itemCount <= $maxItems) {
             $title = $event->title;
             $description = $event->description;
             $url = $event->link;
             $unixdate = $event->date;
             $date = new DateTime();
             $date->setTimestamp((int) $unixdate);
             $monthDisplay = $date->format('M');
             $dayDisplay = $date->format('d');
             $time = $event->time;
             $location = $event->location;
             echo "<li data-equalizer style='display:block;float:none;width:100%;padding:0;'>\n\t\t\t\t    \t<a href='" . $url . "' target='_blank'>\n\t\t\t\t        <p class='event_date' data-equalizer-watch>" . $monthDisplay . "\n\t\t\t\t            <span>" . $dayDisplay . "</span>\n\t\t\t\t        </p>\n\t\t\t\t        <p class='event_info' data-equalizer-watch>\n\t\t\t\t          <span class='event_title'>" . $title . "</span>\n\t\t\t\t          <span class='event_time'>" . $location . "\n\t\t\t\t          <br>" . $time . "</span>\n\t\t\t\t        </p>\n\t\t\t\t      </a>\n\t\t\t\t    </li>";
             $itemCount++;
         }
     }
     if ($itemCount <= 5 && $backfill == '1') {
         getEvents("http://events.uoit.ca/api/v1/rss");
     }
 }
 public function getCurrent(\DateTime $now)
 {
     $date = new \DateTime();
     $date->setTimestamp(strtotime(sprintf('%s %s of %s %d', $this->getOrdinal(), $this->getDay(), $now->format('F'), $now->format('Y'))));
     $date->setTime($now->format('H'), $now->format('i'));
     return $date;
 }
Example #27
0
 public function aggregatedMethods()
 {
     $ts = 374390100;
     $dt = new \DateTime();
     $dt->setTimestamp($ts);
     return array(array('getCurrentUser', array(), new User()), array('setCurrentUser', array(new User()), null), array('hasAccess', array('module', 'function', new User()), array('limitations')), array('canUser', array('module', 'function', new User(), new Location()), false), array('beginTransaction', array(), true), array('commit', array(), true), array('rollback', array(), true), array('createDateTime', array($ts), $dt));
 }
Example #28
0
 public function testMapToCustomClass()
 {
     $albumClass = 'Mechpave\\ImgurClient\\Tests\\Entity\\CustomAlbum';
     $objectMapper = $this->getMockBuilder('Mechpave\\ImgurClient\\Mapper\\ObjectMapper')->disableOriginalConstructor()->getMock();
     $objectMapper->expects($this->once())->method('getAlbumClass')->willReturn($albumClass);
     $insertedIntoGallery = new \DateTime();
     $insertedIntoGallery->setTimestamp((int) $this->albumData['datetime']);
     $imageMapper = new ImageMapper($objectMapper);
     $albumMapper = new AlbumMapper($objectMapper, $imageMapper);
     $album = $albumMapper->buildAlbum($this->albumData);
     $this->assertTrue($album instanceof $albumClass);
     $this->assertEquals($album->getAlbumId(), $this->albumData['id']);
     $this->assertEquals($album->getTitle(), $this->albumData['title']);
     $this->assertEquals($album->getDescription(), $this->albumData['description']);
     $this->assertEquals($album->getInsertedIntoGallery(), $insertedIntoGallery);
     $this->assertEquals($album->getCover(), $this->albumData['cover']);
     $this->assertEquals($album->getCoverWidth(), $this->albumData['cover_width']);
     $this->assertEquals($album->getCoverHeight(), $this->albumData['cover_height']);
     $this->assertEquals($album->getAccountUsername(), $this->albumData['account_url']);
     $this->assertEquals($album->getAccountId(), $this->albumData['account_id']);
     $this->assertEquals($album->getPrivacy(), $this->albumData['privacy']);
     $this->assertEquals($album->getLayout(), $this->albumData['layout']);
     $this->assertEquals($album->getViews(), $this->albumData['views']);
     $this->assertEquals($album->getLink(), $this->albumData['link']);
     $this->assertEquals($album->isFavorite(), $this->albumData['favorite']);
     $this->assertEquals($album->isNsfw(), $this->albumData['nsfw']);
     $this->assertEquals($album->getSection(), $this->albumData['section']);
     $this->assertEquals($album->getOrder(), $this->albumData['order']);
     $this->assertEquals($album->getDeleteHash(), $this->albumData['deletehash']);
     $this->assertEquals($album->getImagesCount(), $this->albumData['images_count']);
 }
Example #29
0
 public function timestampToDateTime($timestamp)
 {
     date_default_timezone_set("UTC");
     $date = new \DateTime();
     $date->setTimestamp($timestamp);
     return $date;
 }
Example #30
0
 private function getResponse(Request $request, $name, array $files, $content_type)
 {
     if (!isset($files[$name])) {
         return new Response('Not Found', 404, array('Content-Type' => 'text/plain'));
     }
     $file = $files[$name];
     $response = new Response();
     $response->setPublic();
     $response->setMaxAge(self::EXPIRED_TIME);
     $response->setSharedMaxAge(self::EXPIRED_TIME);
     $response->headers->set('Content-Type', $content_type);
     // set a custom Cache-Control directive
     $response->headers->addCacheControlDirective('must-revalidate', true);
     $date = new \DateTime();
     $date->setTimestamp(strtotime($this->container->getParameter('sf.version')));
     $response->setETag($date->getTimestamp());
     $response->setLastModified($date);
     if ($response->isNotModified($request)) {
         return $response;
     }
     if (!file_exists($file)) {
         throw new \Exception(sprintf("file `%s`, `%s` not exists", $name, $file));
     }
     $response->setContent(file_get_contents($file));
     return $response;
 }