/** * Retrieves User Data. * * Thie method first checks the local cache database and if needed calls * twitter for more information * * @param string $username * @return stdClass */ private function getUserData($username) { $reCacheCutoff = new DateTime(); $reCacheCutoff->modify("-15 days"); //Check cache $data = $this->dbManager->get_row("SELECT *, DATE_FORMAT(cached_on, '%Y%m%d%h%i%s') AS cacheint FROM " . $this->dbManager->getTableNameFor('user_data_cache') . " WHERE twitter = '" . $username . "'"); if ($data === null || $data->cacheint < $reCacheCutoff->format('YmdHis')) { //Get From Twitter $twData = Tweester_Twitter::getUserData($username); //Clear previous cache $this->dbManager->query("DELETE FROM " . $this->coreManager->getDbManager()->getTableNameFor('user_data_cache') . " WHERE twitter = '" . $username . "'"); //Cache $this->dbManager->insert($this->dbManager->getTableNameFor('user_data_cache'), array('twitter' => $username, 'data' => json_encode($twData), 'cached_on' => date('Y-m-d H:i:s')), array('%s', '%s', '%s')); $userData = $twData; } else { $userData = json_decode($data->data); } return $userData; }
/** * Checks if table exists in the database * @return boolean */ public function exists() { return !($this->db->get_var("SHOW TABLES LIKE '" . $this->getTableName() . "'") != $this->getTableName()); }