Exemple #1
0
 public static function find($id, $columns = array('*'))
 {
     if (is_array($id) && empty($id)) {
         return new Collection();
     }
     $instance = new static();
     $obj = $instance->newQuery()->find($id, $columns);
     if (is_array($id)) {
         $prop = new ReflectionProperty(get_class($obj), 'items');
     }
     $col = array();
     if (isset($prop->name)) {
         $prop->setAccessible(1);
         foreach ($prop->getValue($obj) as $k => $object) {
             $translation = Translations::find($object->table . "_" . $object->id . "_" . strtolower(Config::get('cms.currlang.code')));
             $object->setRawAttributes(json_decode($translation->translation, 1));
             $col[] = $object;
         }
         $prop->setValue($obj, $col);
     } else {
         $translation = Translations::find($obj->table . "_" . $obj->id . "_" . strtolower(Config::get('cms.currlang.code')));
         $obj->setRawAttributes(json_decode($translation->translation, 1));
         $seo = $obj->seo()->first();
         if (!is_null($seo)) {
             Config::set('cms.seo', $seo);
         }
     }
     //
     return $obj;
 }
Exemple #2
0
 /**
  * Merge the translations of two translations.
  * 
  * @param Translations $from
  * @param Translations $to
  * @param int          $options
  */
 public static function mergeTranslations(Translations $from, Translations $to, $options = self::DEFAULTS)
 {
     if ($options & self::REMOVE) {
         $filtered = [];
         foreach ($to as $entry) {
             if ($from->find($entry)) {
                 $filtered[$entry->getId()] = $entry;
             }
         }
         $to->exchangeArray($filtered);
     }
     foreach ($from as $entry) {
         if ($existing = $to->find($entry)) {
             $existing->mergeWith($entry);
         } elseif ($options & self::ADD) {
             $to[] = $entry;
         }
     }
 }