示例#1
0
 /**
  * @brief Save the list with categories
  */
 private function save()
 {
     if (is_array($this->categories)) {
         foreach ($this->categories as $category) {
             OCP\DB::insertIfNotExist(self::CATEGORY_TABLE, array('uid' => $this->user, 'type' => $this->type, 'category' => $category));
         }
         // reload categories to get the proper ids.
         $this->loadCategories();
         // Loop through temporarily cached objectid/categoryname pairs
         // and save relations.
         $categories = $this->categories;
         // For some reason this is needed or array_search(i) will return 0..?
         ksort($categories);
         foreach (self::$relations as $relation) {
             $catid = $this->array_searchi($relation['category'], $categories);
             OC_Log::write('core', __METHOD__ . 'catid, ' . $relation['category'] . ' ' . $catid, OC_Log::DEBUG);
             if ($catid) {
                 OCP\DB::insertIfNotExist(self::RELATION_TABLE, array('objid' => $relation['objid'], 'categoryid' => $catid, 'type' => $this->type));
             }
         }
         self::$relations = array();
         // reset
     } else {
         OC_Log::write('core', __METHOD__ . ', $this->categories is not an array! ' . print_r($this->categories, true), OC_Log::ERROR);
     }
 }