Ejemplo n.º 1
0
 /**
  * Creates a new version of the passed in object
  * 
  * @param MappedObject $object
  * @return ObjectVersion
  */
 public function createVersion(MappedObject $object, $label = '')
 {
     // make sure that there's a versioning table available for this object
     $versionType = get_class($object) . 'Version';
     if (!class_exists($versionType)) {
         throw new Exception("Attempting to create a version for a non-versionable object");
     }
     if (!$object) {
         throw new Exception("Cannot create a version of an empty object");
     }
     // see if there's a previous object version, if so load it
     // so we have an appropriate 'from' time
     $lastVersion = $this->getMostRecentVersion($object);
     $from = date('Y-m-d H:i:s');
     if ($lastVersion) {
         $from = date('Y-m-d H:i:s', strtotime($lastVersion->versioncreated) + 1);
     }
     $newVersion = new $versionType();
     // when creating a version, we want to load the existing state from
     // the DB so that we're being accurate.
     $current = $this->dbService->getById($object->me()->id, get_class($object));
     $properties = $current->unBind();
     unset($properties['id']);
     /*unset($properties['created']);
     		unset($properties['creator']);*/
     $newVersion->bind($properties);
     $newVersion->recordid = $object->id;
     $newVersion->versioncreated = date('Y-m-d H:i:s');
     $newVersion->validfrom = $from;
     $newVersion->label = $label;
     return $this->dbService->saveObject($newVersion);
 }
Ejemplo n.º 2
0
 /**
  * Get a list of related items for the passed in item.
  * 
  * works by comparing the list of things this item has against what all other items have, 
  * and returns the results ordered by the item with the most matches
  */
 public function getRelatedItems($item, $type = null)
 {
     // First get the tags for this item
     $tags = $this->getItemTags($item);
     $in = '';
     $sep = '';
     foreach ($tags as $tag) {
         $in .= $sep . $this->dbService->quote($tag->tag);
         $sep = ',';
     }
     if (!mb_strlen($in)) {
         return new ArrayObject();
     }
     $in = '(' . $in . ')';
     // Alright, now lets query for those items with these tags, ordering by the most tagged
     $select = $this->dbService->select();
     $select->from('tag', array('tag', 'itemid', 'itemtype', new Zend_Db_Expr('count(itemid) as score')));
     $select->where(new Zend_Db_Expr('tag in ' . $in));
     if ($type) {
         $select->where('itemtype=?', $type);
     }
     // Make sure to ignore the current object
     $select->where('itemid<>?', $item->id);
     $select->where('itemtype<>?', mb_strtolower(get_class($item)));
     $select->group('itemid');
     $select->order('score desc');
     $result = $this->dbService->query($select, null);
     $items = new ArrayObject();
     $tags = $result->fetchAll(Zend_Db::FETCH_ASSOC);
     foreach ($tags as $tag) {
         // get the item
         $items[] = $this->dbService->getById($tag['itemid'], $tag['itemtype']);
     }
     return $items;
 }
Ejemplo n.º 3
0
 /**
  * Gets all the items this passed in item is linked to
  * 
  * if $side is 'from', it will return items where
  * this item is the 'from' side. If 'to', will return
  * the 'to' side, otherwise if 'both' will return 
  * both sides.
  *
  * @param  object $item
  * @param  string $side The "side" that $item is linked on. EG left side = 'from'
  */
 public function getLinkedItems($item, $side = 'from', $otherType = null)
 {
     $results = null;
     $finalResults = new ArrayObject();
     if ($otherType) {
         return $this->getLinkedItemsOfType($item, $side, $otherType);
     }
     if ($side == 'from' || $side == 'both') {
         $where = array('fromid=' => $item->id, 'fromtype=' => get_class($item));
         if ($otherType != null) {
             $where['totype='] = $otherType;
         }
         $results = $this->dbService->getObjects('ItemLink', $where);
         foreach ($results as $linkItem) {
             $object = $this->dbService->getById($linkItem->toid, $linkItem->totype);
             if ($object) {
                 $finalResults[] = $object;
             }
         }
     }
     if ($side == 'to' || $side == 'both') {
         $where = array('toid=' => $item->id, 'totype=' => get_class($item));
         if ($otherType != null) {
             $where['fromtype='] = $otherType;
         }
         $results = $this->dbService->getObjects('ItemLink', $where);
         foreach ($results as $linkItem) {
             $object = $this->dbService->getById($linkItem->fromid, $linkItem->fromtype);
             $finalResults[] = $object;
         }
     }
     return $finalResults;
 }
Ejemplo n.º 4
0
 /**
  * Shortcut to getting an object by id
  *
  * @param int $id
  * @param string $type
  * @return mixed
  */
 protected function byId($id = null, $type = '')
 {
     if (is_null($id)) {
         $id = $this->_getParam('id');
     }
     if ($type == '') {
         $type = $this->modelType();
     }
     if (!$id) {
         return null;
     }
     return $this->dbService->getById((int) $id, $type);
 }
Ejemplo n.º 5
0
 /**
  * Gets a list of all items a user is watching
  *
  * @param $user
  * 			The user for whom to get subscribed items
  * @return
  * 			List of items
  */
 public function getWatchedItems($user, $type = null)
 {
     $select = $this->dbService->select();
     $where = array('userid=' => $user->username);
     $select->from('itemwatch', '*');
     if ($type != null) {
         $where['itemtype'] = is_array($type) ? $type : array($type);
         // $select->where('itemtype = ?', $type);
     }
     $this->dbService->applyWhereToSelect($where, $select);
     $select->order('created desc');
     $watches = $this->dbService->fetchObjects('ItemWatch', $select);
     $items = new ArrayObject();
     foreach ($watches as $watch) {
         $item = $this->dbService->getById($watch->itemid, $watch->itemtype);
         if ($item) {
             $items[] = $item;
         }
     }
     return $items;
 }
Ejemplo n.º 6
0
 public function getIssue($id)
 {
     return $this->dbService->getById($id, 'Issue');
 }
Ejemplo n.º 7
0
 public function getExpense($id)
 {
     return $this->dbService->getById((int) $id, 'Expense');
 }
Ejemplo n.º 8
0
 /**
  * Gets a file object by its id
  *
  * @param string $id
  */
 public function getFile($id)
 {
     return $this->dbService->getById((int) $id, 'File');
 }
Ejemplo n.º 9
0
 /**
  * Get a client object by its id
  *
  * @param Contact $id
  */
 public function getContact($id)
 {
     return $this->dbService->getById($id, 'Contact');
 }
Ejemplo n.º 10
0
 /**
  * Get a feature by id
  *
  * @param int $id
  * @return Feature
  */
 public function getFeature($id)
 {
     return $this->dbService->getById($id, 'Feature');
 }
Ejemplo n.º 11
0
 /**
  * Get a user by the given ID
  *
  * @param unknown_type $id
  * @return unknown
  */
 public function getUser($id)
 {
     return $this->dbService->getById($id, $this->userClass);
 }