Can someone explain how address_list works in phpBB? I'm attempting to create a small function for automatically inserting private messages and think I have it up to this point:
We'll say my current user array looks like this:
$users = array('100','150','77','94')
where each number is a user's ID.
current address_list looks like this:
'address_list' => array ('u' => array(2 => 'to'))
Yes, it has been taken directly from http://wiki.phpbb.com/Using_phpBB3%27s_Basic_Functions#1.4.7._Inserting_Posts_and_Private_Messages
As far as I can tell, the explanation is telling me that it uses a two-dimensional array, but I don't need to send to groups, and I'm not even sure how to stick a two-dimensional array into that equation. All I want to do is send to the first userid on that list, and the BCC all the others.
Then again, phpBB's documentation has always been near-impossible for me to follow.
Any and all help is appreciated.
The format is as follows:
'address_list' => array(
'u' => array(2 => 'to', 3 => 'bcc'),
'g' => array(40 => 'to', 41 => 'bcc'),
)
u contains a mapping of user_id => recipient_type.
g contains a mapping of group_id => recipient_type.
A recipient type can be either to or bcc.
This example will send the PM to user 2 and group 40, and also send a BCC to user 3 and group 41.
Related
I have an array like this and it has 120 elements in it
`array (size=120)
0 =>
array (size=8)
'name' => That the quick brown fox jumps over the lazy - 7' (length=53)
'url' => string 'google.com/zyx' (length=134)
'category' => string 'search-engine' (length=6)
1 =>
array (size=8)
'name' => string 'Mr. john brandy gave me a wall nut of quite' (length=67)
'url' => string 'yahoo.com/dzxser' (length=166)
'category' => string 'indian' (length=6)`
I want to insert them to my bookmark table which model I have created and I want to make sure duplication doesn't occur. I have found this https://laravel.com/docs/5.4/eloquent#other-creation-methods specially firstOrCreate method.
I assume I have to use foreach but I am not sure how. Can anyone help me with some workaround.
Actually you don't need firstOrCreate, you need updateOrCreate. Checking Laravel Other Creation methods You will find that method.
Say that array is in $alldata:
foreach($alldata as $data) {
MyModel::updateOrCreate($data); //the fields must be fillable in the model
}
This will run update/or create of 120 queries while cycling through the loop. The advantage is that, you cannot have a duplicate, rather if there is a repetition, its only going to perform an update to the table.
However the best way to ensure that there is no duplication in whatever way the data comes is to set it up when making your database table. You can set unique constraints on many fields if thats your case.
If you don't want duplication to occur when inserting array of records then all you have to do it set a constraint making sure fields are unique.
If you're using migrations to create databse schema you can use something like this: $table->string('name')->unique();
Now for example, this will make sure that 'name' column data is
I have a url stored in a database in the following format
index.php?main_page=product_info&cPath=1_11&products_id=568
I want to be able to extract the cPath data, 1_11 in this case, and the products id '568' to two separate variables. Note that the cPath value could vary from being a single number such as 23 to a series of numbers and underscores such as 17_25_31. If extracting the cPath is too difficult I could use the products_id once it's extracted and query the database again, but this isn't ideal as I want to avoid additional requests as much as possible.
I really don't know the best (correct) way to go about this.
A more refined approach as suggested by Robbie Averill
//first lets the the query string alone
$string=parse_url('index.php?main_page=product_info&cPath=1_11&products_id=568', PHP_URL_QUERY);
parse_str($string,$moo);
print_r($moo);
Output:
Array
(
[main_page] => product_info
[cPath] => 1_11
[products_id] => 568
)
My original suggestion.
parse_str('index.php?main_page=product_info&cPath=1_11&products_id=568',$moo);
print_r($moo);
output:
Array
(
[index_php?main_page] => product_info
[cPath] => 1_11
[products_id] => 568
)
I'm using cakephp validation for a field called birthdate.
my model is
'birthdate' => array(
'rule' => 'date',
'message' => 'Enter a valid date',
'allowEmpty' => true
),
my question is how come it's still save correctly even though it's invalid input. e.g:
March 27, 1988
so, if I put it like this, and the array result like this
//this will work
'birthdate' => array(
'month' => '3#',
'day' => '27',
'year' => '1988'
)
//this will NOT work
'birthdate' => array(
'month' => '#3',
'day' => '27',
'year' => '1988'
)
why the first one still validate it (still save correctly. e.g: the end result still march 27, 1988)? but I would like to have consistency. is there anyway to report an error?
Complex data type deconstruction
Dates are being passed as arrays, so they need to be formatted to a string first. In case the column in the database is of type date*, the value is being formatted automatically so that it fits the proper column type format.
Ultimately this is done in Model::deconstruct() (it ends up there when calling Model::set(), which normally happens before validation), where the individual values are being passed through sprintf():
$date[$index] = sprintf('%02d', $date[$index]);
https://github.com/cakephp/cakephp/blob/2.4.5/lib/Cake/Model/Model.php#L1336
Integer casting
And that's the answer to your first question, it's that formatting directive that is responsible for this behavior, it casts the individual date values to integers, where 3# evaluates to a number, while #3 fails (and ends up as 00), that's how string conversion in PHP works.
See http://php.net/manual/language.types.string.php#language.types.string.conversion
Use custom validation/formatting
So in order to be able to trigger an error on such input you'll either have to use a custom validation rule, which would require to for example pass the data using a different fieldname so that it's not being formatted in Model::set(), or use custom formatting (for example by overwriting Model::set() or Model::deconstruct()) to flatten the complex value in a way that the individual values are not being casted.
Good morning,
I need some help in a survey, which I am not able to do.
Imagine a web application (php), which makes use cakephp.
In this application I have a search field, one normal input.
And imagine that this application has a table in the database with 3 fields, (produtoNome), (categoria), (tags).
how can this research below, I already search for table field (produtoNome).
$this->Anuncio->find('all',array('conditions' => array('produtoNome'=> array('$regex' => (string)$pesq))));
The question is:
How can I do a search, that search the 3 fields of the table not only one?
In other words, when someone types something into the search field, it will perform this search in more than one field of the table.
I tried this:
$produtos = $this->Anuncio->find('all',
array('conditions' =>
array('OR' =>
array(
array('produtoNome'=> array('$regex' => (string)$pesq)),
array('categoria'=> array('$regex' => (string)$pesq))
)
),
)
);
but does not work. Returns nothing.
$produtos = $this->Anuncio->find('all',
array('conditions' =>
array('OR' =>
array(
'produtoNome'=> array('$regex' => (string)$pesq),
'categoria'=> array('$regex' => (string)$pesq)
)
),
)
);
Not sure, but this should do the trick.
I would love to see the query from cake.
Never seen that '$regex' syntax for cake, can't find it in documentation, can't find any reference on the internet - where did you get that from? I'm using cake quite a while now and never came about that (though I never needed regexp for queries)
[sorry, low reputation, could not put this on a comment]
So, I got to do this research.
To work, so I had to modify the 'OR' to '$or'
So I have a MongoDB document that tracks logons to our app. Basic structure appears thusly:
[_id] => MongoId Object
(
[$id] => 50f6da28686ba94b49000003
)
[userId] => 50ef542a686ba95971000004
[action] => login
[time] => 1358354984
Now- the challenge is this: there are about 20,000 of these entries. I have been challenged to look at the number of times each user logged in (as defined by userId)...so I am looking for a good way to do this. There are a couple of possible approaches that I've seen (in SQL, for example, I might pull down number of logins by grouping by UserID and doing a count on it- something like SELECT userID, count(*) from....group by UserId...and then sub-selecting on that (CASE WHEN or something in the top select).
Anyways- wondering if anyone has any suggestions on the best way to do this. Worst case scenario I can limit the result set and do the grouping in memory- but ideally would like to get the full answer directly from Mongo.
The other limitation (even after I get past the first set) is that I am looking to do a unique count by date...which will be even tougher!
Now- the challenge is this: there are about 20,000 of these entries.
At 20,000 you will probably be better off with the aggregation framework ( http://docs.mongodb.org/manual/applications/aggregation/ ):
$db->user->aggregate(array(
array( '$group' => array( '_id' => '$userId', 'num_logins' => array( '$sum' => 1 ) ) )
));
That will group ( http://docs.mongodb.org/manual/reference/aggregation/#_S_group ) by userId and count (sum: http://docs.mongodb.org/manual/reference/aggregation/sum/#_S_sum ) the amount of grouped login there are.
Note: As stated in the comments, the aggregate helper is in version 1.3+ of the PHP driver. Before version 1.3 you must use the command function directly.
You can use MapReduce to group the results by user ID
http://docs.mongodb.org/manual/applications/map-reduce/#map-reduce-examples
Or you can use the Group method:
db.logins.aggregate(
{ $group : {
_id : "$userId",
loginsPerUser : { $sum : 1 }
}}
);
For MongoDB 20K or even more won't be a problem to walk and combine them so no worries about performance.
http://docs.mongodb.org/manual/reference/command/group/
db.user.group({key: {userId: 1}, $reduce: function ( curr, result ) { result.total++ }, initial: {total: 0}});
I ran this on 191000 rows in just a couple seconds but group is limited to 20,000 unique entries so it really isn't a solution for you.