Beispiel #1
0
 public static function onActiveRecordDelete($event)
 {
     $record = $event->sender;
     if ($record->hasAttribute('id')) {
         foreach (Like::findAll(array('object_id' => $record->id, 'object_model' => $record->className())) as $like) {
             $like->delete();
         }
     }
 }
Beispiel #2
0
 /**
  * Like Count for specifc model
  */
 public static function GetLikes($objectModel, $objectId)
 {
     $cacheId = "likes_" . $objectModel . "_" . $objectId;
     $cacheValue = Yii::$app->cache->get($cacheId);
     if ($cacheValue === false) {
         $newCacheValue = Like::findAll(array('object_model' => $objectModel, 'object_id' => $objectId));
         Yii::$app->cache->set($cacheId, $newCacheValue, Yii::$app->settings->get('cache.expireTime'));
         return $newCacheValue;
     } else {
         return $cacheValue;
     }
 }