Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
Y
yii2
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
PSDI Army
yii2
Commits
765d47d0
Commit
765d47d0
authored
Nov 21, 2013
by
Paul Klimov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Sphinx Active Record updated to be compatible with ActiveDataProvider.
parent
d1c87c7e
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
70 additions
and
15 deletions
+70
-15
ActiveRecord.php
extensions/sphinx/ActiveRecord.php
+26
-14
QueryBuilder.php
extensions/sphinx/QueryBuilder.php
+1
-1
ActiveDataProviderTest.php
tests/unit/extensions/sphinx/ActiveDataProviderTest.php
+43
-0
No files found.
extensions/sphinx/ActiveRecord.php
View file @
765d47d0
...
...
@@ -253,11 +253,16 @@ class ActiveRecord extends Model
/**
* Returns the primary key name for this AR class.
* @return string the primary key of the associated Sphinx index.
* The default implementation will return the primary key as declared
* in the Sphinx index, which is associated with this AR class.
*
* Note that an array should be returned even for a table with single primary key.
*
* @return string[] the primary keys of the associated Sphinx index.
*/
public
static
function
primaryKey
()
{
return
static
::
getIndexSchema
()
->
primaryKey
;
return
[
static
::
getIndexSchema
()
->
primaryKey
]
;
}
/**
...
...
@@ -861,8 +866,9 @@ class ActiveRecord extends Model
}
$values
=
$this
->
getDirtyAttributes
(
$attributes
);
if
(
empty
(
$values
))
{
$key
=
$this
->
primaryKey
();
$values
[
$key
]
=
isset
(
$this
->
_attributes
[
$key
])
?
$this
->
_attributes
[
$key
]
:
null
;
foreach
(
$this
->
primaryKey
()
as
$key
)
{
$values
[
$key
]
=
isset
(
$this
->
_attributes
[
$key
])
?
$this
->
_attributes
[
$key
]
:
null
;
}
}
$db
=
static
::
getDb
();
$command
=
$db
->
createCommand
()
->
insert
(
$this
->
indexName
(),
$values
);
...
...
@@ -1231,12 +1237,15 @@ class ActiveRecord extends Model
*/
public
function
getPrimaryKey
(
$asArray
=
false
)
{
$key
=
$this
->
primaryKey
();
$value
=
isset
(
$this
->
_attributes
[
$key
])
?
$this
->
_attributes
[
$key
]
:
null
;
if
(
$asArray
)
{
return
[
$key
=>
$value
];
$keys
=
$this
->
primaryKey
();
if
(
count
(
$keys
)
===
1
&&
!
$asArray
)
{
return
isset
(
$this
->
_attributes
[
$keys
[
0
]])
?
$this
->
_attributes
[
$keys
[
0
]]
:
null
;
}
else
{
return
$value
;
$values
=
[];
foreach
(
$keys
as
$name
)
{
$values
[
$name
]
=
isset
(
$this
->
_attributes
[
$name
])
?
$this
->
_attributes
[
$name
]
:
null
;
}
return
$values
;
}
}
...
...
@@ -1254,12 +1263,15 @@ class ActiveRecord extends Model
*/
public
function
getOldPrimaryKey
(
$asArray
=
false
)
{
$key
=
$this
->
primaryKey
();
$value
=
isset
(
$this
->
_oldAttributes
[
$key
])
?
$this
->
_oldAttributes
[
$key
]
:
null
;
if
(
$asArray
)
{
return
[
$key
=>
$value
];
$keys
=
$this
->
primaryKey
();
if
(
count
(
$keys
)
===
1
&&
!
$asArray
)
{
return
isset
(
$this
->
_oldAttributes
[
$keys
[
0
]])
?
$this
->
_oldAttributes
[
$keys
[
0
]]
:
null
;
}
else
{
return
$value
;
$values
=
[];
foreach
(
$keys
as
$name
)
{
$values
[
$name
]
=
isset
(
$this
->
_oldAttributes
[
$name
])
?
$this
->
_oldAttributes
[
$name
]
:
null
;
}
return
$values
;
}
}
...
...
extensions/sphinx/QueryBuilder.php
View file @
765d47d0
...
...
@@ -493,7 +493,7 @@ class QueryBuilder extends Object
if
(
is_object
(
$direction
))
{
$orders
[]
=
(
string
)
$direction
;
}
else
{
$orders
[]
=
$this
->
db
->
quoteColumnName
(
$name
)
.
(
$direction
===
SORT_DESC
?
' DESC'
:
''
);
$orders
[]
=
$this
->
db
->
quoteColumnName
(
$name
)
.
(
$direction
===
SORT_DESC
?
' DESC'
:
'
ASC
'
);
}
}
...
...
tests/unit/extensions/sphinx/ActiveDataProviderTest.php
0 → 100644
View file @
765d47d0
<?php
namespace
yiiunit\extensions\sphinx
;
use
yii\data\ActiveDataProvider
;
use
yiiunit\data\sphinx\ar\ActiveRecord
;
use
yiiunit\data\sphinx\ar\ArticleIndex
;
/**
* @group sphinx
*/
class
ActiveDataProviderTest
extends
SphinxTestCase
{
protected
function
setUp
()
{
parent
::
setUp
();
ActiveRecord
::
$db
=
$this
->
getConnection
();
}
// Tests :
public
function
testActiveQuery
()
{
$provider
=
new
ActiveDataProvider
([
'query'
=>
ArticleIndex
::
find
()
->
orderBy
(
'id ASC'
),
]);
$models
=
$provider
->
getModels
();
$this
->
assertEquals
(
2
,
count
(
$models
));
$this
->
assertTrue
(
$models
[
0
]
instanceof
ArticleIndex
);
$this
->
assertTrue
(
$models
[
1
]
instanceof
ArticleIndex
);
$this
->
assertEquals
([
1
,
2
],
$provider
->
getKeys
());
$provider
=
new
ActiveDataProvider
([
'query'
=>
ArticleIndex
::
find
(),
'pagination'
=>
[
'pageSize'
=>
1
,
]
]);
$models
=
$provider
->
getModels
();
$this
->
assertEquals
(
1
,
count
(
$models
));
}
}
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment