本文整理汇总了PHP中ActiveRecord::toArray方法的典型用法代码示例。如果您正苦于以下问题:PHP ActiveRecord::toArray方法的具体用法?PHP ActiveRecord::toArray怎么用?PHP ActiveRecord::toArray使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ActiveRecord
的用法示例。
在下文中一共展示了ActiveRecord::toArray方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getRoles
public function getRoles($originalSorting = false)
{
$uid = $this->id;
if (!$uid) {
return [$this->role];
}
## get roles
$roles = Role::model()->with('userRoles')->findAll(ActiveRecord::formatCriteria(['condition' => '|user_id| = :p', 'order' => '|is_default_role|', 'params' => [':p' => $uid]]));
$roles = ActiveRecord::toArray($roles);
if (empty($roles)) {
return false;
}
$idx = 0;
foreach ($roles as $k => $role) {
## find current role index
if ($role['role_name'] == Yii::app()->user->getState('role') && $idx == 0) {
$idx = $k;
}
}
if ($originalSorting) {
return $roles;
}
$role = array_splice($roles, $idx, 1);
array_unshift($roles, $role[0]);
$this->roles = $roles;
return $roles;
}
示例2: afterSave
public function afterSave()
{
parent::doAfterSave(false);
## get assign user id to user roles
$ur = $this->userRoles;
foreach ($ur as $k => $u) {
$ur[$k]['user_id'] = $this->id;
}
$olduser = ActiveRecord::toArray($this->getRelated('userRoles'));
ActiveRecord::batch('UserRole', $ur, $olduser);
## re-subscribe user to notification
if (!$this->isNewRecord) {
Yii::app()->nfy->unsubscribe($this->id, null, true);
}
if ($this->subscribed === "on" || $this->subscribed === "ON" || $this->isNewRecord) {
$roles = array();
$sql = 'select DISTINCT role_name from p_user_role p ' . ' inner join p_role r on p.role_id = r.id ' . ' and p.user_id = ' . $this->id;
$db = Yii::app()->db->createCommand($sql)->queryAll();
foreach ($db as $r) {
if ($this->subscriptionCategories === 'EMPTY' || in_array($r['role_name'], $this->subscriptionCategories)) {
$roles[] = "role_" . $r['role_name'] . ".";
}
}
$category = array_merge(array('uid_' . $this->id), $roles);
Yii::app()->nfy->subscribe($this->id, $this->username, $category);
$this->subscribed = true;
} else {
$this->subscribed = false;
}
return true;
}
示例3: afterSave
public function afterSave()
{
parent::doAfterSave(false);
## get assign user id to user roles
$ur = $this->userRoles;
foreach ($ur as $k => $u) {
$ur[$k]['user_id'] = $this->id;
}
$olduser = ActiveRecord::toArray($this->getRelated('userRoles'));
ActiveRecord::batch('UserRole', $ur, $olduser);
return true;
}
示例4: getList
public function getList()
{
$models = Todo::model()->findAllByAttributes(['user_id' => Yii::app()->user->id], ['order' => 'id desc']);
$array = ActiveRecord::toArray($models);
foreach ($array as $k => $a) {
foreach ($a as $i => $j) {
if (is_array($j)) {
unset($array[$k][$i]);
}
}
}
return $array;
}
示例5: toArray
public function toArray($force = false)
{
$array = parent::toArray($force);
try {
self::executePlugins($array, 'array', get_class($this));
} catch (Exception $e) {
die($e->getMessage() . ' (' . __LINE__);
}
if ($this->specificationInstance && $this->specificationInstance instanceof EavSpecificationManager && (empty($array['attributes']) || $force)) {
$array['attributes'] = $this->specificationInstance->toArray();
EavSpecificationManager::sortAttributesByHandle('EavSpecificationManager', $array);
}
return $array;
}
示例6: toArray
public function toArray($force = false)
{
$array = parent::toArray($force);
self::executePlugins($array, 'array', get_class($this));
if ($this->specificationInstance && $this->specificationInstance instanceof EavSpecificationManager && (empty($array['attributes']) || $force)) {
$array['attributes'] = $this->specificationInstance->toArray();
EavSpecificationManager::sortAttributesByHandle('EavSpecificationManager', $array);
}
return $array;
}