/** * Return object * * @param void * @return ApplicationDataObject */ function getObject() { if (is_null($this->object)) { $this->object = get_object_by_manager_and_id($this->getObjectId(), $this->getObjectManager()); } return $this->object; }
/** * Return associated object * * @param void * @return ProjectDataObject */ function getObject() { if (is_null($this->object)) { $this->object = get_object_by_manager_and_id($this->getId(), get_class($this->manager())); } // if return $this->object; }
/** * Return object connected with this action, that is not equal to the one received * * @access public * @param ProjectDataObject $object * @return ProjectDataObject */ function getOtherObject($object) { if (get_class($object->manager()) != $this->getObjectManager() || $object->getObjectId() != $this->getObjectId()) { return get_object_by_manager_and_id($this->getObjectId(), $this->getObjectManager()); } else { return get_object_by_manager_and_id($this->getRelObjectId(), $this->getRelObjectManager()); } }
/** * Returns all Objects of a Template * * @param integer $template_id * @return array */ static function getObjectsByTemplate($template_id) { $all = self::findAll(array('conditions' => array('`template_id` = ?', $template_id))); if (!is_array($all)) { return array(); } $objs = array(); foreach ($all as $obj) { $objs[] = get_object_by_manager_and_id($obj->getObjectId(), $obj->getObjectManager()); } return $objs; }
/** * Delete tag URL * * @access public * @param void * @return null */ function delete_tag() { if (!logged_user()->isAdministrator()) { flash_error(lang('no access permissions')); ajx_current("empty"); return; } $tag_name = array_var($_GET, 'tag_name'); $object_id = array_var($_GET, 'object_id'); $manager_class = array_var($_GET, 'manager_class'); $obj = get_object_by_manager_and_id($object_id, $manager_class); $obj->deleteTag($tag_name); $this->redirectToReferer(''); }
/** * Do the search * * @param string $conditions * @param integer $limit * @param integer $offset * @return array */ function doSearch($conditions, $limit = null, $offset = null) { $table_name = SearchableObjects::instance()->getTableName(true); $limit_string = ''; if ((int) $limit > 0) { $offset = (int) $offset > 0 ? (int) $offset : 0; $limit_string = " LIMIT {$offset}, {$limit}"; } // if $where = ''; if (trim($conditions) != '') { $where = "WHERE {$conditions}"; } $sql = "SELECT `rel_object_manager`, `rel_object_id` FROM {$table_name} {$where} {$limit_string}"; $result = DB::executeAll($sql); if (!is_array($result)) { return null; } $loaded = array(); $objects = array(); foreach ($result as $row) { $manager_class = array_var($row, 'rel_object_manager'); $object_id = array_var($row, 'rel_object_id'); if (!isset($loaded[$manager_class . '-' . $object_id]) || !$loaded[$manager_class . '-' . $object_id]) { if (class_exists($manager_class)) { $object = get_object_by_manager_and_id($object_id, $manager_class); if ($object instanceof ProjectDataObject) { $loaded[$manager_class . '-' . $object_id] = true; $objects[] = $object; } // if } // if } // if } // foreach return count($objects) ? $objects : null; }
function mark_as_ham() { ajx_current("empty"); $csvids = array_var($_GET, 'ids'); $ids = explode(",", $csvids); $succ = 0; $err = 0; foreach ($ids as $id) { list($manager, $objid) = explode(":", $id); $mail = get_object_by_manager_and_id($objid, $manager); if ($mail instanceof MailContent) { $mail->setState(0); $mail->save(); $succ++; } else { $err++; } } if ($err <= 0) { flash_success(lang('success mark as ham', $succ)); } else { flash_error(lang('error mark as ham', $succ)); } }
private function getTasksAndMilestones($page, $objects_per_page, $tag = null, $order = null, $order_dir = null, $parent_task_id = null, $project = null, $tasksAndOrMilestones = 'both') { if (!$parent_task_id || !is_numeric($parent_task_id)) { $parent_task_id = 0; } $parent_string = " AND parent_id = {$parent_task_id} "; $queries = ObjectController::getDashboardObjectQueries($project, $tag); if ($tasksAndOrMilestones == 'both') { $query = $queries['ProjectTasks'] . $parent_string . " UNION " . $queries['ProjectMilestones']; } else { if ($tasksAndOrMilestones == 'tasks') { $query = $queries['ProjectTasks'] . $parent_string; } else { $query = $queries['ProjectMilestones']; } } if ($order) { $query .= " order by " . $order . " "; if ($order_dir) { $query .= " " . $order_dir . " "; } } else { $query .= " order by last_update desc "; } if ($page && $objects_per_page) { $start = ($page - 1) * $objects_per_page; $query .= " limit " . $start . "," . $objects_per_page . " "; } else { if ($objects_per_page) { $query .= " limit " . $objects_per_page; } } $res = DB::execute($query); $objects = array(); if (!$res) { return $objects; } $rows = $res->fetchAll(); if (!$rows) { return $objects; } $i = 1; foreach ($rows as $row) { $manager = $row['object_manager_value']; $id = $row['oid']; if ($id && $manager) { $obj = get_object_by_manager_and_id($id, $manager); if ($obj->canView(logged_user())) { $dash_object = $obj->getDashboardObject(); // $dash_object['id'] = $i++; $objects[] = $dash_object; } } //if($id && $manager) } //foreach return $objects; }
/** * Add comment * * Through this controller only logged users can post (no anonymous comments here) * * @param void * @return null */ function add() { $this->setTemplate('add_comment'); $object_id = get_id('object_id'); $object_manager = array_var($_GET, 'object_manager'); if (!is_valid_function_name($object_manager)) { flash_error(lang('invalid request')); $this->redirectToUrl(active_project()->getOverviewUrl()); } // if $object = get_object_by_manager_and_id($object_id, $object_manager); if (!$object instanceof ProjectDataObject || !$object->canComment(logged_user())) { flash_error(lang('no access permissions')); $this->redirectToUrl(active_project()->getOverviewUrl()); } // if $comment = new Comment(); $comment_data = array_var($_POST, 'comment'); tpl_assign('comment_form_object', $object); tpl_assign('comment', $comment); tpl_assign('comment_data', $comment_data); if (is_array($comment_data)) { try { try { $attached_files = ProjectFiles::handleHelperUploads(active_project()); } catch (Exception $e) { $attached_files = null; } // try $comment->setFromAttributes($comment_data); $comment->setRelObjectId($object_id); $comment->setRelObjectManager($object_manager); if (!logged_user()->isMemberOfOwnerCompany()) { $comment->setIsPrivate(false); } // if if ($object instanceof ProjectMessage || $object instanceof ProjectFile) { if ($object->getIsPrivate()) { $comment->setIsPrivate(true); } // if } // if DB::beginWork(); $comment->save(); if (is_array($attached_files)) { foreach ($attached_files as $attached_file) { $comment->attachFile($attached_file); } // foreach } // if ApplicationLogs::createLog($comment, active_project(), ApplicationLogs::ACTION_ADD); // Subscribe user to message (if $object is message) if ($object instanceof ProjectMessage) { if (!$object->isSubscriber(logged_user())) { $object->subscribeUser(logged_user()); } // if } // if DB::commit(); flash_success(lang('success add comment')); $redirect_to = $comment->getViewUrl(); if (!is_valid_url($redirect_to)) { $redirect_to = $object->getViewUrl(); } // if $this->redirectToUrl($redirect_to); } catch (Exception $e) { DB::rollback(); tpl_assign('error', $e); } // try } // if }
/** * Do the search * * @param string $conditions * @param integer $limit * @param integer $offset * @return array */ function doSearch($conditions, $limit = null, $offset = null, $search_for = '') { $table_name = SearchableObjects::instance()->getTableName(true); //$tags_table_name = Tags::instance()->getTableName(); $limit_string = ''; if ((int) $limit > 0) { $offset = (int) $offset > 0 ? (int) $offset : 0; $limit_string = " LIMIT {$offset}, {$limit}"; } // if $where = ''; if (trim($conditions) != '') { $where = "WHERE {$conditions}"; } $sql = "SELECT distinct `rel_object_manager`, `rel_object_id` FROM {$table_name} {$where} ORDER BY `rel_object_id` DESC {$limit_string}"; $result = DB::executeAll($sql); if (!is_array($result)) { return null; } $new_where = "'1' = '2' "; foreach ($result as $row) { $manager_class = array_var($row, 'rel_object_manager'); $object_id = array_var($row, 'rel_object_id'); $new_where .= " OR (rel_object_manager = '" . $manager_class . "' AND rel_object_id = '" . $object_id . "')"; } $new_where = " AND (" . $new_where . ')'; $sql = "SELECT `rel_object_manager`, `rel_object_id`, `column_name`, `content` FROM {$table_name} {$where} {$new_where} ORDER BY `rel_object_id`"; $result = DB::executeAll($sql); if (!is_array($result)) { return null; } $loaded = array(); $objects = array(); foreach ($result as $row) { $manager_class = array_var($row, 'rel_object_manager'); $object_id = array_var($row, 'rel_object_id'); if (!isset($loaded[$manager_class . '-' . $object_id])) { if (class_exists($manager_class)) { $object = get_object_by_manager_and_id($object_id, $manager_class); if ($object instanceof ApplicationDataObject) { $objects[] = array('object' => $object, 'context' => array(array('context' => SearchableObjects::getContext(array_var($row, 'content'), $search_for), 'column_name' => array_var($row, 'column_name')))); $loaded[$manager_class . '-' . $object_id] = count($objects) - 1; } // if } // if } else { $objects[$loaded[$manager_class . '-' . $object_id]]['context'][] = array('context' => SearchableObjects::getContext(array_var($row, 'content'), $search_for), 'column_name' => array_var($row, 'column_name')); } // if } // foreach return count($objects) ? $objects : null; }
function add_to() { if (!can_manage_templates(logged_user())) { flash_error(lang("no access permissions")); ajx_current("empty"); return; } $manager = array_var($_GET, 'manager'); $id = get_id(); $object = get_object_by_manager_and_id($id, $manager); $template_id = array_var($_GET, 'template'); if ($template_id) { $template = COTemplates::findById($template_id); if ($template instanceof COTemplate) { try { DB::beginWork(); $template->addObject($object); DB::commit(); flash_success(lang('success add object to template')); ajx_current("start"); } catch (Exception $e) { DB::rollback(); flash_error($e->getMessage()); } } } tpl_assign('templates', COTemplates::findAll()); tpl_assign("object", $object); }
$sub_wss[] = $w; } } } $sub_wss_csv = array(); foreach ($sub_wss as $sub_ws) { $sub_wss_csv[] = $sub_ws->getId(); } $linked_object_actions = array(); $activities = ApplicationLogs::getLastActivities($ws, active_tag(), user_config_option('activity widget elements')); $groups = array(); $first = null; $obj_wss_cache = array(); foreach ($activities as $act) { $user = Users::findById($act->getCreatedById()); $object = get_object_by_manager_and_id($act->getRelObjectId(), $act->getRelObjectManager()); if (!$user || !$object) { continue; } /* if ($user && $object && $act->getAction() != 'login' && $act->getAction() != 'logout' && !can_access($user, $object, ACCESS_LEVEL_READ)) continue; */ $avatar_url = $user->getAvatarUrl(); $date = $act->getCreatedOn() instanceof DateTimeValue ? friendly_date($act->getCreatedOn()) : lang('n/a'); $dontshow = false; $tmp_id = ''; if ($act->getAction() == ApplicationLogs::ACTION_LINK || $act->getAction() == ApplicationLogs::ACTION_UNLINK) { $tmp_id = $act->getRelObjectManager() . ":" . $act->getRelObjectId(); foreach ($linked_object_actions as $loa) { if ($loa['action'] == $act->getAction() && ($loa['source'] == $tmp_id && $loa['dest'] == $act->getLogData() || $loa['source'] == $act->getLogData() && $loa['dest'] == $tmp_id)) { $dontshow = true;
/** * Return object connected with this action * * @access public * @param void * @return ProjectDataObject */ function getObject() { return get_object_by_manager_and_id($this->getRelObjectId(), $this->getRelObjectManager()); }
/** * Detach file from related object * * @param void * @return null */ function detach_from_object() { $manager_class = array_var($_GET, 'manager'); $object_id = get_id('object_id'); $file_id = get_id('file_id'); $object = get_object_by_manager_and_id($object_id, $manager_class); if (!$object instanceof ProjectDataObject) { flash_error(lang('no access permissions')); $this->redirectToReferer(get_url('dashboard')); } // if $file = ProjectFiles::findById($file_id); if (!$file instanceof ProjectFile) { flash_error(lang('file dnx')); $this->redirectToReferer(get_url('dashboard')); } // if $attached_file = AttachedFiles::findById(array('rel_object_manager' => $manager_class, 'rel_object_id' => $object_id, 'file_id' => $file_id)); // findById if (!$attached_file instanceof AttachedFile) { flash_error(lang('file not attached to object')); $this->redirectToReferer(get_url('dashboard')); } // if try { DB::beginWork(); $attached_file->delete(); DB::commit(); flash_success(lang('success detach file')); } catch (Exception $e) { flash_error(lang('error detach file')); DB::rollback(); } // try $this->redirectToReferer($object->getObjectUrl()); }
function add_timespan() { if (!can_manage_time(logged_user(), true)) { flash_error(lang('no access permissions')); ajx_current("empty"); return; } $object_id = get_id('object_id'); $object_manager = array_var($_GET, 'object_manager'); if (!is_valid_function_name($object_manager)) { flash_error(lang('invalid request')); ajx_current("empty"); return; } // if $object = get_object_by_manager_and_id($object_id, $object_manager); if (!$object instanceof ProjectDataObject || !$object->canAddTimeslot(logged_user())) { flash_error(lang('no access permissions')); ajx_current("empty"); return; } // if $timeslot_data = array_var($_POST, 'timeslot'); $hours = array_var($timeslot_data, 'time'); if (strpos($hours, ',') && !strpos($hours, '.')) { $hours = str_replace(',', '.', $hours); } $timeslot = new Timeslot(); $dt = DateTimeValueLib::now(); $dt2 = DateTimeValueLib::now(); $timeslot->setEndTime($dt); $dt2 = $dt2->add('h', -$hours); $timeslot->setStartTime($dt2); $timeslot->setDescription(array_var($timeslot_data, 'description')); $timeslot->setUserId(logged_user()->getId()); $timeslot->setObjectManager($object_manager); $timeslot->setObjectId($object_id); /* Billing */ $billing_category_id = logged_user()->getDefaultBillingId(); $project = $object->getProject(); $timeslot->setBillingId($billing_category_id); $hourly_billing = $project->getBillingAmount($billing_category_id); $timeslot->setHourlyBilling($hourly_billing); $timeslot->setFixedBilling($hourly_billing * $hours); $timeslot->setIsFixedBilling(false); try { DB::beginWork(); $timeslot->save(); ApplicationLogs::createLog($timeslot, $timeslot->getWorkspaces(), ApplicationLogs::ACTION_OPEN); DB::commit(); flash_success(lang('success create timeslot')); ajx_current("reload"); } catch (Exception $e) { DB::rollback(); ajx_current("empty"); flash_error($e->getMessage()); } // try }
function do_share() { $share_data = array_var($_POST, 'share_data'); if (is_array($share_data)) { $obj = get_object_by_manager_and_id(array_var($share_data, 'object_id'), array_var($share_data, 'object_manager')); $emails = array_var($_POST, 'emails'); $companies = array_var($_POST, 'companiesId'); if (!is_array($emails) || !count($emails)) { flash_error(lang('must specify recipients')); ajx_current("empty"); return; } $people = array(); foreach ($emails as $k => $email) { // Retrieve users to notify $lt_pos = strpos_utf($email, '<'); if ($lt_pos !== FALSE) { // only email address $email = substr_utf($email, $lt_pos + 1); $email = str_replace('>', '', $email); } if (trim($email) != '') { $user = Users::findOne(array('conditions' => "`email` = '" . $email . "'")); if (!$user instanceof User) { // User not exists -> create one with minimum permissions try { DB::beginWork(); $user = $this->createMinimumUser($email, $companies[$k]); DB::commit(); } catch (Exception $e) { DB::rollback(); } } if ($user instanceof User) { $people[] = $user; $canWrite = array_var($share_data, 'allow_edit'); if ($canWrite && !$obj->canEdit($user) || !$obj->canView($user)) { $this->setObjUserPermission($user, $obj, $canWrite); } $this->saveSharedObject($obj, $user); } } } Notifier::shareObject($obj, $people); flash_success(lang("success sharing object")); ajx_current("back"); } }
/** * Add comment * * Through this controller only logged users can post (no anonymous comments here) * * @param void * @return null */ function add() { $this->setTemplate('add_comment'); $object_id = get_id('object_id'); $object_manager = array_var($_GET, 'object_manager'); if (!is_valid_function_name($object_manager)) { flash_error(lang('invalid request')); $this->redirectToUrl(active_project()->getOverviewUrl()); } // if $object = get_object_by_manager_and_id($object_id, $object_manager); if (!$object instanceof ProjectDataObject || !$object->canComment(logged_user())) { flash_error(lang('no access permissions')); $this->redirectToUrl(active_project()->getOverviewUrl()); } // if $comment = new Comment(); $comment_data = array_var($_POST, 'comment'); if (!is_array($comment_data)) { $comment_data = array('text' => '', 'is_private' => config_option('default_private', false)); // array } // if tpl_assign('comment_form_object', $object); tpl_assign('comment', $comment); tpl_assign('comment_data', $comment_data); if (is_array($comment_data)) { try { try { $attached_files = ProjectFiles::handleHelperUploads(active_project()); } catch (Exception $e) { $attached_files = null; } // try $comment->setFromAttributes($comment_data); $comment->setRelObjectId($object_id); $comment->setRelObjectManager($object_manager); if (!logged_user()->isMemberOfOwnerCompany()) { $comment->setIsPrivate(false); } // if if ($object instanceof ProjectMessage || $object instanceof ProjectFile) { if ($object->getIsPrivate()) { $comment->setIsPrivate(true); } // if } // if DB::beginWork(); $comment->save(); if (is_array($attached_files)) { foreach ($attached_files as $attached_file) { $comment->attachFile($attached_file); } // foreach } // if ApplicationLogs::createLog($comment, active_project(), ApplicationLogs::ACTION_ADD); // Subscribe user to object (if $object is subscribible) if ($object->isSubscribable()) { if (!$object->isSubscriber(logged_user())) { $object->subscribeUser(logged_user()); } // if } // if DB::commit(); // Try to send notification on comments other than Messages (messages already managed by subscription) if (!$comment->getObject() instanceof ProjectMessage) { // Try to send notifications but don't break submission in case of an error // define all the users to be notified - here all project users, from all companies. // Restrictions if comment is private is taken into account in newOtherComment() try { $notify_people = array(); $project_companies = active_project()->getCompanies(); foreach ($project_companies as $project_company) { $company_users = $project_company->getUsersOnProject(active_project()); if (is_array($company_users)) { foreach ($company_users as $company_user) { if (array_var($comment_data, 'notify_company_' . $project_company->getId()) == 'checked' || array_var($comment_data, 'notify_user_' . $company_user->getId())) { $notify_people[] = $company_user; } // if } // if } // if } // if Notifier::newOtherComment($comment, $notify_people); // send notification email... } catch (Exception $e) { Logger::log("Error: Notification failed, " . $e->getMessage(), Logger::ERROR); } // try } // if flash_success(lang('success add comment')); $redirect_to = $comment->getViewUrl(); if (!is_valid_url($redirect_to)) { $redirect_to = $object->getObjectUrl(); } // if $this->redirectToUrl($redirect_to); } catch (Exception $e) { DB::rollback(); tpl_assign('error', $e); } // try } // if }
/** * Add comment * * Through this controller only logged users can post (no anonymous comments here) * * @param void * @return null */ function add() { $this->setTemplate('add_comment'); $object_id = get_id('object_id'); $object_manager = array_var($_GET, 'object_manager'); if (!is_valid_function_name($object_manager)) { flash_error(lang('invalid request')); ajx_current("empty"); return; } // if $object = get_object_by_manager_and_id($object_id, $object_manager); if (!$object instanceof ProjectDataObject || !$object->canComment(logged_user())) { flash_error(lang('no access permissions')); ajx_current("empty"); return; } // if $comment = new Comment(); $comment_data = array_var($_POST, 'comment'); tpl_assign('comment_form_object', $object); tpl_assign('comment', $comment); tpl_assign('comment_data', $comment_data); if (is_array($comment_data)) { try { try { $attached_files = ProjectFiles::handleHelperUploads(active_or_personal_project()); } catch (Exception $e) { $attached_files = null; } // try $comment->setFromAttributes($comment_data); $comment->setRelObjectId($object_id); $comment->setRelObjectManager($object_manager); // if(!logged_user()->isMemberOfOwnerCompany()) { $comment->setIsPrivate(false); // } // if DB::beginWork(); $comment->save(); if (is_array($attached_files)) { foreach ($attached_files as $attached_file) { $comment->attachFile($attached_file); } // foreach } // if // Subscribe user to object if (!$object->isSubscriber(logged_user())) { $object->subscribeUser(logged_user()); } // if if (strlen($comment->getText()) < 100) { $comment_head = $comment->getText(); } else { $lastpos = strpos($comment->getText(), " ", 100); if ($lastpos === false) { $comment_head = $comment->getText(); } else { $comment_head = substr($comment->getText(), 0, $lastpos) . "..."; } } $comment_head = html_to_text($comment_head); ApplicationLogs::createLog($object, $object->getWorkspaces(), ApplicationLogs::ACTION_COMMENT, false, null, true, $comment_head); DB::commit(); flash_success(lang('success add comment')); ajx_current("reload"); } catch (Exception $e) { DB::rollback(); ajx_current("empty"); flash_error($e->getMessage()); } // try } // if }
function getActivityData() { $user = Users::findById($this->getCreatedById()); $object = get_object_by_manager_and_id($this->getRelObjectId(), $this->getRelObjectManager()); if (!$user) { return false; } $icon_class = ""; if ($object instanceof ProjectFile) { $path = explode("-", str_replace(".", "_", str_replace("/", "-", $object->getTypeString()))); $acc = ""; foreach ($path as $p) { $acc .= $p; $icon_class .= ' ico-' . $acc; $acc .= "-"; } } if ($object) { $object_link = '<a style="font-weight:bold" href="' . $object->getObjectUrl() . '"> ' . '<span style="padding: 1px 0 3px 18px;" class="db-ico ico-unknown ico-' . $object->getObjectTypeName() . $icon_class . '"/>' . clean($object->getObjectName()) . '</a>'; } else { $object_link = clean($this->getObjectName()) . ' ' . lang('object is deleted'); } switch ($this->getAction()) { case ApplicationLogs::ACTION_EDIT: case ApplicationLogs::ACTION_ADD: case ApplicationLogs::ACTION_DELETE: case ApplicationLogs::ACTION_TRASH: case ApplicationLogs::ACTION_UNTRASH: case ApplicationLogs::ACTION_OPEN: case ApplicationLogs::ACTION_CLOSE: case ApplicationLogs::ACTION_ARCHIVE: case ApplicationLogs::ACTION_UNARCHIVE: case ApplicationLogs::ACTION_READ: case ApplicationLogs::ACTION_DOWNLOAD: case ApplicationLogs::ACTION_CHECKIN: case ApplicationLogs::ACTION_CHECKOUT: if ($object) { return lang('activity ' . $this->getAction(), lang('the ' . $object->getObjectTypeName()), $user->getDisplayName(), $object_link); } else { return lang('activity ' . $this->getAction(), lang('the ' . $this->getRelObjectManager()), $user->getDisplayName(), $object_link); } case ApplicationLogs::ACTION_SUBSCRIBE: case ApplicationLogs::ACTION_UNSUBSCRIBE: $user_ids = explode(",", $this->getLogData()); if (count($user_ids) < 8) { $users_str = ""; foreach ($user_ids as $usid) { $su = Users::findById($usid); if ($su instanceof User) { $users_str .= '<a style="font-weight:bold" href="' . $su->getObjectUrl() . '"> <span style="padding: 0 0 3px 18px;" class="db-ico ico-unknown ico-user"/>' . clean($su->getObjectName()) . '</a>, '; } } if (count($user_ids) == 1) { $users_text = substr(trim($users_str), 0, -1); } else { $users_text = lang('x users', count($user_ids), ": {$users_str}"); } } else { $users_text = lang('x users', count($user_ids), ""); } if ($object) { return lang('activity ' . $this->getAction(), lang('the ' . $object->getObjectTypeName()), $user->getDisplayName(), $object_link, $users_text); } else { return lang('activity ' . $this->getAction(), lang('the ' . $this->getRelObjectManager()), $user->getDisplayName(), $object_link, $users_text); } case ApplicationLogs::ACTION_COMMENT: if ($object) { return lang('activity ' . $this->getAction(), lang('the ' . $object->getObjectTypeName()), $user->getDisplayName(), $object_link, $this->getLogData()); } else { return lang('activity ' . $this->getAction(), lang('the ' . $this->getRelObjectManager()), $user->getDisplayName(), $object_link, $this->getLogData()); } case ApplicationLogs::ACTION_LINK: case ApplicationLogs::ACTION_UNLINK: $exploded = explode(":", $this->getLogData()); $linked_object = get_object_by_manager_and_id($exploded[1], $exploded[0]); if ($linked_object instanceof ApplicationDataObject) { $icon_class = ""; if ($linked_object instanceof ProjectFile) { $path = explode("-", str_replace(".", "_", str_replace("/", "-", $linked_object->getTypeString()))); $acc = ""; foreach ($path as $p) { $acc .= $p; $icon_class .= ' ico-' . $acc; $acc .= "-"; } } $linked_object_link = '<a style="font-weight:bold" href="' . $linked_object->getObjectUrl() . '"> <span style="padding: 1px 0 3px 18px;" class="db-ico ico-unknown ico-' . $linked_object->getObjectTypeName() . $icon_class . '"/>' . clean($linked_object->getObjectName()) . '</a>'; } else { $linked_object_link = ''; } if ($object) { return lang('activity ' . $this->getAction(), lang('the ' . $object->getObjectTypeName()), $user->getDisplayName(), $object_link, $linked_object instanceof ApplicationDataObject ? lang('the ' . $linked_object->getObjectTypeName()) : '', $linked_object_link); } else { return lang('activity ' . $this->getAction(), lang('the ' . $this->getRelObjectManager()), $user->getDisplayName(), $object_link); } case ApplicationLogs::ACTION_LOGIN: case ApplicationLogs::ACTION_LOGOUT: return lang('activity ' . $this->getAction(), $user->getDisplayName()); case ApplicationLogs::ACTION_MOVE: $exploded = explode(";", $this->getLogData()); $to_str = ""; $from_str = ""; foreach ($exploded as $str) { if (str_starts_with($str, "from:")) { $wsids_csv = str_replace("from:", "", $str); $wsids = array_intersect(explode(",", logged_user()->getActiveProjectIdsCSV()), explode(",", $wsids_csv)); if (is_array($wsids) && count($wsids) > 0) { $from_str = '<span class="project-replace">' . implode(",", $wsids) . '</span>'; } } else { if (str_starts_with($str, "to:")) { $wsids_csv = str_replace("to:", "", $str); $wsids = array_intersect(explode(",", logged_user()->getActiveProjectIdsCSV()), explode(",", $wsids_csv)); if (is_array($wsids) && count($wsids) > 0) { $to_str = '<span class="project-replace">' . implode(",", $wsids) . '</span>'; } } } } if ($object) { if ($from_str != "" && $to_str != "") { return lang('activity ' . $this->getAction() . ' from to', lang('the ' . $object->getObjectTypeName()), $user->getDisplayName(), $object_link, $from_str, $to_str); } else { if ($from_str != "") { return lang('activity ' . $this->getAction() . ' from', lang('the ' . $object->getObjectTypeName()), $user->getDisplayName(), $object_link, $from_str); } else { if ($to_str != "") { return lang('activity ' . $this->getAction() . ' to', lang('the ' . $object->getObjectTypeName()), $user->getDisplayName(), $object_link, $to_str); } else { return lang('activity ' . $this->getAction() . ' no ws', lang('the ' . $object->getObjectTypeName()), $user->getDisplayName(), $object_link); } } } } else { if ($from_str != "" && $to_str != "") { return lang('activity ' . $this->getAction() . ' from to', lang('the ' . $this->getRelObjectManager()), $user->getDisplayName(), $object_link, $from_str, $to_str); } else { if ($from_str != "") { return lang('activity ' . $this->getAction() . ' from', lang('the ' . $this->getRelObjectManager()), $user->getDisplayName(), $object_link, $from_str); } else { if ($to_str != "") { return lang('activity ' . $this->getAction() . ' to', lang('the ' . $this->getRelObjectManager()), $user->getDisplayName(), $object_link, $to_str); } else { return lang('activity ' . $this->getAction() . ' no ws', lang('the ' . $this->getRelObjectManager()), $user->getDisplayName(), $object_link); } } } } case ApplicationLogs::ACTION_COPY: $to_str = ""; $wsids_csv = str_replace("to:", "", $this->getLogData()); $wsids = array_intersect(explode(",", logged_user()->getActiveProjectIdsCSV()), explode(",", $wsids_csv)); if (is_array($wsids) && count($wsids) > 0) { $to_str = '<span class="project-replace">' . implode(",", $wsids) . '</span>'; } if ($object) { if ($to_str != "") { return lang('activity ' . $this->getAction() . ' to', lang('the ' . $object->getObjectTypeName()), $user->getDisplayName(), $object_link, $to_str); } else { return lang('activity ' . $this->getAction(), lang('the ' . $object->getObjectTypeName()), $user->getDisplayName(), $object_link); } } else { if ($to_str != "") { return lang('activity ' . $this->getAction() . ' to', lang('the ' . $this->getRelObjectManager()), $user->getDisplayName(), $object_link, $to_str); } else { return lang('activity ' . $this->getAction(), lang('the ' . $this->getRelObjectManager()), $user->getDisplayName(), $object_link); } } case ApplicationLogs::ACTION_TAG: if ($object) { return lang('activity ' . $this->getAction(), lang('the ' . $object->getObjectTypeName()), $user->getDisplayName(), $object_link, $this->getLogData()); } else { return lang('activity ' . $this->getAction(), lang('the ' . $this->getRelObjectManager()), $user->getDisplayName(), $object_link, $this->getLogData()); } default: return false; } return false; }
/** * 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; }
static function getSubscriberComments($workspace = null, $tag = null, $orderBy = 'created_on', $orderDir = "DESC", $start = 0, $limit = 20) { $oc = new ObjectController(); $queries = $oc->getDashboardObjectQueries($workspace, $tag, false, false, $orderBy); $query = ''; if (!is_array($queries)) { return array(); } foreach ($queries as $name => $q) { if (str_ends_with($name, "Comments")) { if ($query == '') { $query = $q; } else { $query .= " \n UNION \n" . $q; } } } $query .= " ORDER BY `order_value` "; if ($orderDir != "ASC" && $orderDir != "DESC") { $orderDir = "DESC"; } $query .= " " . $orderDir . " "; $query .= " LIMIT " . $start . "," . $limit . " "; $res = DB::execute($query); $comments = array(); if (!$res) { return $comments; } $rows = $res->fetchAll(); if (!is_array($rows)) { return $comments; } foreach ($rows as $row) { $manager = $row['object_manager_value']; $id = $row['oid']; if ($id && $manager) { $comment = get_object_by_manager_and_id($id, $manager); $object = $comment->getObject(); if ($object instanceof ProjectDataObject && $object->isSubscriber(logged_user())) { $comments[] = $comment; } } } return $comments; }
/** * Delete a tag for a project object * * @access public * @param tag to delete * @param int fileID * @param Project $project * @return null */ function deleteObjectTag($tag_name, $object_id, $manager_class) { $obj = get_object_by_manager_and_id($object_id, $manager_class); if (!$obj instanceof ApplicationDataObject) { return true; } return self::deleteByTagNameAndObject($tag_name, $obj); }
private function getContactObjects($page, $objects_per_page, $tag = null, $order = null, $order_dir = null, $type = null, $project = null) { $queries = $this->getContactQueries($project, $tag, false, $order); if (!$order_dir) { switch ($order) { case 'name': $order_dir = 'ASC'; break; default: $order_dir = 'DESC'; } } if (isset($type) && $type) { $query = $queries[$type]; } else { $query = ''; foreach ($queries as $q) { if ($query == '') { $query = $q; } else { $query .= " \n UNION \n" . $q; } } } $query .= " ORDER BY order_value {$order_dir} "; if ($page && $objects_per_page) { $start = ($page - 1) * $objects_per_page; $query .= " LIMIT " . $start . "," . $objects_per_page . " "; } elseif ($objects_per_page) { $query .= " LIMIT " . $objects_per_page; } $res = DB::execute($query); $objects = array(); if (!$res) { return $objects; } $rows = $res->fetchAll(); if (!$rows) { return $objects; } $i = 1; foreach ($rows as $row) { $manager = $row['object_manager_value']; $id = $row['oid']; if ($id && $manager) { $obj = get_object_by_manager_and_id($id, $manager); if ($obj->canView(logged_user())) { $objects[] = $obj; } } //if($id && $manager) } //foreach return $objects; }