コード例 #1
0
 public function changeavatarAction()
 {
     $this->view->ResultSet = array('message' => 'No avatar updated !', 'status' => 0, 'showtime' => 3, 'modal' => true);
     $r = $this->getRequest();
     if (isset($r->userid) && preg_match('/^[0-9]{1,10}$/', $r->userid)) {
         if (UsersOp::changeAvatar($r->userid, $r->avatarid)) {
             $this->view->ResultSet = array('message' => 'OK success!', 'status' => 1, 'showtime' => 2, 'modal' => false, 'id' => $r->userid);
         }
     }
 }
コード例 #2
0
ファイル: FilfilesOp.php プロジェクト: Cryde/sydney-core
 /**
  * Register the file and location in the DB for quick search and indexing
  *
  * @param $path        Path to the file
  * @param $fileName    File name on the hard disk
  * @param $fileWeight    Weight in bytes
  * @param $type 3 letters extension
  * @param $usersId
  * @param $safinstancesId
  * @param array $params
  * @param string $desc
  * @return bool|mixed|string    id of the file or false on error
  */
 public function registerFileToDb($path, $fileName, $fileWeight, $type, $usersId, $safinstancesId, $params = array(), $desc = '')
 {
     $fileTypeDb = new Filtype();
     $fileTypeId = 1;
     $fileTypeRow = $fileTypeDb->fetchAll("ext = '" . substr($type, 0, 3) . "'");
     if (count($fileTypeRow) == 1) {
         $fileTypeId = $fileTypeRow[0]->id;
     }
     $data = array('label' => $fileName, 'desc' => $desc, 'filename' => $fileName, 'type' => $type, 'fweight' => $fileWeight, 'filtype_id' => $fileTypeId, 'users_id' => $usersId, 'safinstances_id' => $safinstancesId, 'datecreated' => new Zend_Db_Expr('NOW()'), 'datemodified' => new Zend_Db_Expr('NOW()'));
     $fileFile = new Filfiles();
     $files = $fileFile->fetchAll("filename = '{$fileName}' AND safinstances_id = '" . $safinstancesId . "' ");
     $countFiles = count($files);
     if ($countFiles == 1 && $params->calledBy == 'adminpeople' && isset($params->peopleId) && $params->peopleId > 0) {
         UsersOp::changeAvatar($params->peopleId, $files[0]['id']);
         return $files[0]['id'];
     } elseif ($countFiles == 1) {
         // Replace action, we should update the DB datas
         $fileId = $files->current()->id;
         if ($fileFile->update($data, 'id=' . $fileId)) {
             Sydney_Db_Trace::add('trace.event.upload_file [' . $data['filename'] . ']', 'adminfiles', Sydney_Tools::getTableName($fileFile), 'uploadfile', $fileId);
             return $files[0]['id'];
         } else {
             return false;
         }
     } elseif ($countFiles == 0) {
         if ($fileId = $fileFile->insert($data)) {
             // #18 - called by module adminpeople In this case, check if the category 'module > system > adminpeople' exist, if yes then link to this else first create new cat and link this new cat.
             if ($params->calledBy == 'adminpeople') {
                 UsersOp::changeAvatar($params->peopleId, $fileId);
             }
             // add categories to file
             if (isset($params->catids)) {
                 $foids = explode(',', $params->catids);
                 $foids2 = array();
                 for ($i = 0; $i < count($foids); $i++) {
                     if ($foids[$i] > 0) {
                         $foids2[] = $foids[$i];
                     }
                 }
                 $fileDb = new FilfoldersFilfiles();
                 $fileDb->setFilfilesLinkedTo($fileId, $foids2);
             }
             Sydney_Db_Trace::add('trace.event.upload_file' . ' [' . $data['filename'] . ']', 'adminfiles', Sydney_Tools::getTableName($fileFile), 'uploadfile', $fileId);
             return $fileId;
         } else {
             return false;
         }
     }
 }