Put Cursor In found result from sublime text search - sublimetext2

I would like to put cursor all my found search result because I would like to insert text manual for selected text result. Eg
array(
'id' => 'g_arch_layout',
'label' => 'Select Layout For Gallery Archive Page',
'desc' => 'You could select your custom layout for gallery archive page!',
'std' => '',
'type' => 'select',
'section' => 'gallery_settings',
'rows' => '',
'post_type' => '',
'taxonomy' => '',
'min_max_step'=> '',
'class' => '',
'condition' => '',
'operator' => '',
'choices' => array(
array(
'value' => '2col_layout',
'label' => '2Column Layout',
'src' => ''
),
array(
'value' => 'filter_layout',
'label' => 'Filter Layout',
'src' => ''
)
)
),
array(
'id' => 'sb_layout',
'label' => 'Sidebar Layout For all',
'desc' => 'This will effect for all of the pages, post, custom post type and all other pages',
'std' => '',
'type' => 'select',
'section' => 'sidebar_settings',
'rows' => '',
'post_type' => '',
'taxonomy' => '',
'min_max_step'=> '',
'class' => '',
'condition' => '',
'operator' => '',
'choices' => array(
array(
'value' => 'right_sb',
'label' => 'Right Sidebar Single',
'src' => ''
),
array(
'value' => 'no_sb',
'label' => 'Fullwidth Single',
'src' => ''
),
array(
'value' => 'left_sb',
'label' => 'Left Sidebar Single',
'src' => ''
)
)
),
array(
'id' => 'sb_page_layout',
'label' => 'Sidebar Layout For Pages',
'desc' => 'You could customize sidebar Layout for All Pages on the site! It will effect all the pages',
'std' => '',
'type' => 'select',
'section' => 'sidebar_settings',
'rows' => '',
'post_type' => '',
'taxonomy' => '',
'min_max_step'=> '',
'class' => '',
'condition' => '',
'operator' => '',
'choices' => array(
array(
'value' => 'right_sb',
'label' => 'Right Sidebar Page',
'src' => ''
),
array(
'value' => 'no_sb',
'label' => 'Fullwidth Page',
'src' => ''
),
array(
'value' => 'left_sb',
'label' => 'Left Sidebar Page',
'src' => ''
)
)
),
For example, I wanna search and select 'desc' => ' all from this kind of multi array. So my question is , Is that possbile to find and selector or to find and put cursor? As you know, sublime has muti code line type at the same time ,one of those is work, we can be able to edit. My sublime text is version 2

Related

CakePHP specify join condition hasOne/hasMany polymorphic association

I have a polymorphic association that I have set up it goes like this:
Media has a 1-to-1 association with either Photo, Video or Text
an excerpt of the Media model looks like this:
public $hasOne = array(
'Photo' => array(
'className' => 'Photo',
'foreignKey' => 'media_id',
'dependent' => true,
'conditions' => '',
'fields' => '',
'order' => '',
'limit' => '',
'offset' => '',
'exclusive' => '',
'finderQuery' => '',
'counterQuery' => ''
),
'Text' => array(
'className' => 'Text',
'foreignKey' => 'media_id',
'dependent' => true,
'conditions' => '',
'fields' => '',
'order' => '',
'limit' => '',
'offset' => '',
'exclusive' => '',
'finderQuery' => '',
'counterQuery' => ''
),
Is there a way to specify a condition like
'conditions' => ['LfrMomentArticle.type' => 'photo'],
inside the Photo submodel so that it will not query over all the submodels each time but instead look at the type and then pick the correct submodel?
walking in the same shoes.
you can add the condition like:
'conditions' => ['LfrMomentArticle.type' => 'photo'],
if you have a type field in your LfrMomentArticle model(and of course in the db).

Authentication and ID's in CakePHP

My friend built a big form application in CakePHP. It has a central model called "Player" and a bunch of tables and models representing different categories of questions in the form. She asked me to help implementing Auth and we've been having some trouble. I was able to link User and Player together as per the Simple Authentication tutorial on the Cake website but I'm having trouble implementing Auth on the tables related to Player. The problem occurs on the "add"-like sections of the app. Before my implementation the add function looked like this:
public function name( $id =null) //Create the TEAM team name ,type
{
$this->Team->create();
//$this->request->data['Team']['user_id'] = $this->Auth->user('id');
if ($this->Team->save($this->request->data))
{
$idt=$this->Team->id;
$this->Session->setFlash(__('The Team' .$idt . ' has been saved'));
$this->redirect(array('action' => 'position', $idt));
}
else
{
$this->Session->setFlash(__('The Team could not be saved. Please, try again.'));
}
$players = $this->Team->Player->find('list' , array('conditions' => array('Player.id' => $id)));
$this->set(compact('players'));
}
Once this has been submitted a Team is created and the player_id is set. However when I uncomment the commented line where I read the user id, the player id does not write to the database which messes up every subsequent insertion. All tables have a column for both user_id and player_id although user does not have a column for player_id. Don't really know how relevant these are but here are the associations in the models:
User
public $hasOne = array(
'Player' => array(
'className' => 'Player',
'foreignKey' => 'user_id',
'conditions' => '',
'fields' => '',
'order' => ''
));
Player
public $belongsTo = array(
'User' => array(
'className' => 'User',
'foreignKey' => 'user_id',
'conditions' => '',
'fields' => '',
'order' => ''
)
);
public $hasMany = array(
'ContIllnessDetail' => array(
'className' => 'ContIllnessDetail',
'foreignKey' => 'player_id',
'dependent' => false,
'conditions' => '',
'fields' => '',
'order' => '',
'limit' => '',
'offset' => '',
'exclusive' => '',
'finderQuery' => '',
'counterQuery' => ''
),
'ContInjuryDetail' => array(
'className' => 'ContInjuryDetail',
'foreignKey' => 'player_id',
'dependent' => false,
'conditions' => '',
'fields' => '',
'order' => '',
'limit' => '',
'offset' => '',
'exclusive' => '',
'finderQuery' => '',
'counterQuery' => ''
),
'NewIllnessDetail' => array(
'className' => 'NewIllnessDetail',
'foreignKey' => 'player_id',
'dependent' => false,
'conditions' => '',
'fields' => '',
'order' => '',
'limit' => '',
'offset' => '',
'exclusive' => '',
'finderQuery' => '',
'counterQuery' => ''
),
'NewInjuryDetail' => array(
'className' => 'NewInjuryDetail',
'foreignKey' => 'player_id',
'dependent' => false,
'conditions' => '',
'fields' => '',
'order' => '',
'limit' => '',
'offset' => '',
'exclusive' => '',
'finderQuery' => '',
'counterQuery' => ''
),
'PreviousInjuryDetail' => array(
'className' => 'PreviousInjuryDetail',
'foreignKey' => 'player_id',
'dependent' => false,
'conditions' => '',
'fields' => '',
'order' => '',
'limit' => '',
'offset' => '',
'exclusive' => '',
'finderQuery' => '',
'counterQuery' => ''
)
);
and Team
public $hasOne = array(
'TrainingDetail' => array(
'className' => 'TrainingDetail',
'foreignKey' => 'team_id',
'conditions' => '',
'fields' => '',
'order' => ''
)
);
public $belongsTo = array(
'Player' => array(
'className' => 'Player',
'foreignKey' => 'player_id',
'conditions' => '',
'fields' => '',
'order' => ''
)
);
I also copied the isOwnedBy method into every model as per the Auth tutorial. Has anyone got any advice as to how I solve this?

Show authors latest comments on author.php

I have a Wordpress site and I've set up an author.php page where a users information is displayed.
Currently I've managed to get it to show the authors latest posts they've add to the site using query_posts.
However, I want this page to also show the authors latest comments he has posted on the site, but I can't seem to figure out how to do it with a query, as I'm not sure if Wordpress supports this feature.
There's a function for this: get_comments.
Example usage (based on the Codex example):
$auth_id = get_the_author_meta( 'ID' );
$defaults = array(
'author_email' => '',
'ID' => '',
'karma' => '',
'number' => '',
'offset' => '',
'orderby' => '',
'order' => 'DESC',
'parent' => '',
'post_ID' => '',
'post_id' => 0,
'post_author' => '',
'post_name' => '',
'post_parent' => '',
'post_status' => '',
'post_type' => '',
'status' => '',
'type' => '',
'user_id' => $auth_id,
'search' => '',
'count' => false,
'meta_key' => '',
'meta_value' => '',
'meta_query' => '',
);
$auth_comments = get_comments( $defaults );
var_dump( $auth_comments );
Important note: avoid using query_posts, see: When should you use WP_Query vs query_posts() vs get_posts()?

cakephp lot of queries inside a query

I have a site developed in cakephp 2.x
I have a query with contain with a very lot of table relationed. I know that the most efficient way to do this big query is to make the join query manually. But I wanted to try with contain. I have selected only the field that I need but at the end I print how much queries inside are created: 5000 queries!! The database take 6-10 second to elaborate this query and I want to optimize time. Has cakephp a method to optimize? I don't want to use join now because there are a lot of join to create. Is possible? I know that is a crazy query with a lot of data but is the main page of the product with a lot of data.
This is the query:
$this->set('product',$this->Product->find('all', array(
'contain' => array(
'Origin' => array(
'fields'=>array('id','diet_id'),
'OriginAlias' => array(
'fields'=>array('id','origin_id','language','alias'),
'conditions' => array('OriginAlias.language' => $lang)
),
'Diet' => array(
'fields'=>array('id'),
'DietAlias' => array(
'fields'=>array('id','diet_id','language','alias'),
'conditions' => array('DietAlias.language' => $lang)
),
)
),
'ProductAlias' => array(
'conditions' => array('ProductAlias.alias' => $alias),
'User' => array(
'fields'=>array('id','username'),
'Profile' => array(
'fields'=>array('id','user_id','country','sex','diet','show_diet'),
),
'UserOptions' => array ('fields' => array ('avatar_type')),
'Avatar' => array ('fields' => array ('filename'))
),
'User2' => array(
'fields'=>array('id','username'),
'Profile' => array(
'fields'=>array('id','user_id','country','sex','diet','show_diet'),
),
'UserOptions' => array ('fields' => array ('avatar_type')),
'Avatar' => array ('fields' => array ('filename'))
)
),
'ProductImage'=> array(
'limit' => 1,
'ProductImageVote'=> array(
'order' => 'ProductImageVote.vote desc'
),
'User' => array(
'fields'=>array('id','username'),
'Profile' => array(
'fields'=>array('id','user_id','country','sex','diet','show_diet'),
),
)
),
'ProductGroupProduct' => array(
'fields'=>array('id','user_id','product_id','product_group_id'),
'ProductGroup'=> array(
'fields'=>array('id','text','language'),
),
),
'ProductIngredientVersion' => array(
'conditions' => $cond_version,
'limit' => 1,
'ProductIngredient' => array(
/*'Product' => array(
'ProductAlias' => array()
),*/
'Ingredient' => array(
'fields'=>array('id','user_id','origin_id','active'),
'IngredientAlias' => array(
'fields'=>array('id','user_id','ingredient_id','edit_user_id','alias'),
),
),
),
),
'ProductVersion' => array(
'conditions' => array('ProductVersion.active' => '1', 'ProductVersion.product_id' => $id),
'limit' => 1,
'ProductProperty' => array(
'Property' => array(
'fields'=>array('id','user_id','group_id','unit_id'),
'PropertyAlias' => array(
'fields'=>array('id','user_id','property_id','alias','language'),
'conditions' => array('PropertyAlias.language' => $lang)
),
'Unit' => array(
'fields'=>array('id','user_id','symbol','active'),
),
'PropertyGroup' => array(
'fields'=>array('id','user_id'),
'PropertyGroupAlias' => array(
'fields'=>array('id','user_id','group_id','alias'),
'conditions' => array('PropertyGroupAlias.language' => $lang)
)
)
),
),
),
'Manufacturer' => array(
'fields'=>array('id','text'),
),
'Brand' => array(
'fields'=>array('id','text'),
),
'UserProductLike' => array(
'conditions' => array('UserProductLike.product_id' => $id),
),
'UserProductHate' => array(
'conditions' => array('UserProductHate.product_id' => $id),
),
),
'conditions' => array('Product.id' => $id)
)));

CakePHP Model uses the wrong fields in SQL statements!

I have a bunch of models with various associations set up between them and seems like Cakephp at times executes incorrect SQL statement and cause MySQL to barf.
For example, if I have two models, Comment and Tag and a code like this:
$this->Comment->id = 5;
$this->Comment->saveField('read_count', 3);
yields SQL statement:
UPDATE comments SET read_count = 3 WHERE Tag.id = 3;
It doesn't happen all the time but it eventually happens since I am doing everything in a tight loop.
Please help. This really makes me question my decision to go with Cake since this sounds bad.
Thanks.
EDIT 1
I just ran into the problem and here is the faulty SQL:
SELECT COUNT(*) AS `count` FROM `albums_songs` AS `AlbumSong` WHERE `ArtistGenre`.`id` = 26482
AlbumSong and ArtistGenre are two completely separate tables and they are not related at all.
EDIT 2
Just ran into another failure. The code is:
$this->Song->find('first', array('conditions' => array('Song.artist_id' => 30188, 'Song.name' => 'Pal Pal (By.Tarkhanz)'), 'fields' => array('Song.id')))
While the generated SQL is:
SELECT `Song`.`id` FROM `songs` AS `Song` WHERE `Artist`.`name` = 'Annie Villeneuve' LIMIT 1
As you can see no were in the conditions do I specify an Artist.name yet the SQL generated is looking at it.
EDIT 3
Another example failure. Call is as followed:
$this->Song->id = $song_id;
$library_count = $this->Song->field('Song.library_count');
Yet the SQL is:
SELECT `Song`.`library_count` FROM `songs` AS `Song` WHERE `Artist`.`name` = 'Mazikana_Ragheb_Allama' LIMIT 1
where Artist.name is not a column of Song as it belongs to the Artist model.
Thanks.
EDIT 4
models/album.php
<?php
class Album extends AppModel {
var $name = 'Album';
var $belongsTo = array(
'Artist' => array(
'className' => 'Artist',
'foreignKey' => 'artist_id',
'conditions' => '',
'fields' => '',
'order' => ''
)
);
var $hasAndBelongsToMany = array(
'Song' => array(
'className' => 'Song',
'joinTable' => 'albums_songs',
'foreignKey' => 'album_id',
'associationForeignKey' => 'song_id',
'unique' => true,
'conditions' => '',
'fields' => '',
'order' => '',
'limit' => '',
'offset' => '',
'finderQuery' => '',
'deleteQuery' => '',
'insertQuery' => ''
)
);
var $hasMany = array(
'AlbumSong' => array(
'className' => 'AlbumSong',
'foreignKey' => 'album_id',
'dependent' => false,
'conditions' => '',
'fields' => '',
'order' => '',
'limit' => '',
'offset' => '',
'exclusive' => '',
'finderQuery' => '',
'counterQuery' => ''
)
);
}
?>
models/album_song.php
<?php
class AlbumSong extends AppModel {
var $name = 'AlbumSong';
var $useTable = 'albums_songs';
var $belongsTo = array(
'Song' => array(
'className' => 'Song',
'foreignKey' => 'song_id',
'conditions' => '',
'fields' => '',
'order' => ''
),
'Album' => array(
'className' => 'Album',
'foreignKey' => 'album_id',
'conditions' => '',
'fields' => '',
'order' => ''
)
);
}
?>
models/artist.php
<?php
class Artist extends AppModel {
var $name = 'Artist';
var $hasMany = array(
'Album' => array(
'className' => 'Album',
'foreignKey' => 'artist_id',
'dependent' => false,
'conditions' => '',
'fields' => '',
'order' => '',
'limit' => '',
'offset' => '',
'exclusive' => '',
'finderQuery' => '',
'counterQuery' => ''
),
'Song' => array(
'className' => 'Song',
'foreignKey' => 'artist_id',
'dependent' => false,
'conditions' => '',
'fields' => '',
'order' => '',
'limit' => '',
'offset' => '',
'exclusive' => '',
'finderQuery' => '',
'counterQuery' => ''
),
'ArtistGenre' => array(
'className' => 'ArtistGenre',
'foreignKey' => 'artist_id',
'dependent' => false,
'conditions' => '',
'fields' => '',
'order' => '',
'limit' => '',
'offset' => '',
'exclusive' => '',
'finderQuery' => '',
'counterQuery' => ''
)
);
}
?>
models/artist_genre.php
<?php
class ArtistGenre extends AppModel {
var $name = 'ArtistGenre';
var $useTable = 'artists_genres';
var $belongsTo = array(
'Artist' => array(
'className' => 'Artist',
'foreignKey' => 'artist_id',
'conditions' => '',
'fields' => '',
'order' => ''
),
'Genre' => array(
'className' => 'Genre',
'foreignKey' => 'genre_id',
'conditions' => '',
'fields' => '',
'order' => ''
)
);
}
?>
models/genre.php
<?php
class Genre extends AppModel {
var $name = 'Genre';
var $hasAndBelongsToMany = array(
'Artist' => array(
'className' => 'Artist',
'joinTable' => 'artists_genres',
'foreignKey' => 'genre_id',
'associationForeignKey' => 'artist_id',
'unique' => true,
'conditions' => '',
'fields' => '',
'order' => '',
'limit' => '',
'offset' => '',
'finderQuery' => '',
'deleteQuery' => '',
'insertQuery' => ''
)
);
var $hasMany = array(
'ArtistGenre' => array(
'className' => 'ArtistGenre',
'foreignKey' => 'genre_id',
'dependent' => false,
'conditions' => '',
'fields' => '',
'order' => '',
'limit' => '',
'offset' => '',
'exclusive' => '',
'finderQuery' => '',
'counterQuery' => ''
)
);
}
?>
models/song.php
<?php
class Song extends AppModel {
var $name = 'Song';
var $belongsTo = array(
'Artist' => array(
'className' => 'Artist',
'foreignKey' => 'artist_id',
'conditions' => '',
'fields' => '',
'order' => ''
)
);
/*
var $hasAndBelongsToMany = array(
'Album' => array(
'className' => 'Album',
'joinTable' => 'albums_songs',
'foreignKey' => 'song_id',
'associationForeignKey' => 'album_id',
'unique' => true,
'conditions' => '',
'fields' => '',
'order' => '',
'limit' => '',
'offset' => '',
'finderQuery' => '',
'deleteQuery' => '',
'insertQuery' => ''
)
);
*/
var $hasMany = array(
'AlbumSong' => array(
'className' => 'AlbumSong',
'foreignKey' => 'song_id',
'dependent' => false,
'conditions' => '',
'fields' => '',
'order' => '',
'limit' => '',
'offset' => '',
'exclusive' => '',
'finderQuery' => '',
'counterQuery' => ''
)
);
}
?>
That is pretty much of it. For sake of brevity I removed validation
code.
Thanks a lot!
I have had possibly the same problem. The issue I encountered was cache collision in cake's implementation of caching the conditions (i.e. the WHERE clause) of a parsed sql.
For cake 1.3, the results of DboSource::conditions() and DboSource::name() are cached by default. see: DboSource. The cache uses crc32 hashing algorithm, which has a higher chance of collision. Also, running queries in a tight loop can also increase the chance of collision. That may explain why you have mismatching table names in the form of
select * from `table_A` where `table_B`.`field` ...
The solution was to set the data source to not do this caching. So, try
$ds = $this->Comment->getDataSource();
$ds->cacheMethods = false;
before using methods that generate sql statements.
Make sure not to have something like this:
class Tag extends AppModel
{
public $belongsTo = array (
'Comment' => array(
'conditions' => array(
'id' => 3, // Will add this condition on every query.
),
)
);
}
Not sure if this bug has anything to do with it, what version are you running:
[eb76ab9] Fixed issue where Model::saveAll() would incorrectly commit a transaction which was not started in that function call itself.
http://cakephp.org/changelogs/1.3.6
try sticking $this-ModelName->create() before you set the id and save / find. all that does is clear any other data that is hanging around. a bit of a hack, but if it works could provide some clues to the real problem.
I've been learning CakePHP in the last few months and this kind of thing occasionally drove me crazy. dogmatic's comment about using ->create() before your call can help if you've been using that model earlier in your function, it will reset the model's internal state so stale values don't interfere. That may not be your problem.
I agree with yvover and bancer that it's probably an issue of relationships. Posting your models (or links to the code) would be a big help. The thing that caught me more than once during development was thinking I was editing the model for a class when I was actually editing something else due to a name mismatch, so changes weren't reflected because my 'model' was never loaded.