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


PHP ModelBehavior::afterFind方法代码示例

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


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

示例1: afterFind

 public function afterFind(Model $Model, $results, $primary = false)
 {
     if (!$primary) {
         return parent::afterFind($results, $primary);
     }
     foreach ($results as $key => $val) {
         if ($primary && array_key_exists($Model->alias, $val) && array_key_exists('id', $val[$Model->alias])) {
             $Like = ClassRegistry::init('Social.Like');
             // Getting total likes
             $totalLikes = $Like->find('count', array('conditions' => array('Like.object_id' => $val[$Model->alias]['id'], 'Like.object' => $Model->alias)));
             $results[$key]['Liked']['total'] = $totalLikes;
             // Checking if current content is liked by current user
             $uid = CakeSession::read("Auth.User.id");
             $isLiked = 0;
             if ($uid) {
                 $_like = $Like->find('first', array('conditions' => array('Like.object_id' => $val[$Model->alias]['id'], 'Like.object' => $Model->alias, 'Like.user_id' => $uid)));
                 if ($_like) {
                     $results[$key]['Liked']['id'] = $_like['Like']['id'];
                     $results[$key]['Liked']['is_liked'] = 1;
                 } else {
                     $results[$key]['Liked']['is_liked'] = 0;
                 }
             } else {
                 $results[$key]['Liked']['is_liked'] = 0;
             }
             // Getting the name of the last two persons who liked this besides the current user
             $Like->bindModel(array('belongsTo' => array('User')), true);
             $options = array('conditions' => array('Like.object_id' => $val[$Model->alias]['id'], 'Like.object' => $Model->alias, 'User.id NOT' => $uid), 'contain' => array('User' => array('fields' => array('id', 'first_name', 'last_name'))), 'limit' => 2, 'order' => 'Like.created');
             $_like = $Like->find('all', $options);
             $results[$key]['Liked']['last_liked'] = $_like;
         }
     }
     return $results;
 }
开发者ID:eripoll,项目名称:lebiplan,代码行数:34,代码来源:LikeableBehavior.php

示例2: afterFind

 /**
  * After find callback. Can be used to modify any results returned by find.
  *
  * @param Model   $model   Model using this behavior
  * @param mixed   $results The results of the find operation
  * @param boolean $primary Whether this model is being queried directly (vs. being queried as an association)
  *
  * @return mixed An array value will replace the value of $results - any other value will be ignored.
  */
 public function afterFind(Model $model, $results, $primary = false)
 {
     parent::afterFind($model, $results, $primary);
     if ($primary && array_key_exists($model->alias, $results[0])) {
         $arrObj = new ArrayObject($results);
         $iterator = $arrObj->getIterator();
         while ($iterator->valid()) {
             $result = [];
             if (isset($iterator->current()[$model->alias]) && count($iterator->current()[$model->alias]) > 0) {
                 $key = "{$model->alias}.{$this->settings[$model->alias]['key']}";
                 $value = "{$model->alias}.{$this->settings[$model->alias]['value']}";
                 $result = Hash::combine($iterator->current(), $key, $value);
             }
             if (!array_key_exists($this->settings[$model->alias]['key'], $iterator->current()[$model->alias]) && !array_key_exists($this->settings[$model->alias]['value'], $iterator->current()[$model->alias])) {
                 $results[$iterator->key()][$model->alias] = Hash::merge($iterator->current()[$model->alias], $result);
             } else {
                 $results[$iterator->key()][$model->alias] = $result;
             }
             $iterator->next();
         }
     } elseif (array_key_exists($model->alias, $results)) {
         $key = "{n}.{$model->alias}.{$this->settings[$model->alias]['key']}";
         $value = "{n}.{$model->alias}.{$this->settings[$model->alias]['value']}";
         $output = Hash::combine($results, $key, $value);
         $results[$model->alias] = $output;
     }
     return $results;
 }
开发者ID:hurad,项目名称:hurad,代码行数:37,代码来源:KeyValueStorageBehavior.php

示例3: afterFind

 public function afterFind(Model $Model, $results, $primary = false)
 {
     if (!$primary) {
         return parent::afterFind($results, $primary);
     }
     foreach ($results as $key => $val) {
         if (array_key_exists($Model->alias, $val) && array_key_exists('id', $val[$Model->alias]) && array_key_exists('Feed', $val)) {
             //debug($val);
             $Subscription = ClassRegistry::init('Social.Subscription');
             // Getting total Subscriptions
             $totalSubscriptions = $Subscription->find('count', array('conditions' => array('Subscription.feed_id' => $val['Feed']['id'])));
             $results[$key]['Subscribed']['total'] = $totalSubscriptions;
             // Checking if current content is liked by current user
             $uid = CakeSession::read("Auth.User.id");
             if ($uid) {
                 $_subscription = $Subscription->find('first', array('conditions' => array('Subscription.feed_id' => $val['Feed']['id'], 'Subscription.user_id' => $uid)));
                 if ($_subscription) {
                     $results[$key]['Subscribed']['is_subscribed'] = 1;
                 } else {
                     $results[$key]['Subscribed']['is_subscribed'] = 0;
                 }
             } else {
                 $results[$key]['Subscribed']['is_subscribed'] = 0;
             }
         }
     }
     return $results;
 }
开发者ID:eripoll,项目名称:lebiplan,代码行数:28,代码来源:FollowableBehavior.php

示例4: afterFind

 function afterFind(\Model $model, $results, $primary)
 {
     parent::afterFind($model, $results, $primary);
     if ($model->id) {
         $data = array('model' => $model->alias, 'model_id' => $model->id, 'activity_type' => 'R', 'user_id' => $model->loginUser['id']);
         $activity = new Activity();
         $activity->save($data);
     }
 }
开发者ID:khaled-saiful-islam,项目名称:zen_v1.0,代码行数:9,代码来源:ActivityBehavior.php

示例5: afterFind

 /**
  * After find callback. Can be used to modify any results returned by find and findAll.
  *
  * @param object $model Model using this behavior
  * @param mixed $results The results of the find operation
  * @param boolean $primary Whether this model is being queried directly (vs. being queried as an association)
  * @return mixed Result of the find operation
  */
 public function afterFind($model, $results, $primary)
 {
     $return = parent::afterFind($model, $results, $primary);
     if (is_array($return)) {
         $results = $return;
     }
     foreach ($this->settings[$model->alias] as $field) {
         foreach ($results as $i => $record) {
             if (isset($record[$model->alias][$field])) {
                 $results[$i][$model->alias][$field] = $this->uncompress($model, $record[$model->alias][$field]);
             }
         }
     }
     return $results;
 }
开发者ID:rchick,项目名称:syrup,代码行数:23,代码来源:compressible.php

示例6: afterFind

 /**
  * afterFind method
  *
  * @param Model $model
  * @param array $results
  * @param bool $primary
  * @return void
  */
 public function afterFind(Model $model, $results, $primary = false)
 {
     $settings = $this->settings[$model->alias];
     if (!isset($settings['afterFind']) || $settings['afterFind'] === 'off') {
         return parent::afterFind($model, $results, $primary);
     }
     switch ($settings['afterFind']) {
         case 'on':
             return array();
         case 'test':
             return true;
         case 'test2':
             return null;
         case 'modify':
             return Hash::extract($results, "{n}.{$model->alias}");
     }
 }
开发者ID:saihe,项目名称:reservation,代码行数:25,代码来源:BehaviorCollectionTest.php

示例7: afterFind

 public function afterFind(Model $Model, $results, $primary = false)
 {
     if (!$primary) {
         return parent::afterFind($results, $primary);
     }
     foreach ($results as $key => $val) {
         if ($primary && array_key_exists($Model->alias, $val) && array_key_exists('id', $val[$Model->alias])) {
             $Comment = ClassRegistry::init('Social.Comment');
             // Getting total Comments
             $totalComments = $Comment->find('count', array('conditions' => array('Comment.object_id' => $val[$Model->alias]['id'], 'Comment.object' => $Model->alias)));
             $results[$key]['Commented']['total'] = $totalComments;
         }
         // Reorder the Comments by creation order
         // (even though we got them by descending order)
         if (array_key_exists('Comment', $val) && count($val['Comment'])) {
             $results[$key]['Comment'] = Hash::sort($val['Comment'], '{n}.created', 'asc');
         }
     }
     return $results;
 }
开发者ID:eripoll,项目名称:lebiplan,代码行数:20,代码来源:CommentableBehavior.php

示例8: afterFind

 public function afterFind(\Model $model, $results, $primary = false)
 {
     parent::afterFind($model, $results, $primary);
 }
开发者ID:jgprolluxer,项目名称:prosales,代码行数:4,代码来源:AppmenuBehavior.php

示例9: afterFind

 public function afterFind(\Model $model, $results, $primary = false)
 {
     parent::afterFind($model, $results, $primary);
     $this->modifyResults($model, $results);
     return $results;
 }
开发者ID:bokac1984,项目名称:genije,代码行数:6,代码来源:OnlineBehavior.php

示例10: afterFind

 /**
  * AfterFind
  **/
 public function afterFind(Model $model, $results = array(), $primary = false)
 {
     parent::afterFind($model, $results, $primary);
     if ($model->findQueryType == 'count') {
         return $results;
     }
     $curObj = $model->alias;
     foreach ($results as $key => $value) {
         $tmpkeys = array_keys($value);
         foreach ($tmpkeys as $curmodel) {
             $curObj = $curmodel != $model->alias ? $model->{$curmodel} : $model;
             $columnTypes = $curObj->getColumnTypes();
             $fields = array_filter($columnTypes, array($this, 'valueIsDate'));
             /**
              * @todo Array walk might be a solution for deeper associations?
              **/
             foreach ($fields as $field => $fieldvalue) {
                 $curvalues = $results[$key][$curmodel];
                 $dimensions = Hash::dimensions($curvalues);
                 if ($dimensions <= 1) {
                     if (!array_key_exists($field, $results[$key][$curmodel])) {
                         continue;
                     }
                     $results[$key][$curmodel][$field] = $this->formatDate($results[$key][$curmodel][$field]);
                     continue;
                 }
             }
         }
     }
     return $results;
 }
开发者ID:raponiwalter,项目名称:Autodate,代码行数:34,代码来源:AutodateBehavior.php

示例11: afterFind

 /**
  *
  * @param \Model $model
  * @param type $results
  * @param type $primary
  */
 public function afterFind(Model $Model, $results, $primary = false)
 {
     parent::afterFind($Model, $results, $primary);
     if (!empty($results[0][$Model->name]['user_roles'])) {
         $results[0]['RecordLevelAccess']['UserRole'] = unserialize($results[0][$Model->name]['user_roles']);
     }
     return $results;
 }
开发者ID:ayaou,项目名称:Zuha,代码行数:14,代码来源:AclExtraBehavior.php

示例12: afterFind

 /**
  * Format the data after the find to make it look like a normal relation
  *
  * @param object $Model the model that did the find
  * @param array $results the data from the find
  * @param bool $primary is it this model doing the query
  *
  * @return array the modified data from the find
  */
 public function afterFind($Model, $results, $primary = false)
 {
     parent::afterFind($Model, $results, $primary);
     $ignore = array('list', 'count', 'layoutList');
     if (in_array($Model->findQueryType, $ignore) || empty($results)) {
         return $results;
     }
     $globalContentIds = Set::extract('{n}.' . $Model->GlobalContent->alias . '.' . $Model->GlobalContent->primaryKey, $results);
     $globalTags = $Model->GlobalContent->GlobalTagged->find('all', array('fields' => array('GlobalTagged.*', 'GlobalTag.*'), 'conditions' => array('GlobalTagged.foreign_key' => $globalContentIds), 'joins' => array(array('table' => 'global_tags', 'alias' => 'GlobalTag', 'type' => 'LEFT', 'foreignKey' => false, 'conditions' => array('GlobalTag.id = GlobalTagged.tag_id')))));
     foreach ($globalTags as &$tag) {
         $tag['GlobalTagged']['GlobalTag'] = $tag['GlobalTag'];
         unset($tag['GlobalTag']);
     }
     foreach ($results as $k => $result) {
         $template = sprintf('/GlobalTagged[foreign_key=/%s/i]', $results[$k]['GlobalContent'][$Model->GlobalContent->primaryKey]);
         $results[$k]['GlobalTagged'] = Set::extract('{n}.GlobalTagged', Set::extract($template, $globalTags));
         if (isset($results[$k]['GlobalCategoryContent'])) {
             $results[$k]['GlobalCategory'] = array_merge($results[$k]['GlobalCategoryContent'], $results[$k]['GlobalCategory']);
         }
         if (isset($results[$k]['GlobalContent']['GlobalLayout'])) {
             $results[$k]['Layout'] = $results[$k]['GlobalContent']['GlobalLayout'];
         }
         if (isset($results[$k]['GlobalContent']['Group'])) {
             $results[$k]['Group'] = $results[$k]['GlobalContent']['Group'];
         }
         unset($results[$k]['GlobalContent']['GlobalLayout'], $results[$k]['GlobalContent']['Group']);
         if (isset($results[$k]['GlobalContent'])) {
             $results[$k][$Model->alias] = array_merge($results[$k]['GlobalContent'], $results[$k][$Model->alias]);
         }
     }
     return $results;
 }
开发者ID:nani8124,项目名称:infinitas,代码行数:41,代码来源:ContentableBehavior.php


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