コード例 #1
0
ファイル: DeliciousService.php プロジェクト: nyeholt/relapse
 /**
  * Get a feed
  *
  * @param int $id
  * @return Feed
  */
 public function getFeed($url)
 {
     $feed = $this->dbService->getByField(array('url' => $url), 'Feed');
     $update = $feed == null || strtotime($feed->updated) < time() - 60 * 15;
     if ($feed == null) {
         $feed = new Feed();
     }
     if ($update) {
         $this->log->debug("Loading feed {$url}");
         // make the request!
         // $feed->content =
         $content = null;
         try {
             $client = Zend_Feed::getHttpClient();
             $client->setUri($url);
             $response = $client->request('GET');
             if ($response->getStatus() !== 200) {
                 throw new Zend_Feed_Exception('Feed failed to load, got response code ' . $response->getStatus());
             }
             $content = $response->getBody();
         } catch (Exception $zfe) {
             $this->log->err("Failed loading feed from {$url}");
             return $content;
         }
         $feed->content = $content;
         $feed->url = $url;
         $this->dbService->saveObject($feed);
     }
     return $feed;
 }
コード例 #2
0
ファイル: DbAuthComponent.php プロジェクト: nyeholt/relapse
 /**
  * Given a username and password,
  * validates the user and returns the 
  * new object.
  * @param $username thename of the user
  * @param $password the entered password
  * @param $userClass The class of the expected user
  * @return boolean whether auth was successful
  */
 public function authenticate($username, $password, $userClass = 'User')
 {
     $fields = array('username' => $username);
     $user = $this->dbService->getByField($fields, $userClass);
     if ($user != null && $user->id) {
         // check the salted password
         $storedPass = sha1($password . $user->salt);
         if ($storedPass == $user->password) {
             return $user;
         }
     }
     return false;
 }
コード例 #3
0
ファイル: FileService.php プロジェクト: nyeholt/relapse
 /**
  * Gets a file object by its id
  *
  * @param string $id
  */
 public function getFileByPath($path)
 {
     $dir = $this->normalizePath(dirname($path));
     $filename = basename($path);
     za()->log("Searching for path {$path} : {$dir} and {$filename}");
     return $this->dbService->getByField(array('path' => $dir, 'filename' => $filename), 'File');
 }
コード例 #4
0
ファイル: UserService.php プロジェクト: nyeholt/relapse
 /**
  * Retrieves the amount of leave a given user has.
  */
 public function getLeaveForUser(User $user, $leaveType = "Annual")
 {
     $leave = $this->dbService->getByField(array('username' => $user->getUsername(), 'leavetype' => $leaveType), 'Leave');
     if (!$leave && $user) {
         // Need to create new
         $params = array('username' => $user->getUsername(), 'days' => 0, 'leavetype' => $leaveType);
         $leave = $this->dbService->saveObject($params, 'Leave');
     }
     if (!$leave) {
         throw new Exception("Could not retrieve Leave details for " . $user->getUsername());
     }
     return $leave;
 }
コード例 #5
0
ファイル: DbAuthService.php プロジェクト: nyeholt/relapse
 /**
  * Remove access from a particular item 
  * 
  * @param object $item the item to remove access from
  * @param String $user The user to remove access for
  * @param String $role The role to remove (optional)
  */
 public function removeAccess($item, $user, $role = null)
 {
     if (!$item) {
         throw new Exception("Cannot remove access from null object");
     }
     $fields = array('itemid' => $item->id, 'itemtype' => get_class($item), 'authority' => $user->getUsername());
     if ($role != null) {
         $fields['role'] = $role;
     }
     $existing = $this->dbService->getByField($fields, 'UserRole');
     if ($existing != null) {
         // delete away
         $this->dbService->delete($existing);
     }
 }
コード例 #6
0
ファイル: VersioningService.php プロジェクト: nyeholt/relapse
 /**
  * Gets the most recent version of a particular object
  *
  * @param object $object
  */
 public function getMostRecentVersion(MappedObject $object)
 {
     $table = get_class($object) . 'Version';
     return $this->dbService->getByField(array('recordid' => $object->me()->id), $table);
 }
コード例 #7
0
ファイル: ClientService.php プロジェクト: nyeholt/relapse
 /**
  * Get a client object by some fields
  *
  * @param string $field
  * @param string $value
  * @return Contact
  */
 public function getContactByFields($fields)
 {
     return $this->dbService->getByField($fields, 'Contact');
 }
コード例 #8
0
ファイル: ProjectService.php プロジェクト: nyeholt/relapse
 /**
  * Get a project by a given field
  *
  * @param string $field
  * @param mixed $value
  */
 public function getProjectByField($field, $value)
 {
     return $this->dbService->getByField(array($field => $value), 'Project');
 }