public function fn_get_unused($location, $params = array())
 {
     //delete all previous
     $r = new QdImage();
     $r->SETRANGE('type', static::$TYPE_UNUSED);
     foreach ($r->GETLIST() as $item) {
         $item->delete('', false);
     }
     //get unused list
     $media_query = new WP_Query(array('post_type' => 'attachment', 'post_status' => 'inherit', 'posts_per_page' => -1));
     $model_list = new QdQdmvcModel();
     $model_list = $model_list->GETLIST();
     $count = 0;
     foreach ($media_query->posts as $post) {
         $tmp = wp_get_attachment_image_src($post->ID, 'full');
         $url = $tmp[0];
         $found = false;
         foreach ($model_list as $item) {
             $c = $item->id;
             if ($c === 'QdRoot' || $c === 'QdRootSetup') {
                 continue;
             }
             $m = new $c();
             if ($c === 'QdSetupProduct') {
                 $ttt = 1;
             }
             foreach ($c::getImageFields() as $item2) {
                 $m->SETRANGE($item2, $url, QdRoot::$OP_CONTAINS);
                 if ($c === 'QdImage') {
                     $m->SETRANGE('type', QdImage::$TYPE_);
                 }
                 if ($m->COUNTLIST() > 0) {
                     $found = true;
                     break;
                 }
             }
             if ($found) {
                 break;
             }
         }
         if (!$found) {
             $obj = new QdImage();
             $obj->active = false;
             $obj->order = 10;
             $obj->type = QdImage::$TYPE_UNUSED;
             $obj->path = $url . '?id=' . $post->ID;
             $obj->model = '';
             $obj->model_id = '';
             if ($obj->save(false)) {
                 $count++;
             } else {
                 $this->pushValidateError($obj->GETVALIDATION());
             }
         }
     }
     //msg
     $this->pushValidateError('', 'Total unused images: ' . $count, 'info');
     return true;
 }
 public function __get($field_name)
 {
     //check cached value
     if (is_array($this->qd_cached_attr) && isset($this->qd_cached_attr[$field_name])) {
         return $this->qd_cached_attr[$field_name];
     }
     //calculate field value
     if (static::ISFLOWFIELD($field_name)) {
         //CALC FlowField First
         return $this->CALCFIELDS($field_name);
     } else {
         if (static::ISSYSTEMFIELD($field_name)) {
             $class_name = $this->getCalledClassName();
             //system preserved field
             if ($field_name == '__sys_note_url') {
                 $tmp = $this->qd_cached_attr[$field_name] = Qdmvc_Helper::getCompactPageListLink('note', array('model' => $class_name, 'model_id' => $this->id));
                 //COUNT
                 $record = new QdNote();
                 $record->SETRANGE('model', $this->getCalledClassName());
                 $record->SETRANGE('model_id', $this->id);
                 $count = $record->COUNTLIST();
                 return add_query_arg(array('item_count' => $count), $tmp);
             } else {
                 if ($field_name == '__sys_log_url') {
                     $tmp = $this->qd_cached_attr[$field_name] = Qdmvc_Helper::getCompactPageListLink('log', array('model' => $class_name, 'model_id' => $this->id));
                     //COUNT
                     $record = new QdLog();
                     $record->SETRANGE('model', $this->getCalledClassName());
                     $record->SETRANGE('model_id', $this->id);
                     $count = $record->COUNTLIST();
                     return add_query_arg(array('item_count' => $count), $tmp);
                 } else {
                     if ($field_name == '__sys_image_url') {
                         $tmp = $this->qd_cached_attr[$field_name] = Qdmvc_Helper::getCompactPageListLink('image', array('model' => $class_name, 'model_id' => $this->id));
                         //COUNT
                         $record = new QdImage();
                         $record->SETRANGE('model', $this->getCalledClassName());
                         $record->SETRANGE('model_id', $this->id);
                         $count = $record->COUNTLIST();
                         return add_query_arg(array('item_count' => $count), $tmp);
                     } else {
                         if ($field_name == '__lasteditor_name') {
                             if ($this->lasteditor_id > 0) {
                                 $user_info = get_userdata($this->lasteditor_id);
                                 return $this->qd_cached_attr[$field_name] = $user_info->user_login;
                             }
                             return Qdmvc_Helper::getNoneText();
                         } else {
                             if ($field_name == '__owner_name') {
                                 if ($this->owner_id > 0) {
                                     $user_info = get_userdata($this->owner_id);
                                     return $this->qd_cached_attr[$field_name] = $user_info->user_login;
                                 }
                                 return Qdmvc_Helper::getNoneText();
                             } else {
                                 if ($field_name == 'date_created' || $field_name == 'date_modified' || $field_name == 'owner_id') {
                                     return parent::__get($field_name);
                                 } else {
                                     // if ($field_name == '__sys_lines_url') {//Default system Lines Field
                                     return $this->getLinesURL($field_name);
                                 }
                             }
                         }
                     }
                 }
             }
         }
     }
     return parent::__get($field_name);
 }
 public function getImgs()
 {
     $record = new QdImage();
     $record->SETFILTERDEFAULT(array(array('field' => 'model', 'value' => $this->getCalledClassName(), 'exact' => true, 'operator' => '='), array('field' => 'model_id', 'value' => $this->id, 'exact' => true, 'operator' => '=')));
     return $record;
 }