Esempio n. 1
0
 /**
  * Return tag names as array for specific object
  *
  * @access public
  * @param ApplicationDataObject $object
  * @param string $manager_class
  * @return array
  */
 function getTagNamesByObject(ApplicationDataObject $object)
 {
     $rows = DB::executeAll('SELECT distinct `tag` FROM ' . self::instance()->getTableName(true) . ' WHERE `rel_object_id` = ? AND `rel_object_manager` = ? ORDER BY `tag`', $object->getId(), get_class($object->manager()));
     if (!is_array($rows)) {
         return array();
     }
     $tags = array();
     foreach ($rows as $row) {
         $tags[] = $row['tag'];
     }
     return $tags;
 }
	static function deleteByObjectAndName(ApplicationDataObject $object, $name) {
		return self::delete('`rel_object_id` = '.$object->getId()." AND `name` = " . DB::escape($name));
	}
 /**
  * Return entries related to specific object
  *
  * $limit and $offset are there to control the range of the result,
  * usually we don't want to pull the entire log but just the few most recent entries. If NULL they will be ignored
  *
  * @param ApplicationDataObject $object
  * @param integer $limit
  * @param integer $offset
  * @return array
  */
 static function getObjectLogs($object, $limit = null, $offset = null)
 {
     $private_filter = $include_private ? 1 : 0;
     $silent_filter = $include_silent ? 1 : 0;
     return self::findAll(array('conditions' => array('`rel_object_id` = (?)', $object->getId()), 'order' => '`created_on` DESC', 'limit' => $limit, 'offset' => $offset));
     // findAll
 }
 /**
  * Return entries related to specific object
  *
  * If $include_private is set to true private entries will be included in result. If $include_silent is set to true
  * logs marked as silent will also be included. $limit and $offset are there to control the range of the result,
  * usually we don't want to pull the entire log but just the few most recent entries. If NULL they will be ignored
  *
  * @param ApplicationDataObject $object
  * @param boolean $include_private
  * @param boolean $include_silent
  * @param integer $limit
  * @param integer $offset
  * @return array
  */
 static function getObjectLogs($object, $include_private = false, $include_silent = false, $limit = null, $offset = null)
 {
     $private_filter = $include_private ? 1 : 0;
     $silent_filter = $include_silent ? 1 : 0;
     if (get_class($object->manager()) == 'Users') {
         $private_filter = $include_private ? 1 : 0;
         $silent_filter = $include_silent ? 1 : 0;
         $userCond = " AND `taken_by_id` = " . $object->getId();
         if (isset($project_ids) && $project_ids != null) {
             $conditions = array('`is_private` <= ? AND `is_silent` <= ? AND ' . self::getWorkspaceString($project_ids) . $userCond, $private_filter, $silent_filter);
         } else {
             $conditions = array('`is_private` <= ? AND `is_silent` <= ?' . $userCond, $private_filter, $silent_filter);
         }
         // if
         return self::findAll(array('conditions' => $conditions, 'order' => '`created_on` DESC', 'limit' => $limit, 'offset' => $offset));
         // findAll
     } else {
         $logs = self::findAll(array('conditions' => array('`is_private` <= ? AND `is_silent` <= ? AND `rel_object_id` = (?) AND `rel_object_manager` = (?) OR `is_private` <= ? AND `is_silent` <= ? AND `rel_object_id`IN (SELECT `id` FROM ' . Comments::instance()->getTableName(true) . ' WHERE `rel_object_id` = (?) AND `rel_object_manager` = (?)) AND `rel_object_manager` = "Comments"', $private_filter, $silent_filter, $object->getId(), get_class($object->manager()), $private_filter, $silent_filter, $object->getId(), get_class($object->manager())), 'order' => '`created_on` DESC', 'limit' => $limit, 'offset' => $offset));
         // findAll
     }
     $next_offset = $offset + $limit;
     do {
         // Look for objects that user cannot see
         $removed = 0;
         foreach ($logs as $k => $log) {
             if ($log->getAction() == 'link') {
                 $id = explode(":", $log->getLogData());
                 $lobj = get_object_by_manager_and_id($id[1], $id[0]);
                 if (!$lobj instanceof ApplicationDataObject || !can_access(logged_user(), $lobj, ACCESS_LEVEL_READ)) {
                     $removed++;
                     unset($logs[$k]);
                 }
             }
         }
         // Get more objects to substitute the removed ones
         if ($limit && $removed > 0) {
             $other_logs = self::findAll(array('conditions' => array('`is_private` <= ? AND `is_silent` <= ? AND `rel_object_id` = (?) AND `rel_object_manager` = (?) OR `is_private` <= ? AND `is_silent` <= ? AND `rel_object_id`IN (SELECT `id` FROM ' . Comments::instance()->getTableName(true) . ' WHERE `rel_object_id` = (?) AND `rel_object_manager` = (?)) AND `rel_object_manager` = "Comments"', $private_filter, $silent_filter, $object->getId(), get_class($object->manager()), $private_filter, $silent_filter, $object->getId(), get_class($object->manager())), 'order' => '`created_on` DESC', 'limit' => $next_offset + $removed, 'offset' => $next_offset));
             // findAll
             $logs = array_merge($logs, $other_logs);
             $next_offset += $removed;
             if (count($logs) > $limit) {
                 $logs = array_slice($logs, 0, $limit);
             }
         }
     } while ($removed > 0);
     return $logs;
 }
 /**
  * Remove all relations by object
  *
  * @param ProjectDataObject $object
  * @return boolean
  */
 static function clearRelationsByObject(ApplicationDataObject $object)
 {
     return self::delete(array('(`object_id` = ? and `object_manager` = ?) or (`rel_object_id` = ? and `rel_object_manager` = ?)', $object->getId(), get_class($object->manager()), $object->getId(), get_class($object->manager())));
 }
 /**
  * Return unlink object URL
  *
  * @param ProjectDataObject $object
  * @return string
  */
 function getUnlinkObjectUrl(ApplicationDataObject $object)
 {
     return get_url('object', 'unlink_from_object', array('manager' => get_class($this->manager()), 'object_id' => $this->getObjectId(), 'rel_object_id' => $object->getId(), 'rel_object_manager' => get_class($object->manager())));
     // get_url
 }
Esempio n. 7
0
 /**
 * Remove all relations by object
 *
 * @param ProjectDataObject $object
 * @return boolean
 */
 static function clearRelationsByObject(ApplicationDataObject $object) {
   return self::delete(array('(`object_id` = ?) or (`rel_object_id` = ?)', 
   $object->getId(), $object->getId()));
 } // clearRelationsByObject
	/**
	 * Return entries related to specific object
	 *
	 * If $include_private is set to true private entries will be included in result. If $include_silent is set to true
	 * logs marked as silent will also be included. $limit and $offset are there to control the range of the result,
	 * usually we don't want to pull the entire log but just the few most recent entries. If NULL they will be ignored
	 *
	 * @param ApplicationDataObject $object
	 * @param boolean $include_private
	 * @param boolean $include_silent
	 * @param integer $limit
	 * @param integer $offset
	 * @return array
	 */
	static function getObjectLogs($object, $include_private = false, $include_silent = false, $limit = null, $offset = null) {
		$private_filter = $include_private ? 1 : 0;
		$silent_filter = $include_silent ? 1 : 0;		
		
		// User History
		if ($object instanceof Contact && $object->isUser()){		
			$private_filter = $include_private ? 1 : 0;
			$silent_filter = $include_silent ? 1 : 0;		
			$userCond = " AND `taken_by_id` = " . $object->getId();
			
			$conditions =  array(
				'`is_private` <= ? AND `is_silent` <= ? '.$userCond, 
				$private_filter, 
				$silent_filter); 
				
			return self::findAll(array(
				'conditions' => $conditions,
				'order' => '`created_on` DESC',
				'limit' => $limit,
				'offset' => $offset,
			)); // findAll				
		} else {	
			$logs = self::findAll(array(
                            'conditions' => array('`is_private` <= ? AND `is_silent` <= ? AND `rel_object_id` = (?) OR `is_private` <= ? AND `is_silent` <= ? AND (`rel_object_id`IN (SELECT `object_id` FROM '.Comments::instance()->getTableName(true).' WHERE `rel_object_id` = (?)) OR `rel_object_id`IN (SELECT `object_id` FROM '.Timeslots::instance()->getTableName(true).' WHERE `rel_object_id` = (?)))', $private_filter, $silent_filter, $object->getId(),$private_filter, $silent_filter, $object->getId(), $object->getId()),
                            'order' => '`created_on` DESC',
                            'limit' => $limit,
                            'offset' => $offset,
			)); // findAll
		}
		
		$next_offset = $offset + $limit;
		do {
			// Look for objects that user cannot see
			$removed = 0;
			foreach ($logs as $k => $log) {
				if ($log->getAction() == 'link') {
					$id = explode(":", $log->getLogData());
					$lobj = Objects::findObject($id[1]);
					if (!$lobj instanceof ApplicationDataObject || !can_access(logged_user(), $lobj->getMembers(), $lobj->getObjectTypeId(), ACCESS_LEVEL_READ)) {
						$removed++;
						unset($logs[$k]);
					}
				}
			}
			// Get more objects to substitute the removed ones
			if ($limit && $removed > 0) {
				$other_logs = self::findAll(array(
			        'conditions' => array('`is_private` <= ? AND `is_silent` <= ? AND `rel_object_id` = (?) OR `is_private` <= ? AND `is_silent` <= ? AND (`rel_object_id`IN (SELECT `id` FROM '.Comments::instance()->getTableName(true).' WHERE `rel_object_id` = (?)) AND `rel_object_id`IN (SELECT `object_id` FROM '.Timeslots::instance()->getTableName(true).' WHERE `rel_object_id` = (?)))', $private_filter, $silent_filter, $object->getId(),$private_filter, $silent_filter, $object->getId(), $object->getId()),
			        'order' => '`created_on` DESC',
			        'limit' => $next_offset + $removed,
			        'offset' => $next_offset,
				)); // findAll
				$logs = array_merge($logs, $other_logs);
				$next_offset += $removed;
				if (count($logs) > $limit) $logs = array_slice($logs, 0, $limit);
			}
		} while ($removed > 0);
		
		return $logs;
	} // getObjectLogs
	/**
	 * Return entries related to specific object
	 *
	 * $limit and $offset are there to control the range of the result,
	 * usually we don't want to pull the entire log but just the few most recent entries. If NULL they will be ignored
	 *
	 * @param ApplicationDataObject $object
	 * @param integer $limit
	 * @param integer $offset
	 * @return array
	 */
	static function getObjectLogs($object, $limit = null, $offset = null) {

		return self::findAll(array(
                    'conditions' => array('`rel_object_id` = (?)', $object->getId()),
                    'order' => '`created_on` DESC',
                    'limit' => $limit,
                    'offset' => $offset,
		)); // findAll
	} // getObjectLogs
	/**
	 * Return unlink object URL
	 *
	 * @param ApplicationDataObject $object
	 * @return string
	 */
	function getUnlinkObjectUrl(ApplicationDataObject $object) {
		return get_url('object', 'unlink_from_object', array(
        'object_id' => $this->getObjectId(),
        'rel_object_id' => $object->getId(),
		)); // get_url
	} //  getUnlinkedObjectUrl
 /**
  * Reaturn all permissions of a object
  *
  * @param Object $object
  * @return array
  */
 static function getAllPermissionsByObject(ApplicationDataObject $object, $user_id_csvs = null)
 {
     return self::getAllPermissionsByObjectIdAndManager($object->getId(), get_class($object->manager()), $user_id_csvs);
 }