Ejemplo n.º 1
0
 public static function FetchBy($kwargs)
 {
     function is_unique_callback($kw, $rc)
     {
         $res_count = count($rc);
         $eq_conds = array();
         if (isset($kw['eq_conds'])) {
             $eq_conds = $kw['eq_conds'];
         }
         if ($res_count > 1) {
             return new Error('', Error::ambiguously);
         }
         if ($res_count === 0) {
             if (isset($eq_conds['id'])) {
                 if (count(Article::FetchLanguagesByID($eq_conds['id'])) > 0) {
                     return new Error('', Error::no_translation);
                 }
             }
             return new Error('', Error::not_found);
         }
         return true;
     }
     function special_callback($kw, $rc)
     {
         extract($kw, EXTR_PREFIX_ALL, 't');
         $special = array();
         $is_assoc = false;
         $class_parent = NULL;
         if (isset($t_special)) {
             $special = $t_special;
         }
         if (isset($t_is_assoc)) {
             $is_assoc = $t_is_assoc;
         }
         if (isset($t_class_parent)) {
             $class_parent = $t_class_parent;
         }
         $res_count = count($rc);
         for ($i = 0, $count = count($special); $i < $count; ++$i) {
             switch ($special[$i]) {
                 case 'author_link':
                     if ($is_assoc === false) {
                         break;
                     }
                     for ($j = 0; $j < $res_count; ++$j) {
                         if (isset($rc[$j]['author_id'])) {
                             $rc[$j]['author_link'] = User::FetchBy(['select_list' => 'id, name, surname', 'eq_conds' => ['id' => $rc[$j]['author_id']], 'is_unique' => true])->LinkToThis('btn-sm');
                         }
                     }
                     break;
                 case 'link_to_full':
                     if ($is_assoc === false) {
                         break;
                     }
                     for ($j = 0; $j < $res_count; ++$j) {
                         if (isset($rc[$j]['id']) && isset($rc[$j]['name'])) {
                             $rc[$j]['link_to_full'] = $class_parent::LinkToThisUnsafe($rc[$j]['id'], $rc[$j]['name'], 'btn-sm', array('style' => 'color: black;'));
                         }
                     }
                     break;
                 case 'full_vers_link':
                     if ($is_assoc === false) {
                         break;
                     }
                     for ($j = 0; $j < $res_count; ++$j) {
                         if (isset($rc[$j]['id'])) {
                             $rc[$j]['full_vers_link'] = $class_parent::ToHTMLFullVersUnsafe($rc[$j]['id'], true);
                         }
                     }
                     break;
                 case 'path_to_image':
                     global $image_extensions;
                     global $link_to_article_images;
                     global $link_to_service_images;
                     if ($is_assoc) {
                         for ($j = 0; $j < $res_count; ++$j) {
                             if (!isset($rc[$j]['id'])) {
                                 continue;
                             }
                             $path = PathToImage($link_to_article_images . $rc[$j]['id'], 'cover', $link_to_service_images . 'Logo.png', $image_extensions, GetLanguage());
                             $rc[$j]['path_to_image'] = $path;
                         }
                     } else {
                         for ($j = 0; $j < $res_count; ++$j) {
                             $path = PathToImage($link_to_article_images . $rc[$j]->GetID(), 'cover', $link_to_service_images . 'Logo.png', $image_extensions, GetLanguage());
                             $rc[$j]['path_to_image'] = $path;
                         }
                     }
                     break;
                 default:
                     break;
             }
         }
         return $rc;
     }
     $tmp = $kwargs;
     $tmp['is_unique_callback'] = function ($kw, $rc) {
         return is_unique_callback($kw, $rc);
     };
     $tmp['class_parent'] = new Article();
     $tmp['special_callback'] = function ($kw, $rc) {
         return special_callback($kw, $rc);
     };
     return FetchBy($tmp);
 }
Ejemplo n.º 2
0
 public static function FetchBy($kwargs)
 {
     function is_unique_callback($kw, $rc)
     {
         $res_count = count($rc);
         $eq_conds = array();
         if (isset($kw['eq_conds'])) {
             $eq_conds = $kw['eq_conds'];
         }
         if ($res_count > 1) {
             return new Error('', Error::ambiguously);
         }
         if ($res_count === 0) {
             return new Error('', Error::not_found);
         }
         return true;
     }
     $tmp = $kwargs;
     $tmp['is_unique_callback'] = function ($kw, $rc) {
         return is_unique_callback($kw, $rc);
     };
     $tmp['class_parent'] = new SecretLink();
     return FetchBy($tmp);
 }