示例#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;
 }
 /**
  * Create new log entry and return it
  * 
  * Delete actions are automaticly marked as silent if $is_silent value is not provided (not NULL)
  *
  * @param ApplicationDataObject $object
  * @param Project $project
  * @param DataManager $manager
  * @param boolean $save Save log object before you save it
  * @return ApplicationLog
  */
 static function createLog(ApplicationDataObject $object, $project, $action = null, $is_private = false, $is_silent = null, $save = true)
 {
     if (is_null($action)) {
         $action = self::ACTION_ADD;
     }
     // if
     if (!self::isValidAction($action)) {
         throw new Error("'{$action}' is not valid log action");
     }
     // if
     if (is_null($is_silent)) {
         $is_silent = $action == self::ACTION_DELETE;
     } else {
         $is_silent = (bool) $is_silent;
     }
     // if
     $manager = $object->manager();
     if (!$manager instanceof DataManager) {
         throw new Error('Invalid object manager');
     }
     // if
     $log = new ApplicationLog();
     if ($project instanceof Project) {
         $log->setProjectId($project->getId());
     }
     // if
     $log->setTakenById(logged_user()->getId());
     $log->setRelObjectId($object->getObjectId());
     $log->setObjectName($object->getObjectName());
     $log->setRelObjectManager(get_class($manager));
     $log->setAction($action);
     $log->setIsPrivate($is_private);
     $log->setIsSilent($is_silent);
     if ($save) {
         $log->save();
     }
     // if
     // Update is private for this object
     if ($object instanceof ProjectDataObject) {
         ApplicationLogs::setIsPrivateForObject($object);
     }
     // if
     return $log;
 }
 /**
  * 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
 }
 static function deleteByObjectAndName(ApplicationDataObject $object, $name)
 {
     return self::delete('`rel_object_id` = ' . $object->getId() . " AND `rel_object_manager` = '" . get_class($object->manager()) . "' AND `name` = " . DB::escape($name));
 }
 /**
  * Drop columns content from table related to $object
  *
  * @param ApplicationDataObject $object
  * @return boolean
  */
 static function dropContentByObjectColumns(ApplicationDataObject $object, $columns = array())
 {
     $columns_csv = "'" . implode("','", $columns) . "'";
     return SearchableObjects::delete(array('`rel_object_manager` = ? AND `rel_object_id` = ? AND `column_name` in (' . $columns_csv . ')', get_class($object->manager()), $object->getObjectId()));
 }
 /**
  * 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, $limit = null, $offset = null)
 {
     return self::findAll(array('conditions' => array('`rel_object_id` = (?) AND `rel_object_manager` = (?)', $object->getId(), get_class($object->manager())), 'order' => '`created_on` DESC', 'limit' => $limit, 'offset' => $offset));
     // findAll
 }
 /**
  * Clear all attachments by object
  *
  * @param ApplicationDataObject
  * @return boolean
  */
 static function clearAttachmentsByObject(ApplicationDataObject $object)
 {
     return self::delete(array('`rel_object_manager` = ? AND `rel_object_id` = ?', get_class($object->manager()), $object->getObjectId()));
 }
 /**
  * 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);
 }
 /**
  * Return all read objects ( ReadObjects) for specific object and user
  *
  * @param ProjectDataObject $object
  * @return array
  */
 static function getReadByObject(ApplicationDataObject $object, int $user_id)
 {
     return self::findAll(array('conditions' => array('(`rel_object_manager` = ? and `rel_object_id` = ?) and `user_id` = ? and is_read = 1', get_class($object->manager()), $object->getObjectId(), $user_id), 'order' => '`created_on`'));
     // findAll
 }
示例#12
0
 /**
  * Return tags for specific object
  *
  * @access public
  * @param ApplicationDataObject $object
  * @param string $manager_class
  * @return array
  */
 function getTagsByObject(ApplicationDataObject $object, $manager_class)
 {
     return self::findAll(array('conditions' => array('`rel_object_id` = ? AND `rel_object_manager` = ?', $object->getObjectId(), get_class($object->manager())), 'order' => '`tag`'));
     // findAll
 }