Search

Hello.

The scenario : i need to track pages visited by authorized users (kind of 'mark as read' functionality for forum threads).

It's easy to do with ajax, triggering event after page loads, but it adds possibility of mistake, for example if ajax request hangs or js error occurs somewhere on the page, etc.

After reading this fine explanation of Events from brendo i tried to write custom event. Suddenly, it worked. Here is the source code :

http://pastie.org/2739462

However, i have couple of questions about EntryManager. This is my function to get id of entry, if it exists:

    // custom function, it is not Symphony API
    protected function isEntryExists($relation){
        $entry_manager = new EntryManager(Symphony::Engine());

        $entries = $entry_manager->fetch(null, $this->getSource());

        foreach ($entries as $entry) {
            $entry_data = $entry->getData();
            if ($entry_data[38]['relation_id'] == $relation) {
                return $entry->get('id');
            }
        }

        return false;
    }
  1. Im referencing to $entrydata[38]['relationid'] and i don't know what is 38. Is this id going to change if i, for example, add some fields into the section?
  2. How can i force EntryManager to return only the field i'm looking for? I must use 'where' clause but i don't know how.

Structure of my section is :

  • discussion [selectbox link]
  • member [selectbox link]
  • red [checkbox]
  • involved [checkbox]

Thanks in advance!!

Im referencing to $entrydata[38]['relationid'] and i don't know what is 38. Is this id going to change if i, for example, add some fields into the section?

The only way the ID for that field would change is if you deleted the field and added it back again into your section.

How can i force EntryManager to return only the field i'm looking for? I must use 'where' clause but i don't know how.

Not sure, but if the only data you need to retrieve is the entry ID then you should be fine just doing a custom SQL statement for that table and using a where clause.

SELECT
    entry_id
FROM
    sym_entries_data_38
WHERE
    relation_id = '{$relation}'

Actually, initial function was incomplete - it checks only for matching discussion, when it has to check both member and discussion.

However @Lewis pointed me to the right way (thanks!), all i need was simple SQL query.

There is result:

    // returns entry id or false
    protected function isEntryExists($discussionId, $memberId){
        $sql = "
            SELECT
                sym_entries_data_38.entry_id
            FROM
                sym_entries_data_38, sym_entries_data_39
            WHERE
                sym_entries_data_38.relation_id = '{$discussionId}' 
            AND 
                sym_entries_data_39.relation_id = '{$memberId}' 
            AND 
                sym_entries_data_38.entry_id = sym_entries_data_39.entry_id
        ";

        $rows = Symphony::Database()->fetch($sql);

        if (!empty($rows)) {
            return $rows[0]['entry_id'];
        } else {
            return false;
        }
    }

Welcome, glad you worked it out.

Create an account or sign in to comment.

Symphony • Open Source XSLT CMS

Server Requirements

  • PHP 5.3-5.6 or 7.0-7.3
  • PHP's LibXML module, with the XSLT extension enabled (--with-xsl)
  • MySQL 5.5 or above
  • An Apache or Litespeed webserver
  • Apache's mod_rewrite module or equivalent

Compatible Hosts

Sign in

Login details