当前位置: 首页>>代码示例>>PHP>>正文


PHP HC_App::short_model方法代码示例

本文整理汇总了PHP中HC_App::short_model方法的典型用法代码示例。如果您正苦于以下问题:PHP HC_App::short_model方法的具体用法?PHP HC_App::short_model怎么用?PHP HC_App::short_model使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在HC_App的用法示例。


在下文中一共展示了HC_App::short_model方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: changes_by_time

 public function changes_by_time($model, $one = FALSE)
 {
     $new_ones = array();
     $return = array();
     $my_class = $model->my_class();
     $my_id = $model->id;
     $raw = array();
     /* OWN */
     $this->include_related('user', array('id', 'first_name', 'last_name', 'active'), TRUE, TRUE);
     $this->where('object_class', $my_class)->where('object_id', $my_id);
     $this->get();
     // $this->check_last_query();
     foreach ($this as $e) {
         $e->rel_name = '';
         $raw[] = $e;
     }
     /* HAS ONE */
     foreach (array_keys($model->has_one) as $other_class) {
         if (isset($model->has_one[$other_class]['class'])) {
             $other_class = $model->has_one[$other_class]['class'];
         }
         $other_class = HC_App::short_model($other_class);
         $other_model = HC_App::model($other_class);
         $this->where('object_class', $other_class)->where_in_subquery('object_id', $other_model->select('id')->where_related($my_class, 'id', $my_id));
         $this->get();
         foreach ($this as $e) {
             $e->rel_name = $my_class;
             $raw[] = $e;
         }
     }
     /* HAS MANY */
     $relations_already_seen = array();
     foreach (array_keys($model->has_many) as $other_class) {
         if (isset($model->has_many[$other_class]['class'])) {
             $other_class = $model->has_many[$other_class]['class'];
         }
         $other_class = HC_App::short_model($other_class);
         $other_model = HC_App::model($other_class);
         if (!isset($relations_already_seen[$other_class])) {
             $relations_already_seen[$other_class] = array();
         }
         $my_relation_names = $model->my_relation_names($other_model);
         $my_relation_names = array_diff($my_relation_names, $relations_already_seen[$other_class]);
         $relations_already_seen[$other_class] = array_merge($relations_already_seen[$other_class], $my_relation_names);
         foreach ($my_relation_names as $my_relation_name) {
             $this->include_related('user', array('id', 'first_name', 'last_name', 'active'), TRUE, TRUE);
             $this->where('object_class', $other_class)->where_in_subquery('object_id', $other_model->select('id')->where_related($my_relation_name, 'id', $my_id));
             $this->get();
             // $this->check_last_query();
             foreach ($this as $e) {
                 $e->rel_name = $my_relation_name;
                 $raw[] = $e;
             }
         }
     }
     /* sort by action time */
     usort($raw, create_function('$a, $b', 'return ($b->action_time - $a->action_time);'));
     $objects = array();
     foreach ($raw as $e) {
         if (!isset($return[$e->action_time])) {
             if ($one && count($return)) {
                 break;
             }
             $return[$e->action_time] = array();
         }
         $object_full_id = $e->object_class . '.' . $e->object_id . '.' . $e->rel_name;
         if (!isset($return[$e->action_time][$object_full_id])) {
             $return[$e->action_time][$object_full_id] = array();
         }
         if (!isset($objects[$object_full_id])) {
             $objects[$object_full_id] = HC_App::model($e->object_class)->get_by_id($e->object_id);
         }
         $pname = $e->property_name;
         $change = new stdClass();
         $change->old = $e->old_value;
         $change->user = $e->user;
         if (!isset($new_ones[$object_full_id])) {
             $new_ones[$object_full_id] = array();
         }
         if (array_key_exists($pname, $new_ones[$object_full_id])) {
             $change->new = $new_ones[$object_full_id][$pname];
         } else {
             $change->new = $objects[$object_full_id]->{$pname};
         }
         // $new_ones[$object_full_id][$pname] = $e->old;
         $new_ones[$object_full_id][$pname] = $change->old;
         $return[$e->action_time][$object_full_id][$pname] = $change;
         /* add status for newly created objects */
         if ($pname == 'id' && isset($objects[$object_full_id]->status)) {
             $add_pname = 'status';
             $add_change = new stdClass();
             $add_change->old = NULL;
             $add_change->user = $e->user;
             if (array_key_exists($add_pname, $new_ones[$object_full_id])) {
                 $add_change->new = $new_ones[$object_full_id][$add_pname];
             } else {
                 $add_change->new = $objects[$object_full_id]->{$add_pname};
             }
             $return[$e->action_time][$object_full_id][$add_pname] = $add_change;
         }
//.........这里部分代码省略.........
开发者ID:RCMmedia,项目名称:rubicon,代码行数:101,代码来源:logaudit.php


注:本文中的HC_App::short_model方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。