public function executeGoogleCalendarIntegration(sfWebRequest $request) { $deactivate = $request->getParameter('deactivate', 0); if ($deactivate) { PcGoogleCalendarPeer::retrieveByUser(PcUserPeer::getLoggedInUser())->setIsActive(false)->save(); } }
public function deActivate() { $dbEntry = PcGoogleCalendarPeer::retrieveByUser($this->user); $dbEntry->setIsActive(false)->save(); }
public function hasGoogleCalendarIntegrationActive() { if ($googleCalendar = PcGoogleCalendarPeer::retrieveByUser($this)) { if ($googleCalendar->getIsActive() && $googleCalendar->getCalendarUrl() && $googleCalendar->getSessionToken()) { return true; } else { return false; } } }
/** * Populates the object using an array. * * This is particularly useful when populating an object from one of the * request arrays (e.g. $_POST). This method goes through the column * names, checking to see whether a matching key exists in populated * array. If so the setByName() method is called for that column. * * You can specify the key type of the array by additionally passing one * of the class type constants BasePeer::TYPE_PHPNAME, BasePeer::TYPE_STUDLYPHPNAME, * BasePeer::TYPE_COLNAME, BasePeer::TYPE_FIELDNAME, BasePeer::TYPE_NUM. * The default key type is the column's phpname (e.g. 'AuthorId') * * @param array $arr An array to populate the object from. * @param string $keyType The type of keys the array uses. * @return void */ public function fromArray($arr, $keyType = BasePeer::TYPE_PHPNAME) { $keys = PcGoogleCalendarPeer::getFieldNames($keyType); if (array_key_exists($keys[0], $arr)) { $this->setId($arr[$keys[0]]); } if (array_key_exists($keys[1], $arr)) { $this->setUserId($arr[$keys[1]]); } if (array_key_exists($keys[2], $arr)) { $this->setCalendarUrl($arr[$keys[2]]); } if (array_key_exists($keys[3], $arr)) { $this->setSessionToken($arr[$keys[3]]); } if (array_key_exists($keys[4], $arr)) { $this->setEmailAddress($arr[$keys[4]]); } if (array_key_exists($keys[5], $arr)) { $this->setIsActive($arr[$keys[5]]); } if (array_key_exists($keys[6], $arr)) { $this->setIsSyncing($arr[$keys[6]]); } if (array_key_exists($keys[7], $arr)) { $this->setLatestSyncStartTimestamp($arr[$keys[7]]); } if (array_key_exists($keys[8], $arr)) { $this->setLatestSyncEndTimestamp($arr[$keys[8]]); } if (array_key_exists($keys[9], $arr)) { $this->setUpdatedAt($arr[$keys[9]]); } if (array_key_exists($keys[10], $arr)) { $this->setCreatedAt($arr[$keys[10]]); } }
/** * Executes index action * * @param sfRequest $request A request object */ public function executeIndex(sfWebRequest $request) { // for performance reasons, we insert this configuration inside the method itself $methods = array('getToken', 'getServerTime', 'getUserSettings', 'getLists', 'getDeletedLists', 'getTags', 'getDeletedTags', 'getRepetitions', 'getRepetitionOptions', 'getTasks', 'getDeletedTasks', 'completeTask', 'uncompleteTask', 'deleteTask', 'addTask', 'editTask', 'setTaskNote', 'sync', 'whatHasChanged'); // token, sig, api_ver are required for each method $extraRequiredParamsMap = array('getToken' => array('api_key'), 'getServerTime' => array(), 'getUserSettings' => array(), 'getLists' => array(), 'getDeletedLists' => array('from_ts', 'to_ts'), 'getTags' => array(), 'getDeletedTags' => array('from_ts', 'to_ts'), 'getRepetitions' => array(), 'getRepetitionOptions' => array(), 'getTasks' => array(), 'getDeletedTasks' => array('from_ts', 'to_ts'), 'completeTask' => array('task_id'), 'uncompleteTask' => array('task_id'), 'addTask' => array('descr'), 'editTask' => array('task_id'), 'setTaskNote' => array('task_id', 'note'), 'deleteTask' => array('task_id'), 'sync' => array('local_changes'), 'whatHasChanged' => array('from_ts', 'to_ts')); $optionalParamsMap = array('getToken' => array('user_key', 'user_email', 'user_pwd', 'extra_info'), 'getServerTime' => array(), 'getUserSettings' => array(), 'getLists' => array('from_ts', 'to_ts'), 'getDeletedLists' => array(), 'getTags' => array('from_ts', 'to_ts'), 'getDeletedTags' => array(), 'getRepetitions' => array('from_ts', 'to_ts'), 'getRepetitionOptions' => array('from_ts', 'to_ts'), 'getTasks' => array('from_ts', 'to_ts', 'task_id', 'list_id', 'tag_id', 'completed', 'only_with_due_date', 'only_without_due_date', 'only_due_today_or_tomorrow', 'only_starred', 'by_date', 'search_query'), 'getDeletedTasks' => array(), 'completeTask' => array('baseline_due_date'), 'uncompleteTask' => array(), 'addTask' => array('list_id', 'is_header', 'due_date', 'due_time', 'is_starred', 'repetition_id', 'repetition_param', 'repetition_ical_rrule', 'note', 'tag_ids'), 'editTask' => array('list_id', 'descr', 'is_header', 'due_date', 'due_time', 'is_starred', 'repetition_id', 'repetition_param', 'repetition_ical_rrule', 'note', 'tag_ids'), 'setTaskNote' => array(), 'deleteTask' => array(), 'sync' => array(), 'whatHasChanged' => array()); $methodName = $request->getParameter('method_name'); $token = $request->getParameter('token'); $sig = $request->getParameter('sig'); $apiVersion = $request->getParameter('api_ver'); if (!in_array($methodName, $methods)) { return $this->returnError(PlancakeApiServer::INVALID_METHOD_ERROR); } $this->methodName = $methodName; if ($token === null) { return $this->returnError(PlancakeApiServer::MISSING_TOKEN_ERROR); } if (!$sig) { return $this->returnError(PlancakeApiServer::MISSING_SIGNATURE_ERROR); } if (!$apiVersion) { return $this->returnError(PlancakeApiServer::MISSING_API_VERSION); } $params = array(); $params['token'] = $token; $params['sig'] = $sig; $params['api_ver'] = $apiVersion; $extraRequiredParams = $extraRequiredParamsMap[$methodName]; foreach ($extraRequiredParams as $extraRequiredParam) { $paramValue = $request->getParameter($extraRequiredParam); if ($paramValue !== null) { $params[$extraRequiredParam] = $paramValue; } else { return $this->returnError(PlancakeApiServer::MISSING_PARAMETER_ERROR); } } if (!$this->isTokenValid($token)) { return $this->returnError(PlancakeApiServer::INVALID_TOKEN_ERROR); } $apiKey = isset($params['api_key']) ? $params['api_key'] : null; $apiApp = $this->getApiApp($params['token'], $apiKey); if ($apiApp === null) { return $this->returnError(PlancakeApiServer::INVALID_API_KEY_OR_TOKEN_ERROR); } if ($apiApp->isLimited()) { if ($apiApp->hasReachedLimits()) { return $this->returnError(PlancakeApiServer::RATE_LIMIT_REACHED); } } $apiSecret = $apiApp->getApiSecret(); // loading optional params $optionalParams = $optionalParamsMap[$methodName]; foreach ($optionalParams as $optionalParam) { $paramValue = $request->getParameter($optionalParam); if ($paramValue !== null) { $params[$optionalParam] = $paramValue; } } // if from_ts is specified, also to_ts if (isset($params['from_ts']) && !isset($params['to_ts']) || isset($params['to_ts']) && !isset($params['from_ts']) || isset($params['from_ts']) && isset($params['from_ts']) && !((int) $params['from_ts'] > 0) || isset($params['from_ts']) && isset($params['from_ts']) && !((int) $params['to_ts'] > 0)) { return $this->returnError(PlancakeApiServer::MISSING_FROMTS_OR_TOTS_PARAMETER_ERROR); } if (!(strlen($apiSecret) > 0)) { return $this->returnError(PlancakeApiServer::INVALID_API_KEY_ERROR); } if (!$this->isSignatureValid($params, $apiSecret)) { return $this->returnError(PlancakeApiServer::INVALID_SIGNATURE_ERROR); } $user = null; if (strlen($token) > 0) { $userId = PcApiTokenPeer::retrieveByPK($token)->getUserId(); $user = PcUserPeer::retrieveByPK($userId); PcUserPeer::setLoggedInUser($user); $user->refreshLastLogin()->save(); } unset($params['token']); unset($params['sig']); $response = call_user_func(array('PlancakeApiServer', $methodName), $params); $jsonResponse = json_encode($response); $apiApp->recordStats(strlen($jsonResponse)); if ($user && $user->hasGoogleCalendarIntegrationActive()) { $gcalRecord = PcGoogleCalendarPeer::retrieveByUser($user); if ($gcalRecord && time() - $gcalRecord->getLatestSyncEndTimestamp() > sfConfig::get('app_api_googleCalendarSyncMinInterval')) { $gcal = new GoogleCalendarInterface($user); $gcal->init(); $gcal->syncPlancake(); } } if ($callback = $request->getParameter('callback')) { $this->getResponse()->setContentType('text/javascript'); $response = $callback . '(' . $jsonResponse . ')'; } else { $this->getResponse()->setContentType('application/json'); $response = $jsonResponse; } return $this->renderText($response); }
/** * Returns the number of related PcGoogleCalendar objects. * * @param Criteria $criteria * @param boolean $distinct * @param PropelPDO $con * @return int Count of related PcGoogleCalendar objects. * @throws PropelException */ public function countPcGoogleCalendars(Criteria $criteria = null, $distinct = false, PropelPDO $con = null) { if ($criteria === null) { $criteria = new Criteria(PcUserPeer::DATABASE_NAME); } else { $criteria = clone $criteria; } if ($distinct) { $criteria->setDistinct(); } $count = null; if ($this->collPcGoogleCalendars === null) { if ($this->isNew()) { $count = 0; } else { $criteria->add(PcGoogleCalendarPeer::USER_ID, $this->id); $count = PcGoogleCalendarPeer::doCount($criteria, false, $con); } } else { // criteria has no effect for a new object if (!$this->isNew()) { // the following code is to determine if a new query is // called for. If the criteria is the same as the last // one, just return count of the collection. $criteria->add(PcGoogleCalendarPeer::USER_ID, $this->id); if (!isset($this->lastPcGoogleCalendarCriteria) || !$this->lastPcGoogleCalendarCriteria->equals($criteria)) { $count = PcGoogleCalendarPeer::doCount($criteria, false, $con); } else { $count = count($this->collPcGoogleCalendars); } } else { $count = count($this->collPcGoogleCalendars); } } return $count; }
printf(__('ACCOUNT_SETTINGS_MANAGE_GCAL_DOC'), 'http://www.plancake.com/services/google-calendar-integration'); ?> </p> <p> <br /> <?php if (PcUserPeer::getLoggedInUser()->hasGoogleCalendarIntegrationActive()) { ?> <?php __('ACCOUNT_SETTINGS_MANAGE_GCAL_EMAIL'); ?> <br /> <em><?php PcGoogleCalendarPeer::retrieveByUser(PcUserPeer::getLoggedInUser())->getEmailAddress(); ?> </em> <br /> <a onclick="javascript:return confirm(<?php echo __('ACCOUNT_MISC_CONFIRM_MSG'); ?> )" href="<?php echo url_for('settings/googleCalendarIntegration?deactivate=1'); ?> "> <?php echo __('ACCOUNT_SETTINGS_MANAGE_GCAL_DEACTIVATE'); ?>
/** * Retrieve multiple objects by pkey. * * @param array $pks List of primary keys * @param PropelPDO $con the connection to use * @throws PropelException Any exceptions caught during processing will be * rethrown wrapped into a PropelException. */ public static function retrieveByPKs($pks, PropelPDO $con = null) { if ($con === null) { $con = Propel::getConnection(PcGoogleCalendarPeer::DATABASE_NAME, Propel::CONNECTION_READ); } $objs = null; if (empty($pks)) { $objs = array(); } else { $criteria = new Criteria(PcGoogleCalendarPeer::DATABASE_NAME); $criteria->add(PcGoogleCalendarPeer::ID, $pks, Criteria::IN); $objs = PcGoogleCalendarPeer::doSelect($criteria, $con); } return $objs; }