Currently in my application I have a single table that is giving me a bit of trouble. The issue at hand is I have a value object that is mapped to this table. When the data is returned to me as an array of value objects, I have to then loop through this array and begin my recursion by matching the ParentID to parent ObjectID's.
The column ParentID is either null (acts a parent) or it holds the value of an ObjectID.
I know there has to be a better way to create this data structure so that I do not have to do recursive loops to match ParentID's with their ObjectID's.
Any help with this is greatly appreciated.
Here is the table in describe form:
+----------------+------------------+------+-----+---------------------+-----------------------------+
| Field | Type | Null | Key | Default | Extra |
+----------------+------------------+------+-----+---------------------+-----------------------------+
| ObjectID | int(11) unsigned | NO | PRI | NULL | auto_increment |
| ObjectHeight | decimal(6,2) | NO | | NULL | |
| ObjectWidth | decimal(6,2) | NO | | NULL | |
| ObjectX | decimal(6,2) | NO | | NULL | |
| ObjectY | decimal(6,2) | NO | | NULL | |
| ObjectLabel | varchar(255) | NO | | NULL | |
| TemplateID | int(11) unsigned | NO | MUL | NULL | |
| ObjectTypeID | int(11) unsigned | NO | MUL | NULL | |
| ParentID | int(11) unsigned | YES | MUL | NULL | |
| CreationDate | datetime | YES | | 0000-00-00 00:00:00 | |
| LastModifyDate | timestamp | YES | | NULL | on update CURRENT_TIMESTAMP |
+----------------+------------------+------+-----+---------------------+-----------------------------+e
You could use a nested set model. See the very good explanation here: http://mikehillyer.com/articles/managing-hierarchical-data-in-mysql/
Related
I have setup a Kamailio server and am able to establish calls. I need a way to get call related information like from, to, duration,etc. I have enabled the dialog module in the config but no avail. I am not well versed with config files and I am not sure if I am doing something wrong in the config file.
You need to Modify the config file to log the call related information in kamailio database tables.Here's the link
You have to uncomment the lines in the config file those add columns to database tables.
In addition to this,a web interface siremis for monitoring server can also be installed
It's impossible to blindly know if config is good or bad. However, as general advise, be sure you use dlg_manage() before relaying the INVITE and the other SIP requests related to calls.
For troubleshooting, you can list active dialogs with 'kamctl mi dlg_list' to see if they are correctly tracked or not.
since the link you mentioned is no longer working, here is my suggestion. To get Call information you can best use CDRs , which can be done in 2 ways
set acc module CDR or
get dialog variable and send to external CDR processor.
If you want to obtain further more details about dialogs , its routes , scokets , tiemouts etc then use
dialog DB storage , which looks like
+------------------+------------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+------------------+------------------+------+-----+---------+----------------+
| id | int(10) unsigned | NO | PRI | NULL | auto_increment |
| hash_entry | int(10) unsigned | NO | MUL | NULL | |
| hash_id | int(10) unsigned | NO | | NULL | |
| callid | varchar(255) | NO | | NULL | |
| from_uri | varchar(128) | NO | | NULL | |
| from_tag | varchar(64) | NO | | NULL | |
| to_uri | varchar(128) | NO | | NULL | |
| to_tag | varchar(64) | NO | | NULL | |
| caller_cseq | varchar(20) | NO | | NULL | |
| callee_cseq | varchar(20) | NO | | NULL | |
| caller_route_set | varchar(512) | YES | | NULL | |
| callee_route_set | varchar(512) | YES | | NULL | |
| caller_contact | varchar(128) | NO | | NULL | |
| callee_contact | varchar(128) | NO | | NULL | |
| caller_sock | varchar(64) | NO | | NULL | |
| callee_sock | varchar(64) | NO | | NULL | |
| state | int(10) unsigned | NO | | NULL | |
| start_time | int(10) unsigned | NO | | NULL | |
| timeout | int(10) unsigned | NO | | 0 | |
| sflags | int(10) unsigned | NO | | 0 | |
| iflags | int(10) unsigned | NO | | 0 | |
| toroute_name | varchar(32) | YES | | NULL | |
| req_uri | varchar(128) | NO | | NULL | |
| xdata | varchar(512) | YES | | NULL | |
+------------------+------------------+------+-----+---------+----------------+
I setup dynamic queues in Asterisk according to this: http://libryder.com/Ez7llN
The queues connect successfully and all members are recognized but it always rings to voicemail, never trying the next member.
+----+------------+-------------+----------+---------+---------+--------------+----------------+------------------+----------------+--------------------+----------------+---------------+---------------+----------------+----------------+------------------+--------------------+------------------------+-------------------+-------+------------+--------+--------------+----------+-----------+----------------+-------------------+-----------------+----------------+-------------+--------+----------------+-----------+-----------------+----------+-----------------+
| id | name | musiconhold | announce | context | timeout | monitor_join | monitor_format | queue_youarenext | queue_thereare | queue_callswaiting | queue_holdtime | queue_minutes | queue_seconds | queue_lessthan | queue_thankyou | queue_reporthold | announce_frequency | announce_round_seconds | announce_holdtime | retry | wrapuptime | maxlen | servicelevel | strategy | joinempty | leavewhenempty | eventmemberstatus | eventwhencalled | reportholdtime | memberdelay | weight | timeoutrestart | ringinuse | setinterfacevar | autofill | timeoutpriority |
+----+------------+-------------+----------+---------+---------+--------------+----------------+------------------+----------------+--------------------+----------------+---------------+---------------+----------------+----------------+------------------+--------------------+------------------------+-------------------+-------+------------+--------+--------------+----------+-----------+----------------+-------------------+-----------------+----------------+-------------+--------+----------------+-----------+-----------------+----------+-----------------+
| 5 | 4352754426 | NULL | NULL | NULL | 5 | NULL | NULL | NULL | NULL | NULL | NULL | NULL | NULL | NULL | NULL | NULL | NULL | NULL | NULL | NULL | NULL | 0 | NULL | ringall | NULL | NULL | NULL | NULL | NULL | 0 | NULL | NULL | NULL | yes | yes | conf |
+----+------------+-------------+----------+---------+---------+--------------+----------------+------------------+----------------+--------------------+----------------+---------------+---------------+----------------+----------------+------------------+--------------------+------------------------+-------------------+-------+------------+--------+--------------+----------+-----------+----------------+-------------------+-----------------+----------------+-------------+--------+----------------+-----------+-----------------+----------+-----------------+
+----------+------------+------------+---------------------------+---------+--------+---------+
| uniqueid | membername | queue_name | interface | penalty | paused | hunt_id |
+----------+------------+------------+---------------------------+---------+--------+---------+
| 18 | agent1 | 4352754426 | local/4352151050#outbound | NULL | NULL | 5 |
| 19 | agent2 | 4352754426 | local/4352151052#outbound | NULL | NULL | 5 |
| 20 | agent3 | 4352754426 | local/4352151054#outbound | NULL | NULL | 5 |
+----------+------------+------------+---------------------------+---------+--------+---------+
Am I missing some option?
Please try with different ring strategy instead of ringall like random or rrmemory. And please also check timeout field it look too low ?
I've created a custom Role for my Group.
I've assigned a user, who was a member of the Group, to this special Role.
Now, I want to access a user's Role in the Group via PHP, but I can't find it anywhere.
I've pored over the Devels of both the User and Group. I can access the fact that the user is a member of the group in the user's group_audience array, but not what their role is in that group.
Any advice?
Edit: Drupal 7
Edit: There's some background here first, then the actual answer is after that.
Background
Looking in the mySQL database on our development server, there seems to be a handful of OG-related tables in our Drupal database. I'm pretty sure the version running on the devserver is og-7.x-1.x-dev.
og
og_membership
og_membership_type
og_menu
og_role
og_role_permission
og_users_roles
field_data_og_membership_request
field_revision_og_membership_request
Their definitions look like this:
mysql> describe og;
+-------------+------------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+-------------+------------------+------+-----+---------+----------------+
| gid | int(10) unsigned | NO | PRI | NULL | auto_increment |
| etid | int(10) unsigned | NO | MUL | 0 | |
| entity_type | varchar(32) | NO | | | |
| label | varchar(255) | NO | | | |
| state | int(11) | NO | | 1 | |
| created | int(11) | NO | | 0 | |
+-------------+------------------+------+-----+---------+----------------+
6 rows in set (0.02 sec)
mysql> describe og_membership;
+-------------+------------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+-------------+------------------+------+-----+---------+----------------+
| id | int(10) unsigned | NO | PRI | NULL | auto_increment |
| type | varchar(255) | NO | | | |
| etid | int(10) unsigned | NO | MUL | 0 | |
| entity_type | varchar(32) | NO | | | |
| gid | int(11) | NO | MUL | NULL | |
| state | varchar(255) | YES | | | |
| created | int(11) | NO | | 0 | |
+-------------+------------------+------+-----+---------+----------------+
7 rows in set (0.00 sec)
mysql> describe og_membership_type;
+-------------+--------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+-------------+--------------+------+-----+---------+----------------+
| id | int(11) | NO | PRI | NULL | auto_increment |
| name | varchar(255) | NO | UNI | | |
| description | varchar(255) | NO | | | |
| status | tinyint(4) | NO | | 1 | |
| module | varchar(255) | YES | | NULL | |
+-------------+--------------+------+-----+---------+----------------+
5 rows in set (0.00 sec)
mysql> describe og_menu;
+-----------+--------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-----------+--------------+------+-----+---------+-------+
| gid | int(11) | NO | PRI | NULL | |
| menu_name | varchar(128) | NO | PRI | | |
+-----------+--------------+------+-----+---------+-------+
2 rows in set (0.00 sec)
mysql> describe og_role;
+-------+------------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+-------+------------------+------+-----+---------+----------------+
| rid | int(10) unsigned | NO | PRI | NULL | auto_increment |
| gid | int(11) | NO | | NULL | |
| name | varchar(64) | NO | | | |
+-------+------------------+------+-----+---------+----------------+
3 rows in set (0.00 sec)
mysql> describe og_role_permission;
+------------+------------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+------------+------------------+------+-----+---------+-------+
| rid | int(10) unsigned | NO | PRI | NULL | |
| permission | varchar(64) | NO | PRI | | |
| module | varchar(255) | NO | | | |
+------------+------------------+------+-----+---------+-------+
3 rows in set (0.00 sec)
mysql> describe og_users_roles;
+-------+------------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-------+------------------+------+-----+---------+-------+
| uid | int(10) unsigned | NO | PRI | 0 | |
| rid | int(10) unsigned | NO | PRI | 0 | |
| gid | int(11) | NO | PRI | NULL | |
+-------+------------------+------+-----+---------+-------+
3 rows in set (0.00 sec)
mysql> describe field_data_og_membership_request;
+------------------------------+------------------+------+-----+---------+
| Field | Type | Null | Key | Default |
+------------------------------+------------------+------+-----+---------+
| entity_type | varchar(128) | NO | PRI | |
| bundle | varchar(128) | NO | MUL | |
| deleted | tinyint(4) | NO | PRI | 0 |
| entity_id | int(10) unsigned | NO | PRI | NULL |
| revision_id | int(10) unsigned | YES | MUL | NULL |
| language | varchar(32) | NO | PRI | |
| delta | int(10) unsigned | NO | PRI | NULL |
| og_membership_request_value | longtext | YES | | NULL |
| og_membership_request_format | varchar(255) | YES | MUL | NULL |
+------------------------------+------------------+------+-----+---------+
9 rows in set (0.00 sec)
mysql> describe field_revision_og_membership_request;
+------------------------------+------------------+------+-----+---------+
| Field | Type | Null | Key | Default |
+------------------------------+------------------+------+-----+---------+
| entity_type | varchar(128) | NO | PRI | |
| bundle | varchar(128) | NO | MUL | |
| deleted | tinyint(4) | NO | PRI | 0 |
| entity_id | int(10) unsigned | NO | PRI | NULL |
| revision_id | int(10) unsigned | NO | PRI | NULL |
| language | varchar(32) | NO | PRI | |
| delta | int(10) unsigned | NO | PRI | NULL |
| og_membership_request_value | longtext | YES | | NULL |
| og_membership_request_format | varchar(255) | YES | MUL | NULL |
+------------------------------+------------------+------+-----+---------+
9 rows in set (0.00 sec)
(I've removed the empty Extras column from the two field_* tables to avoid horizontal scrolling.) Hope that helps?
My workings
Having just had to mess with this myself on my own Drupal site, it turns out that og_membership has a row for each user in each group (I've abbreviated the type, which read og_membership_type_default):
mysql> select * from og_membership where gid = 324 and etid = 182905;
+--------+-----------------+--------+-------------+-----+-------+------------+
| id | type | etid | entity_type | gid | state | created |
+--------+-----------------+--------+-------------+-----+-------+------------+
| 223562 | og_m..._default | 182905 | user | 324 | 1 | 1329388409 |
+--------+-----------------+--------+-------------+-----+-------+------------+
1 row in set (0.01 sec)
In this row, the id is an autoincrementing identifier for the table og_membership, the etid corresponds to the users.uid for the user in question and gid corresponds to to the og.gid for the group in question.
So if I run the query
update og_membership set gid = 38 where gid = 324;
then all the members of group #324 are moved to group #38 (which is what I've just needed to do, due to an error in an import script).
I think the answer to your question is that the og_membership.type corresponds to an og_membership_type.name. Looking at that table:
mysql> select * from og_membership_type;
+----+----------------------------+-------------+--------+--------+
| id | name | description | status | module |
+----+----------------------------+-------------+--------+--------+
| 1 | og_membership_type_default | Default | 2 | og |
+----+----------------------------+-------------+--------+--------+
1 row in set (0.00 sec)
, I think the og_membership_type.status corresponds to the og_role.rid:
mysql> select * from og_role;
+-----+-----+----------------------+
| rid | gid | name |
+-----+-----+----------------------+
| 1 | 0 | non-member |
| 2 | 0 | member |
| 3 | 0 | administrator member |
+-----+-----+----------------------+
3 rows in set (0.00 sec)
Actual answer
So I think the query you want is:
select og_role.name
from og_role
inner join og_membership_type on og_role.rid = og_membership_type.status
inner join og_membership on og_membership_type.name = og_membership.type
where og_membership.gid = $group_id;
where $group_id is the og.gid of the group in question. (The ID that appears in the URL is the og.etid, so you might want to add another join to that query.
Product
+----------------+----------------+--------+-------+----------+----------------+
|Field | Type | Null | Key | Default | Extra |
+----------------+----------------+--------+-------+----------+----------------+
|id | int(11) | No | PRI | Null | auto_increment |
|modelNumber | varchar(150) | No | | | |
|manufacturer_id | int(11) | No | | | |
|name | varchar(100) | No | | | |
|department_id | int(11) | No | | | |
|class_id | int(11) | No | | | |
|subclass_id | int(11) | No | | | |
+----------------+----------------+--------+-------+----------+----------------+
Department_id
+---------------+----------------+--------+-------+----------+-------------+
|Field | Type | Null | Key | Default | Extra |
+---------------+----------------+--------+-------+----------+-------------+
|department_id | int(11) | | PRI | | |
|name | varchar(100) | | | | |
+---------------+----------------+--------+-------+----------+-------------+
Manufacturer
+----------------+----------------+--------+-------+----------+---------------+
|Field | Type | Null | Key | Default | Extra |
+----------------+----------------+--------+-------+----------+---------------+
|manufacturer_id | int(11) | | PRI | | |
|name | varchar(100) | | | | |
+----------------+----------------+--------+-------+----------+---------------+
Class
+-----------+----------------+--------+-------+----------+----------+
|Field | Type | Null | Key | Default | Extra |
+-----------+----------------+--------+-------+----------+----------+
|class_id | int(11) | | PRI | | |
|name | varchar(100) | | | | |
+-----------+----------------+--------+-------+----------+----------+
Subclass
+---------------+----------------+--------+-------+----------+------------+
|Field | Type | Null | Key | Default | Extra |
+---------------+----------------+--------+-------+----------+------------+
|subclass_id | int(11) | | PRI | | |
|name | varchar(100) | | | | |
+---------------+----------------+--------+-------+----------+------------+
I do not have full control over how I obtain the data, as I am getting a large amount of data via XML. I need to create a database that will allow me to expand.
if classid and subclassid are not related,it is in 3nf and not in BCNF because modelNumber is not a dependency on id. but if they are related its not even in 3nf
I am writing a CakePHP application to log the work I do for various clients, but after trying for days I seem unable to get it to do what I want. I have read most of the book CakePHP's website.
and googled for all I'm worth, so I presume I am missing something obvious!
Every 'log item' belongs to a 'sub-project, which in turn belongs to a 'project', which in turn belongs to a 'sub-client' which finally belongs to a client. These are the 5 MySQL tables I am using:
mysql> DESCRIBE log_items;
+-----------------+--------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+-----------------+--------------+------+-----+---------+----------------+
| id | int(11) | NO | PRI | NULL | auto_increment |
| date | date | NO | | NULL | |
| time | time | NO | | NULL | |
| time_spent | int(11) | NO | | NULL | |
| sub_projects_id | int(11) | NO | MUL | NULL | |
| title | varchar(100) | NO | | NULL | |
| description | text | YES | | NULL | |
| created | datetime | YES | | NULL | |
| modified | datetime | YES | | NULL | |
+-----------------+--------------+------+-----+---------+----------------+
mysql> DESCRIBE sub_projects;
+-------------+--------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+-------------+--------------+------+-----+---------+----------------+
| id | int(11) | NO | PRI | NULL | auto_increment |
| name | varchar(100) | NO | | NULL | |
| projects_id | int(11) | NO | MUL | NULL | |
| created | datetime | YES | | NULL | |
| modified | datetime | YES | | NULL | |
+-------------+--------------+------+-----+---------+----------------+
mysql> DESCRIBE projects;
+----------------+--------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+----------------+--------------+------+-----+---------+----------------+
| id | int(11) | NO | PRI | NULL | auto_increment |
| name | varchar(100) | NO | | NULL | |
| sub_clients_id | int(11) | NO | MUL | NULL | |
| created | datetime | YES | | NULL | |
| modified | datetime | YES | | NULL | |
+----------------+--------------+------+-----+---------+----------------+
mysql> DESCRIBE sub_clients;
+------------+--------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+------------+--------------+------+-----+---------+----------------+
| id | int(11) | NO | PRI | NULL | auto_increment |
| name | varchar(100) | NO | | NULL | |
| clients_id | int(11) | NO | MUL | NULL | |
| created | datetime | YES | | NULL | |
| modified | datetime | YES | | NULL | |
+------------+--------------+------+-----+---------+----------------+
mysql> DESCRIBE clients;
+----------+--------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+----------+--------------+------+-----+---------+----------------+
| id | int(11) | NO | PRI | NULL | auto_increment |
| name | varchar(100) | NO | | NULL | |
| created | datetime | YES | | NULL | |
| modified | datetime | YES | | NULL | |
+----------+--------------+------+-----+---------+----------------+
I have set up the following associations in CakePHP:
LogItem belongsTo SubProjects
SubProject belongsTo Projects
Project belongsTo SubClients
SubClient belongsTo Clients
Client hasMany SubClients
SubClient hasMany Projects
Project hasMany SubProjects
SubProject hasMany LogItems
Using 'cake bake' I have created the models, controllers (index, view add, edit and delete) and views, and things seem to function - as in I am able to perform simple CRUD operations successfully.
The Question
When editing a 'log item' at www.mydomain/log_items/edit I am presented with the view you would all suspect; namely the columns of the log_items table with the appropriate textfields/select boxes etc. I would also like to incorporate select boxes to choose the client, sub-client, project and sub-project in the 'log_items' edit view.
Ideally the 'sub-client' select box should populate itself depending upon the 'client' chosen, the 'project' select box should also populate itself depending on the 'sub-client' selected etc, etc.
I guess the way to go about populating the select boxes with relevant options is Ajax, but I am unsure of how to go about actually accessing a model from the child view of a indirectly related model, for example how to create a 'sub-client' select box in the 'log_items' edit view.
I have have found this example:
http://forum.phpsitesolutions.com/php-frameworks/cakephp/ajax-cakephp-dynamically-populate-html-select-dropdown-box-t29.html
where someone achieves something similar for US states, counties and cities. However, I noticed in the database schema - which is downloadable from the site above link - that the database tables don't have any foreign keys, so now I'm wondering if I'm going about things in the correct manner.
Any pointers and advice would be very much appreciated.
Kind regards,
Chris
Your foreign key names should be singular. So projects_id should be project_id and sub_projects_id should be sub_project_id and so forth. If you are using cake bake or scaffolding, you should not be able to edit associated data in each model edit page. As a side note, make sure all you created model classes are singular (in the /models/folder).
To edit multiple levels of association, it maybe as easy as setting the $recursive class member to 2 in each of the models where you want the edit page to have multiple levels of association. Let me know how this works out for you.
In response to your second issue.
Make sure your models have all the proper association. If you baked them they should include them but given your error it looks like they somehow weren't included. So in log_item.php you should have something like
var $belongsTo = array('SubProject');