Exemple #1
0
 public function countGroupMembers()
 {
     $select = $this->membership()->getMembersObjectSelect();
     $models = new User_Model_DbTable_Users();
     $count = 0;
     foreach ($models->fetchAll($select) as $member) {
         $count++;
     }
     return $count;
 }
Exemple #2
0
 public function importRawBooks()
 {
     try {
         $bookTbl = new Book_Model_DbTable_Books();
         $select = $bookTbl->select();
         $select->from($bookTbl->info('name'), new Zend_Db_Expr('MAX(`rawbook_id`) as max_rawbook_id'));
         $data = $select->query()->fetch();
         $maxRawbookId = (int) $data['max_rawbook_id'];
         $userTbl = new User_Model_DbTable_Users();
         $rawBookTbl = new Book_Model_DbTable_Rawbooks();
         $rawBookSelect = $rawBookTbl->select();
         $rawBookSelect->where('rawbook_id > ?', $maxRawbookId);
         $rawBookSelect->order('rawbook_id ASC');
         $rawBookSelect->limit(self::DEFAULT_LIMIT);
         $rawBooks = $rawBookTbl->fetchAll($rawBookSelect);
         foreach ($rawBooks as $rawBook) {
             if (!empty($rawBook['publisher'])) {
                 $publisherSelect = $userTbl->select()->where('displayname LIKE ?', $rawBook['publisher']);
                 $publisher = $userTbl->fetchRow($publisherSelect);
             }
             if (!empty($rawBook['book_company'])) {
                 $bookCompanySelect = $userTbl->select()->where('displayname LIKE ?', $rawBook['book_company']);
                 $bookCompany = $userTbl->fetchRow($bookCompanySelect);
             }
             $data = array('book_name' => $rawBook->book_name, 'published_date' => date('Y-m-d H:i:s', $rawBook->published_date), 'price' => $rawBook->price, 'num_page' => $rawBook->num_page, 'description' => $rawBook->description, 'rawbook_id' => $rawBook->getIdentity(), 'user_id' => 1);
             if (isset($publisher) && !empty($publisher)) {
                 $data['publisher_id'] = $publisher->getIdentity();
             }
             if (isset($bookCompany) && !empty($bookCompany)) {
                 $data['book_company_id'] = $bookCompany->getIdentity();
             }
             $book = $bookTbl->createRow($data);
             $book->save();
             if (!empty($rawBook['photo'])) {
                 $image = Engine_Image::factory();
                 $name = basename($rawBook['photo']);
                 $path = APPLICATION_PATH . DIRECTORY_SEPARATOR . 'temporary';
                 $params = array('parent_id' => $book->getIdentity(), 'parent_type' => $book->getType(), 'user_id' => 1);
                 // Save
                 $storage = Engine_Api::_()->storage();
                 $image->open($rawBook['photo'])->write($path . '/m_' . $name)->destroy();
                 // Store
                 $iMain = $storage->create($path . '/m_' . $name, $params);
                 // Remove temp files
                 @unlink($path . '/m_' . $name);
                 $book->photo_id = $iMain->getIdentity();
                 $book->save();
                 $photoTbl = new Book_Model_DbTable_Photos();
                 $photo = $photoTbl->createRow(array('parent_object_type' => $book->getType(), 'parent_object_id' => $book->getIdentity(), 'file_id' => $iMain->getIdentity(), 'user_id' => 1, 'approved' => 1, 'default' => 1));
                 $photo->save();
             }
         }
         return true;
     } catch (Exception $e) {
         throw $e;
     }
 }
 public function indexAction()
 {
     if ($this->checkModuleExisted('ynidea')) {
         if (!isset($_SESSION['ynmoderation_checked_idea_collation'])) {
             $db_adapter = Engine_Db_Table::getDefaultAdapter();
             $sql = "ALTER TABLE  `engine4_ynidea_ideas` CHANGE  `title`  `title` VARCHAR( 256 ) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL";
             $db_adapter->query($sql);
             $_SESSION['ynmoderation_checked_idea_collation'] = 1;
         }
     }
     if ($this->checkModuleExisted('ynwiki')) {
         if (!isset($_SESSION['ynmoderation_checked_wiki_collation'])) {
             $db_adapter = Engine_Db_Table::getDefaultAdapter();
             $sql = "ALTER TABLE  `engine4_ynwiki_pages` CHANGE  `title`  `title` VARCHAR( 256 ) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL";
             $db_adapter->query($sql);
             $_SESSION['ynmoderation_checked_wiki_collation'] = 1;
         }
     }
     $this->view->formFilter = $formFilter = new Ynmoderation_Form_Admin_Moderations_Filter();
     $this->view->navigation = $navigation = Engine_Api::_()->getApi('menus', 'core')->getNavigation('ynmoderation_admin_main', array(), 'ynmoderation_admin_main_moderations');
     //Getting Plugins list
     $type = $this->_getParam('type_id');
     $params = array('enabled' => '1');
     if (!empty($type) && is_numeric($type)) {
         $params['id'] = $type;
     }
     $pluginTbl = Engine_Api::_()->getDbTable('modules', 'ynmoderation');
     $pluginList = $pluginTbl->fetchAll($pluginTbl->getModulesSelect($params));
     if (!$formFilter->isValid($this->_getAllParams())) {
         return;
     }
     //Checking Post status for removing data
     if ($this->getRequest()->isPost()) {
         $values = $this->getRequest()->getPost();
         foreach ($pluginList as $plugin) {
             $type = $plugin->object_type;
             if (Engine_Api::_()->hasModuleBootstrap("advalbum") && $type == 'album') {
                 $type = 'advalbum_album';
             } else {
                 if (Engine_Api::_()->hasModuleBootstrap("advalbum") && $type == 'album_photo') {
                     $type = 'advalbum_photo';
                 }
             }
             if (is_array($values[$type])) {
                 for ($i = 0; $i < count($values[$type]); $i++) {
                     $id = $values[$type][$i];
                     $item = Engine_Api::_()->getItem($type, $id);
                     $item->delete();
                     //Getting moderation module record
                     $tmpPlugin = $pluginTbl->fetchRow($pluginTbl->getModulesSelect(array('object_type' => $type)));
                     if (is_object($tmpPlugin)) {
                         if ($tmpPlugin->report_object_type) {
                             $reportObjType = $tmpPlugin->report_object_type;
                             $reportField = $tmpPlugin->report_field;
                             $reportTbl = Engine_Api::_()->getItemTable($reportObjType);
                             $reportTbl->delete("{$reportField} = {$id}");
                         }
                     }
                 }
             }
         }
     }
     //Getting content
     $modulesObj = new Core_Model_DbTable_Modules();
     $db = Engine_Db_Table::getDefaultAdapter();
     $select = $db->select();
     $unionArr = array();
     if (count($pluginList) <= 0) {
         return;
     }
     foreach ($pluginList as $plugin) {
         if (Engine_Api::_()->hasModuleBootstrap("advalbum") && $plugin->object_type == 'album') {
             $plugin->object_type = 'advalbum_album';
         } else {
             if (Engine_Api::_()->hasModuleBootstrap("advalbum") && $plugin->object_type == 'album_photo') {
                 $plugin->object_type = 'advalbum_photo';
             }
         }
         //Checking module is existed/enabled or not
         if (Engine_Api::_()->hasItemType($plugin->object_type) && $plugin->moderation_query) {
             $unionArr[] = $plugin->moderation_query;
         }
     }
     if (count($unionArr) == 0) {
         return;
     }
     $select = $select->union($unionArr);
     $mainSelect = $db->select()->from(array('t' => $select))->limit(500)->order(' t.creation_date DESC ');
     //Filter content by user
     $userName = $this->_getParam('username');
     if (!empty($userName)) {
         //$user = Engine_Api::_() -> user() -> getUser($userName);
         $userTable = new User_Model_DbTable_Users();
         $userSelect = $userTable->select()->from($userTable->info('name'), 'user_id')->where(" username = '******' OR displayname = '{$userName}' ");
         $users = $userTable->fetchAll($userSelect)->toArray();
         $uidArr = array();
         if (count($users)) {
             foreach ($users as $user) {
                 $uidArr[] = $user['user_id'];
             }
             $mainSelect->where("t.creator IN (?)", $uidArr);
         } else {
             $mainSelect->where("t.creator = 0");
         }
     }
     //Filter content by title
     $title = $this->_getParam('title');
     if (!empty($title)) {
         $mainSelect->where("t.title LIKE ? ", "%{$title}%");
     }
     $page = $this->_getParam('page', 1);
     $this->view->paginator = $paginator = Zend_Paginator::factory($mainSelect);
     $this->view->paginator->setItemCountPerPage(500);
     $this->view->paginator->setCurrentPageNumber($page);
 }
Exemple #4
0
 public function getUser()
 {
     $Users = new User_Model_DbTable_Users();
     return $Users->findRow($this->user_id);
 }